Skip to main content

ytm

YouTube Music in the terminal: search, queue, radio and lyrics, with mpv doing the playing.

PyPI Tests License Last commit Python 3.11+

ytm's TUI: search results on top, queue, playlists and lyrics in the middle, the current track with its cover at the bottom

Overview

YouTube Music has no desktop client that is not a browser. ytm is a small Python CLI and a Textual TUI over three tools that already do the hard parts: ytmusicapi for the catalogue, yt-dlp for stream resolution and mpv for audio.

mpv is the only long-running process. ytm starts it once, idle, with a JSON IPC socket, and every command after that is a stateless message to it. Close the terminal and the music keeps playing. A Lua script inside mpv keeps the queue fed with the station for whatever is playing, so it never runs dry.

Quickstart

pipx install ytm              # or: uv tool install ytm   /   pip install ytm

ytm auth                      # cookies from a logged-in browser, see Authentication
ytm play "daft punk"          # search, play the first hit, radio follows
ytm                           # the TUI
ytm update                    # later: newest ytm and yt-dlp, whatever installed it

To hack on it instead:

git clone https://github.com/MaheshBhushan/yt-music-cli.git && cd yt-music-cli
python3 -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]'

[!IMPORTANT] mpv must be on your PATH; pip cannot install it. pacman -S mpv, apt install mpv, brew install mpv, or the installers at https://mpv.io. Node is optional but recommended: yt-dlp uses it to solve YouTube's JavaScript challenges.

Usage

The TUI is ytm with no arguments. Results appear as you type; Enter plays the first one. Every key is listed in the bar at the bottom, and everything is clickable: results, queue rows, playlists, the progress bar, the shortcuts.

Key Action
/ or s Focus search
Enter Play the selected result, queue entry or playlist
q Enqueue the selected result
space Play / pause
n p Next / previous
Seek 5 s
+ - Volume
a Add the selected song to a playlist: a, pick the list with , a or Enter
l Focus playlists
Tab Cycle panes
e Exit, music keeps playing
x Exit and stop mpv

One-shot commands talk to the same mpv. Add --json to any of them for machine-readable output.

ytm search "song name" -n 10   # results are numbered
ytm play 3                     # a number from the last search, an 11-char video id, or a query
ytm add 4                      # enqueue
ytm radio                      # replace the queue with a station for the current track
ytm status | queue | lyrics | like
ytm pause | resume | toggle | next | prev | stop
ytm seek -10 | seek --to 90 | volume 60 | clear | shuffle
ytm quit                       # stop mpv entirely
ytm update                     # upgrade ytm and yt-dlp; --check only reports

The queue never holds a track twice: playing something already queued jumps to it, and radio skips what is there.

Authentication

Search works signed out, but library, playlists, likes and lyrics need your account. Credentials live in ~/.config/ytm/auth.json (mode 0600) and are validated with a live call before being kept.

ytm auth                          # cookies from Chrome, Chromium, Edge, Brave, Vivaldi, Opera or Firefox
ytm auth --from-browser firefox   # pick one
ytm auth --manual                 # paste request headers copied from DevTools
ytm auth --oauth                  # device-code flow, for SSH and headless boxes

Browser cookies expire after a few weeks; re-run ytm auth when the app says so. OAuth needs your own Google Cloud client (YouTube removed the shared one in 2024): create an OAuth client of type TVs and Limited Input devices and pass --client-id/--client-secret, or set YTM_OAUTH_CLIENT_ID/YTM_OAUTH_CLIENT_SECRET.

[!NOTE] Streams resolve anonymously by default. With account cookies, YouTube hands out URLs that require an account-bound proof-of-origin token and then answers 403. Anonymous resolution plays the same catalogue. Set behaviour.authenticated_streams = true only if you need private or age-gated tracks.

Configuration

~/.config/ytm/config.toml. A missing file means these defaults; a partial file overrides only what it names; a bad value is warned about and ignored.

[audio]
volume = 70
device = "auto"                 # an mpv --audio-device name

[behaviour]
autoplay_radio = true           # keep the queue fed with radio
confirm_remote_delete = true
authenticated_streams = false   # see the note above

[ui]
theme = "dark"                  # or "light"
art = "blocks"                  # blocks | kitty | sixel | auto | ascii | off

[pot]
enabled = true                  # proof-of-origin tokens via bgutil-ytdlp-pot-provider
base_url = "http://127.0.0.1:4416"

[keys]
toggle = "space"
next = "n"
prev = "p"
search = "/"
quit = "e"

[update]
check = true                    # ask PyPI once a day, toast in the TUI when newer
auto = false                    # true: install it (and fresh yt-dlp) automatically

art = "blocks" draws the cover with coloured half-cell glyphs and works in every terminal, tmux included. kitty and sixel use the terminal's pixel protocol; Sixel is known to freeze the pane in Konsole, which is why it is opt-in.

The proof-of-origin token provider is a yt-dlp plugin installed with ytm. It asks an HTTP service for tokens when YouTube demands one; run docker run -d --name bgutil-provider -p 4416:4416 brainicism/bgutil-ytdlp-pot-provider if you want it, or set enabled = false. Playback works without it for most accounts.

More

  • Offline cache. ytm cache add <video_id> downloads a track into ~/.cache/ytm/tracks/; cache rm and cache list manage it. 2 GB cap, least-recently-played evicted first.
  • Local playlists live in ~/.local/state/ytm/playlists.json and show up next to your YouTube Music playlists in the TUI.
  • Media keys. ytm has no MPRIS of its own; install the mpv-mpris plugin and mpv announces itself to your desktop.
  • Updating. ytm update upgrades ytm and yt-dlp through whatever installed them (pipx, uv tool, or pip), so the new version lands where the ytm command runs from. The TUI checks PyPI once a day and shows a toast when there is a newer release; set auto = true under [update] to have it install without asking. yt-dlp is why this matters: YouTube changes things and yt-dlp follows within days, so a stale copy is the usual cause of sudden "could not resolve" failures.
  • Windows is supported in design (named-pipe IPC, no D-Bus) but has not been tested.
  • Logs. mpv writes to ~/.local/state/ytm/mpv.log.

Repository structure

ytm/
  cli.py            commands and the mpv launch configuration
  player.py         Player: mpv over JSON IPC
  music.py          ytmusicapi wrappers, Track
  state.py          remembered searches and track metadata
  auth.py           browser cookies, DevTools headers, OAuth
  cache.py          offline downloads
  update.py         version check against PyPI, in-place upgrade
  mpv/autoplay.lua  radio autoplay inside mpv
  tui/              Textual app, panes, backend over Player
tests/              pytest; no network and no mpv needed
.github/workflows/  tests on 3.11-3.13; publish to PyPI on a v* tag
pip install -e '.[dev]' && pytest -q

License

MIT, see LICENSE.

Download files

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

Source Distribution

ytm-0.3.1.tar.gz (84.8 kB view details)

Uploaded Source

Built Distribution

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

ytm-0.3.1-py3-none-any.whl (59.0 kB view details)

Uploaded Python 3

File details

Details for the file ytm-0.3.1.tar.gz.

File metadata

  • Download URL: ytm-0.3.1.tar.gz
  • Upload date:
  • Size: 84.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ytm-0.3.1.tar.gz
Algorithm Hash digest
SHA256 7b8e68a53874b9c37ce40f5f3e0362db292c32cc55833bf3a29be6fea192061f
MD5 753ff721502c7a3e7da9aecc0d0fad54
BLAKE2b-256 b8f54beedc57f114e5544e541ef2c5a68a7302b37eccb3b761441f097c6b90c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ytm-0.3.1.tar.gz:

Publisher: publish.yml on MaheshBhushan/yt-music-cli

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

File details

Details for the file ytm-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: ytm-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 59.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ytm-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1c901f1dc77189c54229c42bdbec592ea651f6b45b57b7ddd3d9f22dc4344c8
MD5 c67157cca33c080c838d91dc8d49df40
BLAKE2b-256 9455d8ad82ade61addf6f987a4ee82e40fb97996b6f9ea2bb3cc6805397730bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for ytm-0.3.1-py3-none-any.whl:

Publisher: publish.yml on MaheshBhushan/yt-music-cli

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

Release history Release notifications | RSS feed

0.5.15

2 files

0.5.14

2 files

0.5.13

2 files

0.5.12

2 files

0.5.11

2 files

0.5.10

2 files

0.5.9

2 files

0.5.8

2 files

0.5.7

2 files

0.5.6

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.3

2 files

0.3.2

2 files

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page