File size: 1,607 Bytes
91cad35 10d81e6 91cad35 7cc5d2b 91cad35 4bc0853 7cc5d2b 10d81e6 7cc5d2b 91cad35 7cc5d2b 91cad35 10d81e6 91cad35 7cc5d2b 91cad35 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | from flask import Flask, request, jsonify
import yt_dlp
import os
app = Flask(__name__)
@app.route('/')
def home():
return "Manhal API with Cookies is Running!"
@app.route('/get_link', methods=['GET'])
def get_link():
url = request.args.get('url')
if not url:
return jsonify({"error": "No URL provided"}), 400
# الإعدادات التي تدمج الكوكيز مع نظام الأندرويد لتجاوز الحظر تماماً
ydl_opts = {
'format': 'best',
'quiet': True,
'no_warnings': True,
'cachedir': False,
'nocheckcertificate': True,
'cookiefile': 'cookies.txt', # <--- هذا هو السطر الأهم الذي يربط الملف بالكود
'extractor_args': {
'youtube': {
'player_client': ['android'],
'player_skip': ['webpage'],
}
},
'user_agent': 'com.google.android.youtube/19.12.35 (Linux; U; Android 14) gzip',
}
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
return jsonify({
"title": info.get('title'),
"download_url": info.get('url'),
"thumbnail": info.get('thumbnail'),
"duration": info.get('duration')
})
except Exception as e:
# إذا ظهر خطأ، سيخبرنا السيرفر بالسبب بدقة في الـ Logs
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860) |