New supported objects: Genre, Title, RadioIcon, Images
The following methods are wrapped: - /genres - /feed/wizard/is-passed Changed getting playlists to another post request with multiple choice and tracks inside Playlist now parse tracks :) Keys that start with a digit now with a lower underscore...
このコミットが含まれているのは:
コミット
7edef8ef8b
|
@ -70,6 +70,11 @@ from landing.chart import Chart
|
|||
from landing.play_contexts_data import PlayContextsData
|
||||
from landing.personal_playlists_data import PersonalPlaylistsData
|
||||
|
||||
from genre.title import Title
|
||||
from genre.radio_icon import RadioIcon
|
||||
from genre.images import Images
|
||||
from genre.genre import Genre
|
||||
|
||||
__all__ = ['YandexMusicObject', 'Account', 'PassportPhone', 'InvocationInfo', 'Permissions', 'Plus', 'Subscription',
|
||||
'Status', 'Price', 'Product', 'AutoRenewable', 'Settings', 'PermissionAlerts', 'Experiments', 'Cover',
|
||||
'Ratings', 'Counts', 'Link', 'Artist', 'User', 'CaseForms', 'MadeFor', 'Label', 'Album', 'PlayCounter',
|
||||
|
@ -78,4 +83,5 @@ __all__ = ['YandexMusicObject', 'Account', 'PassportPhone', 'InvocationInfo', 'P
|
|||
'Feed', 'Event', 'PromoCodeStatus', 'DownloadInfo', 'Video', 'SearchResult', 'AlbumSearchResult', 'Best',
|
||||
'ArtistSearchResult', 'PlaylistSearchResult', 'TrackSearchResult', 'VideoSearchResult', 'Search',
|
||||
'Suggestions', 'MixLink', 'BlockEntity', 'Block', 'PlayContextsData', 'TrackId', 'TrackShortOld',
|
||||
'PersonalPlaylistsData', 'Promotion', 'Landing', 'Chart', 'ChartItem', 'PlayContext']
|
||||
'PersonalPlaylistsData', 'Promotion', 'Landing', 'Chart', 'ChartItem', 'PlayContext', 'Title', 'Genre',
|
||||
'RadioIcon', 'Images']
|
||||
|
|
|
@ -3,7 +3,7 @@ from datetime import datetime
|
|||
|
||||
from yandex_music import YandexMusicObject, Status, Settings, PermissionAlerts, Experiments, Artist, Album, Playlist, \
|
||||
TracksLikes, Track, AlbumsLikes, ArtistsLikes, PlaylistsLikes, Feed, PromoCodeStatus, DownloadInfo, Search, \
|
||||
Suggestions, Landing
|
||||
Suggestions, Landing, Genre
|
||||
from yandex_music.utils.request import Request
|
||||
from yandex_music.utils.difference import Difference
|
||||
from yandex_music.exceptions import InvalidToken
|
||||
|
@ -110,6 +110,13 @@ class Client(YandexMusicObject):
|
|||
|
||||
return Feed.de_json(result, self)
|
||||
|
||||
def feed_wizard_is_passed(self, timeout=None, *args, **kwargs):
|
||||
url = f'{self.base_url}/feed/wizard/is-passed'
|
||||
|
||||
result = self._request.get(url, timeout=timeout, *args, **kwargs)
|
||||
|
||||
return result.get('is_wizard_passed') or False
|
||||
|
||||
def landing(self, blocks: str or list, timeout=None, *args, **kwargs):
|
||||
url = f'{self.base_url}/landing3'
|
||||
|
||||
|
@ -117,6 +124,13 @@ class Client(YandexMusicObject):
|
|||
|
||||
return Landing.de_json(result, self)
|
||||
|
||||
def genres(self, timeout=None, *args, **kwargs):
|
||||
url = f'{self.base_url}/genres'
|
||||
|
||||
result = self._request.get(url, timeout=timeout, *args, **kwargs)
|
||||
|
||||
return Genre.de_list(result, self)
|
||||
|
||||
def tracks_download_info(self, track_id: str or int, get_direct_links=False, timeout=None, *args, **kwargs):
|
||||
url = f'{self.base_url}/tracks/{track_id}/download-info'
|
||||
|
||||
|
@ -189,15 +203,19 @@ class Client(YandexMusicObject):
|
|||
|
||||
return Suggestions.de_json(result, self)
|
||||
|
||||
def users_playlists(self, kind: str or int, user_id: str = None, timeout=None, *args, **kwargs):
|
||||
def users_playlists(self, kind: str or int or list, user_id: str = None, timeout=None, *args, **kwargs):
|
||||
if user_id is None:
|
||||
user_id = self.account.uid
|
||||
|
||||
url = f'{self.base_url}/users/{user_id}/playlists/{kind}'
|
||||
url = f'{self.base_url}/users/{user_id}/playlists'
|
||||
|
||||
result = self._request.get(url, timeout=timeout, *args, **kwargs)
|
||||
data = {
|
||||
'kinds': kind
|
||||
}
|
||||
|
||||
return Playlist.de_json(result, self)
|
||||
result = self._request.post(url, data, timeout=timeout, *args, **kwargs)
|
||||
|
||||
return Playlist.de_list(result, self)
|
||||
|
||||
def users_playlists_create(self, title: str, visibility: str = 'public', user_id: str = None,
|
||||
timeout=None, *args, **kwargs):
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
from yandex_music import YandexMusicObject
|
||||
|
||||
|
||||
class Genre(YandexMusicObject):
|
||||
def __init__(self,
|
||||
id,
|
||||
weight,
|
||||
composer_top,
|
||||
title,
|
||||
titles,
|
||||
images,
|
||||
show_in_menu,
|
||||
full_title=None,
|
||||
url_part=None,
|
||||
color=None,
|
||||
radio_icon=None,
|
||||
sub_genres=None,
|
||||
hide_in_regions=None,
|
||||
client=None,
|
||||
**kwargs):
|
||||
self.id = id
|
||||
self.weight = weight
|
||||
self.composer_top = composer_top
|
||||
self.title = title
|
||||
self.titles = titles
|
||||
self.images = images
|
||||
self.show_in_menu = show_in_menu
|
||||
|
||||
self.full_title = full_title
|
||||
self.url_part = url_part
|
||||
self.color = color
|
||||
self.radio_icon = radio_icon
|
||||
self.sub_genres = sub_genres
|
||||
self.hide_in_regions = hide_in_regions
|
||||
|
||||
self.client = client
|
||||
self._id_attrs = (self.id,)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, client):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data = super(Genre, cls).de_json(data, client)
|
||||
from yandex_music import Title, RadioIcon, Images
|
||||
data['titles'] = Title.de_dict(data.get('titles'), client)
|
||||
data['images'] = Images.de_json(data.get('images'), client)
|
||||
data['radio_icon'] = RadioIcon.de_json(data.get('radio_icon'), client)
|
||||
data['sub_genres'] = Genre.de_list(data.get('sub_genres'), client)
|
||||
|
||||
return cls(client=client, **data)
|
||||
|
||||
@classmethod
|
||||
def de_list(cls, data, client):
|
||||
if not data:
|
||||
return []
|
||||
|
||||
genres = list()
|
||||
for genre in data:
|
||||
genres.append(cls.de_json(genre, client))
|
||||
|
||||
return genres
|
|
@ -0,0 +1,23 @@
|
|||
from yandex_music import YandexMusicObject
|
||||
|
||||
|
||||
class Images(YandexMusicObject):
|
||||
def __init__(self,
|
||||
_208x208=None,
|
||||
_300x300=None,
|
||||
client=None,
|
||||
**kwargs):
|
||||
self._208x208 = _208x208
|
||||
self._300x300 = _300x300
|
||||
|
||||
self.client = client
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, client):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data = super(Images, cls).de_json(data, client)
|
||||
|
||||
return cls(client=client, **data)
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
from yandex_music import YandexMusicObject
|
||||
|
||||
|
||||
class RadioIcon(YandexMusicObject):
|
||||
def __init__(self,
|
||||
background_color,
|
||||
image_url,
|
||||
client=None,
|
||||
**kwargs):
|
||||
self.background_color = background_color
|
||||
self.image_url = image_url
|
||||
|
||||
self.client = client
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, client):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data = super(RadioIcon, cls).de_json(data, client)
|
||||
|
||||
return cls(client=client, **data)
|
|
@ -0,0 +1,33 @@
|
|||
from yandex_music import YandexMusicObject
|
||||
|
||||
|
||||
class Title(YandexMusicObject):
|
||||
def __init__(self,
|
||||
title,
|
||||
full_title=None,
|
||||
client=None,
|
||||
**kwargs):
|
||||
self.title = title
|
||||
self.full_title = full_title
|
||||
|
||||
self.client = client
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, client):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data = super(Title, cls).de_json(data, client)
|
||||
|
||||
return cls(client=client, **data)
|
||||
|
||||
@classmethod
|
||||
def de_dict(cls, data, client):
|
||||
if not data:
|
||||
return {}
|
||||
|
||||
titles = dict()
|
||||
for lang, title in data.items():
|
||||
titles.update({lang: cls.de_json(title, client)})
|
||||
|
||||
return titles
|
|
@ -25,6 +25,7 @@ class Playlist(YandexMusicObject):
|
|||
is_premiere=None,
|
||||
duration_ms=None,
|
||||
og_image=None,
|
||||
tracks=None,
|
||||
prerolls=None,
|
||||
likes_count=None,
|
||||
generated_playlist_type=None,
|
||||
|
@ -56,6 +57,7 @@ class Playlist(YandexMusicObject):
|
|||
self.is_premiere = is_premiere
|
||||
self.duration_ms = duration_ms
|
||||
self.og_image = og_image
|
||||
self.tracks = tracks
|
||||
self.prerolls = prerolls
|
||||
self.likes_count = likes_count
|
||||
self.animated_cover_uri = animated_cover_uri
|
||||
|
@ -90,10 +92,11 @@ class Playlist(YandexMusicObject):
|
|||
return None
|
||||
|
||||
data = super(Playlist, cls).de_json(data, client)
|
||||
from yandex_music import User, MadeFor, Cover, PlayCounter
|
||||
from yandex_music import User, MadeFor, Cover, PlayCounter, TrackShort
|
||||
data['owner'] = User.de_json(data.get('owner'), client)
|
||||
data['cover'] = Cover.de_json(data.get('cover'), client)
|
||||
data['made_for'] = MadeFor.de_json(data.get('made_for'), client)
|
||||
data['tracks'] = TrackShort.de_list(data.get('tracks'), client)
|
||||
data['play_counter'] = PlayCounter.de_json(data.get('play_counter'), client)
|
||||
|
||||
return cls(client=client, **data)
|
||||
|
|
|
@ -46,6 +46,10 @@ class Request(object):
|
|||
for key, value in obj.items():
|
||||
key = Request._convert_camel_to_snake(key.replace('-', '_'))
|
||||
key = key.replace('client', 'client_')
|
||||
|
||||
if len(key) and key[0].isdigit():
|
||||
key = '_' + key
|
||||
|
||||
cleaned_object.update({key: value})
|
||||
|
||||
return cleaned_object
|
||||
|
|
読み込み中…
新しいイシューから参照