Developer Interface¶
Yandex music client library.
Client¶
Yandex music service client.
-
class
yamusic.client.
OAuthCred
(access_token, user_id)¶ -
property
access_token
¶ Alias for field number 0
-
property
user_id
¶ Alias for field number 1
-
property
-
class
yamusic.client.
YaMusicClient
(login: Optional[str] = None, password: Optional[str] = None, *, device_id: Optional[str] = None, app_uuid: Optional[str] = None, oauth_cred: Optional[yamusic.client.OAuthCred] = None)¶ A Yandex music service client. Creates a client instance and authenticates on the service if login and password are provided.
- Parameters
login – yandex account user name
password – yandex account password
device_id – local device id (will be automatically generated if omitted)
app_uuid – unique identifier (will be automatically generated if omitted)
auth_cred – authentication data, (access_token, user_id) pair
-
auth
(login: str, password: str) → None¶ Authenticates on the service as a login user.
- Parameters
login – yandex account user name
password – yandex account password
- Raises
exceptions.AuthenticationError – if the credentials are not valid
-
logout
() → None¶ Forget current user credentials.
-
property
is_authenticated
¶ Checks if the client is authenticated.
- Returns
True if the client is authenticated otherwise False
-
get_genres
() → List[yamusic.models.Genre]¶ Returns a list of available genres.
- Returns
genre list
-
get_playlists
(*, user_id: Optional[int] = None) → List[yamusic.models.Playlist]¶ Returns user’s playlist list. If user_id argument is omitted current user id is used.
- Parameters
user_id – user id
- Returns
playlist list
- Return type
List[entities.Playlist]
-
get_playlist
(playlist_id: Optional[int] = None, *, title: Optional[str] = None, user_id: Optional[int] = None, rich_tracks: bool = False) → Union[yamusic.models.Playlist[TrackWrapper], yamusic.models.Playlist[Track]]¶ Returns a playlist by id or title. If user_id argument is omitted current user id is used.
- Parameters
playlist_id – playlist id
title – playlist title
user_id – user id
rich_tracks – whether to add additional information to the tracks
- Returns
requested playlist
-
create_playlist
(title: str, *, visibility: yamusic.models.Visibility = <Visibility.PRIVATE: 'private'>) → yamusic.models.Playlist¶ Creates a new playlist. Client should be authenticated on the service.
- Parameters
title – playlist title
visibility – playlist visibility
- Returns
created playlist
-
delete_playlist
(playlist_id: int) → None¶ Deletes playlist by an id. Client should be authenticated on the service.
- Parameters
playlist_id – playlist id
-
rename_playlist
(playlist_id: int, *, title: str) → None¶ Renames playlist by an id. Client should be authenticated on the service.
- Parameters
playlist_id – playlist id
title – new title
-
add_tracks_to_playlist
(playlist_id: int, tracks: List[Union[yamusic.models.TrackWrapper, yamusic.models.Track]], *, at_position: int = 0, ignore_duplicates: bool = False) → None¶ Adds tracks to a playlist. Client should be authenticated on the service.
- Parameters
playlist_id – playlist id to add the tracks to
tracks – track list to add to the playlist
at_position – position to add tracks at
ignore_duplicates – ignore duplicate tracks
-
delete_tracks_from_playlist
(playlist_id: int, *, from_track: int, to_track: int) → None¶ Deletes tracks from the playlist. Client should be authenticated on the service.
- Parameters
playlist_id – playlist id
from_track – start position of the tracks to delete
to_track – end position of the tracks to delete
-
search
(query: str, *, search_type: yamusic.models.SearchType = <SearchType.ALL: 'all'>, page: int = 0) → yamusic.models.SearchResult¶ Search for entities.
- Parameters
query – query string
search_type – search type
page – result page number
- Returns
search result
-
search_artist
(name: str, *, page: int = 0) → List[yamusic.models.Artist]¶ Searches for artists with the requested name.
- Parameters
name – artist name
page – result page number
- Returns
a list of the requested artists
-
search_album
(title: str, *, page: int = 0) → List[yamusic.models.Album]¶ Searches for albums with the requested title.
- Parameters
title – album title
page – result page number
- Returns
a list of the requested albums
-
search_track
(title: str, *, page: int = 0) → List[yamusic.models.Track]¶ Searches for tracks with the requested title.
- Parameters
title – track title
page – result page number
- Returns
a list of the requested tracks
-
get_album
(album_id: int) → List[yamusic.models.Album]¶ Returns an album with album_id id
- Parameters
album_id – album id
- Returns
requested album
-
get_similar_tracks
(track_id: int) → yamusic.models.Similar¶ Returns tracks similar to the track with track_id id
- Parameters
track_id – track id
- Returns
list of similar tracks
Models¶
-
class
yamusic.models.
Visibility
¶ Visibility.
-
class
yamusic.models.
Sex
¶ Sex.
-
class
yamusic.models.
SearchType
¶ Search type.
-
class
yamusic.models.
Genre
¶ Music genre model.
- Parameters
id – genre identifier
title – genre title
full_title – genre full title
-
class
yamusic.models.
User
¶ User model.
- Parameters
uid – user identifier
login – user login name
sex – user sex
verified – whether user is verified
-
class
yamusic.models.
Album
¶ Album model.
- Parameters
id – album identifier
title – album title
track_count – album tracks count
genre – album genre
year – album recording year
release_date – album release date
-
class
yamusic.models.
Artist
¶ Artist model.
- Parameters
id – artist identifier
name – artist name
composer – whether artist is a composer
genres – artist genre list
-
class
yamusic.models.
Track
¶ Audio track model.
- Parameters
id – track identifier
title – track title
albums – track albums
artists – track artists
available – whether track available
lyrics_available – whether lyrics available
type – track type
duration_ms – track duration
real_id – track read id
cover_uri – track cover url
major – track major (label)
files_size – track file size
normalization – track audio normalization information
-
property
album_id
¶ Returns track album identifier.
-
property
uid
¶ Playlist unique identifier.
-
class
yamusic.models.
TrackWrapper
¶ Audio track wrapper model. Contains
- Parameters
id – track identifier
album_id – track album identifier
timestamp – track timestamp
track – detailed track information
-
property
is_rich
¶ Whether track wrapper is reach (contains detailed track information).
-
property
uid
¶ Playlist unique identifier.
-
unwrap
() → yamusic.models.Track¶ Returns detailed track information if wrapper is reach, raise ValueError exception otherwise.
-
class
yamusic.models.
Similar
¶ Similar tracks request result.
- Parameters
track – requested track
similar_tracks – list of similar tracks
-
class
yamusic.models.
Playlist
¶ Music playlist model. Represents a collection of tracks plus some meta-information.
- Parameters
kind – playlist identifier
title – playlist title
track_count – playlist track count
owner – playlist owner
tags – playlist tag list
cover – playlist cover
track_ids – playlist track id list
duration – playlist duration
tracks – playlist track list
modified – playlist last modification time
revision – playlist revision number (modification counter)
visibility – whether playlist is visible
likes_count – plyalsit likes count
collective – whether playlist is collective
-
property
uid
¶ Playlist unique identifier.
-
class
yamusic.models.
SearchResult
¶ Search result.
- Parameters
albums – list of found albums
artists – list of found artists
tracks – list of found tracks
playlists – list of found playlists
Exceptions¶
Exception classes for library-related errors.
-
exception
yamusic.exceptions.
BaseError
¶ Base module exception.
-
exception
yamusic.exceptions.
AuthenticationError
¶ Authentication error.
-
exception
yamusic.exceptions.
ResponseFormatError
¶ Response formant is not correct.
-
exception
yamusic.exceptions.
NotFoundError
¶ Requested object not found.