From e2e8676e4db3e727cebc98a0d4a249c28d6de1e0 Mon Sep 17 00:00:00 2001 From: Eshan Singh Date: Sat, 30 Dec 2017 10:55:52 +0000 Subject: [PATCH] Enable connecting to a custom MusicBrainz server Under the new [musicbrainz] section in the config, you can set a server to connect to. Closes #172. --- README.md | 3 +++ whipper/command/main.py | 3 ++- whipper/common/config.py | 9 +++++++++ whipper/image/table.py | 4 ++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c7db11..c9248ff 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/whipper/command/main.py b/whipper/command/main.py index 6e02547..88af530 100644 --- a/whipper/command/main.py +++ b/whipper/command/main.py @@ -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,7 @@ def main(): # set user agent musicbrainzngs.set_useragent("whipper", whipper.__version__, "https://github.com/JoeLametta/whipper") + musicbrainzngs.set_hostname(config.Config().get_musicbrainz_server()) # register plugins with pkg_resources distributions, _ = pkg_resources.working_set.find_plugins( pkg_resources.Environment([directory.data_path('plugins')]) diff --git a/whipper/common/config.py b/whipper/common/config.py index 30cdbea..4ff75e9 100644 --- a/whipper/common/config.py +++ b/whipper/common/config.py @@ -21,9 +21,11 @@ import ConfigParser import codecs import os.path +import re import shutil import tempfile import urllib +from urlparse import urlparse from whipper.common import directory @@ -72,6 +74,13 @@ 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 = server if re.match(r'^\D*//', server) else '//' + server + return urlparse(server_url).netloc + # drive sections def setReadOffset(self, vendor, model, release, offset): diff --git a/whipper/image/table.py b/whipper/image/table.py index 28dd04e..7761781 100644 --- a/whipper/image/table.py +++ b/whipper/image/table.py @@ -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()