async def main(): shazam = Shazam() top_world_tracks = await shazam.top_world_tracks(limit=10) print(top_world_tracks) for track in top_world_tracks['tracks']: serialized = FactoryTrack(track).serializer() print(serialized)
async def main(): # Example: https://www.shazam.com/track/559284007/rampampam shazam = Shazam() track_id = 559284007 count = await shazam.listening_counter(track_id=track_id) print(count)
async def main(): shazam = Shazam() top_rock_in_the_world = await shazam.top_world_genre_tracks( genre=GenreMusic.ROCK, limit=10) for track in top_rock_in_the_world['tracks']: serialized_track = FactoryTrack(track).serializer() print(serialized_track.spotify_url)
async def main(): shazam = Shazam() track_id = 546891609 related = await shazam.related_tracks(track_id=track_id, limit=5, start_from=2) # ONLY №3, №4 SONG print(related)
async def main(): shazam = Shazam() out = await shazam.recognize_song('data/dora.ogg') result = Serialize.full_track(data=out) youtube_data = await shazam.get_youtube_data(link=result.track.youtube_link ) serialized_youtube = Serialize.youtube(data=youtube_data) print(serialized_youtube.uri)
async def main(): shazam = Shazam() top_rock_in_the_world = await shazam.top_world_genre_tracks( genre=GenreMusic.ROCK, limit=10) for track in top_rock_in_the_world['tracks']: serialized_track = serialize_track(data=track) print(serialized_track)
async def main(): shazam = Shazam() artist_id = 201896832 top_three_artist_tracks = await shazam.artist_top_tracks( artist_id=artist_id, limit=3) for track in top_three_artist_tracks['tracks']: serialized_track = FactoryTrack(data=track).serializer() print(serialized_track)
async def main(): shazam = Shazam() track_id = 552406075 about_track = await shazam.track_about(track_id=track_id) serialized = serialize_track(data=about_track) print(about_track) # dict print(serialized) # serialized from dataclass factory
async def main(): shazam = Shazam() artist_id = 43328183 about_artist = await shazam.artist_about(artist_id) serialized = serialize_artist(about_artist) print(about_artist) # dict print(serialized) # serialized from dataclass factory
async def main(): shazam = Shazam() top_ten_moscow_tracks = await shazam.top_city_tracks(country_code='RU', city_name='Moscow', limit=10) print(top_ten_moscow_tracks) # ALL TRACKS DICT for track in top_ten_moscow_tracks['tracks']: serialized = serialize_track(data=track) # SERIALIZE FROM DATACLASS FACTORY print(serialized)
async def test_recognize_song_file(): shazam = Shazam() out = await shazam.recognize_song(data='examples/data/dora.ogg') assert out.get("matches") != [] assert out['track']['key'] == "549679333"
async def sonf_REG(client, message): chat_id = message.chat.id user_id = message.from_user.id user_name = message.from_user.first_name mention = "[" + user_name + "](tg://user?id=" + str(user_id) + ")" if not message.reply_to_message: await message.reply_text("Reply to a short video to recognize song.") return if not message.reply_to_message.video: await message.reply_text("Reply to a short video to recognize song.") return m = await message.reply_text("Listening 🎶") target = message.reply_to_message.video.file_id print(target) #-------------------test await app.download_media(target, file_name=f"res/blackmusic-{message.message_id}.mp4") shazam = Shazam() out = await shazam.recognize_song(f'res/blackmusic-{message.message_id}.mp4') try: await m.edit("Analysing 🔎") item = out.get("track") title = item.get("title") artist = item.get("subtitle") query = (f"{title} - {artist}") except Exception: await m.edit("Sorry, failed to find your song ☹️") return #------------------------------------------------------+ new func await m.edit('Trying to download 😎') ydl_opts = {"format": "bestaudio[ext=m4a]"} try: results = [] count = 0 while len(results) == 0 and count < 6: if count>0: time.sleep(1) results = YoutubeSearch(query, max_results=1).to_dict() count += 1 try: duration = results[0]["duration"] if time_to_seconds(duration) >= 900: await m.edit("**Sorry!**\n\nMax Duration is 15min") return link = f"https://youtube.com{results[0]['url_suffix']}" title = results[0]["title"][:35] thumbnail = results[0]["thumbnails"][0] thumb_name = f'thumb{message.message_id}.jpg' thumb = requests.get(thumbnail, allow_redirects=True) open(thumb_name, 'wb').write(thumb.content) title_turple = (str(chat_id),title) user_turple = (str(user_id), title) except Exception as e: print(e) await m.edit( f"**No results Error 🐞**" f"\n\nSorry {message.from_user.first_name} i did't find anything with your keyword: `{query}`" ) return except Exception as e: await m.edit( "" ) print(str(e)) return await m.edit("⏬ Downloading.") try: with youtube_dl.YoutubeDL(ydl_opts) as ydl: info_dict = ydl.extract_info(link, download=False) audio_file = ydl.prepare_filename(info_dict) ydl.process_info(info_dict) secmul, dur, dur_arr = 1, 0, duration.split(':') for i in range(len(dur_arr)-1, -1, -1): dur += (int(dur_arr[i]) * secmul) secmul *= 60 song = await message.reply_audio(audio_file, parse_mode='md',quote=False,thumb=thumb_name, reply_to_message_id=message.message_id, title=title, duration=dur, caption=f"☈ Title**: {title}" f"\n**☈ Duration**: `{duration}`" f"\n**☈ Link**: [Click here]({link})" f"\n**☈ Requested by**: {mention}") await m.delete() except Exception as e: print(e) try: os.remove(audio_file) os.remove(thumb_name) os.remove(f'res/blackmusic-{message.message_id}.mp4') except Exception as e: print(e)
# PLease read the GNU Affero General Public License in # <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>. """ ✘ Commands Available - • `{i}whichsong` Reply to a song file, to recognise the song. """ from os import remove from shazamio import Shazam from . import * shazam = Shazam() @ultroid_cmd(pattern="whichsong$") async def song_recog(event): if not event.reply_to_msg_id: return await eod(event, "`Reply to a song file to recognise it!`", time=10) xx = await eor(event, get_string("com_1")) reply = await event.get_reply_message() t_ = mediainfo(reply.media) if t_ != "audio": return await eod(xx, "`Please use as reply to an audio file.`", time=5) await xx.edit("`Downloading...`") path_to_song = "./temp/shaazam_cache/unknown.mp3"
async def main(): shazam = Shazam() artists = await shazam.search_artist(query='Lil', limit=5) for artist in artists['artists']['hits']: serialized = serialize_artist(data=artist) print(serialized)
async def main(): shazam = Shazam() out = await shazam.recognize_song('data/dora.ogg') print(out)
async def main(): shazam = Shazam() top_five_track_from_amsterdam = await shazam.top_country_tracks('NL', 5) for track in top_five_track_from_amsterdam['tracks']: serialized = serialize_track(data=track) print(serialized)
async def main(): shazam = Shazam() top_spain_rap = await shazam.top_country_genre_tracks( country_code='ES', genre=GenreMusic.HIP_HOP_RAP, limit=4) print(top_spain_rap)
async def test_recognize_song_bytes(song_bytes: bytes): shazam = Shazam() out = await shazam.recognize_song(data=song_bytes) assert out.get("matches") != [] assert out['track']['key'] == "549679333"
async def main(): shazam = Shazam() tracks = await shazam.search_track(query='Lil', limit=5) print(tracks)
async def main(): shazam = Shazam() artists = await shazam.search_artist(query='Lil', limit=5) for artist in artists['artists']['hits']: serialized = FactoryArtist(artist).serializer() print(serialized)