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
|
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
|
# Usage
|
||||||
|
|
||||||
python main.py
|
python main.py
|
||||||
|
|||||||
14
index.html
14
index.html
@ -15,11 +15,14 @@
|
|||||||
.container {
|
.container {
|
||||||
margin-top: 50px;
|
margin-top: 50px;
|
||||||
}
|
}
|
||||||
input[type="url"] {
|
input[type="url"], select {
|
||||||
width: 80%;
|
width: 80%;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
}
|
}
|
||||||
|
select {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
button {
|
button {
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
background-color: #ff0000;
|
background-color: #ff0000;
|
||||||
@ -42,7 +45,11 @@
|
|||||||
<h1>YouTube Video Downloader</h1>
|
<h1>YouTube Video Downloader</h1>
|
||||||
<form id="downloadForm">
|
<form id="downloadForm">
|
||||||
<input type="url" id="videoUrl" placeholder="Enter YouTube URL" required>
|
<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>
|
</form>
|
||||||
<div id="status"></div>
|
<div id="status"></div>
|
||||||
</div>
|
</div>
|
||||||
@ -51,11 +58,12 @@
|
|||||||
document.getElementById('downloadForm').addEventListener('submit', function(e) {
|
document.getElementById('downloadForm').addEventListener('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const url = document.getElementById('videoUrl').value;
|
const url = document.getElementById('videoUrl').value;
|
||||||
|
const downloadType = document.getElementById('downloadType').value;
|
||||||
const status = document.getElementById('status');
|
const status = document.getElementById('status');
|
||||||
|
|
||||||
status.textContent = 'Starting download...';
|
status.textContent = 'Starting download...';
|
||||||
|
|
||||||
fetch('http://localhost:5000/download?url=' + encodeURIComponent(url))
|
fetch(`http://localhost:5000/download?url=${encodeURIComponent(url)}&type=${downloadType}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return response.text().then(text => {
|
return response.text().then(text => {
|
||||||
|
|||||||
27
main.py
27
main.py
@ -14,23 +14,40 @@ def index():
|
|||||||
def download_video():
|
def download_video():
|
||||||
try:
|
try:
|
||||||
video_url = request.args.get('url')
|
video_url = request.args.get('url')
|
||||||
|
download_type = request.args.get('type', 'video') # Default to video if not specified
|
||||||
|
|
||||||
if not video_url:
|
if not video_url:
|
||||||
return "Please provide a YouTube URL", 400
|
return "Please provide a YouTube URL", 400
|
||||||
|
|
||||||
# Configure yt-dlp options
|
# Configure yt-dlp options based on download type
|
||||||
|
if download_type == 'audio':
|
||||||
|
try:
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format': 'best', # Download best quality
|
'format': 'bestaudio/best',
|
||||||
'outtmpl': '%(title)s.%(ext)s', # Output template - download to current directory
|
'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:
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||||
info = ydl.extract_info(video_url, download=True)
|
info = ydl.extract_info(video_url, download=True)
|
||||||
|
|
||||||
return "Download completed", 200
|
return "Download completed", 200
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {str(e)}") # Add this for debugging
|
print(f"Error: {str(e)}")
|
||||||
return str(e), 500
|
return str(e), 500
|
||||||
|
|
||||||
@app.route('/ping')
|
@app.route('/ping')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user