def download_playlistspo(self, URL, output=stock_output + "/", quality=stock_quality, recursive_quality=stock_recursive_quality, recursive_download=stock_recursive_download, not_interface=stock_not_interface, zips=stock_zip): array = [] URL = URL.split("?")[0].split("/") try: tracks = self.spo.user_playlist_tracks(URL[-3], playlist_id=URL[-1]) except Exception as a: if not "The access token expired" in str(a): raise exceptions.InvalidLink("Invalid link ;)") self.spo = Spotify(generate_token()) tracks = self.spo.user_playlist_tracks(URL[-3], playlist_id=URL[-1]) for a in tracks['items']: try: array.append( self.download_trackspo( a['track']['external_urls']['spotify'], output, quality, recursive_quality, recursive_download, not_interface)) except: print("Track not found :(") array.append("None") if tracks['total'] != 100: for a in range(tracks['total'] // 100): try: tracks = self.spo.next(tracks) except: self.spo = Spotify(generate_token()) tracks = self.spo.next(tracks) for a in tracks['items']: try: array.append( self.download_trackspo( a['track']['external_urls']['spotify'], output, quality, recursive_quality, recursive_download, not_interface)) except: print("Track not found :(") array.append("None") if zips: zip_name = "{}playlist {}.zip".format(output, URL[-1]) create_zip(zip_name, array) return array, zip_name return array
def download_playlistspo( self, URL, output=stock_output, quality=stock_quality, recursive_quality=stock_recursive_quality, recursive_download=stock_recursive_download, not_interface=stock_not_interface, zips=stock_zip, ): array = [] URL = URL.split("?")[0].split("/") try: tracks = self.spo.user_playlist_tracks(URL[-3], URL[-1]) except Exception as a: if not "The access token expired" in str(a): raise exceptions.InvalidLink("Invalid link ;)") self.spo = utils.generate_token() tracks = self.spo.user_playlist_tracks(URL[-3], URL[-1]) def lazy(tracks): for a in tracks["items"]: try: array.append( self.download_trackspo( a["track"]["external_urls"]["spotify"], output, quality, recursive_quality, recursive_download, not_interface, )) except: print("Track not found :(") array.append("None") lazy(tracks) tot = tracks["total"] for a in range(tot // 100 - 1): try: tracks = self.spo.next(tracks) except: self.spo = utils.generate_token() tracks = self.spo.next(tracks) lazy(tracks) if zips: zip_name = "{}playlist {}.zip".format(output, URL[-1]) utils.create_zip(zip_name, array) return array, zip_name return array
def download_trackspo(self, URL, output=stock_output + "/", quality=stock_quality, recursive_quality=stock_recursive_quality, recursive_download=stock_recursive_download, not_interface=stock_not_interface): URL = URL.split("?")[0] try: url = self.spo.track(URL) except Exception as a: if not "The access token expired" in str(a): raise exceptions.InvalidLink("Invalid link ;)") self.spo = Spotify(generate_token()) url = self.spo.track(URL) isrc = url['external_ids']['isrc'] url = request("https://api.deezer.com/track/isrc:%s" % isrc, True).json() name = self.download_trackdee(url['link'], output, quality, recursive_quality, recursive_download, not_interface) return name
def download_name( self, artist, song, output=stock_output, quality=stock_quality, recursive_quality=stock_recursive_quality, recursive_download=stock_recursive_download, not_interface=stock_not_interface, ): query = "track:{} artist:{}".format(song, artist) try: search = self.spo.search(query) except: self.spo = utils.generate_token() search = self.spo.search(query) try: return self.download_trackspo( search["tracks"]["items"][0]["external_urls"]["spotify"], output, quality, recursive_quality, recursive_download, not_interface, ) except IndexError: raise exceptions.TrackNotFound("Track not found: :(")
def download_trackspo( self, URL, output=stock_output, quality=stock_quality, recursive_quality=stock_recursive_quality, recursive_download=stock_recursive_download, not_interface=stock_not_interface, ): URL = URL.split("?")[0] try: url = self.spo.track(URL) except Exception as a: if not "The access token expired" in str(a): raise exceptions.InvalidLink("Invalid link ;)") self.spo = utils.generate_token() url = self.spo.track(URL) isrc = "isrc:%s" % url["external_ids"]["isrc"] url = utils.request(self.api_track % isrc, True).json() name = self.download_trackdee( url["link"], output, quality, recursive_quality, recursive_download, not_interface, ) return name
def download_name(self, artist, song, output=stock_output + "/", quality=stock_quality, recursive_quality=stock_recursive_quality, recursive_download=stock_recursive_download, not_interface=stock_not_interface): query = ("track:%s artist:%s" % (song, artist)) try: search = self.spo.search(query) except: self.spo = Spotify(generate_token()) search = self.spo.search(query) try: return self.download_trackspo( search['tracks']['items'][0]['external_urls']['spotify'], output, quality, recursive_quality, recursive_download, not_interface) except IndexError: raise exceptions.TrackNotFound("Track not found: " + artist + " - " + song)
def __init__(self, token): self.spo = Spotify(generate_token()) self.req = Session() self.req.cookies['arl'] = token user_id = self.get_api(method_get_user)['USER']['USER_ID'] if user_id == 0: raise exceptions.BadCredentials("Wrong token: %s :(" % token)
def __init__(self, token): self.spo = Spotify(generate_token()) self.req = Session() self.req.cookies['arl'] = token user_id = (self.req.get("https://www.deezer.com/").text.split( "'deezer_user_id': ")[1].split(",")[0]) if user_id == "0": raise exceptions.BadCredentials("Wrong token: %s :(" % token)
def __init__(self, token): self.spo = utils.generate_token() self.req = Session() self.req.cookies["arl"] = token self.get_user_data = methods.method_get_user_data self.private_api_link = deezer_settings.private_api_link user_id = self.get_api(self.get_user_data)["USER"]["USER_ID"] if user_id == 0: raise exceptions.BadCredentials("Wrong token: %s :(" % token) self.qualities = deezer_settings.qualities self.songs_server = deezer_settings.songs_server self.get_song_data = methods.method_get_song_data self.get_lyric = methods.method_get_lyric self.get_album = methods.method_get_album self.get_album_data = methods.method_get_album_data self.api_track = deezer_settings.api_track self.api_album = deezer_settings.api_album self.api_playlist = deezer_settings.api_playlist
def download_albumspo(self, URL, output=stock_output + "/", quality=stock_quality, recursive_quality=stock_recursive_quality, recursive_download=stock_recursive_download, not_interface=stock_not_interface, zips=stock_zip): URL = URL.split("?")[0] try: tracks = self.spo.album(URL) except Exception as a: if not "The access token expired" in str(a): raise exceptions.InvalidLink("Invalid link ;)") self.spo = Spotify(generate_token()) tracks = self.spo.album(URL) tot = tracks['total_tracks'] try: upc = tracks['external_ids']['upc'] while upc[0] == "0": upc = upc[1:] url = request("https://api.deezer.com/album/upc:%s" % upc).json() names = self.download_albumdee(url['link'], output, quality, recursive_quality, recursive_download, not_interface, zips) except KeyError: search = tot // 5 try: url = self.spo.track(tracks['tracks']['items'][search] ['external_urls']['spotify']) except: self.spo = Spotify(generate_token()) url = self.spo.track(tracks['tracks']['items'][search] ['external_urls']['spotify']) isrc = url['external_ids']['isrc'] try: ids = request("https://api.deezer.com/track/isrc:%s" % isrc, True).json()['album']['id'] tracks = request("https://api.deezer.com/album/%d" % ids, True).json() if tot != tracks['nb_tracks']: raise exceptions.TrackNotFound("") names = self.download_albumdee(tracks['link'], output, quality, recursive_quality, recursive_download, not_interface, zips) except (exceptions.TrackNotFound, exceptions.NoDataApi): raise exceptions.AlbumNotFound("Album %s not found :(" % tracks['name']) return names
def global_search(query): global final_res, ind_search, res_search, link_search, links, raw_response q = '\"' + query + '\"' offset = 0 again = False new = None while True: if again: q = '\"' + input('= ') + '\"' new = None token = generate_token() # print(token) # My Search headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': f'Bearer {token}', } params = { 'q': q, 'type': 'track', 'limit': 5, 'offset': offset } try: raw_response = requests.get('https://api.spotify.com/v1/search', headers=headers, params=params) except: print('Impossibile raggiungere il servizio, controlla la tua connessione...') input('Premi \'Invio\' per chiudere il programma') quit() # print(raw_response.url) response = raw_response.json() # print(response) if len(response['tracks']['items']) == 0: new = input('Non ci sono più risultati, riprovare (vuoto = si, e = exit)?\n') if new == 'e': print('\nOk, alla prossima!') exit() elif new == '': again = True continue index = 1 for sg in response['tracks']['items']: artist = sg['artists'][0]['name'] song = sg['name'] print(f'{index}) {artist} - {song}') index += 1 # print(res) ind = 1 links = {} for link in response['tracks']['items']: url = link['external_urls']['spotify'] links.setdefault(ind, url) ind += 1 # print(ind_search) # print(res_search) final_res = input('\nQuale canzone (inserisci numero, lasciare vuoto per riprovare, n = next, e = exit)?\n') if len(final_res) == 0: again = True offset = 0 elif final_res == 'n': offset += 5 again = False elif final_res == 'e': print('\nOk, alla prossima!') quit() elif int(final_res) not in range(index): print('Numero invalido :(') continue else: break link = links[int(final_res)] return link
def download_albumspo( self, URL, output=stock_output, quality=stock_quality, recursive_quality=stock_recursive_quality, recursive_download=stock_recursive_download, not_interface=stock_not_interface, zips=stock_zip, ): URL = URL.split("?")[0] try: tracks = self.spo.album(URL) except Exception as a: if not "The access token expired" in str(a): raise exceptions.InvalidLink("Invalid link ;)") self.spo = utils.generate_token() tracks = self.spo.album(URL) try: upc = "0%s" % tracks["external_ids"]["upc"] while upc[0] == "0": upc = upc[1:] try: upc = "upc:%s" % upc url = utils.request(self.api_album % upc, True).json() names = self.download_albumdee( url["link"], output, quality, recursive_quality, recursive_download, not_interface, zips, ) break except exceptions.NoDataApi: if upc[0] != "0": raise KeyError except KeyError: tot = tracks["total_tracks"] for a in tracks["tracks"]["items"]: try: isrc = self.spo.track( a["external_urls"]["spotify"])["external_ids"]["isrc"] except: self.spo = utils.generate_token() isrc = self.spo.track( a["external_urls"]["spotify"])["external_ids"]["isrc"] try: isrc = "isrc:%s" % isrc ids = utils.request(self.api_track % isrc, True).json()["album"]["id"] tracks = utils.request(self.api_album % str(ids), True).json() if tot == tracks["nb_tracks"]: break except exceptions.NoDataApi: pass try: if tot != tracks["nb_tracks"]: raise KeyError names = self.download_albumdee( tracks["link"], output, quality, recursive_quality, recursive_download, not_interface, zips, ) except KeyError: raise exceptions.AlbumNotFound("Album not found :(") return names
def global_search(query): global final_res, ind_search, res_search, link_search, links q = '\"' + query + '\"' offset = 0 again = False new = None while True: if again: q = '\"' + input('= ') + '\"' new = None token = generate_token() # print(token) # My Search headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': f'Bearer {token}', } params = { 'q': q, 'type': 'track', 'limit': 5, 'offset': offset } raw_response = requests.get('https://api.spotify.com/v1/search', headers=headers, params=params) # print(raw_response.url) response = raw_response.json() # print(response) if len(response['tracks']['items']) == 0: new = input('There are no more results, retry? (empty = yes, e = exit)\n') if new == 'e': print('\nOk, goodbye!') exit() elif new == '': again = True continue index = 1 for sg in response['tracks']['items']: artist = sg['artists'][0]['name'] song = sg['name'] print(f'{index}) {artist} - {song}') index += 1 # print(res) ind = 1 links = {} for link in response['tracks']['items']: url = link['external_urls']['spotify'] links.setdefault(ind, url) ind += 1 # print(ind_search) # print(res_search) final_res = input('\nWhich song? (insert number, leave empty to retry, n = next, e = exit)\n') if len(final_res) == 0: again = True offset = 0 elif final_res == 'n': offset += 5 again = False elif final_res == 'e': print('\nOk, goodbye!') quit() elif int(final_res) not in range(index): print('Number outrange :(') continue else: break link = links[int(final_res)] return link