youtube-clip-catcher
is a Python script designed to fetch and display metadata of a YouTube clip (not a full YouTube video) and download it with custom buffered start and end times.
Given a YouTube clip URL, e.g. https://www.youtube.com/clip/<clip-id>
this script queries the YouTube APIs to obtain the start and end time codes of the sub-clip in relation to the full video and downloads only that specific segment.
- Fetches video details using YouTube API.
- Extracts start and end times of YouTube clips in relation to the full video.
- The specified segment of the video is downloaded using
yt-dlp
for the download process andffmpeg
for extraction.
Given a YouTube clip URL:
https://youtube.com/clip/UgkxYimXng8oFu_jEOyBKr5Lx2lv8ELOKcHy?si=bVLQt1Bdnk8AkusH
The script will return the start and end times of the sub-clip in relation to the full video and download that segment.
- Clone the repository:
git clone https://github.com/yourusername/youtube-clip-catcher.git
- Install the dependencies:
poetry install
Next, you need to create a .env
file in the root directory of the project. This file will store your YouTube Data API v3 key. Use the following command to create and add your API key to the .env
file:
echo "API_KEY=<your-key>" > .env
Ensure your .env
file contains your API_KEY
key in this format:
API_KEY=<your-key>
- Run the script:
poetry run python main.py
- Follow the prompts to enter the YouTube clip URL and download the specified segment.
The script uses a configuration file config.json
to set the desired video buffer:
{
"desired_video_buffer": 30
}
This project is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request.
- Change the output encoding to H.264.
- Output the timecode using YT-DLP friendly bash syntax.
yt-dlp --download-sections "*HH:MM:SS-HH:MM:SS" [VIDEO_URL]