mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-17 16:45:13 -04:00
Fix Qobuz discography filters
This commit is contained in:
parent
a05aebe021
commit
c04938fe22
3 changed files with 39 additions and 57 deletions
|
@ -104,7 +104,7 @@ def filter_discography(ctx, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
filters = kwargs.copy()
|
filters = kwargs.copy()
|
||||||
filters.remove("urls")
|
filters.pop("urls")
|
||||||
config.session["filters"] = filters
|
config.session["filters"] = filters
|
||||||
logger.debug(f"downloading {kwargs['urls']} with filters {filters}")
|
logger.debug(f"downloading {kwargs['urls']} with filters {filters}")
|
||||||
core.handle_urls(" ".join(kwargs["urls"]))
|
core.handle_urls(" ".join(kwargs["urls"]))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -1263,30 +1264,26 @@ class Artist(Tracklist):
|
||||||
:type filters: Optional[Tuple]
|
:type filters: Optional[Tuple]
|
||||||
:param no_repeats: Remove repeats
|
:param no_repeats: Remove repeats
|
||||||
:type no_repeats: bool
|
:type no_repeats: bool
|
||||||
:param quality: in (4, 5, 6, 7, 27)
|
:param quality: in (0, 1, 2, 3, 4)
|
||||||
:type quality: int
|
:type quality: int
|
||||||
"""
|
"""
|
||||||
folder = sanitize_filename(self.name)
|
folder = sanitize_filename(self.name)
|
||||||
folder = os.path.join(parent_folder, folder)
|
folder = os.path.join(parent_folder, folder)
|
||||||
|
|
||||||
logger.debug("Artist folder: %s", folder)
|
logger.debug("Artist folder: %s", folder)
|
||||||
|
|
||||||
logger.debug(f"Length of tracklist {len(self)}")
|
logger.debug(f"Length of tracklist {len(self)}")
|
||||||
if no_repeats:
|
logger.debug(f"Filters: {filters}")
|
||||||
|
|
||||||
|
if 'repeats' in filters:
|
||||||
final = self._remove_repeats(bit_depth=max, sampling_rate=min)
|
final = self._remove_repeats(bit_depth=max, sampling_rate=min)
|
||||||
|
filters = tuple(f for f in filters if f != 'repeats')
|
||||||
else:
|
else:
|
||||||
final = self
|
final = self
|
||||||
|
|
||||||
if isinstance(filters, tuple) and self.client.source == "qobuz":
|
if isinstance(filters, tuple) and self.client.source == "qobuz":
|
||||||
filters = [getattr(self, filter_) for filter_ in filters]
|
filter_funcs = (getattr(self, f"_{filter_}") for filter_ in filters)
|
||||||
logger.debug("Filters: %s", filters)
|
for func in filter_funcs:
|
||||||
for filter_ in filters:
|
final = filter(func, final)
|
||||||
|
|
||||||
def inter(album):
|
|
||||||
"""Intermediate function to pass self into f"""
|
|
||||||
return filter_(self, album)
|
|
||||||
|
|
||||||
final = filter(inter, final)
|
|
||||||
|
|
||||||
self.download_message()
|
self.download_message()
|
||||||
for album in final:
|
for album in final:
|
||||||
|
@ -1294,6 +1291,7 @@ class Artist(Tracklist):
|
||||||
album.load_meta()
|
album.load_meta()
|
||||||
except NonStreamable:
|
except NonStreamable:
|
||||||
logger.info("Skipping album, not available to stream.")
|
logger.info("Skipping album, not available to stream.")
|
||||||
|
continue
|
||||||
album.download(
|
album.download(
|
||||||
parent_folder=folder,
|
parent_folder=folder,
|
||||||
quality=quality,
|
quality=quality,
|
||||||
|
@ -1321,28 +1319,6 @@ class Artist(Tracklist):
|
||||||
# equivalent to Artist(client=client, **info)
|
# equivalent to Artist(client=client, **info)
|
||||||
return cls(client=client, **info)
|
return cls(client=client, **info)
|
||||||
|
|
||||||
def _remove_repeats(self, bit_depth=max, sampling_rate=max):
|
|
||||||
"""Remove the repeated albums from self. May remove different
|
|
||||||
versions of the same album.
|
|
||||||
|
|
||||||
:param bit_depth: either max or min functions
|
|
||||||
:param sampling_rate: either max or min functions
|
|
||||||
"""
|
|
||||||
groups = dict()
|
|
||||||
for album in self:
|
|
||||||
if (t := self.essence(album.title)) not in groups:
|
|
||||||
groups[t] = []
|
|
||||||
groups[t].append(album)
|
|
||||||
|
|
||||||
for group in groups.values():
|
|
||||||
assert bit_depth in (min, max) and sampling_rate in (min, max)
|
|
||||||
best_bd = bit_depth(a["bit_depth"] for a in group)
|
|
||||||
best_sr = sampling_rate(a["sampling_rate"] for a in group)
|
|
||||||
for album in group:
|
|
||||||
if album["bit_depth"] == best_bd and album["sampling_rate"] == best_sr:
|
|
||||||
yield album
|
|
||||||
break
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_get_resp(item: dict, client: ClientInterface):
|
def _parse_get_resp(item: dict, client: ClientInterface):
|
||||||
"""Parse a result from a client.search call.
|
"""Parse a result from a client.search call.
|
||||||
|
@ -1369,11 +1345,30 @@ class Artist(Tracklist):
|
||||||
|
|
||||||
# ----------- Filters --------------
|
# ----------- Filters --------------
|
||||||
|
|
||||||
@staticmethod
|
def _remove_repeats(self, bit_depth=max, sampling_rate=max):
|
||||||
def studio_albums(artist, album: Album) -> bool:
|
"""Remove the repeated albums from self. May remove different
|
||||||
"""Passed as a parameter by the user.
|
versions of the same album.
|
||||||
|
|
||||||
>>> artist.download(filters=Artist.studio_albums)
|
:param bit_depth: either max or min functions
|
||||||
|
:param sampling_rate: either max or min functions
|
||||||
|
"""
|
||||||
|
groups = dict()
|
||||||
|
for album in self:
|
||||||
|
if (t := self.essence(album.title)) not in groups:
|
||||||
|
groups[t] = []
|
||||||
|
groups[t].append(album)
|
||||||
|
|
||||||
|
for group in groups.values():
|
||||||
|
assert bit_depth in (min, max) and sampling_rate in (min, max)
|
||||||
|
best_bd = bit_depth(a["bit_depth"] for a in group)
|
||||||
|
best_sr = sampling_rate(a["sampling_rate"] for a in group)
|
||||||
|
for album in group:
|
||||||
|
if album["bit_depth"] == best_bd and album["sampling_rate"] == best_sr:
|
||||||
|
yield album
|
||||||
|
break
|
||||||
|
|
||||||
|
def _non_studio_albums(self, album: Album) -> bool:
|
||||||
|
"""Passed as a parameter by the user.
|
||||||
|
|
||||||
This will download only studio albums.
|
This will download only studio albums.
|
||||||
|
|
||||||
|
@ -1387,12 +1382,9 @@ class Artist(Tracklist):
|
||||||
and TYPE_REGEXES["extra"].search(album.title) is None
|
and TYPE_REGEXES["extra"].search(album.title) is None
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
def _features(self, album):
|
||||||
def no_features(artist, album):
|
|
||||||
"""Passed as a parameter by the user.
|
"""Passed as a parameter by the user.
|
||||||
|
|
||||||
>>> artist.download(filters=Artist.no_features)
|
|
||||||
|
|
||||||
This will download only albums where the requested
|
This will download only albums where the requested
|
||||||
artist is the album artist.
|
artist is the album artist.
|
||||||
|
|
||||||
|
@ -1401,14 +1393,11 @@ class Artist(Tracklist):
|
||||||
:type album: Album
|
:type album: Album
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
return artist["name"] == album["albumartist"]
|
return self["name"] == album["albumartist"]
|
||||||
|
|
||||||
@staticmethod
|
def _extras(self, album):
|
||||||
def no_extras(artist, album):
|
|
||||||
"""Passed as a parameter by the user.
|
"""Passed as a parameter by the user.
|
||||||
|
|
||||||
>>> artist.download(filters=Artist.no_extras)
|
|
||||||
|
|
||||||
This will skip any extras.
|
This will skip any extras.
|
||||||
|
|
||||||
:param artist: usually self
|
:param artist: usually self
|
||||||
|
@ -1418,12 +1407,9 @@ class Artist(Tracklist):
|
||||||
"""
|
"""
|
||||||
return TYPE_REGEXES["extra"].search(album.title) is None
|
return TYPE_REGEXES["extra"].search(album.title) is None
|
||||||
|
|
||||||
@staticmethod
|
def _non_remasters(self, album):
|
||||||
def remaster_only(artist, album):
|
|
||||||
"""Passed as a parameter by the user.
|
"""Passed as a parameter by the user.
|
||||||
|
|
||||||
>>> artist.download(filters=Artist.remaster_only)
|
|
||||||
|
|
||||||
This will download only remasterd albums.
|
This will download only remasterd albums.
|
||||||
|
|
||||||
:param artist: usually self
|
:param artist: usually self
|
||||||
|
@ -1433,12 +1419,9 @@ class Artist(Tracklist):
|
||||||
"""
|
"""
|
||||||
return TYPE_REGEXES["remaster"].search(album.title) is not None
|
return TYPE_REGEXES["remaster"].search(album.title) is not None
|
||||||
|
|
||||||
@staticmethod
|
def _non_albums(self, album):
|
||||||
def albums_only(artist, album):
|
|
||||||
"""This will ignore non-album releases.
|
"""This will ignore non-album releases.
|
||||||
|
|
||||||
>>> artist.download(filters=(albums_only))
|
|
||||||
|
|
||||||
:param artist: usually self
|
:param artist: usually self
|
||||||
:param album: the album to check
|
:param album: the album to check
|
||||||
:type album: Album
|
:type album: Album
|
||||||
|
|
|
@ -170,7 +170,6 @@ class TrackMetadata:
|
||||||
|
|
||||||
def _mod_title(self, version, work):
|
def _mod_title(self, version, work):
|
||||||
if version is not None:
|
if version is not None:
|
||||||
logger.debug("Version found: %s", version)
|
|
||||||
self.title = f"{self.title} ({version})"
|
self.title = f"{self.title} ({version})"
|
||||||
if work is not None:
|
if work is not None:
|
||||||
logger.debug("Work found: %s", work)
|
logger.debug("Work found: %s", work)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue