From 4d8118356a0ee683a943810d5afa95e6aa15fd86 Mon Sep 17 00:00:00 2001 From: Nathan Thomas Date: Wed, 29 Sep 2021 12:24:13 -0700 Subject: [PATCH] Add explicit tag for track names #192 --- pyproject.toml | 2 +- rip/config.toml | 4 +++- streamrip/__init__.py | 2 +- streamrip/media.py | 11 ++++++----- streamrip/metadata.py | 21 +++++++++++++++++++-- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6c7cd89..a7fa6e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "streamrip" -version = "1.6" +version = "1.7" description = "A fast, all-in-one music ripper for Qobuz, Deezer, Tidal, and SoundCloud" authors = ["nathom "] license = "GPL-3.0-only" diff --git a/rip/config.toml b/rip/config.toml index f649236..6bb1ee8 100644 --- a/rip/config.toml +++ b/rip/config.toml @@ -46,6 +46,8 @@ token_expiry = "" [deezer] # 0, 1, or 2 +# This only applies to paid Deezer subscriptions. Those using deezloader +# are automatically limited to quality = 1 quality = 2 # An authentication cookie that allows streamrip to use your Deezer account # See https://github.com/nathom/streamrip/wiki/Finding-Your-Deezer-ARL-Cookie @@ -167,4 +169,4 @@ progress_bar = "dainty" [misc] # Metadata to identify this config file. Do not change. -version = "1.6" +version = "1.7" diff --git a/streamrip/__init__.py b/streamrip/__init__.py index 175a1f7..9d45105 100644 --- a/streamrip/__init__.py +++ b/streamrip/__init__.py @@ -1,5 +1,5 @@ """streamrip: the all in one music downloader.""" -__version__ = "1.6" +__version__ = "1.7" from . import clients, constants, converter, downloadtools, media diff --git a/streamrip/media.py b/streamrip/media.py index 42047e6..88bf0b1 100644 --- a/streamrip/media.py +++ b/streamrip/media.py @@ -755,14 +755,15 @@ class Track(Media): :rtype: str """ - if hasattr(self, "meta"): + try: _title = self.meta.title - if self.meta.explicit: - _title = f"{_title} (Explicit)" - return _title - else: + except AttributeError: raise Exception("Track must be loaded before accessing title") + if self.meta.explicit: + _title = f"{_title} (Explicit)" + return _title + def get(self, *keys, default=None) -> Any: """Safe get method that allows for layered access. diff --git a/streamrip/metadata.py b/streamrip/metadata.py index 86caba5..c0a6e82 100644 --- a/streamrip/metadata.py +++ b/streamrip/metadata.py @@ -23,7 +23,6 @@ from .utils import get_cover_urls, get_quality_id, safe_get logger = logging.getLogger("streamrip") -# TODO: remove OrderedDict bc normal dicts are ordered now class TrackMetadata: """Contains all of the metadata needed to tag the file. @@ -50,7 +49,6 @@ class TrackMetadata: * disctotal """ - title: str albumartist: str composer: Optional[str] = None albumcomposer: Optional[str] = None @@ -82,6 +80,7 @@ class TrackMetadata: _artist: Optional[str] = None _copyright: Optional[str] = None _genres: Optional[Iterable] = None + _title: Optional[str] def __init__( self, @@ -286,6 +285,24 @@ class TrackMetadata: self.bit_depth = 24 if self.get("quality") == 3 else 16 self.sampling_rate = 44100 + @property + def title(self) -> Optional[str]: + logger.debug("accessign title") + if not hasattr(self, "_title"): + logger.debug("no title") + return None + + if self.explicit: + logger.debug("explicit title") + return f"{self._title} (Explicit)" + + logger.debug("non explicit title") + return self._title + + @title.setter + def title(self, new_title): + self._title = new_title + @property def album(self) -> str: """Return the album of the track.