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 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 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 send_track(chat_id, track): if not already_downloading(track.full_id): var.downloading[track.full_id] = int(time()) else: return file_id = await db_utils.get_vk_track(track.full_id) if file_id: return await bot.send_audio(chat_id, file_id) return await var.session.post('http://localhost:8082/vk/send.track', json={ 'track': track.data, 'chat_id': chat_id })
async def send_track(chat_id, track, Redownload=False): quality = await db_utils.get_quality_setting(chat_id) if not already_downloading(track.id): var.downloading[track.id] = int(time()) else: return if not Redownload: file_id = await db_utils.get_track(track.id, quality) if file_id: await bot.send_audio(chat_id, file_id) var.downloading.pop(track.id) sent_message_logger.info( f'[send track {track.id} to {chat_id}] {track}') return True try: if quality == 'mp3': path = await track.download('MP3_320') elif quality == 'flac': path = await track.download('FLAC') asyncio.create_task(delete_later(path)) except ValueError as e: print(e) await bot.send_message( chat_id, ("🚫This track is not available " f"({track.artist.name} - {track.title})")) raise await bot.send_chat_action(chat_id, 'upload_audio') thumb = await track.get_thumb() if os.path.getsize(path) >> 20 < 49: msg = await bot.send_audio( chat_id=-1001246220493, audio=InputFile(path), thumb=InputFile(thumb), performer=track.artist.name, title=track.title, duration=track.duration) file_id = msg.audio.file_id await db_utils.add_track(track.id, file_id, quality) else: file_id = await post_large_track(path, track, quality, thumb=thumb) await bot.send_audio(chat_id, file_id) shutil.rmtree(path.rsplit('/', 1)[0]) var.downloading.pop(track.id) sent_message_logger.info( f'[send track {track.id} to {chat_id}] {track}') return True
async def send_track(chat_id, track, Redownload=False): quality = await db_utils.get_quality_setting(chat_id) if not already_downloading(track.id): var.downloading[track.id] = int(time()) else: return if not Redownload: file_id = await db_utils.get_track(track.id, quality) if file_id: await bot.send_audio(chat_id, file_id) var.downloading.pop(track.id) sent_message_logger.info( f'[send track {track.id} to {chat_id}] {track}') return True try: if quality == 'mp3': track_file = await track.download('MP3_320') elif quality == 'flac': track_file = await track.download('FLAC') filename = f"{track.artist.name} - {track.title}.{quality}".replace( '/', '_') except ValueError as e: print(e) await bot.send_message(chat_id, ("🚫This track is not available " f"({track.artist.name} - {track.title})")) raise await bot.send_chat_action(chat_id, 'upload_audio') thumb = await track.get_thumb() if thumb: thumb = BytesIO(thumb) msg = await bot.send_audio(chat_id=-1001246220493, audio=InputFile(track_file, filename=filename), thumb=InputFile(thumb, filename='thumb.jpg'), performer=track.artist.name, title=track.title, duration=track.duration) file_id = msg.audio.file_id await db_utils.add_track(track.id, file_id, quality) await bot.send_audio(chat_id, file_id) var.downloading.pop(track.id) sent_message_logger.info(f'[send track {track.id} to {chat_id}] {track}') return True
async def send_track(track, chat, Redownload=False): quality = await db_utils.get_quality_setting(chat.id) if not already_downloading(track.id): var.downloading[track.id] = int(time()) else: return if not Redownload: if (await check_and_forward(track, chat, quality)): return if quality == 'mp3': path = await track.download('MP3_320') elif quality == 'flac': path = await track.download('FLAC') await bot.send_chat_action(chat.id, 'upload_audio') if (os.path.getsize(path) >> 20) > 50: msg = await bot.send_message( chat_id=chat.id, text= 'File is larger than 50 MB, uploading can take a while, please wait' ) await post_large_track(path, track, quality) await sleep(1) file_id = await db_utils.get_track(track.id, quality) await bot.send_audio(chat.id, file_id) await msg.delete() else: msg = await upload_track(track, path) await msg.forward(chat.id) await db_utils.add_track(track.id, msg.audio.file_id, quality) shutil.rmtree(path.rsplit('/', 1)[0]) var.downloading.pop(track.id) sent_message_logger.info( f'[send track {track.id} to {format_name(chat)}] {track}')
async def track_handler(message): track = await deezer_api.gettrack(message.text.split('/')[-1]) if utils.already_downloading(track.id): return await methods.send_track(track, message.chat) db_utils.add_user(message.from_user)
async def track_handler(message, track_id): track = await deezer_api.gettrack(track_id) if utils.already_downloading(track.id): return await methods.send_track(message.chat.id, track) db_utils.add_user(message.from_user)