Merge pull request #210 from naiveaiguy/custom-mbserver
Enable connecting to a custom MusicBrainz server
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -10,7 +10,7 @@ import whipper
|
||||
|
||||
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
|
||||
|
||||
@@ -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')])
|
||||
|
||||
@@ -24,6 +24,7 @@ import os.path
|
||||
import shutil
|
||||
import tempfile
|
||||
import urllib
|
||||
from urlparse import urlparse
|
||||
|
||||
from whipper.common import directory
|
||||
|
||||
@@ -72,6 +73,15 @@ class Config:
|
||||
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):
|
||||
|
||||
@@ -28,7 +28,7 @@ import urlparse
|
||||
|
||||
import whipper
|
||||
|
||||
from whipper.common import common
|
||||
from whipper.common import common, config
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -390,7 +390,7 @@ class Table(object):
|
||||
return result
|
||||
|
||||
def getMusicBrainzSubmitURL(self):
|
||||
host = 'musicbrainz.org'
|
||||
host = config.Config().get_musicbrainz_server()
|
||||
|
||||
discid = self.getMusicBrainzDiscId()
|
||||
values = self._getMusicBrainzValues()
|
||||
|
||||
@@ -66,3 +66,29 @@ class ConfigTestCase(tcommon.TestCase):
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user