YouTube / app.py
Akwbw's picture
Update app.py
9e0629c verified
from flask import Flask, request, jsonify
from flask_cors import CORS
import yt_dlp
import os
app = Flask(__name__)
CORS(app) # Taakay koi bhi website isay call kar sakay
@app.route('/')
def home():
return "Gm gpt API is Running!"
@app.route('/api/download', methods=['GET'])
def download():
video_url = request.args.get('url')
if not video_url:
return jsonify({"error": "URL missing"}), 400
try:
ydl_opts = {
'format': 'best',
'quiet': True,
'no_warnings': True,
'noplaylist': True,
'source_address': '0.0.0.0', # Force IPv4 (Fixes Errno -5)
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36'
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(video_url, download=False)
return jsonify({
"status": "success",
"title": info.get('title'),
"thumbnail": info.get('thumbnail'),
"download_url": info.get('url')
})
except Exception as e:
return jsonify({"status": "error", "message": str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860)