Skip to content

mafful/youtube_loader

Repository files navigation

YouTube Video Loader

A Python-based application for downloading short video segments (30 seconds) from YouTube using yt-dlp. This project supports asynchronous downloads and is fully containerized with Docker for streamlined execution.


Features

  • Cookie Management: Automatically handle cookies file specified in .env.
  • Asynchronous Video Downloads: Use yt-dlp and ffmpeg to download the first 30 seconds of videos.
  • Logging: Comprehensive logging system for tracking operations.
  • Dockerized: Fully containerized environment, eliminating local setup complexities.

Prerequisites

  • Docker and Docker Compose
  • .env file with the path to your cookies file.

Installation and Usage

1. Clone the Repository

git clone <repository-url>
cd <repository-directory>

2. Prepare .env File

Create a .env file in the project root and specify the path to your cookies file:

COOKIES_FILE_PATH=/path/to/your/youtube.com_cookies.txt

You may use a browser extension to export cookies, such as:
	•	Get cookies.txt LOCALLY for Chrome
	•	cookies.txt for Firefox

This cookies file is needed because YouTube uses Google’s authentication system, which can involve Two-Factor Authentication (2FA) when logging in. By using a cookies file, you can bypass the need to manually log in and enter the verification code every time the application interacts with YouTube.

The cookies file captures the session details after a successful login, including the token generated by Google Authenticator or other 2FA methods. This allows the application to authenticate automatically without requiring you to re-enter your credentials or 2FA code.

⚠️ Important: Be cautious when installing browser extensions. If you had previously installed the “Get cookies.txt” extension (not “LOCALLY”) for Chrome, it has been reported as malware and removed from the Chrome Web Store. Uninstall it immediately if it’s still present on your system.

The application will continuously monitor the input_dir volume for new loading_instructions.csv files and start processing them.

3. Usage

Steps to Use the Application

•	Open the Chrome browser.
•	Install one of the extensions mentioned in the Prepare .env File section:
•	Log in to YouTube with your account.
•	Use the extension to export cookies and save the file (e.g., into /Downloads).
•	Navigate to the Directory of the project

•	Open create_loading_instructions.py file.
•	Update the sample_data list with the desired YouTube video URLs:

•	Execute the script to copy the cookies file and create the loading_instructions.csv file:
python3 create_loading_instructions.py

Once the CSV is created, the Docker container will automatically start processing the file if it’s running.

Note: You can open separate terminal windows to run new create_loading_instructions.py scripts at any time. This is useful if you want to create multiple loading_instructions.csv files and have them processed simultaneously, even if Docker is already running.

4. Build and Run with Docker

1.	Build the Docker image:
docker-compose build
2.	Start the application:
docker-compose up

5. File Structure

project/
│
├── main.py               # Main script to monitor and process video downloads.
├── settings.py           # Configuration and setup of directories and logging.
├── Dockerfile            # Docker container setup.
├── docker-compose.yml    # Docker Compose configuration.
├── requirements.txt      # Python dependencies.
├── .env                  # Environment configuration.
├── input_dir/            # Directory for input files.
├── output_dir/           # Directory for downloaded videos.
└── logs_dir/             # Directory for application logs.

Configuration

.env file

	# Example .env file for YouTube Video Loader
	# Rename this file to `.env` and update the value below with the actual path.

	# Path to the exported cookies file from your browser extension
	COOKIES_FILE_PATH=/path/to/your/youtube.com_cookies.txt

Docker Volumes

The following directories are mapped as volumes:

	•	./input_dir:/app/input_dir - Directory for input files.
	•	./output_dir:/app/output_dir - Directory for downloaded videos.
	•	./logs_dir:/app/logs_dir - Directory for application logs.

Logs

	•	Logs are saved in ./logs_dir/project.log and streamed to the console in real-time.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors