Skip to content

Commit 34819d4

Browse files
committed
Added id based downloading
1 parent ddbb8c6 commit 34819d4

File tree

4 files changed

+87
-6
lines changed

4 files changed

+87
-6
lines changed

readme.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,24 @@ How to use
105105
--file The URLs to download inside a .txt file with a single
106106
track/album/artist each line.
107107

108-
Searching
109-
---------
108+
####Searching
109+
110110
Searching for tracks, albums and videos is now supported.
111111

112112
Usage: `python redsea.py search [track/album/video] [name of song/video, spaces are allowed]`
113113

114114
Example: `python redsea.py search video Darkside Alan Walker`
115115

116-
Exploring
117-
---------
116+
####ID downloading
117+
118+
Download an album/track/artist/video/playlist with just the ID instead of an URL
119+
120+
Usage: `python redsea.py id [album/track/artist/video/playlist ID]`
121+
122+
Example: `python redsea.py id id 92265335`
123+
124+
####Exploring
125+
118126
Exploring new Dolby Atmos or 360 Reality Audio releases is now supported
119127

120128
Usage: `python redsea.py explore (dolby atmos/sony 360)`
@@ -134,7 +142,7 @@ Tidal issues
134142

135143
To do/Whishlist
136144
---------------
137-
* ID based downloading (check if ID is a track, album, video, ...)
145+
* ~~ID based downloading (check if ID is a track, album, video, ...)~~
138146
* Complete `mediadownloader.py` rewrite
139147
* Move lyrics support to tagger.py
140148
* Support for being used as a python module (maybe pip?)

redsea.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import traceback
44
import sys
55
import os
6+
import re
67

78
import redsea.cli as cli
89

@@ -79,6 +80,41 @@ def main():
7980
RSF.reauth()
8081
exit()
8182

83+
elif args.urls[0] == 'id':
84+
type = None
85+
md = MediaDownloader(TidalApi(RSF.load_session(args.account)), preset, Tagger(preset))
86+
87+
if len(args.urls) == 2:
88+
id = args.urls[1]
89+
if not id.isdigit():
90+
# Check if id is playlist (UUIDv4)
91+
pattern = re.compile('^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$')
92+
if pattern.match(id):
93+
try:
94+
result = md.playlist_from_id(id)
95+
type = 'p'
96+
except TidalError:
97+
print("The playlist id " + str(id) + " could not be found!")
98+
exit()
99+
100+
else:
101+
print('The id ' + str(id) + ' is not valid.')
102+
exit()
103+
else:
104+
print('Example usage: python redsea.py id 92265335')
105+
exit()
106+
107+
if type is None:
108+
type = md.type_from_id(id)
109+
110+
if type:
111+
media_to_download = [{'id': id, 'type': type}]
112+
113+
else:
114+
print("The id " + str(id) + " could not be found!")
115+
exit()
116+
117+
82118
elif args.urls[0] == 'explore':
83119
if len(args.urls) == 3:
84120
if args.urls[1] == 'dolby' and args.urls[2] == 'atmos':
@@ -114,8 +150,10 @@ def main():
114150
else:
115151
explicittag = ""
116152

153+
date = " (" + item['streamStartDate'].split('T')[0] + ")"
154+
117155
print(str(i + 1) + ") " + str(item['title']) + " - " + str(
118-
item['artists'][0]['name']) + explicittag + specialtag)
156+
item['artists'][0]['name']) + explicittag + specialtag + date)
119157

120158
print(str(total_items+1) + ") Exit")
121159

redsea/mediadownloader.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ def search_for_id(self, term):
140140
def page(self, pageurl):
141141
return self.api.get_page(pageurl)
142142

143+
def type_from_id(self, id):
144+
return self.api.get_type_from_id(id)
145+
146+
def playlist_from_id(self, id):
147+
return self.api.get_playlist(id)
148+
143149
def download_media(self, track_info, preset, album_info=None, overwrite=False):
144150
track_id = track_info['id']
145151
assert track_info['allowStreaming'], 'Unable to download track {0}: not allowed to stream/download'.format(

redsea/tidal_api.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ def get_playlist_items(self, playlist_id):
137137

138138
return result
139139

140+
def get_playlist(self, playlist_id):
141+
return self._get('playlists/' + str(playlist_id))
142+
140143
def get_album_tracks(self, album_id):
141144
return self._get('albums/' + str(album_id) + '/tracks')
142145

@@ -167,6 +170,32 @@ def get_artist_albums(self, artist_id):
167170
def get_artist_albums_ep_singles(self, artist_id):
168171
return self._get('artists/' + str(artist_id) + '/albums', params={'filter': 'EPSANDSINGLES'})
169172

173+
def get_type_from_id(self, id):
174+
result = None
175+
try:
176+
result = self.get_album(id)
177+
return 'a'
178+
except TidalError:
179+
pass
180+
try:
181+
result = self.get_artist(id)
182+
return 'r'
183+
except TidalError:
184+
pass
185+
try:
186+
result = self.get_track(id)
187+
return 't'
188+
except TidalError:
189+
pass
190+
try:
191+
result = self.get_video(id)
192+
return 'v'
193+
except TidalError:
194+
pass
195+
196+
return result
197+
198+
170199
@classmethod
171200
def get_album_artwork_url(cls, album_id, size=1280):
172201
return 'https://resources.tidal.com/images/{0}/{1}x{1}.jpg'.format(

0 commit comments

Comments
 (0)