Skip to main content

CLI tool to download YouTube playlists as audio with metadata

Project description

ytmusic-cli

Python License

CLI tool to download YouTube playlists as audio with metadata.

A command-line tool that downloads YouTube playlists as audio files, automatically identifies songs using the iTunes API, and embeds rich metadata (artist, album, cover art) directly into the audio files.

Background

This tool was created to solve the problem of downloading music from YouTube playlists while maintaining proper metadata. Many existing tools download videos or audio without proper tagging, resulting in a disorganized music library. This tool:

  • Automatically identifies songs using the iTunes API
  • Downloads only audio streams (no video)
  • Embeds cover art and metadata directly into audio files
  • Names files consistently as "Artist - Song Title"
  • Skips songs with poor metadata matches

Install

# Install from PyPI
pip install ytmusic-cli

# Or with pipx (recommended for CLI tools)
pipx install ytmusic-cli

# Or install from source with uv
uv sync

Dependencies

  • Python 3.10+
  • pytubefix (YouTube downloading)
  • mutagen (audio metadata)
  • rich (CLI output)
  • requests (API calls)

See pyproject.toml for full dependency list.

Usage

# Run via the installed CLI
ytmusic "PLAYLIST_URL"

# Or module execution
python -m ytmusic "PLAYLIST_URL"

CLI

usage: ytmusic [-h] [-o DIR] [-t 0.0-1.0] [--dry-run] [--version] url

Download YouTube playlists as audio with rich metadata

positional arguments:
  url                   YouTube playlist URL or ID

options:
  -h, --help            show this help message and exit
  -o DIR, --output DIR  Output directory (default: music_library)
  -t 0.0-1.0, --threshold 0.0-1.0
                        Similarity threshold 0.0-1.0 (default: 0.5)
  --dry-run             Preview what would be downloaded
  --version             show program's version number and exit

Examples:
  # Basic usage
  ytmusic "https://www.youtube.com/playlist?list=PLAYLIST_ID"
  
  # Custom output with stricter matching
  ytmusic "PLAYLIST_URL" -o "my_music" -t 0.7
  
  # Preview without downloading
  ytmusic "PLAYLIST_URL" --dry-run

How It Works

  1. Playlist Fetching - Retrieves all video URLs from the playlist
  2. Title Parsing - Extracts "Artist - Song" from YouTube titles
  3. Metadata Search - Queries iTunes API for matching songs
  4. Similarity Check - Compares YouTube title with iTunes result
  5. Download - Gets audio-only stream (skips if similarity < threshold)
  6. Tagging - Embeds metadata and cover art into audio file
  7. Naming - Saves as "Artist - Song Title.m4a"

Configuration

Similarity Threshold

The threshold controls how strictly songs must match metadata:

Threshold Result
0.3 Lenient - More songs, less accurate
0.5 Balanced - (default)
0.7 Strict - Fewer songs, more accurate
0.9 Very strict - Only exact matches

Output Organization

music_library/
└── Playlist Name/
    ├── Artist - Song Title.m4a
    ├── Artist - Song Title.m4a
    └── ...

Configuration File

Create a config file at ~/.config/ytmusic/config.yaml to set default options:

# Generate default config file
ytmusic --init-config

Example Config

# ytmusic-cli configuration
output: "my_music"
threshold: 0.7
format: "mp3"
bitrate: "320k"
convert: true
quiet: false
verbose: false
summary: true
workers: 4

Config Precedence

  1. CLI arguments (highest priority)
  2. Config file values
  3. Built-in defaults (lowest priority)

Environment Variable

Set a custom config path:

export YTMUSIC_CONFIG=/path/to/my/config.yaml
ytmusic "PLAYLIST_URL"

License

MIT © 2026

Releases

Prebuilt executables are available on GitHub Releases (Linux/macOS/Windows).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ytmusic_cli-1.5.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ytmusic_cli-1.5.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file ytmusic_cli-1.5.0.tar.gz.

File metadata

  • Download URL: ytmusic_cli-1.5.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ytmusic_cli-1.5.0.tar.gz
Algorithm Hash digest
SHA256 59743c6bf9327168dee4c2880e9d69ea3ccd83a8f419d82540ea373cc0e5473a
MD5 f0be4cb9526467a8cd48705c21e7da1c
BLAKE2b-256 ab8e3a23fd9a007fd13143e6284e6111f947631b3b61c77686feef2be63d3c81

See more details on using hashes here.

Provenance

The following attestation bundles were made for ytmusic_cli-1.5.0.tar.gz:

Publisher: release.yml on ilyeshdz/ytmusic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ytmusic_cli-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: ytmusic_cli-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ytmusic_cli-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46094658ac00ac6b43eb9c8b8a1d68e566d99830a1ee43e94654edc140778343
MD5 fa1872e7b8db48e37c0d7f9dde675546
BLAKE2b-256 62a775c1802838927e3874802e59c239c7d450aaae7223d1c90840dacc8f3e05

See more details on using hashes here.

Provenance

The following attestation bundles were made for ytmusic_cli-1.5.0-py3-none-any.whl:

Publisher: release.yml on ilyeshdz/ytmusic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page