mirror of
https://github.com/beetbox/beets.git
synced 2025-12-24 01:25:47 +01:00
Refactor Beatport plugin to use _get_id
from MetadataSourcePlugin and save beatport_id_regex in id_extractors module. This streamlines the Beatport release ID extraction magic with plugins Deezer and Spotify.
This commit is contained in:
parent
8ab25694a5
commit
f36c55f730
2 changed files with 12 additions and 3 deletions
|
|
@ -28,6 +28,11 @@ deezer_id_regex = {
|
|||
'match_group': 4,
|
||||
}
|
||||
|
||||
beatport_id_regex = {
|
||||
'pattern': r'(^|beatport\.com/release/.+/)(\d+)$',
|
||||
'match_group': 2,
|
||||
}
|
||||
|
||||
|
||||
def extract_discogs_id_regex(album_id):
|
||||
"""Returns the Discogs_id or None."""
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import beets.ui
|
|||
from beets.autotag.hooks import AlbumInfo, TrackInfo
|
||||
from beets.plugins import BeetsPlugin, MetadataSourcePlugin, get_distance
|
||||
import confuse
|
||||
from beets.util.id_extractors import beatport_id_regex
|
||||
|
||||
|
||||
AUTH_ERRORS = (TokenRequestDenied, TokenMissing, VerifierMissing)
|
||||
|
|
@ -267,6 +268,7 @@ class BeatportTrack(BeatportObject):
|
|||
|
||||
class BeatportPlugin(BeetsPlugin):
|
||||
data_source = 'Beatport'
|
||||
id_regex = beatport_id_regex
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
|
@ -380,11 +382,13 @@ class BeatportPlugin(BeetsPlugin):
|
|||
or None if the query is not a valid ID or release is not found.
|
||||
"""
|
||||
self._log.debug('Searching for release {0}', release_id)
|
||||
match = re.search(r'(^|beatport\.com/release/.+/)(\d+)$', release_id)
|
||||
if not match:
|
||||
|
||||
release_id = self._get_id('album', release_id, self.id_regex)
|
||||
if release_id is None:
|
||||
self._log.debug('Not a valid Beatport release ID.')
|
||||
return None
|
||||
release = self.client.get_release(match.group(2))
|
||||
|
||||
release = self.client.get_release(release_id)
|
||||
if release:
|
||||
return self._get_album_info(release)
|
||||
return None
|
||||
|
|
|
|||
Loading…
Reference in a new issue