Skip to content

A Python script to fetch and display metadata of a YouTube clip (not a full YouTube video) and download it with custom buffered start and end times.

Notifications You must be signed in to change notification settings

alexfazio/youtube-clip-catcher

Repository files navigation

YouTube-clips-banner-new.png

youtube-clip-catcher

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.

Features

  • 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 and ffmpeg for extraction.

Example

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.

Usage

  1. Clone the repository:
git clone https://github.com/yourusername/youtube-clip-catcher.git
  1. Install the dependencies:
poetry install
  1. YouTube Data API v3

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>
  1. Run the script:
poetry run python main.py
  1. Follow the prompts to enter the YouTube clip URL and download the specified segment.

Configuration

The script uses a configuration file config.json to set the desired video buffer:

{
    "desired_video_buffer": 30
}

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Acknowledgements

TODOs

  • 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]

About

A Python script to fetch and display metadata of a YouTube clip (not a full YouTube video) and download it with custom buffered start and end times.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages