Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion streamrip/metadata/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class AlbumMetadata:
grouping: str | None = None
lyrics: str | None = None
purchase_date: str | None = None
# Edition name, e.g. "Deluxe Edition". Only some sources provide one.
version: str | None = None

def get_genres(self) -> str:
return ", ".join(self.genre)
Expand All @@ -64,7 +66,11 @@ def get_copyright(self) -> str | None:

def format_folder_path(self, formatter: str) -> str:
# Available keys: "albumartist", "title", "year", "bit_depth", "sampling_rate",
# "id", and "albumcomposer",
# "id", "albumcomposer", "container", "tracktotal", and "version".
#
# Two different editions of the same album can otherwise render to the
# same folder and get merged together -- "tracktotal" and "version"
# give a readable way to tell them apart without resorting to "id".

none_str = "Unknown"
info: dict[str, str | int | float] = {
Expand All @@ -76,13 +82,22 @@ def format_folder_path(self, formatter: str) -> str:
"title": clean_filename(self.album),
"year": self.year,
"container": self.info.container,
"tracktotal": self.tracktotal,
"version": clean_filename(self.version or "") or none_str,
}

return clean_filepath(formatter.format(**info))

@classmethod
def from_qobuz(cls, resp: dict) -> AlbumMetadata:
album = resp.get("title", "Unknown Album")
version = resp.get("version")
# The edition is part of what the album *is* -- a standard and a deluxe
# release otherwise share a title, so they tag identically and collide
# in the same download folder. Fold it into the title (unless the title
# already says it) and keep it in `version` for tagging as well.
if version and version.lower() not in album.lower():
album = f"{album} ({version})"
tracktotal = resp.get("tracks_count", 1)
genre = [safe_get(resp, "genre", "name")] or resp.get("genre") or []
genres = list(set(genre_clean.findall("/".join(genre))))
Expand Down Expand Up @@ -156,6 +171,7 @@ def from_qobuz(cls, resp: dict) -> AlbumMetadata:
lyrics=None,
purchase_date=None,
tracktotal=tracktotal,
version=resp.get("version"),
)

@classmethod
Expand Down
5 changes: 5 additions & 0 deletions streamrip/metadata/tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
"disctotal",
"date",
"isrc",
# Keep "version" last: MP3_KEY/MP4_KEY zip this tuple against their own
# positional key tuples, so a trailing entry with no counterpart is simply
# dropped for those formats. FLAC_KEY is built by comprehension and picks
# it up as the standard Vorbis VERSION field.
"version",
)


Expand Down