Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@

import logging
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, ContextTypes
import yt_dlp

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
return 'Hello, World!'
def hello():
return "Hello world"

logging.basicConfig(level=logging.INFO)

BOT_TOKEN = "8414363077:AAFiflBPXEBqI08IlsHhfcvuhiHwrbaCZ2Q"

async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("Send me a video page URL, and I will extract video URLs for you (no downloading).")

async def handle_url(update: Update, context: ContextTypes.DEFAULT_TYPE):
url = update.message.text.strip()
await update.message.reply_text("Extracting video URLs. Please wait...")

ydl_opts = {
'quiet': True,
'skip_download': True,
'no_warnings': True,
}

try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
formats = info.get('formats', [])
urls = [f['url'] for f in formats if f.get('url')]
if urls:
response = "Found video URLs:\n" + "\n".join(urls[:10]) # limiting to first 10 URLs
else:
response = "No video URLs found."
except Exception as e:
response = f"Error occurred: {e}"

await update.message.reply_text(response)


def main():
app = ApplicationBuilder().token(BOT_TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_url))
print("Bot is polling...")
app.run_polling()


if __name__ == '__main__':
main()
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Flask
Gunicorn
python-telegram-bot
yt-dlp
gunicorn