Spaces:
Runtime error
Runtime error
Arifzyn19
commited on
Commit
·
db25fa4
1
Parent(s):
65559ba
Add application file
Browse files- app.py +66 -0
- requirements.txt +2 -0
- www.youtube.com_cookies.txt +22 -0
app.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify, send_file
|
2 |
+
from yt_dlp import YoutubeDL
|
3 |
+
import os
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
# Endpoint untuk mendapatkan daftar format video/audio
|
8 |
+
@app.route('/formats', methods=['POST'])
|
9 |
+
def get_formats():
|
10 |
+
data = request.json
|
11 |
+
url = data.get('url')
|
12 |
+
|
13 |
+
if not url:
|
14 |
+
return jsonify({'error': 'URL is required'}), 400
|
15 |
+
|
16 |
+
try:
|
17 |
+
with YoutubeDL({'listformats': True}) as ydl:
|
18 |
+
info = ydl.extract_info(url, download=False)
|
19 |
+
formats = [{
|
20 |
+
'format_id': f['format_id'],
|
21 |
+
'format_note': f.get('format_note', 'N/A'),
|
22 |
+
'ext': f['ext'],
|
23 |
+
'filesize': f.get('filesize'),
|
24 |
+
'resolution': f.get('resolution', 'audio only'),
|
25 |
+
} for f in info['formats']]
|
26 |
+
|
27 |
+
return jsonify({'title': info['title'], 'formats': formats})
|
28 |
+
|
29 |
+
except Exception as e:
|
30 |
+
return jsonify({'error': str(e)}), 500
|
31 |
+
|
32 |
+
# Endpoint untuk mendownload video atau audio
|
33 |
+
@app.route('/download', methods=['POST'])
|
34 |
+
def download_file():
|
35 |
+
data = request.json
|
36 |
+
url = data.get('url')
|
37 |
+
format_id = data.get('format_id')
|
38 |
+
|
39 |
+
if not url or not format_id:
|
40 |
+
return jsonify({'error': 'URL and format_id are required'}), 400
|
41 |
+
|
42 |
+
try:
|
43 |
+
# Konfigurasi yt-dlp
|
44 |
+
ydl_opts = {
|
45 |
+
'format': format_id,
|
46 |
+
'outtmpl': '%(title)s.%(ext)s',
|
47 |
+
'cookiefile': 'www.youtube.com_cookies.txt' # Jika dibutuhkan
|
48 |
+
}
|
49 |
+
|
50 |
+
with YoutubeDL(ydl_opts) as ydl:
|
51 |
+
info = ydl.extract_info(url, download=True)
|
52 |
+
file_name = ydl.prepare_filename(info)
|
53 |
+
|
54 |
+
# Kirim file ke client
|
55 |
+
return send_file(file_name, as_attachment=True)
|
56 |
+
|
57 |
+
except Exception as e:
|
58 |
+
return jsonify({'error': str(e)}), 500
|
59 |
+
|
60 |
+
finally:
|
61 |
+
# Bersihkan file setelah dikirim
|
62 |
+
if os.path.exists(file_name):
|
63 |
+
os.remove(file_name)
|
64 |
+
|
65 |
+
if __name__ == '__main__':
|
66 |
+
app.run(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
flask
|
2 |
+
yt-dlp
|
www.youtube.com_cookies.txt
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Netscape HTTP Cookie File
|
2 |
+
# This file is generated by yt-dlp. Do not edit.
|
3 |
+
|
4 |
+
.youtube.com TRUE / FALSE 1769653894 APISID hgFxa9YoCI8017FM/AHEveI3Rkpf7goUZE
|
5 |
+
.youtube.com TRUE / FALSE 1769653894 HSID AM8JCxl963E3A16gz
|
6 |
+
.youtube.com TRUE / TRUE 1739133241 LOGIN_INFO AFmmF2swRQIgSUgOHMt6Fp6qgrSNHqGu3qyoIq8kxpbc4NN7TQ3xbOsCIQD_8aRx_RU8Tld4EgI42WrtLi3X3cGLIbrHUATBUKu1UQ:QUQ3MjNmejlYaW1SSWVPWUhDUGdTaTRMME1yR0lxMzRNbVFiUUhsNGpac3ZKTVVINWZyS1lDbTZMSlBwWDM1WjNpbUlYLTZVODN6VFotSDQ1eG8zdTN1a2Y5aWhsd3pQN0wzbU9zMTdrdEZpWEdZNC16OUdFdnd5b2pBUmJOc3RocnFVUGpKSG1hMmhqbWlMN2gzT2VXQ1ZPejJ4ZVRSa05B
|
7 |
+
.youtube.com TRUE / FALSE 0 PREF f7=4100&tz=UTC&hl=en
|
8 |
+
.youtube.com TRUE / TRUE 1769653894 SAPISID B24S3jX0kqW7TySF/AIKj1Jwq_znO1aTNQ
|
9 |
+
.youtube.com TRUE / FALSE 1769653894 SID g.a000rgiWK_2t5pA98D-xnBAqWGAUK4CQ6tx5T9XARKIOdY5Xbs6rYTIkjGSA8DaaZEaIGvcVnQACgYKASgSARcSFQHGX2MiganIF13U84Tm9vn218Q30hoVAUF8yKpYLn4uPiEEBn1VFqykxfyv0076
|
10 |
+
.youtube.com TRUE / FALSE 1766759427 SIDCC AKEyXzXTrolNIjS9xXUeeoM_js9kgamTCINKNGl12Ac2FSVUvjhklvKBdp50j9vqph1gyAf22-s
|
11 |
+
.youtube.com TRUE / TRUE 1769653894 SSID AyG8Gfzz0d-Px0BKO
|
12 |
+
.youtube.com TRUE / TRUE 1750775426 VISITOR_INFO1_LIVE f1WiKC29wlw
|
13 |
+
.youtube.com TRUE / TRUE 1750775426 VISITOR_PRIVACY_METADATA CgJJRBIEGgAgRA%3D%3D
|
14 |
+
.youtube.com TRUE / TRUE 0 YSC M1eMujXRP2k
|
15 |
+
.youtube.com TRUE / TRUE 1769653894 __Secure-1PAPISID B24S3jX0kqW7TySF/AIKj1Jwq_znO1aTNQ
|
16 |
+
.youtube.com TRUE / TRUE 1769653894 __Secure-1PSID g.a000rgiWK_2t5pA98D-xnBAqWGAUK4CQ6tx5T9XARKIOdY5Xbs6rgxsJ5xL8ND3ke7_tg83iGwACgYKAR0SARcSFQHGX2MibvE5yBaIeCUkZrC9GHcjhBoVAUF8yKryqB2bxNzzvcsdYmyBvtWs0076
|
17 |
+
.youtube.com TRUE / TRUE 1766759427 __Secure-1PSIDCC AKEyXzX_L14BISjsCJ_b28CRSDQp8vE1iQml2dozFuWj93h3g0cXWNcClI_b7OOEOfSRc3cuJQ
|
18 |
+
.youtube.com TRUE / TRUE 1766757505 __Secure-1PSIDTS sidts-CjEB7wV3sYYeY62tfLNGNFHtVxJ-tkuKgD7j0kMeNUct3LDpLYUsD0NDxQYZZyLKy3DVEAA
|
19 |
+
.youtube.com TRUE / TRUE 1769653894 __Secure-3PAPISID B24S3jX0kqW7TySF/AIKj1Jwq_znO1aTNQ
|
20 |
+
.youtube.com TRUE / TRUE 1769653894 __Secure-3PSID g.a000rgiWK_2t5pA98D-xnBAqWGAUK4CQ6tx5T9XARKIOdY5Xbs6rzkFXzSoKG3qUxhiK9NM3BgACgYKAfASARcSFQHGX2Mi2UnjcAQBAbxMFk_4a1v_XRoVAUF8yKqP6OtAq1mOZAA6kB9TuBHp0076
|
21 |
+
.youtube.com TRUE / TRUE 1766759427 __Secure-3PSIDCC AKEyXzVEsfkXRGpvWoQs-lcqChWc7vfe12s_xYg1XwR7YPvVIQCUMmInAdUo-eGjnW6lTDRWHw
|
22 |
+
.youtube.com TRUE / TRUE 1766757505 __Secure-3PSIDTS sidts-CjEB7wV3sYYeY62tfLNGNFHtVxJ-tkuKgD7j0kMeNUct3LDpLYUsD0NDxQYZZyLKy3DVEAA
|