mirror of
https://github.com/beetbox/beets.git
synced 2026-02-05 15:03:21 +01:00
Determine IDs from MusicBrainz and Discogs URLs
This commit is contained in:
parent
e3418be75d
commit
f17e8550ca
2 changed files with 14 additions and 6 deletions
|
|
@ -16,6 +16,7 @@
|
|||
"""
|
||||
import logging
|
||||
import musicbrainzngs
|
||||
import re
|
||||
import traceback
|
||||
|
||||
import beets.autotag.hooks
|
||||
|
|
@ -326,13 +327,19 @@ def album_for_id(albumid):
|
|||
object or None if the album is not found. May raise a
|
||||
MusicBrainzAPIError.
|
||||
"""
|
||||
# Find the first thing that looks like a UUID/MBID.
|
||||
match = re.search('[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}', albumid)
|
||||
if not match:
|
||||
log.error('Invalid MBID.')
|
||||
return None
|
||||
try:
|
||||
res = musicbrainzngs.get_release_by_id(albumid, RELEASE_INCLUDES)
|
||||
res = musicbrainzngs.get_release_by_id(match.group(),
|
||||
RELEASE_INCLUDES)
|
||||
except musicbrainzngs.ResponseError:
|
||||
log.debug('Album ID match failed.')
|
||||
return None
|
||||
except musicbrainzngs.MusicBrainzError as exc:
|
||||
raise MusicBrainzAPIError(exc, 'get release by ID', albumid,
|
||||
raise MusicBrainzAPIError(exc, 'get release by ID', match.group(),
|
||||
traceback.format_exc())
|
||||
return album_info(res['release'])
|
||||
|
||||
|
|
|
|||
|
|
@ -64,12 +64,13 @@ class DiscogsPlugin(BeetsPlugin):
|
|||
"""Fetches an album by its Discogs ID and returns an AlbumInfo object
|
||||
or None if the album is not found.
|
||||
"""
|
||||
log.debug('Searching for release with id %s' % str(album_id))
|
||||
log.debug('Searching discogs for release %s' % str(album_id))
|
||||
# discogs-client can handle both int and str, so we just strip
|
||||
# the leading 'r' that might be accidentally pasted into the form
|
||||
if not isinstance(album_id, int) and album_id.startswith('r'):
|
||||
album_id = album_id[1:]
|
||||
result = Release(album_id)
|
||||
match = re.search('\d+', album_id)
|
||||
if not match:
|
||||
return None
|
||||
result = Release(match.group())
|
||||
# Try to obtain title to verify that we indeed have a valid Release
|
||||
try:
|
||||
getattr(result, 'title')
|
||||
|
|
|
|||
Loading…
Reference in a new issue