def download_link(link, output, quality, recursive_quality, recursive_download, not_gui, zips): link = what_kind(link) if "track/" in link: if "spotify" in link: func = downloa.download_trackspo elif "deezer" in link: func = downloa.download_trackdee else: return func( link, output, quality, recursive_quality, recursive_download, not_gui, ) elif "album/" in link: if "spotify" in link: func = downloa.download_albumspo elif "deezer" in link: func = downloa.download_albumdee else: return func( link, output, quality, recursive_quality, recursive_download, not_gui, zips, ) elif "playlist/" in link: if "spotify" in link: func = downloa.download_playlistspo elif "deezer" in link: func = downloa.download_playlistdee else: return func( link, output, quality, recursive_quality, recursive_download, not_gui, zips, )
def Link(link, chat_id, quality, message_id): global spo global del1 del1 += 1 done = 0 quali = quality.split("MP3_")[-1] link = what_kind(link) link = link.split("?")[0] ids = link.split("/")[-1] try: if "track/" in link: if "spotify" in link: try: url = spo.track(link) except Exception as a: if not "The access token expired" in str(a): sendMessage( chat_id, "Invalid link %s ;)" % link, reply_to_message_id = message_id ) delete(chat_id) return spo = Spotify( generate_token() ) url = spo.track(link) try: image1 = url['album']['images'][0]['url'] except IndexError: image1 = song_default_image name = url['name'] artist = url['album']['artists'][0]['name'] album = url['album']['name'] date = url['album']['release_date'] elif "deezer" in link: kind = "track" api_link = api_track % ids try: url = reque(api_link, chat_id, True).json() except AttributeError: delete(chat_id) return image1 = check_image( url['album']['cover_xl'], ids, kind ) name = url['title'] artist = url['artist']['name'] album = url['album']['title'] date = url['album']['release_date'] if any( a in link for a in services_supported ): sendPhoto( chat_id, image1, caption = ( send_image_track_query % ( name, artist, album, date ) ) ) track(link, chat_id, quality) else: sendMessage(chat_id, not_supported_links % link) elif "album/" in link: links = [] count = [0] if "spotify" in link: try: tracks = spo.album(link) except Exception as a: if not "The access token expired" in str(a): sendMessage( chat_id, "Invalid link %s ;)" % link, reply_to_message_id = message_id ) delete(chat_id) return spo = Spotify( generate_token() ) tracks = spo.album(link) try: image3 = tracks['images'][2]['url'] image1 = tracks['images'][0]['url'] except IndexError: image3 = image_resize(song_default_image, 90) image1 = song_default_image name = tracks['name'] artist = tracks['artists'][0]['name'] date = tracks['release_date'] tot = tracks['total_tracks'] def lazy(a): count[0] += a['duration_ms'] links.append( a['external_urls']['spotify'] ) for a in tracks['tracks']['items']: lazy(a) tracks = tracks['tracks'] for a in range(tot // 50 - 1): try: tracks = spo.next(tracks) except: spo = Spotify( generate_token() ) tracks = spo.next(tracks) for a in tracks['items']: lazy(a) count[0] //= 1000 mode = downloa.download_albumspo elif "deezer" in link: api_link = api_album % ids kind = "album" try: url = reque(api_link, chat_id, True).json() except AttributeError: delete(chat_id) return count[0] = url['duration'] image1 = check_image(url['cover_xl'], ids, kind) image3 = image_resize(image1, 90) tot = url['nb_tracks'] links = [ a['link'] for a in url['tracks']['data'] ] name = url['title'] artist = url['artist']['name'] date = url['release_date'] mode = downloa.download_albumdee if any( a in link for a in services_supported ): if count[0] > seconds_limits_album: sendMessage(chat_id, "If you do this again I will come to your home and I will ddos your ass :)") delete(chat_id) return message_id = sendPhoto( chat_id, image1, caption = ( send_image_album_query % ( name, artist, date, tot ) ) )['message_id'] conn = connect(db_file) c = conn.cursor() exists = [] for a in links: ids = a.split("/")[-1] lins = "track/%s" % ids exist = c.execute( where_query.format(lins, quali) ).fetchone() if exist: exists.append(exist) if len(exists) < len(links) // 3: z = mode( link, quality = quality, recursive_quality = True, recursive_download = True, not_interface = not_interface ) image3 = get_image(image3) for a in range( len(z) ): sendAudio(chat_id, z[a], links[a], image3) else: for a in links: track(a, chat_id, quality) done = 1 else: sendMessage(chat_id, not_supported_links % link) elif "playlist/" in link: links = [] if "spotify" in link: musi = link.split("/") try: tracks = spo.user_playlist(musi[-3], musi[-1]) except Exception as a: if not "The access token expired" in str(a): sendMessage( chat_id, "Invalid link ;)", reply_to_message_id = message_id ) delete(chat_id) return spo = Spotify( generate_token() ) tracks = spo.user_playlist(musi[-3], musi[-1]) try: image1 = tracks['images'][0]['url'] except IndexError: image1 = song_default_image def lazy(a): try: links.append( a['track']['external_urls']['spotify'] ) except (KeyError, TypeError): links.append("Error :(") for a in tracks['tracks']['items']: lazy(a) added = tracks['tracks']['items'][0]['added_at'] owner = tracks['owner']['display_name'] tot = tracks['tracks']['total'] tracks = tracks['tracks'] for a in range(tot // 100 - 1): try: tracks = spo.next(tracks) except: spo = Spotify( generate_token() ) tracks = spo.next(tracks) for a in tracks['items']: lazy(a) elif "deezer" in link: api_link = api_playlist % ids try: url = reque(api_link, chat_id, True).json() except AttributeError: delete(chat_id) return links = [ a['link'] for a in url['tracks']['data'] ] image1 = url['picture_xl'] tot = url['nb_tracks'] added = url['creation_date'] owner = url['creator']['name'] if any( a in link for a in services_supported ): if tot > max_songs: sendMessage(chat_id, "F**k you") delete(chat_id) return sendPhoto( chat_id, image1, caption = ( send_image_playlist_query % ( added, owner, tot ) ) ) for a in links: if a.startswith("http"): try: track(a, chat_id, quality) except: sendMessage(chat_id, "Cannot download %s:(" % a) else: sendMessage(chat_id, a) done = 1 else: sendMessage(chat_id, not_supported_links % link) elif "artist/" in link: if "deezer" in link: api_link = api_artist % ids try: url = reque(api_link, chat_id, True).json() except AttributeError: delete(chat_id) return keyboard = [ [ InlineKeyboardButton( queries['top']['text'], callback_data = queries['top']['query'] % api_link ), InlineKeyboardButton( queries['albums']['text'], callback_data = queries['albums']['query'] % api_link ) ], [ InlineKeyboardButton( queries['radio']['text'], callback_data = queries['radio']['query'] % api_link ), InlineKeyboardButton( queries['related']['text'], callback_data = queries['related']['query'] % api_link ) ] ] image1 = url['picture_xl'] artist = url['name'] albums = url['nb_album'] fans = url['nb_fan'] if any( a in link for a in services_supported[1:] ): sendPhoto( chat_id, image1, caption = ( send_image_artist_query % ( artist, albums, fans ) ), reply_markup = InlineKeyboardMarkup(keyboard) ) else: sendMessage(chat_id, not_supported_links % link) else: sendMessage(chat_id, not_supported_links % link) except FileNotFoundError: sendMessage( chat_id, "Resend link please...", reply_to_message_id = message_id ) except error.TimedOut: sendMessage(chat_id, "Retry after a few minutes") except exceptions.QuotaExceeded: sendMessage(chat_id, "Please send the link %s again :(" % link) except exceptions.AlbumNotFound: sendMessage(chat_id, "Album %s didn't find on Deezer :(" % link) sendMessage(chat_id, "Try to search it throught inline mode or search the link on Deezer") except Exception as a: logging.error(a) logging.error(quality) logging.error(link) sendMessage( chat_id, "OPS :( Something went wrong please send to @An0nimia this link: {} {}, if this happens again".format(link, quality) ) if done == 1: sendMessage( chat_id, end_message, reply_to_message_id = message_id, reply_markup = InlineKeyboardMarkup(end_keyboard) ) delete(chat_id)