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
|
||||
|
||||
# (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
|
||||
# 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
|
||||
pip install -r requirements.txt
|
||||
|
||||
28
index.html
28
index.html
@ -1,10 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- DOCTYPE html -->
|
||||
<html lang="en">
|
||||
<!-- head section -->
|
||||
<head>
|
||||
<!-- Character encoding and viewport meta tags -->
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>YouTube Video Downloader</title>
|
||||
<!-- CSS styles -->
|
||||
<style>
|
||||
/* Body styles */
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
@ -12,17 +16,21 @@
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
/* Container spacing */
|
||||
.container {
|
||||
margin-top: 50px;
|
||||
}
|
||||
/* Input and select field styles */
|
||||
input[type="url"], select {
|
||||
width: 80%;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
/* Select field width override */
|
||||
select {
|
||||
width: auto;
|
||||
}
|
||||
/* Button styles */
|
||||
button {
|
||||
padding: 10px 20px;
|
||||
background-color: #ff0000;
|
||||
@ -31,9 +39,11 @@
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
/* Button hover effect */
|
||||
button:hover {
|
||||
background-color: #cc0000;
|
||||
}
|
||||
/* Status message styles */
|
||||
#status {
|
||||
margin-top: 20px;
|
||||
color: #666;
|
||||
@ -41,38 +51,54 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Main container -->
|
||||
<div class="container">
|
||||
<!-- Page title -->
|
||||
<h1>YouTube Video Downloader</h1>
|
||||
<!-- Download form -->
|
||||
<form id="downloadForm">
|
||||
<!-- URL input field -->
|
||||
<input type="url" id="videoUrl" placeholder="Enter YouTube URL" required>
|
||||
<!-- Download type selector -->
|
||||
<select id="downloadType">
|
||||
<option value="video">Video</option>
|
||||
<option value="audio">Audio (MP3)</option>
|
||||
</select>
|
||||
<!-- Submit button -->
|
||||
<button type="submit">Download</button>
|
||||
</form>
|
||||
<!-- Status message container -->
|
||||
<div id="status"></div>
|
||||
</div>
|
||||
|
||||
<!-- JavaScript for handling form submission -->
|
||||
<script>
|
||||
// Add event listener for form submission
|
||||
document.getElementById('downloadForm').addEventListener('submit', function(e) {
|
||||
// Prevent default form submission
|
||||
e.preventDefault();
|
||||
// Get form values
|
||||
const url = document.getElementById('videoUrl').value;
|
||||
const downloadType = document.getElementById('downloadType').value;
|
||||
const status = document.getElementById('status');
|
||||
|
||||
// Update status message
|
||||
status.textContent = 'Starting download...';
|
||||
|
||||
// Make API request to download endpoint
|
||||
fetch(`http://localhost:5000/download?url=${encodeURIComponent(url)}&type=${downloadType}`)
|
||||
.then(response => {
|
||||
// Check if response is ok
|
||||
if (!response.ok) {
|
||||
return response.text().then(text => {
|
||||
throw new Error(text || 'Download failed');
|
||||
});
|
||||
}
|
||||
// Update status on successful download
|
||||
status.textContent = 'Download completed!';
|
||||
})
|
||||
.catch(error => {
|
||||
// Handle and display any errors
|
||||
console.error('Error:', error);
|
||||
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
|
||||
import yt_dlp
|
||||
import os
|
||||
from flask_cors import CORS
|
||||
|
||||
# Initialize Flask app and enable CORS
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
# Route for serving index page
|
||||
@app.route('/')
|
||||
def index():
|
||||
return send_file('index.html')
|
||||
|
||||
# Route for handling video/audio downloads
|
||||
@app.route('/download', methods=['GET'])
|
||||
def download_video():
|
||||
try:
|
||||
# Get URL and download type from request parameters
|
||||
video_url = request.args.get('url')
|
||||
download_type = request.args.get('type', 'video') # Default to video if not specified
|
||||
|
||||
# Validate URL parameter
|
||||
if not video_url:
|
||||
return "Please provide a YouTube URL", 400
|
||||
|
||||
# Configure yt-dlp options based on download type
|
||||
if download_type == 'audio':
|
||||
try:
|
||||
# Options for audio download - MP3 format
|
||||
ydl_opts = {
|
||||
'format': 'bestaudio/best',
|
||||
'postprocessors': [{
|
||||
@ -35,24 +42,28 @@ def download_video():
|
||||
print(f"Error: {str(e)}")
|
||||
return str(e), 500
|
||||
else: # video
|
||||
# Options for video download - best quality
|
||||
ydl_opts = {
|
||||
'format': 'best',
|
||||
'outtmpl': '%(title)s.%(ext)s',
|
||||
}
|
||||
|
||||
# Download the video/audio
|
||||
# Download the video/audio using yt-dlp
|
||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||
info = ydl.extract_info(video_url, download=True)
|
||||
|
||||
return "Download completed", 200
|
||||
|
||||
except Exception as e:
|
||||
# Handle any errors during download
|
||||
print(f"Error: {str(e)}")
|
||||
return str(e), 500
|
||||
|
||||
# Health check endpoint
|
||||
@app.route('/ping')
|
||||
def ping():
|
||||
return 'pong'
|
||||
|
||||
# Run the Flask app in debug mode if executed directly
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port=5000)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user