A PowerShell module for managing YouTube Music through automation and scripting.
YouTubeMusicPS provides cmdlets for interacting with your YouTube Music library. Currently focused on retrieving liked songs, with more features planned. The module uses cookie-based authentication with a guided setup process that walks you through each step.
- Guided Authentication: Step-by-step interactive setup that walks you through copying cookies from your browser
- Liked Songs Retrieval: Get your complete liked songs library with full pagination support
- Playlist Management: List playlists, view contents, and remove songs with tab completion
- Progress Tracking: Visual progress indicator when retrieving large libraries
- Pipeline Support: All cmdlets follow PowerShell conventions for pipeline operations
- Secure Storage: Credentials stored locally in your user profile
- PowerShell 5.1 or higher (PowerShell 7+ recommended)
- A YouTube Music account
- A web browser (Chrome, Edge, Firefox, etc.)
# Clone the repository
git clone https://github.com/tablackburn/YouTubeMusicPS.git
cd YouTubeMusicPS
# Import the module
Import-Module ./YouTubeMusicPS/YouTubeMusicPS.psd1# Run the guided authentication
Connect-YtmAccountThis opens YouTube Music in your browser and walks you through copying your authentication cookies. The process takes about 30 seconds.
# Get all liked songs
Get-YtmLikedMusic
# Get first 50 songs
Get-YtmLikedMusic -Limit 50
# Export to CSV
Get-YtmLikedMusic | Export-Csv -Path liked_songs.csv# Get all liked songs with full details
$songs = Get-YtmLikedMusic
$songs.Count # Total number of liked songs
# Display as table
Get-YtmLikedMusic | Format-Table Title, Artist, Album -AutoSize
# Get songs by a specific artist
Get-YtmLikedMusic | Where-Object { $_.Artist -like "*Taylor Swift*" }
# Get total duration of liked songs
$songs = Get-YtmLikedMusic
$totalMinutes = ($songs | Measure-Object -Property DurationSeconds -Sum).Sum / 60
Write-Host "Total: $([math]::Round($totalMinutes / 60, 1)) hours"# Each song has these properties
Get-YtmLikedMusic | Select-Object -First 1 | Format-List
# VideoId : dQw4w9WgXcQ
# Title : Never Gonna Give You Up
# Artist : Rick Astley
# ArtistId : UCuAXFkgsw1L7xaCfnd5JJOw
# Album : Whenever You Need Somebody
# AlbumId : MPREb_...
# Duration : 3:33
# DurationSeconds : 213
# ThumbnailUrl : https://...
# LikeStatus : LIKE# List all your playlists
Get-YtmPlaylist
# Get songs in a specific playlist (tab completion works!)
Get-YtmPlaylist -Name "Chill Vibes"
# Remove a song from a playlist using pipeline
Get-YtmPlaylist -Name "Chill Vibes" | Where-Object Title -eq "Bad Song" | Remove-YtmPlaylistItem
# Remove multiple songs matching a pattern
Get-YtmPlaylist -Name "Chill Vibes" | Where-Object Artist -match "Nickelback" | Remove-YtmPlaylistItem
# Remove a song using direct parameters
Remove-YtmPlaylistItem -Name "Chill Vibes" -Title "Bad Song"
# Preview what would be removed without actually removing
Get-YtmPlaylist -Name "Chill Vibes" | Where-Object Title -eq "Bad Song" | Remove-YtmPlaylistItem -WhatIf# Remove stored credentials
Disconnect-YtmAccountYouTube Music uses cookie-based authentication. The Connect-YtmAccount command guides you through:
- Opening YouTube Music in your browser
- Opening Developer Tools (F12)
- Going to the Network tab
- Copying the Cookie header from any request
Your cookies are stored locally and remain valid for approximately 2 years unless you log out of your Google account.
If you prefer to provide cookies directly:
Connect-YtmAccount -Cookie 'SAPISID=abc123; HSID=xyz789; ...'Credentials are stored in:
- Windows:
%LOCALAPPDATA%\YouTubeMusicPS\config.json - macOS/Linux:
~/.config/YouTubeMusicPS/config.json
- Cookies are stored in plaintext on your local machine
- Never share your cookies or commit them to source control
- Your YouTube Music cookies grant access to your Google account
- Run
Disconnect-YtmAccountto remove stored credentials
# Run all tests
Invoke-Pester -Path ./tests
# Run with code coverage
$config = New-PesterConfiguration
$config.Run.Path = './tests'
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.Path = './YouTubeMusicPS/**/*.ps1'
Invoke-Pester -Configuration $configYouTubeMusicPS/
├── YouTubeMusicPS/
│ ├── Public/ # Exported cmdlets
│ ├── Private/ # Internal functions
│ ├── YouTubeMusicPS.psd1
│ └── YouTubeMusicPS.psm1
├── tests/ # Pester tests
├── build.ps1 # Build script
└── README.md
| Cmdlet | Description |
|---|---|
Connect-YtmAccount |
Authenticate with YouTube Music (guided or manual) |
Disconnect-YtmAccount |
Remove stored credentials |
Get-YtmLikedMusic |
Retrieve liked songs from your library |
Get-YtmPlaylist |
List playlists or get playlist contents |
Remove-YtmPlaylistItem |
Remove songs from a playlist |
For detailed help on any cmdlet:
Get-Help Connect-YtmAccount -Full
Get-Help Get-YtmLikedMusic -ExamplesFuture features under consideration:
- Search functionality
- Library statistics
- Album/artist browsing
- Playlist creation and editing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
- Inspired by ytmusicapi (Python) and YouTubeMusicAPI (C#)
- Developed with assistance from Claude by Anthropic
MIT License - see LICENSE for details.
- GitHub Repository: https://github.com/tablackburn/YouTubeMusicPS
- ytmusicapi (Python): https://github.com/sigma67/ytmusicapi