From 10d60e3aa21ec2ee66389448da9c97e6794d2437 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sun, 6 Oct 2019 11:26:09 -0500 Subject: [PATCH] tidal: Add track number to results when tracks are part of an album in artist search --- changes.md | 1 + src/services/tidal.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/changes.md b/changes.md index 5dc31df..fee0fba 100644 --- a/changes.md +++ b/changes.md @@ -4,6 +4,7 @@ * changes in Tidal: * In the settings dialog, you can control wether Albums, compilations and singles will be added when searching by artist (by using artist://...). + * When searching by artists, results that belong to an album will be numbered. ## Version 0.6 diff --git a/src/services/tidal.py b/src/services/tidal.py index 2ad1d27..ea6f3ff 100644 --- a/src/services/tidal.py +++ b/src/services/tidal.py @@ -81,10 +81,14 @@ class interface(base.baseInterface): for album in singles: tracks = self.session.get_album_tracks(album.id) for track in tracks: + track.single = True data.append(track) for search_result in data: s = base.song(self) - s.title = search_result.name + if not hasattr(search_result, "single"): + s.title = "{0}. {1}".format(self.format_number(search_result.track_num), search_result.name) + else: + s.title = search_result.name s.artist = search_result.artist.name s.duration = seconds_to_string(search_result.duration) s.url = search_result.id @@ -92,6 +96,12 @@ class interface(base.baseInterface): self.results.append(s) log.debug("{0} results found.".format(len(self.results))) + def format_number(self, number): + if number < 10: + return "0%d" % (number) + else: + return number + def get_download_url(self, url): url = self.session.get_media_url(url) if url.startswith("https://") or url.startswith("http://") == False: