diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3232871 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +ffmpeg.exe +ffplay.exe +ffprobe.exe diff --git a/README.md b/README.md index 04992fd..98a1096 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ Basic self hosted, private YouTube downloader client pip install -r requirements.txt +# (Optional for audio-only downloads) Install ffmpeg + +https://ffmpeg.org/download.html # Download to this directory or add to PATH + # Usage python main.py diff --git a/index.html b/index.html index b06739d..a059f66 100644 --- a/index.html +++ b/index.html @@ -15,11 +15,14 @@ .container { margin-top: 50px; } - input[type="url"] { + input[type="url"], select { width: 80%; padding: 10px; margin: 10px 0; } + select { + width: auto; + } button { padding: 10px 20px; background-color: #ff0000; @@ -42,7 +45,11 @@

YouTube Video Downloader

- + +
@@ -51,11 +58,12 @@ document.getElementById('downloadForm').addEventListener('submit', function(e) { e.preventDefault(); const url = document.getElementById('videoUrl').value; + const downloadType = document.getElementById('downloadType').value; const status = document.getElementById('status'); status.textContent = 'Starting download...'; - fetch('http://localhost:5000/download?url=' + encodeURIComponent(url)) + fetch(`http://localhost:5000/download?url=${encodeURIComponent(url)}&type=${downloadType}`) .then(response => { if (!response.ok) { return response.text().then(text => { diff --git a/main.py b/main.py index c65d553..60129bf 100644 --- a/main.py +++ b/main.py @@ -14,23 +14,40 @@ def index(): def download_video(): try: video_url = request.args.get('url') + download_type = request.args.get('type', 'video') # Default to video if not specified + if not video_url: return "Please provide a YouTube URL", 400 - # Configure yt-dlp options - ydl_opts = { - 'format': 'best', # Download best quality - 'outtmpl': '%(title)s.%(ext)s', # Output template - download to current directory - } + # Configure yt-dlp options based on download type + if download_type == 'audio': + try: + ydl_opts = { + 'format': 'bestaudio/best', + 'postprocessors': [{ + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'mp3', + 'preferredquality': '192', + }], + 'outtmpl': '%(title)s.%(ext)s', + } + except Exception as e: + print(f"Error: {str(e)}") + return str(e), 500 + else: # video + ydl_opts = { + 'format': 'best', + 'outtmpl': '%(title)s.%(ext)s', + } - # Download the video + # Download the video/audio with yt_dlp.YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(video_url, download=True) return "Download completed", 200 except Exception as e: - print(f"Error: {str(e)}") # Add this for debugging + print(f"Error: {str(e)}") return str(e), 500 @app.route('/ping')