Skip to content

chentda/yt-audio-chopper

Repository files navigation

YouTube Audio Chopper

A simple CLI tool for snipping/chopping/sampling audio from a YouTube video in the audio format of your choice given start and end timestamps. If no timestamps are provided, the whole audio of the YouTube video URL provided is downloaded. By default, highest quality bitrate for audio format of choice is used.

It is not intended for use in downloading an entire playlist of YouTube videos.

Motivation

Most YouTube Audio downloader websites do not have an option to slice and download the audio of a video by start and end timestamps (they only convert and download the whole audio!). In addition, they are often slow due to Ads and consistently get shut down. Furthermore if you want a small sample from a long video, it is inefficient to download the whole audio. This CLI tool built on top of yt-dlp addresses the aforementioned pain points and provides a way to quickly download a sample by passing the YouTube URL and a few arguments, including start and end timestamps of the audio section you want, via terminal to download an audio snippet for use in your multimedia project.

Warning

  • Downloading audio from YouTube to use in your content violates YouTube's Terms of Service and infringes on copyright laws. Use this CLI tool at your own risk.
  • Recommendation is to use this CLI sparingly to avoid rate limits and temporary IP blocks.

Preview

Screenshot 2026-05-24 at 12 27 45 pm

Prerequisites

This CLI tool depends on the below two open source software projects being installed on your device:

  1. FFmpeg - an open source multimedia processing software. Install via the following terminal commands for your OS:

    • macOS

      brew install ffmpeg
    • Linux (Ubuntu/Debian)

      sudo apt update && sudo apt install -y ffmpeg
    • Windows and other instructions

  2. uv - an extremely fast Python package and project manager. It replaces several tools for installing and locking packages, including pip & poetry. Install via the following terminal commands:

    • macOS

      brew install uv
    • Linux (Ubuntu/Debian)

      wget -qO- https://astral.sh/uv/install.sh | sh
    • Windows and other instructions

Installation

Once the Prerequisites above are set up:

  1. Clone this repo
    git clone https://github.com/chentda/yt-audio-chopper.git
  2. Go into folder
    cd yt-audio-chopper
  3. Download all dependencies using uv
    uv sync

Usage

  1. Pick YouTube video you want to chop audio from and copy URL. To avoid unnecessary errors, make sure to get the YoutTube video URL using the Share button instead of the address bar. Sometimes you might unkowingly copy a playlist URL in the address bar causing the CLI tool to error, hence click the "Share" button below the video, then select "Copy" to ensure the single video URL.

  2. Note down start and end timestamps of audio section you want, otherwise whole audio will be extracted.

  3. Run yt-audio-chopper CLI tool either non-interactively (passing URL string and other arguments as flags) or interactively (program will ask you to enter arguments one by one).

    • Non-interactive
    uv run yt-audio-chopper \
      --url "<URL>" \
      --format "wav" \
      --start-time "00:00:10" \
      --end-time "00:00:20" \
      --output-filename "sample_example"
    • Interactive
    uv run yt-audio-chopper
  4. OPTIONAL if you want to make yt-audio-chopper a system-wide command: The following commands install the tool into an isolated environment and adds its entry point to your system's PATH so you can call it from any directory. While in the yt-audio-chopper project directory do the following:

    uv tool install .

    This will install the binaries into ~/.local/bin on macOS/Linux or %USERPROFILE%\.local\bin on Windows. Ensure this directory is in your PATH by adding the following line to your ~/.zshrc or ~/.bashrc:

    export PATH="$HOME/.local/bin:$PATH"

    You can then call yt-audio-chopper directly by its name from your terminal from any directory as follows:

    yt-audio-chopper

    To uninstall system-wide:

    uv tool uninstall yt-audio-chopper

Arguments

Argument Description Required Default if left empty
--url The YouTube URL string of the video you want to extract audio from
--format Digital audio format of extracted audio. Audio format options are "aac", "alac", "flac", "m4a", "mp3", "opus", "vorbis", "wav" "wav"
--start-time Starting timestamp of your audio snippet/sample. Timestamp string has to match format [HH:][MM:]SS[.ss] for e.g. "00:01:30" or "90" "00:00:00"/ beginning of video
--end-time Ending timestamp of your audio snippet/sample. Timestamp string has to match format [HH:][MM:]SS[.ss] for e.g. "00:01:30" or "90" Full video duration
--output-filename Optional filename for audio file. Do not include audio file extension Name of YouTube video

About

Command line (CLI) tool for snipping/sampling audio from YouTube in the audio format of your choice

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages