This project allows you to download videos from a specified YouTube channel using the YouTube Data API and the yt-dlp library.
- Docker
- Docker Compose
- Python 3.11 (for local development without Docker)
- PostgreSQL (managed by Docker Compose)
Follow these steps to clone, set up, and run the project on your local machine.
Start by cloning the repository to your local machine:
git clone <repository-url>
cd <repository-directory>Create a .env file in the root directory of the project and add the following environment variables:
# YouTube API Key and Channel ID
YOUTUBE_API_KEY=your_youtube_api_key_here
YOUTUBE_CHANNEL_ID=your_channel_id_here
# Database configuration for development
DB_HOST=db
DB_NAME=your_db_name_here
DB_USER=your_db_user_here
DB_PASSWORD=your_db_password_hereMake sure to replace your_youtube_api_key_here, your_channel_id_here, and the database configuration with the correct values.
Ensure that Docker and Docker Compose are installed on your machine.
Run the following command to build and start the containers:
docker-compose up --buildThis will build the Docker images for your Django application and PostgreSQL, and then start the containers.
Once the containers are up and running, apply the database migrations:
docker-compose exec web python manage.py migrateThis will create the necessary tables in your PostgreSQL database.
Once the server is running, you can access the application in your browser at http://localhost:8000.
To start downloading videos from the specified YouTube channel, hit the following endpoint via your browser or a tool like Postman:
http://localhost:8000/api/fetch-videos
This will trigger the video download process, and the videos will be saved in the media/videos/ directory inside your project.
The main components of the project are as follows:
- Django: The web framework handling API requests, including the video fetching and downloading process.
- yt-dlp: The library used to download videos from YouTube.
- PostgreSQL: The database used to store video and channel information.
- Docker: The containers that package the app and its dependencies.
If you prefer to run the project without Docker, follow these steps:
-
Install Python 3.11 and the required dependencies from
requirements.txt:pip install -r requirements.txt
-
Create a
.envfile in the root directory with the same contents as above. -
Apply the migrations:
python manage.py migrate
-
Run the Django development server:
python manage.py runserver
-
Access the app at
http://localhost:8000and hit the endpoint to start downloading videos.
- The app fetches and downloads videos from a specific YouTube channel using the YouTube API and
yt-dlplibrary. - Video downloads are triggered by hitting the endpoint
http://localhost:8000/api/fetch-videos.
This README.md provides clear instructions on how to clone, set up, and run the Django project using Docker, with details on how to hit the API endpoint to download videos.