Comments and improved README
This commit is contained in:
parent
42214ad6a1
commit
938a60bf99
50
README.md
50
README.md
@ -1,20 +1,54 @@
|
|||||||
### YouTubeDownloader
|
# YouTube Downloader
|
||||||
|
|
||||||
Basic self hosted, private YouTube downloader client
|
A simple, self-hosted YouTube downloader that allows you to download videos and audio from YouTube. Built with Flask and yt-dlp.
|
||||||
|
|
||||||
### Installation
|
## Features
|
||||||
|
|
||||||
|
- 🎥 Download YouTube videos in best quality
|
||||||
|
- 🎵 Extract audio as MP3 files
|
||||||
|
- 🌐 Simple web interface
|
||||||
|
- 🏃♂️ Easy to set up and run
|
||||||
|
- 🔒 Private and self-hosted
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- Python 3.6+
|
||||||
|
- FFmpeg (required for audio downloads)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Clone the repository:
|
||||||
|
|
||||||
|
git clone https://gitea.patrolbuddygo.com/wesleyneuhaus/YouTubeDownloader.git
|
||||||
|
cd YouTubeDownloader
|
||||||
|
|
||||||
|
2. Install dependencies:
|
||||||
|
|
||||||
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
|
3. Install FFmpeg (required for audio downloads):
|
||||||
|
- Download from [FFmpeg's official website](https://ffmpeg.org/download.html)
|
||||||
|
- Either place the FFmpeg executable in the project directory or add it to your system PATH
|
||||||
|
|
||||||
### Usage
|
## Usage
|
||||||
|
|
||||||
|
1. Start the server:
|
||||||
|
|
||||||
python main.py
|
python main.py
|
||||||
# From here, simply open the HTML file in your browser.
|
|
||||||
|
|
||||||
### Update
|
2. Open your web browser and navigate to:
|
||||||
|
|
||||||
|
http://localhost:5000
|
||||||
|
|
||||||
|
|
||||||
|
3. Enter a YouTube URL and select your preferred download format (video or audio)
|
||||||
|
|
||||||
|
4. Click "Download" and wait for the process to complete
|
||||||
|
|
||||||
|
## Updating
|
||||||
|
|
||||||
|
To update to the latest version:
|
||||||
|
|
||||||
git pull
|
git pull
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|||||||
28
index.html
28
index.html
@ -1,10 +1,14 @@
|
|||||||
<!DOCTYPE html>
|
<!-- DOCTYPE html -->
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
<!-- head section -->
|
||||||
<head>
|
<head>
|
||||||
|
<!-- Character encoding and viewport meta tags -->
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>YouTube Video Downloader</title>
|
<title>YouTube Video Downloader</title>
|
||||||
|
<!-- CSS styles -->
|
||||||
<style>
|
<style>
|
||||||
|
/* Body styles */
|
||||||
body {
|
body {
|
||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
@ -12,17 +16,21 @@
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
/* Container spacing */
|
||||||
.container {
|
.container {
|
||||||
margin-top: 50px;
|
margin-top: 50px;
|
||||||
}
|
}
|
||||||
|
/* Input and select field styles */
|
||||||
input[type="url"], select {
|
input[type="url"], select {
|
||||||
width: 80%;
|
width: 80%;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
}
|
}
|
||||||
|
/* Select field width override */
|
||||||
select {
|
select {
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
/* Button styles */
|
||||||
button {
|
button {
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
background-color: #ff0000;
|
background-color: #ff0000;
|
||||||
@ -31,9 +39,11 @@
|
|||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
/* Button hover effect */
|
||||||
button:hover {
|
button:hover {
|
||||||
background-color: #cc0000;
|
background-color: #cc0000;
|
||||||
}
|
}
|
||||||
|
/* Status message styles */
|
||||||
#status {
|
#status {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
color: #666;
|
color: #666;
|
||||||
@ -41,38 +51,54 @@
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<!-- Main container -->
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<!-- Page title -->
|
||||||
<h1>YouTube Video Downloader</h1>
|
<h1>YouTube Video Downloader</h1>
|
||||||
|
<!-- Download form -->
|
||||||
<form id="downloadForm">
|
<form id="downloadForm">
|
||||||
|
<!-- URL input field -->
|
||||||
<input type="url" id="videoUrl" placeholder="Enter YouTube URL" required>
|
<input type="url" id="videoUrl" placeholder="Enter YouTube URL" required>
|
||||||
|
<!-- Download type selector -->
|
||||||
<select id="downloadType">
|
<select id="downloadType">
|
||||||
<option value="video">Video</option>
|
<option value="video">Video</option>
|
||||||
<option value="audio">Audio (MP3)</option>
|
<option value="audio">Audio (MP3)</option>
|
||||||
</select>
|
</select>
|
||||||
|
<!-- Submit button -->
|
||||||
<button type="submit">Download</button>
|
<button type="submit">Download</button>
|
||||||
</form>
|
</form>
|
||||||
|
<!-- Status message container -->
|
||||||
<div id="status"></div>
|
<div id="status"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- JavaScript for handling form submission -->
|
||||||
<script>
|
<script>
|
||||||
|
// Add event listener for form submission
|
||||||
document.getElementById('downloadForm').addEventListener('submit', function(e) {
|
document.getElementById('downloadForm').addEventListener('submit', function(e) {
|
||||||
|
// Prevent default form submission
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
// Get form values
|
||||||
const url = document.getElementById('videoUrl').value;
|
const url = document.getElementById('videoUrl').value;
|
||||||
const downloadType = document.getElementById('downloadType').value;
|
const downloadType = document.getElementById('downloadType').value;
|
||||||
const status = document.getElementById('status');
|
const status = document.getElementById('status');
|
||||||
|
|
||||||
|
// Update status message
|
||||||
status.textContent = 'Starting download...';
|
status.textContent = 'Starting download...';
|
||||||
|
|
||||||
|
// Make API request to download endpoint
|
||||||
fetch(`http://localhost:5000/download?url=${encodeURIComponent(url)}&type=${downloadType}`)
|
fetch(`http://localhost:5000/download?url=${encodeURIComponent(url)}&type=${downloadType}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
// Check if response is ok
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return response.text().then(text => {
|
return response.text().then(text => {
|
||||||
throw new Error(text || 'Download failed');
|
throw new Error(text || 'Download failed');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// Update status on successful download
|
||||||
status.textContent = 'Download completed!';
|
status.textContent = 'Download completed!';
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
// Handle and display any errors
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
status.textContent = 'Error: ' + error.message;
|
status.textContent = 'Error: ' + error.message;
|
||||||
});
|
});
|
||||||
|
|||||||
13
main.py
13
main.py
@ -1,27 +1,34 @@
|
|||||||
|
# Import required libraries
|
||||||
from flask import Flask, request, send_file
|
from flask import Flask, request, send_file
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
import os
|
import os
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
|
|
||||||
|
# Initialize Flask app and enable CORS
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CORS(app)
|
CORS(app)
|
||||||
|
|
||||||
|
# Route for serving index page
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return send_file('index.html')
|
return send_file('index.html')
|
||||||
|
|
||||||
|
# Route for handling video/audio downloads
|
||||||
@app.route('/download', methods=['GET'])
|
@app.route('/download', methods=['GET'])
|
||||||
def download_video():
|
def download_video():
|
||||||
try:
|
try:
|
||||||
|
# Get URL and download type from request parameters
|
||||||
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
|
download_type = request.args.get('type', 'video') # Default to video if not specified
|
||||||
|
|
||||||
|
# Validate URL parameter
|
||||||
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 based on download type
|
# Configure yt-dlp options based on download type
|
||||||
if download_type == 'audio':
|
if download_type == 'audio':
|
||||||
try:
|
try:
|
||||||
|
# Options for audio download - MP3 format
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format': 'bestaudio/best',
|
'format': 'bestaudio/best',
|
||||||
'postprocessors': [{
|
'postprocessors': [{
|
||||||
@ -35,24 +42,28 @@ def download_video():
|
|||||||
print(f"Error: {str(e)}")
|
print(f"Error: {str(e)}")
|
||||||
return str(e), 500
|
return str(e), 500
|
||||||
else: # video
|
else: # video
|
||||||
|
# Options for video download - best quality
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format': 'best',
|
'format': 'best',
|
||||||
'outtmpl': '%(title)s.%(ext)s',
|
'outtmpl': '%(title)s.%(ext)s',
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download the video/audio
|
# Download the video/audio using yt-dlp
|
||||||
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:
|
||||||
|
# Handle any errors during download
|
||||||
print(f"Error: {str(e)}")
|
print(f"Error: {str(e)}")
|
||||||
return str(e), 500
|
return str(e), 500
|
||||||
|
|
||||||
|
# Health check endpoint
|
||||||
@app.route('/ping')
|
@app.route('/ping')
|
||||||
def ping():
|
def ping():
|
||||||
return 'pong'
|
return 'pong'
|
||||||
|
|
||||||
|
# Run the Flask app in debug mode if executed directly
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, port=5000)
|
app.run(debug=True, port=5000)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user