Skip to content

un1tz3r0/ytmusicapi

 
 

Repository files navigation

ytmusicapi: Unofficial API for YouTube Music

PyPI Downloads

Ask questions at https://gitter.im/sigma67/ytmusicapi

Code coverage

Latest release

Commits since latest release

YTMusicAPI ======= ytmusicapi is a Python 3 library to send requests to the YouTube Music API. It emulates YouTube Music web client requests using the user's cookie data for authentication.

This is a fork of sigma67's work-in-progress API that emulates web requests from the YouTube Music web client, that adds downloading of streams to disk for offline listening.

Currently you need to extract your authentication data from your web browser and provide it through a file for it to work.

Features

Downloading:
  • download songs by videoId
  • batch-download playlists, albums and artists
  • uses highest-quality stream available, prefers audio-only formats but will fall back to video/* mimetypes if there are no audio/* streams available
  • uses pytube to decode signatureCipher-protected stream urls by analyzing decoding steps in the generated base.js referenced by the watch page (tricky!)
  • names and places downloaded files into subdirectories based on artist/album/title metadata
  • downloads and saves thumbnail images for artists, albums and songs
  • uses mutagen to tag downloaded files with artist/album/title/thumbnail metadata
Browsing:
  • search (including all filters)
  • get artist information and releases (songs, videos, albums, singles, related artists)
  • get user information (videos, playlists)
  • get albums
  • get song metadata
  • get watch playlists (playlist that appears when you press play in YouTube Music)
  • get song lyrics
Exploring music:
  • get moods and genres playlists
  • get latest charts (globally and per country)
Library management:
  • get library contents: playlists, songs, artists, albums and subscriptions
  • add/remove library content: rate songs, albums and playlists, subscribe/unsubscribe artists
Playlists:
  • create and delete playlists
  • modify playlists: edit metadata, add/move/remove tracks
  • get playlist contents
Uploads:
  • Upload songs and remove them again
  • List uploaded songs, artists and albums

Usage

Basic usage and search querying:

from ytmusicapi import YTMusic

ytmusic = YTMusic('headers_auth.json')
playlistId = ytmusic.create_playlist('test', 'test description')
search_results = ytmusic.search('Oasis Wonderwall')
ytmusic.add_playlist_items(playlistId, [search_results[0]['videoId']])

Downloading for offline listening:

import os
import ytmusicapi

ytm = ytmusicapi.YTMusic(os.path.expanduser("~/.headers_auth.json"))

# download an artists discography
ytm.download_artist_albums("Floating Points", "~/Music")

# download the last 10 songs in your playback history
ytm.download_playlist(ytm.get_history())

# download the most recent 100 songs you liked
ytm.download_playlist(ytm.get_liked_songs(limit=100))

The tests are also a great source of usage examples.

Requirements

Setup and Usage

See the Documentation for detailed instructions

Contributing

Pull requests are welcome. There are still some features that are not yet implemented. Please, refer to CONTRIBUTING.rst for guidance.

About

Fork of Unofficial API for YouTube Music that adds the ability to download and save full-quality streams.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.9%
  • Shell 0.1%