async def sc_callback_handler(callback): print(callback.data) mode, obj_id, method = parse_callback(callback.data) keyboard = None if mode == 'playlist_soundcloud': await callback.answer() playlist = await soundcloud_api.get_playlist(obj_id) if method == 'send': return await sc_methods.send_soundcloud_playlist( callback.message.chat.id, playlist) elif method == 'download': return await sc_methods.send_soundcloud_playlist( callback.message.chat.id, playlist, pic=False, send_all=True) elif method == 'post': return await sc_methods.send_soundcloud_playlist(-1001171972924, playlist, send_all=True) elif mode == 'track_soundcloud': if utils.already_downloading(int(obj_id)): return await callback.answer('already downloading, please wait...') else: await callback.answer('downloading...') track = await soundcloud_api.get_track(obj_id) await sc_methods.send_soundcloud_track(callback.message.chat.id, track)
async def sc_artist_callback_handler(callback): print(callback.data) await callback.answer() _, obj_id, method = parse_callback(callback.data) artist = await soundcloud_api.get_artist(obj_id) if method == 'main': keyboard = sc_keyboards.sc_artist_keyboard(artist) elif method == 'tracks': tracks = await artist.get_tracks() keyboard = sc_keyboards.sc_artist_tracks_keyboard(tracks, artist.id) elif method == 'playlists': playlists = await artist.get_playlists() keyboard = sc_keyboards.sc_artist_playlists_keyboard( playlists, artist.id) elif method == 'download': tracks = await artist.get_tracks() for track in tracks: await methods.send_soundcloud_track(callback.message.chat.id, track) await sleep(.3) return return await bot.edit_message_reply_markup(callback.message.chat.id, callback.message.message_id, reply_markup=keyboard)
async def callback_handler(callback): print(callback.data) mode, obj_id, method = parse_callback(callback.data) if mode == 'album': if method == 'download': await callback.answer() album = await deezer_api.getalbum(obj_id) await bot.edit_message_reply_markup(callback.message.chat.id, callback.message.message_id, None) return await methods.send_album(album, callback.message.chat, pic=False, send_all=True) elif method == 'post': await callback.answer() album = await deezer_api.getalbum(obj_id) chat = await bot.get_chat(-1001171972924) await methods.send_album(album, chat, send_all=True) elif method == 'send': await callback.answer('downloading') album = await deezer_api.getalbum(obj_id) return await methods.send_album(album, callback.message.chat) elif mode == 'track_deezer': if utils.already_downloading(int(obj_id)): return await callback.answer('already downloading, please wait...') else: await callback.answer('downloading...') track = await deezer_api.gettrack(obj_id) await methods.send_track(track, callback.message.chat)
async def quality_setting_hanlder(callback): _, setting = parse_callback(callback.data) await db_utils.set_quality_setting(callback.from_user.id, setting) await callback.answer(f'quality set to {setting}') with suppress(exceptions.MessageNotModified): await bot.edit_message_reply_markup( chat_id=callback.message.chat.id, message_id=callback.message.message_id, reply_markup=inline_keyboards.quality_settings_keyboard(setting))
async def pages_handler(callback): await callback.answer() _, page = parse_callback(callback.data) q = callback.message.text[:-1] search_results = await deezer_api.search(q=q) await bot.edit_message_reply_markup( chat_id=callback.message.chat.id, message_id=callback.message.message_id, reply_markup=inline_keyboards.search_results_keyboard(search_results, int(page)))
async def artist_callback_handler(callback): await callback.answer() print(callback.data) _, obj_id, method = parse_callback(callback.data) artist = await deezer_api.getartist(obj_id) if method == 'top5': top = await artist.top(5) return await bot.edit_message_reply_markup( chat_id=callback.message.chat.id, message_id=callback.message.message_id, reply_markup=inline_keyboards.top5_keyboard(artist, top)) elif method == 'albums': albums = await artist.albums() return await bot.edit_message_reply_markup( chat_id=callback.message.chat.id, message_id=callback.message.message_id, reply_markup=inline_keyboards.albums_keyboard(artist, albums)) elif method == 'related': related = await artist.related() return await bot.edit_message_reply_markup( chat_id=callback.message.chat.id, message_id=callback.message.message_id, reply_markup=inline_keyboards.related_artists_keyboard( related, artist.id)) elif method == 'radio': radio = await artist.radio() return await bot.edit_message_reply_markup( chat_id=callback.message.chat.id, message_id=callback.message.message_id, reply_markup=inline_keyboards.artist_radio_keyboard( radio, artist.id)) elif method == 'main': kboard = inline_keyboards.artist_keyboard(artist) return await bot.edit_message_reply_markup( chat_id=callback.message.chat.id, message_id=callback.message.message_id, reply_markup=kboard) elif method == 'send': return await bot.send_photo( chat_id=callback.message.chat.id, photo=artist.picture_xl, caption=f'[{artist.name}]({artist.share})', parse_mode='markdown', reply_markup=inline_keyboards.artist_keyboard(artist)) elif method == 'wiki': artist = await deezer_api.getartist(obj_id) r = await bot.session.get( f'https://wikipedia.org/w/index.php?search={artist.name}') return await bot.send_message(callback.message.chat.id, r.url)
async def soundcloud_track(callback): await callback.answer() _, obj_id, method = parse_callback(callback.data) if already_downloading(int(obj_id)): return await callback.answer('already downloading, please wait...') else: await callback.answer('downloading...') track = await soundcloud_api.get_track(obj_id) await methods.send_track(callback.message.chat.id, track)
async def soundcloud_artist(callback): await callback.answer() _, obj_id, method = parse_callback(callback.data) artist = await soundcloud_api.get_artist(obj_id) if method == 'main': keyboard = keyboards.artist_keyboard(artist) elif method == 'tracks': tracks = await artist.get_tracks() keyboard = keyboards.artist_tracks_keyboard(tracks, artist.id) elif method == 'playlists': playlists = await artist.get_playlists() keyboard = keyboards.artist_playlists_keyboard(playlists, artist.id) elif method == 'likes': likes = await artist.get_likes() keyboard = keyboards.likes_keyboard(likes, artist.id) elif method == 'download': tracks = await artist.get_tracks() for track in tracks: try: await methods.send_track(callback.message.chat.id, track) await sleep(.3) except Exception as e: print(e) await bot.send_message( callback.message.chat.id, f'track {track.title} is not available') return elif method == 'likes_download': likes = await artist.get_likes() for track in likes: try: await methods.send_track(callback.message.chat.id, track) await sleep(.3) except Exception as e: print(e) await bot.send_message( callback.message.chat.id, f'track {track.title} is not available') return return await bot.edit_message_reply_markup(callback.message.chat.id, callback.message.message_id, reply_markup=keyboard)
async def vk_playlist(callback): await query_answer(callback) _, obj_id, action = parse_callback(callback.data) if action == 'download': owner_id, playlist_id, access_key = obj_id.split('_') playlist = await vk_api.get_playlist(owner_id, playlist_id, access_key) await methods.send_playlist(callback.message.chat.id, playlist, pic=False, send_all=True) elif action == 'post': owner_id, playlist_id, access_key = obj_id.split('_') playlist = await vk_api.get_playlist(owner_id, playlist_id, access_key) await methods.send_playlist(-1001171972924, playlist, pic=True, send_all=True)
async def soundcloud_playlist(callback): await callback.answer() _, obj_id, method = parse_callback(callback.data) playlist = await soundcloud_api.get_playlist(obj_id) if method == 'send': return await methods.send_playlist(callback.message.chat.id, playlist) elif method == 'download': return await methods.send_playlist(callback.message.chat.id, playlist, pic=False, send_all=True) elif method == 'post': return await methods.send_playlist(-1001171972924, playlist, send_all=True)
async def pages_handler(callback): await callback.answer() mode, page = parse_callback(callback.data) q = callback.message.text[:-1] with suppress(exceptions.MessageNotModified): if mode == 'page': search_results = await deezer_api.search(q=q) await bot.edit_message_reply_markup( chat_id=callback.message.chat.id, message_id=callback.message.message_id, reply_markup=inline_keyboards.search_results_keyboard( search_results, int(page))) elif mode == 'sc_page': search_results = await soundcloud_api.search(q=q) await bot.edit_message_reply_markup( chat_id=callback.message.chat.id, message_id=callback.message.message_id, reply_markup=sc_keyboards.sc_search_results_keyboard( search_results, int(page)))
async def pages_handler(callback): mode, page = parse_callback(callback.data) q = callback.message.text[:-1] await callback.answer() if mode == 'page': search_results = await deezer_api.search(q=q) keyboard = dz_keyboards.search_results_keyboard( search_results, int(page), 7) elif mode == 'sc_page': await callback.answer() search_results = await soundcloud_api.search(q=q) keyboard = sc_keyboards.search_results_keyboard( search_results, int(page), 7) elif mode == 'vk_page': await callback.answer() search_results = await vk_api.search(q) keyboard = vk_keyboards.search_results_keyboard( search_results, int(page), 7) with suppress(exceptions.MessageNotModified): return await bot.edit_message_reply_markup( chat_id=callback.message.chat.id, message_id=callback.message.message_id, reply_markup=keyboard)
async def vk_track(callback): await query_answer(callback) _, obj_id, action = parse_callback(callback.data) track_id = callback.data.split(':')[1] track = await vk_api.get_track(track_id) await methods.send_track(callback.message.chat.id, track)
async def vk_profile_audio(callback): await query_answer(callback) _, profile_id, page = parse_callback(callback.data) tracks = await vk_api.get_audio(profile_id) return await callback.message.edit_reply_markup( keyboards.profile_keyboard(tracks, profile_id, int(page)))