def test_album(): """ Test if the [Album][deethon.types.Album] class raises a [DeezerApiError][deethon.errors.DeezerApiError] when an invalid album ID is passed. """ album = deethon.Album(103248) assert album.id == 103248 # Test album covers assert isinstance(album.cover_small, bytes) assert isinstance(album.cover_medium, bytes) assert isinstance(album.cover_big, bytes) assert isinstance(album.cover_xl, bytes) # Test caching assert album is deethon.Album(103248) # Test errors with pytest.raises(deethon.errors.DeezerApiError): deethon.Album(1234567890)
async def album_link(event: NewMessage.Event): try: album = deethon.Album(event.pattern_match.group(1)) except deethon.errors.DeezerApiError: await event.respond("Not found") raise StopPropagation await event.respond( translate.ALBUM_MSG.format( album.title, album.artist, album.release_date, album.total_tracks, ), file=album.cover_xl, ) quality = users[event.chat_id]["quality"] msg = await event.reply(translate.DOWNLOAD_MSG) tracks = deezer.download_album(album, quality, stream=True) await msg.delete() async with bot.action(event.chat_id, "audio"): for num, track in enumerate(tracks): file_ext = ".mp3" if quality.startswith("MP3") else ".flac" file_name = f"{album.artist} - {album.tracks[num].title}{file_ext}" upload_status = UploadStatus(event, num + 1, album.total_tracks) await upload_status.start() r = await upload_file( file_name=file_name, client=bot, file=open(track, 'rb'), progress_callback=upload_status.progress ) upload_status.finished() await bot.send_file( event.chat_id, r, attributes=[ DocumentAttributeAudio( voice=False, title=album.tracks[num].title, duration=album.tracks[num].duration, performer=album.artist, ) ], ) await msg.delete() await event.reply(file=translate.END_MSG) raise StopPropagation
async def album_playlist_link(event: Union[NewMessage.Event, Message]): if users[event.chat_id]["downloading"]: await event.reply(translate.USER_IS_DOWNLOADING) raise events.StopPropagation method = event.pattern_match.group(1) # if is an album if method == 'album': try: album_playlist = deethon.Album(event.pattern_match.group(2)) except deethon.errors.DeezerApiError: await event.reply("Album non trovato.") raise events.StopPropagation await event.respond( translate.ALBUM_MSG.format( album_playlist.title, album_playlist.artist, get_italian_date_format(album_playlist.release_date), album_playlist.total_tracks, ), file=album_playlist.cover_xl, ) # if is a playlist elif method == 'playlist': try: album_playlist = deethon.Playlist(event.pattern_match.group(2)) except deethon.errors.DeezerApiError: await event.delete() await event.reply("Playlist non trovata.") raise events.StopPropagation await event.respond( translate.PLAYLIST_MSG.format( album_playlist.title, album_playlist.total_tracks, ), file=album_playlist.picture_xl, ) users[event.chat_id]["downloading"] = True quality = users[event.from_id]["quality"] msg = await event.reply(translate.DOWNLOAD_MSG) if method == 'album': tracks = deezer.download_album(album_playlist, quality, stream=True) if method == 'playlist': tracks = deezer.download_playlist(album_playlist, quality, stream=True) await msg.delete() async with bot.action(event.chat_id, "audio"): for num, track in enumerate(tracks): if users[event.chat_id]["stopped"]: users[event.chat_id]['stopped'] = False break artist = album_playlist.tracks[num].artist title = album_playlist.tracks[num].title if not track: await bot.send_message( event.chat_id, f"Non posso scaricare\n{artist} - {title}") continue file_ext = ".mp3" if quality.startswith("MP3") else ".flac" file_name = f"{artist} - {title}{file_ext}" upload_status = UploadStatus(event, num + 1, album_playlist.total_tracks) await upload_status.start() r = await upload_file(file_name=file_name, client=bot, file=open(track, 'rb'), progress_callback=upload_status.progress) await upload_status.finished() await bot.send_file( event.chat_id, r, attributes=[ DocumentAttributeAudio( voice=False, title=title, duration=album_playlist.tracks[num].duration, performer=artist, ) ], ) await msg.delete() await event.reply(translate.END_MSG) users[event.chat_id]["downloading"] = False raise events.StopPropagation