Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable connecting to a custom MusicBrainz server #210

Merged
merged 3 commits into from Jan 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ The possible sections are:
- Main section: `[main]`
- `path_filter_fat`: whether to filter path components for FAT file systems
- `path_filter_special`: whether to filter path components for special characters

- MusicBrainz section: `[musicbrainz]`
- `server`: the MusicBrainz server to connect to, in `host:[port]` format. Defaults to `musicbrainz.org`.

- Drive section: `[drive:IDENTIFIER]`, one for each configured drive. All these values are probed by whipper and should not be edited by hand.
- `defeats_cache`: whether this drive can defeat the audio cache
Expand Down
10 changes: 9 additions & 1 deletion whipper/command/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from whipper.command import cd, offset, drive, image, accurip, debug
from whipper.command.basecommand import BaseCommand
from whipper.common import common, directory
from whipper.common import common, directory, config
from whipper.extern.task import task
from whipper.program.utils import eject_device

Expand All @@ -22,6 +22,14 @@ def main():
# set user agent
musicbrainzngs.set_useragent("whipper", whipper.__version__,
"https://github.com/JoeLametta/whipper")

try:
server = config.Config().get_musicbrainz_server()
except KeyError, e:
sys.stderr.write('whipper: %s\n' % e.message)
sys.exit()

musicbrainzngs.set_hostname(server)
# register plugins with pkg_resources
distributions, _ = pkg_resources.working_set.find_plugins(
pkg_resources.Environment([directory.data_path('plugins')])
Expand Down
10 changes: 10 additions & 0 deletions whipper/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import shutil
import tempfile
import urllib
from urlparse import urlparse

from whipper.common import directory

Expand Down Expand Up @@ -72,6 +73,15 @@ def get(self, section, option):
def getboolean(self, section, option):
return self._getter('boolean', section, option)

# musicbrainz section

def get_musicbrainz_server(self):
server = self.get('musicbrainz', 'server') or 'musicbrainz.org'
server_url = urlparse('//' + server)
if server_url.scheme != '' or server_url.path != '':
raise KeyError('Invalid MusicBrainz server: %s' % server)
return server

# drive sections

def setReadOffset(self, vendor, model, release, offset):
Expand Down
4 changes: 2 additions & 2 deletions whipper/image/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import whipper

from whipper.common import common
from whipper.common import common, config

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -390,7 +390,7 @@ def getMusicBrainzDiscId(self):
return result

def getMusicBrainzSubmitURL(self):
host = 'musicbrainz.org'
host = config.Config().get_musicbrainz_server()

discid = self.getMusicBrainzDiscId()
values = self._getMusicBrainzValues()
Expand Down
26 changes: 26 additions & 0 deletions whipper/test/test_common_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,29 @@ def testDefeatsCache(self):
defeats = self._config.getDefeatsCache(
'PLEXTOR ', 'DVDR PX-L890SA', '1.05')
self.assertEquals(defeats, True)

def test_get_musicbrainz_server(self):
self.assertEquals(self._config.get_musicbrainz_server(),
'musicbrainz.org',
msg='Default value is correct')

self._config._parser.add_section('musicbrainz')

self._config._parser.set('musicbrainz', 'server',
'192.168.2.141:5000')
self._config.write()
self.assertEquals(self._config.get_musicbrainz_server(),
'192.168.2.141:5000',
msg='Correctly returns user-set value')

self._config._parser.set('musicbrainz', 'server',
'192.168.2.141:5000/hello/world')
self._config.write()
self.assertRaises(KeyError, self._config.get_musicbrainz_server)

self._config._parser.set('musicbrainz', 'server',
'http://192.168.2.141:5000')
self._config.write()
self.assertRaises(KeyError, self._config.get_musicbrainz_server)

self._config._parser.remove_section('musicbrainz')