Misc bug fixes related to playlist downloads

This commit is contained in:
nathom 2021-04-19 12:39:23 -07:00
parent 69e8a5d05b
commit 86d877f1f5
5 changed files with 23 additions and 7 deletions

View file

@ -387,11 +387,11 @@ class Track:
meta = TrackMetadata(track=item, source=client.source)
try:
if client.source == "qobuz":
cover_url = item["album"]["image"]["small"]
cover_url = item["album"]["image"]["large"]
elif client.source == "tidal":
cover_url = tidal_cover_url(item["album"]["cover"], 320)
cover_url = tidal_cover_url(item["album"]["cover"], 640)
elif client.source == "deezer":
cover_url = item["album"]["cover_medium"]
cover_url = item["album"]["cover_large"]
else:
raise InvalidSourceError(client.source)
except KeyError:

View file

@ -248,6 +248,7 @@ def lastfm(ctx, source, url):
@cli.command()
@click.option("-o", "--open", is_flag=True, help="Open the config file")
@click.option("-d", "--directory", is_flag=True, help="Open the config directory")
@click.option("-q", "--qobuz", is_flag=True, help="Set Qobuz credentials")
@click.option("-t", "--tidal", is_flag=True, help="Re-login into Tidal")
@click.option("--reset", is_flag=True, help="RESET the config file")
@ -261,6 +262,11 @@ def config(ctx, **kwargs):
click.secho(f"Opening {CONFIG_PATH}", fg="green")
click.launch(CONFIG_PATH)
if kwargs['directory']:
config_dir = os.path.dirname(CONFIG_PATH)
click.secho(f"Opening {config_dir}", fg="green")
click.launch(config_dir)
if kwargs["qobuz"]:
config.file["qobuz"]["email"] = input(click.style("Qobuz email: ", fg="blue"))

View file

@ -268,6 +268,8 @@ class MusicDL(list):
raise ParsingError(f"Error parsing URL: `{url}`")
def handle_lastfm_urls(self, urls):
# https://www.last.fm/user/nathan3895/playlists/12058911
user_regex = re.compile(r"https://www\.last\.fm/user/([^/]+)/playlists/\d+")
lastfm_urls = self.lastfm_url_parse.findall(urls)
lastfm_source = self.config.session["lastfm"]["source"]
tracks_not_found = 0
@ -276,6 +278,8 @@ class MusicDL(list):
global tracks_not_found
try:
track = next(self.search(lastfm_source, query, media_type="track"))
if self.config.session['metadata']['set_playlist_to_album']:
track.version = track.work = None
playlist.append(track)
except NoResultsFound:
tracks_not_found += 1
@ -286,6 +290,8 @@ class MusicDL(list):
title, queries = self.get_lastfm_playlist(purl)
pl = Playlist(client=self.get_client(lastfm_source), name=title)
pl.creator = user_regex.search(purl).group(1)
processes = []
for title, artist in queries:
@ -382,7 +388,12 @@ class MusicDL(list):
results = tuple(self.search(source, query, media_type, limit=50))
def title(res):
return f"{res[0]+1}. {res[1].album}"
if isinstance(res[1], Album):
return f"{res[0]+1}. {res[1].meta.album}"
elif isinstance(res[1], Track):
return f"{res[0]+1}. {res[1].meta.title}"
else:
raise NotImplementedError(type(res[1]).__name__)
def from_title(s):
num = []

View file

@ -327,7 +327,6 @@ class Playlist(Tracklist):
:param new_tracknumbers: replace tracknumber tag with playlist position
:type new_tracknumbers: bool
"""
# TODO: redundant parsing with _parse_get_pres
if self.client.source == "qobuz":
self.name = self.meta["name"]
self.image = self.meta["images"]
@ -408,7 +407,7 @@ class Playlist(Tracklist):
fname = sanitize_filename(self.name)
self.folder = os.path.join(parent_folder, fname)
self.__download_index = 1
self.__download_index = 1 # used for tracknumbers
self.download_message()
def _download_item(self, item: Track, **kwargs):
@ -422,7 +421,6 @@ class Playlist(Tracklist):
if kwargs.get("new_tracknumbers", True):
item["tracknumber"] = self.__download_index
item["discnumber"] = 1
self.__download_index += 1
self.downloaded = item.download(**kwargs)

View file

@ -277,6 +277,7 @@ class TrackMetadata:
assert hasattr(self, "_album"), "Must set album before accessing"
album = self._album
if self.get("version") and self["version"] not in album:
album = f"{self._album} ({self.version})"