A simple Neovim plugin to play YouTube Music directly from your editor.
- mpv: Must be in your
$PATH. - yt-dlp: CRITICAL - Must be the LATEST version.
- YouTube frequently changes their backend. The version in
aptorbrewis often too old.
- YouTube frequently changes their backend. The version in
Using lazy.nvim
{
"shardulvs/ytmusic.nvim",
}If you get errors like "Sign in to confirm you’re not a bot" or "403 Forbidden":
- Export your cookies from your browser (Netscape format).
- Use a browser extension like "Get cookies.txt LOCALLY".
- Set the environment variable in your shell (
.bashrc/.zshrc):export YOUTUBE_COOKIES_FILE="/path/to/your/cookies.txt"
- Create a file with
.ytmusicextension (e.g.,playlist.ytmusic). - Paste YouTube Music URLs:
https://music.youtube.com/watch?v=d9S4diaWjos - Open the file in Neovim. Titles will be fetched automatically.
- Controls:
<Enter>: Play / Stop.:YtStop: Emergency stop all playback.:FetchTitles: Manually re-scan the file for new links and fetch their titles.- Closing Buffer: Stops playback immediately.
To easily get all links from a YouTube Music playlist:
- Open the playlist in your browser.
- Scroll down to load all songs.
- Open Developer Tools (F12) -> Console.
- Paste this snippet to copy all links:
console.log([...new Set(Array.from(document.querySelectorAll("ytmusic-responsive-list-item-renderer a[href*='watch?v=']")).map(a=>"https://music.youtube.com/watch?v="+a.href.split("v=")[1].split("&")[0]))].join("\n"))If this plugin breaks in the future, feel free to blame YouTube. They love changing their backend APIs just to mess with us. If that happens, update yt-dlp and pray.
MIT