Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- Dockerfile +29 -0
- requirements.txt +2 -0
- srv.py +101 -0
- www.youtube.com_cookies.txt +13 -0
Dockerfile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# Install required system packages
|
| 6 |
+
RUN apt-get update && apt-get install -y ffmpeg
|
| 7 |
+
|
| 8 |
+
# Create a non-root user
|
| 9 |
+
RUN useradd -m -u 1000 appuser
|
| 10 |
+
|
| 11 |
+
# Copy requirements and install Python packages
|
| 12 |
+
COPY requirements.txt .
|
| 13 |
+
RUN pip install -r requirements.txt
|
| 14 |
+
|
| 15 |
+
# Copy the application files
|
| 16 |
+
COPY . .
|
| 17 |
+
|
| 18 |
+
# Set permissions for all files and directories
|
| 19 |
+
RUN find /app -type f -exec chmod 644 {} \; && \
|
| 20 |
+
find /app -type d -exec chmod 755 {} \; && \
|
| 21 |
+
chmod 644 www.youtube.com_cookies.txt && \
|
| 22 |
+
chown -R appuser:appuser /app
|
| 23 |
+
|
| 24 |
+
# Switch to non-root user
|
| 25 |
+
USER appuser
|
| 26 |
+
|
| 27 |
+
EXPOSE 7860
|
| 28 |
+
|
| 29 |
+
CMD ["python", "srv.py"]
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
yt-dlp
|
srv.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
ydl_opts = {
|
| 21 |
+
'cookiefile': 'www.youtube.com_cookies.txt'
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
with YoutubeDL(ydl_opts) as ydl:
|
| 25 |
+
info = ydl.extract_info(url, download=False)
|
| 26 |
+
return jsonify({
|
| 27 |
+
'title': info['title'],
|
| 28 |
+
'thumbnail': info.get('thumbnail'),
|
| 29 |
+
'duration': info.get('duration'),
|
| 30 |
+
'channel': info.get('channel')
|
| 31 |
+
})
|
| 32 |
+
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return jsonify({'error': str(e)}), 500
|
| 35 |
+
|
| 36 |
+
@app.route('/download', methods=['POST'])
|
| 37 |
+
def download():
|
| 38 |
+
data = request.json
|
| 39 |
+
url = data.get('url')
|
| 40 |
+
format_type = data.get('format', 'mp3')
|
| 41 |
+
quality = data.get('quality', 'best')
|
| 42 |
+
|
| 43 |
+
if not url:
|
| 44 |
+
return jsonify({'error': 'URL is required'}), 400
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
if format_type == 'mp3':
|
| 48 |
+
ydl_opts = {
|
| 49 |
+
'format': 'bestaudio/best',
|
| 50 |
+
'outtmpl': '%(title)s.%(ext)s',
|
| 51 |
+
'cookiefile': 'www.youtube.com_cookies.txt',
|
| 52 |
+
'postprocessors': [{
|
| 53 |
+
'key': 'FFmpegExtractAudio',
|
| 54 |
+
'preferredcodec': 'mp3',
|
| 55 |
+
'preferredquality': '192',
|
| 56 |
+
}],
|
| 57 |
+
}
|
| 58 |
+
else:
|
| 59 |
+
quality_map = {
|
| 60 |
+
'144': 'bv*[height=144][ext=mp4]+ba[ext=m4a]/b[height=144][ext=mp4]',
|
| 61 |
+
'240': 'bv*[height=240][ext=mp4]+ba[ext=m4a]/b[height=240][ext=mp4]',
|
| 62 |
+
'360': 'bv*[height=360][ext=mp4]+ba[ext=m4a]/b[height=360][ext=mp4]',
|
| 63 |
+
'480': 'bv*[height=480][ext=mp4]+ba[ext=m4a]/b[height=480][ext=mp4]',
|
| 64 |
+
'720': 'bv*[height=720][ext=mp4]+ba[ext=m4a]/b[height=720][ext=mp4]',
|
| 65 |
+
'1080': 'bv*[height=1080][ext=mp4]+ba[ext=m4a]/b[height=1080][ext=mp4]',
|
| 66 |
+
'best': 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]'
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
selected_quality = quality_map.get(quality, quality_map['best'])
|
| 70 |
+
|
| 71 |
+
ydl_opts = {
|
| 72 |
+
'format': selected_quality,
|
| 73 |
+
'outtmpl': '%(title)s.%(ext)s',
|
| 74 |
+
'merge_output_format': 'mp4',
|
| 75 |
+
'cookiefile': 'www.youtube.com_cookies.txt',
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
with YoutubeDL(ydl_opts) as ydl:
|
| 79 |
+
info = ydl.extract_info(url, download=True)
|
| 80 |
+
|
| 81 |
+
if format_type == 'mp3':
|
| 82 |
+
file_name = ydl.prepare_filename(info).rsplit(".", 1)[0] + ".mp3"
|
| 83 |
+
else:
|
| 84 |
+
file_name = ydl.prepare_filename(info)
|
| 85 |
+
|
| 86 |
+
return send_file(
|
| 87 |
+
file_name,
|
| 88 |
+
as_attachment=True,
|
| 89 |
+
download_name=os.path.basename(file_name),
|
| 90 |
+
mimetype='video/mp4' if format_type == 'mp4' else 'audio/mp3'
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
except Exception as e:
|
| 94 |
+
return jsonify({'error': str(e)}), 500
|
| 95 |
+
|
| 96 |
+
finally:
|
| 97 |
+
if 'file_name' in locals() and os.path.exists(file_name):
|
| 98 |
+
os.remove(file_name)
|
| 99 |
+
|
| 100 |
+
if __name__ == '__main__':
|
| 101 |
+
app.run(host='0.0.0.0', port=7860, debug=True,threaded=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
|