def track(link, chat_id, quality): global spo conn = sqlite3.connect(db_file) c = conn.cursor() c.execute("SELECT query FROM DWSONGS WHERE id = '%s' and quality = '%s'" % ( link, quality.split("MP3_")[-1])) match = c.fetchone() conn.close() if match != None: sendAudio(chat_id, match[0]) else: try: youtube = False if "spotify" in link: try: url = spo.track(link) except: spo = spotipy.Spotify(auth=generate_token()) url = spo.track(link) try: image = url['album']['images'][2]['url'] except IndexError: image = "https://e-cdns-images.dzcdn.net/images/cover/90x90-000000-80-0-0.jpg" z = downloa.download_trackspo( link, quality=quality, recursive_quality=False, recursive_download=False) elif "deezer" in link: try: url = request("https://api.deezer.com/track/" + link.split("/")[-1], chat_id, True).json() except AttributeError: return try: image = url['album']['cover_xl'].replace( "1000x1000", "90x90") except AttributeError: URL = "https://www.deezer.com/track/" + link.split("/")[-1] image = request(URL).text image = BeautifulSoup(image, "html.parser").find( "img", class_="img_main").get("src").replace("120x120", "90x90") ima = request(image).content if len(ima) == 13: image = "https://e-cdns-images.dzcdn.net/images/cover/90x90-000000-80-0-0.jpg" z = downloa.download_trackdee( link, quality=quality, recursive_quality=False, recursive_download=False) except deezloader.TrackNotFound: sendMessage(chat_id, translate( languag[chat_id], "Track doesn't exist on Deezer or maybe it isn't readable, it'll be downloaded from YouTube...")) try: if "spotify" in link: z = dwytsongs.download_trackspo(link, check=False) elif "deezer" in link: z = dwytsongs.download_trackdee(link, check=False) youtube = True except dwytsongs.TrackNotFound: sendMessage(chat_id, translate( languag[chat_id], "Sorry I cannot download this song :(")) return image = request(image).content sendAudio(chat_id, z, link, image, youtube)
def Link2(chat_id, music, image): try: if "spotify" in music: if "track" in music: z = dwytsongs.download_trackspo(music, check=False) elif "album" in music: z = dwytsongs.download_albumspo(music, check=False) elif "deezer" in music: if "track" in music: z = dwytsongs.download_trackdee(music, check=False) elif "album" in music: z = dwytsongs.download_albumdee(music, check=False) if type(z) is str: z = [z] image = [image] for a in range(len(z)): try: sendAudio(chat_id, open(z[a], "rb"), image[a]) except FileNotFoundError: bot.sendMessage( chat_id, "Error downloading " + z.split("/")[-1] + " :(") except UnboundLocalError: bot.sendMessage(chat_id, "Invalid link ;)")
def track(link, chat_id, quality): global spo conn = connect(db_file) c = conn.cursor() lin = "track/%s" % link.split("/")[-1] qua = quality.split("MP3_")[-1] match = c.execute( where_query.format(lin, qua) ).fetchone() conn.close() if match: sendAudio(chat_id, match[0]) else: try: youtube = False if "spotify" in link: try: url = spo.track(link) except: spo = Spotify( generate_token() ) url = spo.track(link) try: image = url['album']['images'][2]['url'] except IndexError: image = "https://e-cdns-images.dzcdn.net/images/cover/90x90-000000-80-0-0.jpg" z = downloa.download_trackspo( link, quality = quality, recursive_quality = True, recursive_download = True, not_interface = True ) elif "deezer" in link: ids = link.split("/")[-1] try: url = request( "https://api.deezer.com/track/%s" % ids, chat_id, True ).json()['album']['cover_xl'] except AttributeError: return image = check_image(url, ids).replace("1000x1000", "90x90") z = downloa.download_trackdee( link, quality = quality, recursive_quality = True, recursive_download = True, not_interface = True ) except (exceptions.TrackNotFound, exceptions.NoDataApi): sendMessage(chat_id, "Track doesn't %s exist on Deezer or maybe it isn't readable, it'll be downloaded from YouTube..." % link) try: if "spotify" in link: z = dwytsongs.download_trackspo( link, recursive_download = True, not_interface = True ) elif "deezer" in link: z = dwytsongs.download_trackdee( link, recursive_download = True, not_interface = True ) youtube = True except: sendMessage(chat_id, "Sorry I cannot download this song %s :(" % link) return image = request(image).content sendAudio(chat_id, z, link, image, youtube)
def track(link, chat_id, quality): global spo conn = sqlite3.connect(db_file) c = conn.cursor() c.execute(where_query % (link, quality.split("MP3_")[-1])) match = c.fetchone() conn.close() if match != None: sendAudio(chat_id, match[0]) else: try: youtube = False if "spotify" in link: try: url = spo.track(link) except: spo = spotipy.Spotify(auth=generate_token()) url = spo.track(link) try: image = url['album']['images'][2]['url'] except IndexError: image = "https://e-cdns-images.dzcdn.net/images/cover/90x90-000000-80-0-0.jpg" z = downloa.download_trackspo( link, quality=quality, recursive_quality=True, recursive_download=True, ) elif "deezer" in link: ids = link.split("/")[-1] try: url = request("https://api.deezer.com/track/" + ids, chat_id, True).json() except AttributeError: return try: image = url['album']['cover_xl'].replace( "1000x1000", "90x90") except AttributeError: URL = "https://www.deezer.com/track/" + ids image = request(URL).text image = (BeautifulSoup(image, "html.parser").find( "meta", property="og:image").get("content").replace( "500x500", "90x90")) ima = request(image).content if len(ima) == 13: image = "https://e-cdns-images.dzcdn.net/images/cover/90x90-000000-80-0-0.jpg" z = downloa.download_trackdee( link, quality=quality, recursive_quality=True, recursive_download=True, ) except (deezloader.exceptions.TrackNotFound, deezloader.exceptions.NoDataApi): sendMessage( chat_id, "Track doesn't exist on Deezer or maybe it isn't readable, it'll be downloaded from YouTube..." ) try: if "spotify" in link: z = dwytsongs.download_trackspo(link, check=False) elif "deezer" in link: z = dwytsongs.download_trackdee(link, check=False) youtube = True except dwytsongs.TrackNotFound: sendMessage(chat_id, "Sorry I cannot download this song :(") return image = request(image).content sendAudio(chat_id, z, link, image, youtube)