From 6edb422effb611f5bc35da4ab266decdd8616976 Mon Sep 17 00:00:00 2001 From: nathom Date: Tue, 30 Mar 2021 14:23:28 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20issue=20where=20Deezer=20track=20wouldn?= =?UTF-8?q?=E2=80=99t=20download?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- streamrip/config.py | 6 ++++-- streamrip/core.py | 4 +++- streamrip/downloader.py | 15 +++++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/streamrip/config.py b/streamrip/config.py index fec35d5..69dfb6b 100644 --- a/streamrip/config.py +++ b/streamrip/config.py @@ -1,12 +1,11 @@ import copy import logging import os -from pathlib import Path from pprint import pformat from ruamel.yaml import YAML -from .constants import CONFIG_PATH, DOWNLOADS_DIR, FOLDER_FORMAT, TRACK_FORMAT +from .constants import (CONFIG_PATH, DOWNLOADS_DIR, FOLDER_FORMAT, TRACK_FORMAT, CONFIG_DIR) from .exceptions import InvalidSourceError yaml = YAML() @@ -95,6 +94,9 @@ class Config: self.dump(self.file) def reset(self): + if not os.path.isdir(CONFIG_DIR): + os.makedirs(CONFIG_DIR, exist_ok=True) + self.dump(self.defaults) def load(self): diff --git a/streamrip/core.py b/streamrip/core.py index 8f2110f..38e9913 100644 --- a/streamrip/core.py +++ b/streamrip/core.py @@ -256,11 +256,13 @@ class MusicDL(list): ) elif isinstance(media, Artist): fmt = "{name}" + elif isinstance(media, Track): + fmt = "{artist} - {title}\nReleased on {year}" else: raise NotImplementedError fields = (fname for _, fname, _, _ in Formatter().parse(fmt) if fname) - ret = fmt.format(**{k: media.get(k, "Unknown") for k in fields}) + ret = fmt.format(**{k: media.get(k, default="Unknown") for k in fields}) return ret def interactive_search( diff --git a/streamrip/downloader.py b/streamrip/downloader.py index adf028f..ad14433 100644 --- a/streamrip/downloader.py +++ b/streamrip/downloader.py @@ -152,11 +152,12 @@ class Track: progress_bar: bool = True, database: MusicDB = None, tag: bool = False, + **kwargs, ): """ Download the track. - :param quality: (5, 6, 7, 27) + :param quality: (0, 1, 2, 3, 4) :type quality: int :param folder: folder to download the files to :type folder: Optional[Union[str, os.PathLike]] @@ -243,6 +244,9 @@ class Track: if tag: self.tag() + if not kwargs.get("keep_cover", True) and hasattr(self, 'cover_path'): + os.remove(self.cover_path) + return True def download_cover(self): @@ -269,7 +273,6 @@ class Track: """ formatter = self.meta.get_formatter() logger.debug("Track meta formatter %s", pformat(formatter)) - # filename = sanitize_filepath(self.file_format.format(**formatter)) filename = clean_format(self.file_format, formatter) self.final_path = ( os.path.join(self.folder, filename)[:250].strip() @@ -439,6 +442,13 @@ class Track: click.secho(f"Converting {self!s}", fg="blue") engine.convert() + @property + def title(self): + if hasattr(self, 'meta'): + return self.meta.title + else: + raise Exception("Track must be loaded before accessing title") + def get(self, *keys, default=None): """Safe get method that allows for layered access. @@ -1025,6 +1035,7 @@ class Playlist(Tracklist): quality: int = 6, filters: Callable = None, database: MusicDB = None, + **kwargs, ): """Download and tag all of the tracks.