Download main.py from Manhal-1/README: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/spaces/Manhal-1/README/resolve/main/main.py
- Command line
-
hf download hf://spaces/Manhal-1/README/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Manhal-1/README/resolve/main/main.py
1.61 kB
| from flask import Flask, request, jsonify | |
| import yt_dlp | |
| import os | |
| app = Flask(__name__) | |
| def home(): | |
| return "Manhal API with Cookies is Running!" | |
| 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) |