ssiisnsksksnsjsksk commited on
Commit
1954490
·
verified ·
1 Parent(s): 0116377

Upload 3 files

Browse files
Files changed (3) hide show
  1. requirements.txt +2 -0
  2. srv.py +91 -0
  3. www.youtube.com_cookies.txt +13 -0
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ flask
2
+ yt-dlp
srv.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify, send_file, render_template
2
+ from yt_dlp import YoutubeDL
3
+ import os
4
+
5
+ app = Flask(__name__)
6
+
7
+ @app.route('/')
8
+ def home():
9
+ return render_template('index.html')
10
+
11
+ @app.route('/get-info', methods=['POST'])
12
+ def get_info():
13
+ data = request.json
14
+ url = data.get('url')
15
+
16
+ if not url:
17
+ return jsonify({'error': 'URL is required'}), 400
18
+
19
+ try:
20
+ with YoutubeDL() as ydl:
21
+ info = ydl.extract_info(url, download=False)
22
+ formats = [
23
+ {
24
+ "format_id": f["format_id"],
25
+ "ext": f["ext"],
26
+ "resolution": f.get("resolution", "Unknown"),
27
+ "filesize": f.get("filesize", "Unknown")
28
+ }
29
+ for f in info.get('formats', [])
30
+ ]
31
+ return jsonify({
32
+ 'title': info['title'],
33
+ 'thumbnail': info.get('thumbnail'),
34
+ 'duration': info.get('duration'),
35
+ 'channel': info.get('channel'),
36
+ 'formats': formats # Send available formats
37
+ })
38
+
39
+ except Exception as e:
40
+ return jsonify({'error': str(e)}), 500
41
+
42
+ @app.route('/download', methods=['POST'])
43
+ def download_media():
44
+ data = request.json
45
+ url = data.get('url')
46
+ format_id = data.get('format_id') # User-defined format ID
47
+ media_type = data.get('type', 'mp4') # Default type: MP4
48
+
49
+ if not url:
50
+ return jsonify({'error': 'URL is required'}), 400
51
+
52
+ try:
53
+ if media_type == 'mp3':
54
+ ydl_opts = {
55
+ 'format': 'bestaudio',
56
+ 'outtmpl': '%(title)s.%(ext)s',
57
+ 'cookiefile': 'www.youtube.com_cookies.txt',
58
+ 'postprocessors': [{
59
+ 'key': 'FFmpegExtractAudio',
60
+ 'preferredcodec': 'mp3',
61
+ 'preferredquality': '128',
62
+ }],
63
+ }
64
+ file_ext = "mp3"
65
+ else:
66
+ ydl_opts = {
67
+ 'format': format_id if format_id else 'bestvideo+bestaudio/best',
68
+ 'outtmpl': '%(title)s.%(ext)s',
69
+ 'cookiefile': 'www.youtube.com_cookies.txt'
70
+ }
71
+ file_ext = "mp4"
72
+
73
+ with YoutubeDL(ydl_opts) as ydl:
74
+ info = ydl.extract_info(url, download=True)
75
+ file_name = ydl.prepare_filename(info).rsplit(".", 1)[0] + f".{file_ext}"
76
+
77
+ return send_file(
78
+ file_name,
79
+ as_attachment=True,
80
+ download_name=os.path.basename(file_name)
81
+ )
82
+
83
+ except Exception as e:
84
+ return jsonify({'error': str(e)}), 500
85
+
86
+ finally:
87
+ if 'file_name' in locals() and os.path.exists(file_name):
88
+ os.remove(file_name)
89
+
90
+ if __name__ == '__main__':
91
+ app.run(host='0.0.0.0', port=7860, debug=True)
www.youtube.com_cookies.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Netscape HTTP Cookie File
2
+ # http://curl.haxx.se/rfc/cookie_spec.html
3
+ # This file was generated by Cookie-Editor
4
+ #HttpOnly_.youtube.com TRUE / TRUE 1754736586 VISITOR_PRIVACY_METADATA CgJJRBIEGgAgYw%3D%3D
5
+ #HttpOnly_.youtube.com TRUE / TRUE 1769995034 __Secure-3PSID g.a000rwhSzA2RD0-bMwGPFIaTjX1-EoQZ_oTsCkvkTFXufiMR46hWqEiosD4JorjK9ZI-Zu5EfgACgYKAe0SARYSFQHGX2MivSsTolX9V9hHSGDkV_cgnhoVAUF8yKprbxk1JW13kVufGChUNpFb0076
6
+ #HttpOnly_.youtube.com TRUE / TRUE 1739271025 YSC ZObMIoHyd84
7
+ #HttpOnly_.youtube.com TRUE / TRUE 1766971034 __Secure-1PSIDTS sidts-CjEB7wV3sbDAOW8ujWkdA51M5Ftyi8u23Dj3bFW-zyHgFZ2NGpZDBpyt12nwDb0UfelgEAA
8
+ .youtube.com TRUE / TRUE 1769995034 __Secure-3PAPISID VK_9id4M31HRxkhQ/AI2Tehi52SzX-GALS
9
+ #HttpOnly_.youtube.com TRUE / TRUE 1770720601 __Secure-3PSIDCC AKEyXzVgFG3r_LxXXrzqj3opxeIC_My9w6IN7dL3jVc5PPQ5xNAAdUlhFGKCgfiORSdq5HMY
10
+ #HttpOnly_.youtube.com TRUE / TRUE 1766971034 __Secure-3PSIDTS sidts-CjEB7wV3sbDAOW8ujWkdA51M5Ftyi8u23Dj3bFW-zyHgFZ2NGpZDBpyt12nwDb0UfelgEAA
11
+ #HttpOnly_.youtube.com TRUE / TRUE 1769995034 LOGIN_INFO AFmmF2swRAIgVgAqg2ZplXhG9tY-8MB4inM0eu8NoaT6wTkwncKcJRUCIBp6pnf7nY6-AHbw7Vz9k-5gnunocZgIsxK7c_z_PBku:QUQ3MjNmeG5veVd2WHkyeGx4VGxGTGxKaTJnUi1ENlEzeXkyak8zSVJvZ0taSXBWamo1bE1tQ0p0ajVjaHNIa05fVFRGLXkyY0tMSnpZcmNwVEtsUlNsS1lHRjFDMzFTYXpBVFdzSkpBbUFZOGFtMndBblBGeUlNMWh6RU02UXU4cWNRaVdOMFFITTg5VTRzR2ZQR0dzQ0twMHZEMTRMMm1n
12
+ .youtube.com TRUE / TRUE 1773744589 PREF f6=40000000&tz=Asia.Jakarta
13
+ #HttpOnly_.youtube.com TRUE / TRUE 1754736586 VISITOR_INFO1_LIVE 04VB-2Wh0ig