Giter Site home page Giter Site logo

dapper91 / yandex-music-client Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 0.0 228 KB

python3 Yandex Music service client

Home Page: https://dapper91.github.io/yandex-music-client/

License: The Unlicense

Python 100.00%
python yandex-music backup yandex music music-services playlist audio-tracks

yandex-music-client's Introduction

Yandex Music client

A python3 Yandex Music service library.

This library doesn't provide an ability to download or listen audio tracks bypassing the official audio players, which violates the user agreements. The purpose of the library is to provide a sufficient way of managing your audio tracks, backup your playlists, import/export your playlists from/to your local audio library or other music services like Spotify, Apple Music and so on.

The library uses OAuth 2.0 protocol password grant type for the authentication, which means it doesn't store your password, instead it fetches a temporary token granted to access only your yandex music service data so that it doesn't jeopardize your privacy.

NB: This module uses an unofficial Yandex Music service api that has been grasped through some reverse engineering research which means it can be modified any time and the client would break down.

Dependencies

Usage example

Playlists backup

import getpass
import csv
import sys

from yamusic import exceptions, YaMusicClient


username = getpass.getuser()
username = input(f"Login ({username}): ") or username
password = getpass.getpass("Password: ")

filename = 'backup.csv'
filename = input(f"filename: ({filename}): ") or filename

print("Connecting to Yandex Music...")

try:
    ym_client = YaMusicClient(username, password)
except exceptions.AuthenticationError:
    print("Authentication error: username or password is incorrect")
    sys.exit(1)


with open(filename, 'w', newline='') as backup_file:
    csv_writer = csv.DictWriter(backup_file, fieldnames=['playlist', 'artist', 'title', 'album'])
    csv_writer.writeheader()

    print("Downloading user's playlists...")

    for playlist in ym_client.get_playlists():
        print("Backing up '{}' playlist...".format(playlist.title))

        for track in ym_client.get_playlist(playlist.kind, rich_tracks=True):
            csv_writer.writerow({
                'playlist': playlist.title,
                'artist': track.artists[0].name,
                'title': track.title,
                'album': track.albums[0].title if track.albums else '',
            })

Playlists manipulation

from yamusic import YaMusicClient


client = YaMusicClient('user', 'password')

print("User's playlists:")
for playlist in client.get_playlists():
    print("{title} ({track_count})".format(
        title=playlist.title,
        track_count=playlist.track_count)
    )


playlist_name = 'Folk'
print("{} playlist:".format(playlist_name))

for track in client.get_playlist(title=playlist_name, rich_tracks=True).tracks:
    print("\t{title} - {artists} - {albums}".format(
        title=track.title,
        artists=', '.join(map(str, track.artists)),
        albums=', '.join(map(str, track.albums)))
    )


playlist = client.create_playlist('Russian Rock')

tracks = [
    client.search_track('{} - {}'.format(artist_name, track_name))[0] for artist_name, track_name in [
        ('ДДТ',  'В последнюю осень'), 
        ('Ария', 'Я здесь'), 
        ('Кино', 'Хочу перемен'), 
        ('ДДТ',  'Просвистела'),
        ('ДДТ',  'Просвистела')
    ]
]
    
client.add_tracks_to_playlist(playlist.kind, tracks, ignore_duplicates=True)

API

https://dapper91.github.io/yandex-music-client/yamusic/api.html

License

Unlicense

yandex-music-client's People

Contributors

dapper91 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.