Skip to content

Commit

Permalink
Use https and http approriately in Musicbrainz URL
Browse files Browse the repository at this point in the history
The tests need to be updated.

Fixes:
- MusicBrainz submit URL always has https as protocol: hardcoded, even when
inappropriate. It's just a graphical issue.
- Whipper appears to always communicate with MusicBrainz using musicbrainzngs
over http. The musicbrainzngs.set_hostname(server).
- musicbrainzngs.set_hostname(server) always defaults to http. With musicbrainzngs
version 0.7 the method `set_hostname` takes an optional argument named `use_https`
(defaults to `False`) which whipper never passes.

Fixes whipper-team#437.

Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
  • Loading branch information
JoeLametta committed Jan 16, 2020
1 parent caa2c8b commit ec34eea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 7 additions & 1 deletion whipper/command/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@

def main():
server = config.Config().get_musicbrainz_server()
musicbrainzngs.set_hostname(server)
https_enabled = True if server['scheme'] == 'https' else False
try:
musicbrainzngs.set_hostname(server['netloc'], https_enabled)
# Parameter 'use_https' is missing in versions of musicbrainzngs < 0.7
except TypeError as e:
logger.warning(e)
musicbrainzngs.set_hostname(server['netloc'])

# Find whipper's plugins paths (local paths have higher priority)
plugins_p = [directory.data_path('plugins')] # local path (in $HOME)
Expand Down
10 changes: 6 additions & 4 deletions whipper/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ def getboolean(self, 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)
conf = self.get('musicbrainz', 'server') or 'https://musicbrainz.org'
if not conf.startswith(('http://', 'https://')):
raise KeyError('Invalid MusicBrainz server: unsupported '
'or missing scheme')
scheme, netloc, _, _, _, _ = urlparse(conf)
server = {'scheme': scheme, 'netloc': netloc}
return server

# drive sections
Expand Down
4 changes: 2 additions & 2 deletions whipper/image/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def getMusicBrainzDiscId(self):
return disc.id

def getMusicBrainzSubmitURL(self):
host = config.Config().get_musicbrainz_server()
serv = config.Config().get_musicbrainz_server()

discid = self.getMusicBrainzDiscId()
values = self._getMusicBrainzValues()
Expand All @@ -363,7 +363,7 @@ def getMusicBrainzSubmitURL(self):
])

return urlunparse((
'https', host, '/cdtoc/attach', '', query, ''))
serv['scheme'], serv['netloc'], '/cdtoc/attach', '', query, ''))

def getFrameLength(self, data=False):
"""
Expand Down

0 comments on commit ec34eea

Please sign in to comment.