Add ffmpeg executables and update project structure
This commit is contained in:
parent
145fcd3b55
commit
51a214d03a
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
ffmpeg.exe
|
||||
ffplay.exe
|
||||
ffprobe.exe
|
||||
@ -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
|
||||
|
||||
14
index.html
14
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 @@
|
||||
<h1>YouTube Video Downloader</h1>
|
||||
<form id="downloadForm">
|
||||
<input type="url" id="videoUrl" placeholder="Enter YouTube URL" required>
|
||||
<button type="submit">Download Video</button>
|
||||
<select id="downloadType">
|
||||
<option value="video">Video</option>
|
||||
<option value="audio">Audio (MP3)</option>
|
||||
</select>
|
||||
<button type="submit">Download</button>
|
||||
</form>
|
||||
<div id="status"></div>
|
||||
</div>
|
||||
@ -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 => {
|
||||
|
||||
31
main.py
31
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')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user