mirror of
https://github.com/nathom/streamrip.git
synced 2025-06-04 08:59:47 -04:00
Merge branch 'dev' into fix-regex-appid-appsecret
This commit is contained in:
commit
c5bbd11414
7 changed files with 51 additions and 33 deletions
|
@ -1,5 +1,5 @@
|
|||
"""streamrip: the all in one music downloader."""
|
||||
|
||||
__version__ = "1.9.5"
|
||||
__version__ = "1.9.6"
|
||||
|
||||
from . import clients, constants, converter, downloadtools, media
|
||||
|
|
|
@ -29,12 +29,7 @@ from pathvalidate import sanitize_filepath
|
|||
|
||||
from . import converter
|
||||
from .clients import Client, DeezloaderClient
|
||||
from .constants import (
|
||||
ALBUM_KEYS,
|
||||
FLAC_MAX_BLOCKSIZE,
|
||||
FOLDER_FORMAT,
|
||||
TRACK_FORMAT,
|
||||
)
|
||||
from .constants import ALBUM_KEYS, FLAC_MAX_BLOCKSIZE, FOLDER_FORMAT, TRACK_FORMAT
|
||||
from .downloadtools import DownloadPool, DownloadStream
|
||||
from .exceptions import (
|
||||
InvalidQuality,
|
||||
|
@ -1516,7 +1511,9 @@ class Album(Tracklist, Media):
|
|||
parent_folder = kwargs.get("parent_folder", "StreamripDownloads")
|
||||
if self.folder_format:
|
||||
self.folder = self._get_formatted_folder(
|
||||
parent_folder, restrict=kwargs.get("restrict_filenames", False)
|
||||
parent_folder,
|
||||
restrict=kwargs.get("restrict_filenames", False),
|
||||
truncate=kwargs.get("truncate_filenames", True),
|
||||
)
|
||||
else:
|
||||
self.folder = parent_folder
|
||||
|
@ -1525,7 +1522,7 @@ class Album(Tracklist, Media):
|
|||
|
||||
self.download_message()
|
||||
|
||||
cover_path = (
|
||||
cover_path: Optional[str] = (
|
||||
_choose_and_download_cover(
|
||||
self.cover_urls,
|
||||
kwargs.get("embed_cover_size", "large"),
|
||||
|
@ -1660,7 +1657,9 @@ class Album(Tracklist, Media):
|
|||
logger.debug("Formatter: %s", fmt)
|
||||
return fmt
|
||||
|
||||
def _get_formatted_folder(self, parent_folder: str, restrict: bool = False) -> str:
|
||||
def _get_formatted_folder(
|
||||
self, parent_folder: str, restrict: bool = False, truncate: bool = True
|
||||
) -> str:
|
||||
"""Generate the folder name for this album.
|
||||
|
||||
:param parent_folder:
|
||||
|
@ -1675,8 +1674,8 @@ class Album(Tracklist, Media):
|
|||
self._get_formatter(),
|
||||
restrict=restrict,
|
||||
)
|
||||
if len(formatted_folder) > 120:
|
||||
formatted_folder = f"{formatted_folder[:120]}..."
|
||||
if truncate and len(formatted_folder) > 120:
|
||||
formatted_folder = formatted_folder[:120]
|
||||
|
||||
return os.path.join(parent_folder, formatted_folder)
|
||||
|
||||
|
@ -1840,13 +1839,13 @@ class Playlist(Tracklist, Media):
|
|||
self.append(Track(self.client, id=track["id"]))
|
||||
else:
|
||||
for track in tracklist:
|
||||
# TODO: This should be managed with .m3u files and alike. Arbitrary
|
||||
# tracknumber tags might cause conflicts if the playlist files are
|
||||
# inside of a library folder
|
||||
meta = TrackMetadata(track=track, source=self.client.source)
|
||||
cover_url = get_cover_urls(track["album"], self.client.source)[
|
||||
kwargs.get("embed_cover_size", "large")
|
||||
]
|
||||
cover_urls = get_cover_urls(track["album"], self.client.source)
|
||||
cover_url = (
|
||||
cover_urls[kwargs.get("embed_cover_size", "large")]
|
||||
if cover_urls is not None
|
||||
else None
|
||||
)
|
||||
|
||||
self.append(
|
||||
Track(
|
||||
|
@ -2052,7 +2051,7 @@ class Artist(Tracklist, Media):
|
|||
else:
|
||||
self.folder = parent_folder
|
||||
|
||||
logger.debug("Artist folder: %s", folder)
|
||||
logger.debug("Artist folder: %s", self.folder)
|
||||
logger.debug("Length of tracklist %d", len(self))
|
||||
logger.debug("Filters: %s", filters)
|
||||
|
||||
|
@ -2322,7 +2321,7 @@ def _choose_and_download_cover(
|
|||
directory: str,
|
||||
keep_hires_cover: bool = True,
|
||||
downsize: Tuple[int, int] = (999999, 999999),
|
||||
) -> str:
|
||||
) -> Optional[str]:
|
||||
# choose optimal cover size and download it
|
||||
|
||||
hashcode: str = hashlib.md5(
|
||||
|
@ -2346,12 +2345,16 @@ def _choose_and_download_cover(
|
|||
), f"Invalid cover size. Must be in {cover_urls.keys()}"
|
||||
|
||||
embed_cover_url = cover_urls[preferred_size]
|
||||
|
||||
logger.debug("Chosen cover url: %s", embed_cover_url)
|
||||
if not os.path.exists(temp_cover_path):
|
||||
# Sometimes a size isn't available. When this is the case, find
|
||||
# the first `not None` url.
|
||||
if embed_cover_url is None:
|
||||
embed_cover_url = next(filter(None, cover_urls.values()))
|
||||
urls = tuple(filter(None, cover_urls.values()))
|
||||
if len(urls) == 0:
|
||||
return None
|
||||
embed_cover_url = urls[0]
|
||||
|
||||
logger.debug("Downloading cover from url %s", embed_cover_url)
|
||||
|
||||
|
|
|
@ -306,7 +306,7 @@ def get_container(quality: int, source: str) -> str:
|
|||
return "MP3"
|
||||
|
||||
|
||||
def get_cover_urls(resp: dict, source: str) -> dict:
|
||||
def get_cover_urls(resp: dict, source: str) -> Optional[dict]:
|
||||
"""Parse a response dict containing cover info according to the source.
|
||||
|
||||
:param resp:
|
||||
|
@ -318,7 +318,7 @@ def get_cover_urls(resp: dict, source: str) -> dict:
|
|||
|
||||
if source == "qobuz":
|
||||
cover_urls = resp["image"]
|
||||
cover_urls["original"] = cover_urls["large"].replace("600", "org")
|
||||
cover_urls["original"] = "org".join(cover_urls["large"].rsplit('600', 1))
|
||||
return cover_urls
|
||||
|
||||
if source == "tidal":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue