Akwbw commited on
Commit
abd4c62
·
verified ·
1 Parent(s): c6ebdae

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import yt_dlp
3
+ import os
4
+
5
+ app = Flask(__name__)
6
+
7
+ @app.route('/')
8
+ def home():
9
+ return "Gm gpt API is Running! Use /api/download?url=YOUR_URL"
10
+
11
+ @app.route('/api/download', methods=['GET'])
12
+ def download():
13
+ video_url = request.args.get('url')
14
+ if not video_url:
15
+ return jsonify({"error": "URL parameter is missing"}), 400
16
+
17
+ try:
18
+ # yt-dlp settings
19
+ ydl_opts = {
20
+ 'format': 'best',
21
+ 'quiet': True,
22
+ 'no_warnings': True,
23
+ 'noplaylist': True,
24
+ }
25
+
26
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
27
+ info = ydl.extract_info(video_url, download=False)
28
+
29
+ # Direct download link nikalna
30
+ download_link = info.get('url')
31
+ title = info.get('title')
32
+ thumbnail = info.get('thumbnail')
33
+ duration = info.get('duration')
34
+
35
+ return jsonify({
36
+ "status": "success",
37
+ "title": title,
38
+ "thumbnail": thumbnail,
39
+ "duration": f"{duration} seconds",
40
+ "download_url": download_link
41
+ })
42
+
43
+ except Exception as e:
44
+ return jsonify({"status": "error", "message": str(e)}), 500
45
+
46
+ if __name__ == '__main__':
47
+ # Hugging Face default port 7860 use karta hai
48
+ app.run(host='0.0.0.0', port=7860)