Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing enhancements #5276

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
79 changes: 75 additions & 4 deletions beetsplug/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def _missing_albums(self, lib, query):
matching query.
"""
total = self.config["total"].get()
show_years = self.config["albums"]["years"].get(bool)
recent_albums_only = self.config["albums"]["recent"].get(bool)

albums = lib.albums(query)
# build dict mapping artist to list of their albums in library
Expand Down Expand Up @@ -207,9 +209,16 @@ def _missing_albums(self, lib, query):

missing = []
present = []

most_recent_album_year = None
if recent_albums_only:
most_recent_album_year = 0

for rg in release_groups:
missing.append(rg)
for alb in albums:
if recent_albums_only and "year" in alb and alb["year"] > most_recent_album_year:
most_recent_album_year = alb["year"]
if alb["mb_releasegroupid"] == rg["id"]:
missing.remove(rg)
present.append(rg)
Expand All @@ -219,10 +228,14 @@ def _missing_albums(self, lib, query):
if total:
continue

missing_titles = {rg["title"] for rg in missing}

for release_title in missing_titles:
print_("{} - {}".format(artist[0], release_title))
if show_years:
missing_releases = self._missing_releases(missing, most_recent_album_year)
# print out missing albums for artist sorted by release year
for entry in list(sorted(missing_releases, key=lambda item: item[1])):
print_("{} - [{}] {} ({})".format(artist[0], entry[1], entry[2], entry[3]))
else:
for release_group in missing:
print_("{} - {} ({})".format(artist[0], release_group["title"], release_group["type"]))

if total:
print(total_missing)
Expand All @@ -243,3 +256,61 @@ def _missing(self, album):
album_info.album_id,
)
yield item

def _missing_releases(self, release_groups, _most_recent_album_year=None):
"""Get the releases for the passed release groups.
Returns releases not before _most_recent_album_year if passed.
Returns releases as list of (release_group_id, release_year, title, release_type)
"""
missing_releases = []

for missing_release_group in release_groups:
# Get releases (e.g. album editions) for release-group
try:
resp = musicbrainzngs.browse_releases(release_group=missing_release_group["id"])
releases = resp["release-list"]
except MusicBrainzError as err:
self._log.info(
"Couldn't fetch info for release-group '{}' ({}) - '{}'",
missing_release_group["title"],
missing_release_group["id"],
err,
)
continue

release_year = self._year_of_oldest_release(releases)

# skip if only recent albums are searched for and it is not one
if _most_recent_album_year is not None and release_year < _most_recent_album_year:
continue

release_type = "No Type"

if "type" in missing_release_group:
release_type = missing_release_group["type"]

missing_release = (missing_release_group["id"],
release_year, missing_release_group["title"], release_type)

missing_releases.append(missing_release)

return missing_releases

def _year_of_oldest_release(self, releases):
"""Returns the year of the oldest release out of the releases passed"""
oldest_year = 3000
for release in releases:
if "date" in release:
# Get year from date, convert it and add it to list of years
year = int(release["date"][:4])
if year < oldest_year:
oldest_year = year
self._log.debug(
"year {0} in release {1}",
year,
release["title"]
)

# return oldest year as first release year of the group
# return default-value for the rare case there are no years found
return oldest_year
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Changelog

Changelog goes here! Please add your entry to the bottom of one of the lists below!

New features:

* :doc:`/plugins/missing`: Add config options to show release years for missing albums and to show only releases not older than the latest in the library.


2.0.0 (May 30, 2024)
--------------------
Expand Down
9 changes: 9 additions & 0 deletions docs/plugins/missing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,22 @@ configuration file. The available options are:
Default: :ref:`format_item`.
- **total**: Print a single count of missing tracks in all albums.
Default: ``no``.
- albums: Configuration options for displaying missing albums.
- **years**: Show release years of missing albums (see note below).
- **recent**: Show only releases of an artist not older than those already in the library.

**Note:** Fetching the release year of missing releases results in additional data fetched from MusicBrainz, which
makes this process rather slow. So make sure to grab a coffee while waiting for the results ;-).

Here's an example ::

missing:
format: $albumartist - $album - $title
count: no
total: no
albums:
years: no
recent: no

Template Fields
---------------
Expand Down