Telegram Bot Download Youtube Playlist ~repack~ [WORKING]

def main(): os.makedirs("downloads", exist_ok=True) app = Application.builder().token(BOT_TOKEN).build() app.add_handler(CommandHandler("start", start)) app.add_handler(CommandHandler("video", video)) app.add_handler(CommandHandler("audio", audio)) app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, playlist_link)) app.run_polling()

for file in sorted(os.listdir(folder)): file_path = os.path.join(folder, file) if os.path.isfile(file_path): with open(file_path, 'rb') as f: await update.message.reply_document(f, filename=file) os.remove(file_path) os.rmdir(folder) await update.message.reply_text("✅ All files sent and cleaned up.") telegram bot download youtube playlist

async def download_playlist(update: Update, context: ContextTypes.DEFAULT_TYPE, mode='video'): url = context.user_data.get('playlist_url') if not url: await update.message.reply_text("❌ Send a playlist link first.") return def main(): os

opts = VIDEO_OPTS if mode == 'video' else AUDIO_OPTS await update.message.reply_text(f"⏳ Downloading mode playlist... This may take a while.") def main(): os.makedirs("downloads"

try: with yt_dlp.YoutubeDL(opts) as ydl: info = ydl.extract_info(url, download=True) playlist_title = info.get('playlist_title', 'playlist') folder = f"downloads/playlist_title"

except Exception as e: await update.message.reply_text(f"❌ Error: str(e)") async def video(update: Update, context: ContextTypes.DEFAULT_TYPE): await download_playlist(update, context, 'video')

async def audio(update: Update, context: ContextTypes.DEFAULT_TYPE): await download_playlist(update, context, 'audio')