Skip to content

Commit

Permalink
Implement multi-tag genres field
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrokemypie committed Sep 19, 2024
1 parent d3c6296 commit 4b84406
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 115 deletions.
12 changes: 6 additions & 6 deletions beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def __init__(
country: Optional[str] = None,
style: Optional[str] = None,
genre: Optional[str] = None,
genres: Optional[str] = None,
albumstatus: Optional[str] = None,
media: Optional[str] = None,
albumdisambig: Optional[str] = None,
Expand Down Expand Up @@ -152,6 +153,7 @@ def __init__(
self.country = country
self.style = style
self.genre = genre
self.genres = genres
self.albumstatus = albumstatus
self.media = media
self.albumdisambig = albumdisambig
Expand Down Expand Up @@ -221,6 +223,7 @@ def __init__(
bpm: Optional[str] = None,
initial_key: Optional[str] = None,
genre: Optional[str] = None,
genres: Optional[str] = None,
album: Optional[str] = None,
**kwargs,
):
Expand Down Expand Up @@ -255,6 +258,7 @@ def __init__(
self.bpm = bpm
self.initial_key = initial_key
self.genre = genre
self.genres = genres
self.album = album
self.update(kwargs)

Expand Down Expand Up @@ -684,15 +688,11 @@ def album_candidates(
if config["musicbrainz"]["enabled"]:
# Base candidates if we have album and artist to match.
if artist and album:
yield from invoke_mb(
mb.match_album, artist, album, len(items), extra_tags
)
yield from invoke_mb(mb.match_album, artist, album, len(items), extra_tags)

# Also add VA matches from MusicBrainz where appropriate.
if va_likely and album:
yield from invoke_mb(
mb.match_album, None, album, len(items), extra_tags
)
yield from invoke_mb(mb.match_album, None, album, len(items), extra_tags)

# Candidates from plugins.
yield from plugins.candidates(items, artist, album, va_likely, extra_tags)
Expand Down
43 changes: 13 additions & 30 deletions beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ def is_path_query(cls, query_part):

# Test both `sep` and `altsep` (i.e., both slash and backslash on
# Windows).
if not (
os.sep in query_part or (os.altsep and os.altsep in query_part)
):
if not (os.sep in query_part or (os.altsep and os.altsep in query_part)):
return False

if cls.force_implicit_query_detection:
Expand Down Expand Up @@ -450,10 +448,7 @@ def album_keys(self):
if self.included_keys == self.ALL_KEYS:
# Performance note: this triggers a database query.
for key in self.album.keys(computed=True):
if (
key in Album.item_keys
or key not in self.item._fields.keys()
):
if key in Album.item_keys or key not in self.item._fields.keys():
album_keys.append(key)
else:
album_keys = self.included_keys
Expand Down Expand Up @@ -531,6 +526,7 @@ class Item(LibModel):
"albumartist_credit": types.STRING,
"albumartists_credit": types.MULTI_VALUE_DSV,
"genre": types.STRING,
"genres": types.MULTI_VALUE_DSV,
"style": types.STRING,
"discogs_albumid": types.INTEGER,
"discogs_artistid": types.INTEGER,
Expand Down Expand Up @@ -622,9 +618,7 @@ class Item(LibModel):
# Any kind of field (fixed, flexible, and computed) may be a media
# field. Only these fields are read from disk in `read` and written in
# `write`.
_media_fields = set(MediaFile.readable_fields()).intersection(
_fields.keys()
)
_media_fields = set(MediaFile.readable_fields()).intersection(_fields.keys())

# Set of item fields that are backed by *writable* `MediaFile` tag
# fields.
Expand Down Expand Up @@ -736,8 +730,7 @@ def __repr__(self):
return "{}({})".format(
type(self).__name__,
", ".join(
"{}={!r}".format(k, self[k])
for k in self.keys(with_album=False)
"{}={!r}".format(k, self[k]) for k in self.keys(with_album=False)
),
)

Expand Down Expand Up @@ -931,19 +924,13 @@ def move_file(self, dest, operation=MoveOperation.MOVE):
destination=dest,
)
util.move(self.path, dest)
plugins.send(
"item_moved", item=self, source=self.path, destination=dest
)
plugins.send("item_moved", item=self, source=self.path, destination=dest)
elif operation == MoveOperation.COPY:
util.copy(self.path, dest)
plugins.send(
"item_copied", item=self, source=self.path, destination=dest
)
plugins.send("item_copied", item=self, source=self.path, destination=dest)
elif operation == MoveOperation.LINK:
util.link(self.path, dest)
plugins.send(
"item_linked", item=self, source=self.path, destination=dest
)
plugins.send("item_linked", item=self, source=self.path, destination=dest)
elif operation == MoveOperation.HARDLINK:
util.hardlink(self.path, dest)
plugins.send(
Expand Down Expand Up @@ -1173,6 +1160,7 @@ class Album(LibModel):
"albumartists_credit": types.MULTI_VALUE_DSV,
"album": types.STRING,
"genre": types.STRING,
"genres": types.MULTI_VALUE_DSV,
"style": types.STRING,
"discogs_albumid": types.INTEGER,
"discogs_artistid": types.INTEGER,
Expand Down Expand Up @@ -1229,6 +1217,7 @@ class Album(LibModel):
"albumartists_credit",
"album",
"genre",
"genres",
"style",
"discogs_albumid",
"discogs_artistid",
Expand Down Expand Up @@ -1451,9 +1440,7 @@ def art_destination(self, image, item_dir=None):
subpath = util.asciify_path(
subpath, beets.config["path_sep_replace"].as_str()
)
subpath = util.sanitize_path(
subpath, replacements=self._db.replacements
)
subpath = util.sanitize_path(subpath, replacements=self._db.replacements)
subpath = bytestring_path(subpath)

_, ext = os.path.splitext(image)
Expand Down Expand Up @@ -1681,16 +1668,12 @@ def _fetch(self, model_cls, query, sort=None):
@staticmethod
def get_default_album_sort():
"""Get a :class:`Sort` object for albums from the config option."""
return dbcore.sort_from_strings(
Album, beets.config["sort_album"].as_str_seq()
)
return dbcore.sort_from_strings(Album, beets.config["sort_album"].as_str_seq())

@staticmethod
def get_default_item_sort():
"""Get a :class:`Sort` object for items from the config option."""
return dbcore.sort_from_strings(
Item, beets.config["sort_item"].as_str_seq()
)
return dbcore.sort_from_strings(Item, beets.config["sort_item"].as_str_seq())

def albums(self, query=None, sort=None) -> Results[Album]:
"""Get :class:`Album` objects matching the query."""
Expand Down
Loading

0 comments on commit 4b84406

Please sign in to comment.