radiojavanapi 0.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- radiojavanapi/__init__.py +50 -0
- radiojavanapi/constants.py +11 -0
- radiojavanapi/exceptions.py +46 -0
- radiojavanapi/extractors.py +159 -0
- radiojavanapi/helper.py +11 -0
- radiojavanapi/mixins/__init__.py +1 -0
- radiojavanapi/mixins/account.py +231 -0
- radiojavanapi/mixins/album.py +45 -0
- radiojavanapi/mixins/artist.py +76 -0
- radiojavanapi/mixins/auth.py +106 -0
- radiojavanapi/mixins/browse.py +89 -0
- radiojavanapi/mixins/playlist.py +312 -0
- radiojavanapi/mixins/podcast.py +74 -0
- radiojavanapi/mixins/private.py +109 -0
- radiojavanapi/mixins/search.py +35 -0
- radiojavanapi/mixins/song.py +85 -0
- radiojavanapi/mixins/story.py +75 -0
- radiojavanapi/mixins/user.py +110 -0
- radiojavanapi/mixins/video.py +86 -0
- radiojavanapi/models.py +232 -0
- radiojavanapi-0.7.0.dist-info/METADATA +120 -0
- radiojavanapi-0.7.0.dist-info/RECORD +25 -0
- radiojavanapi-0.7.0.dist-info/WHEEL +5 -0
- radiojavanapi-0.7.0.dist-info/licenses/LICENSE +21 -0
- radiojavanapi-0.7.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from radiojavanapi.mixins.song import SongMixin
|
|
3
|
+
from radiojavanapi.mixins.album import AlbumMixin
|
|
4
|
+
from radiojavanapi.mixins.story import StoryMixin
|
|
5
|
+
from radiojavanapi.mixins.browse import BrowseMixin
|
|
6
|
+
from radiojavanapi.mixins.playlist import MusicPlayListMixin, VideoPlayListMixin
|
|
7
|
+
from radiojavanapi.mixins.podcast import PodcastMixin
|
|
8
|
+
from radiojavanapi.mixins.video import VideoMixin
|
|
9
|
+
from radiojavanapi.mixins.account import AccountMixin
|
|
10
|
+
|
|
11
|
+
class Client(
|
|
12
|
+
AccountMixin,
|
|
13
|
+
VideoMixin,
|
|
14
|
+
SongMixin,
|
|
15
|
+
PodcastMixin,
|
|
16
|
+
BrowseMixin,
|
|
17
|
+
VideoPlayListMixin,
|
|
18
|
+
MusicPlayListMixin,
|
|
19
|
+
StoryMixin,
|
|
20
|
+
AlbumMixin
|
|
21
|
+
):
|
|
22
|
+
"""
|
|
23
|
+
Class used to access all features, this is the only class that
|
|
24
|
+
needs to be imported (along with the exceptions)
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def set_proxy(self, proxy:dict) -> None:
|
|
28
|
+
assert isinstance(proxy, dict), f'Proxy must been Dict, but now "{proxy}" ({type(proxy)})'
|
|
29
|
+
self.private.proxies = self.proxy = proxy
|
|
30
|
+
|
|
31
|
+
def unset_proxy(self) -> None:
|
|
32
|
+
self.private.proxies = self.proxy = None
|
|
33
|
+
|
|
34
|
+
def save_session(self, path: str) -> bool:
|
|
35
|
+
with open(path, 'w') as wf:
|
|
36
|
+
json.dump({
|
|
37
|
+
'cookie': self.cookie,
|
|
38
|
+
'email': self.email
|
|
39
|
+
}, wf, indent=4)
|
|
40
|
+
return True
|
|
41
|
+
|
|
42
|
+
def load_session(self, path: str) -> bool:
|
|
43
|
+
with open(path, 'r') as rf:
|
|
44
|
+
json_data = json.load(rf)
|
|
45
|
+
self.initial()
|
|
46
|
+
self.authorized = True
|
|
47
|
+
self.cookie = json_data['cookie']
|
|
48
|
+
self.email = json_data['email']
|
|
49
|
+
self.private.headers.update({'Cookie': self.cookie})
|
|
50
|
+
return True
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
API_DOMAIN = "https://rj-deskcloud.com/api2/{}"
|
|
2
|
+
|
|
3
|
+
BASE_HEADERS = {
|
|
4
|
+
'Accept': 'application/json, text/plain, */*',
|
|
5
|
+
'Accept-Language': 'en-US',
|
|
6
|
+
'Accept-Encoding': 'gzip, deflate',
|
|
7
|
+
'Host': 'rj-deskcloud.com',
|
|
8
|
+
'Connection': 'keep-alive',
|
|
9
|
+
'x-rj-user-agent': 'Radio Javan/5.0.0 (Desktop) com.radioJavan.rj.desktop',
|
|
10
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RadioJavan/5.2.0 Chrome/130.0.6723.118 Electron/33.2.0 Safari/537.36',
|
|
11
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
class ClientError(Exception):
|
|
2
|
+
def __init__(self, *args, **kwargs):
|
|
3
|
+
super().__init__(*args, **kwargs)
|
|
4
|
+
|
|
5
|
+
class ClientLoginRequired(ClientError):
|
|
6
|
+
pass
|
|
7
|
+
|
|
8
|
+
class ClientJSONDecodeError(ClientError):
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
class ClientConnectionError(ClientError):
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
class PrivateError(ClientError):
|
|
15
|
+
"""For Private API"""
|
|
16
|
+
|
|
17
|
+
class BadCredentials(PrivateError):
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
class InvalidName(PrivateError):
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
class LongString(PrivateError):
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
class EmailExists(PrivateError):
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
class UsernameExists(PrivateError):
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
class DuplicateName(PrivateError):
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
class InvalidMediaId(PrivateError):
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
class InvalidEmail(PrivateError):
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
class DuplicatePassword(PrivateError):
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
class UnknownError(PrivateError):
|
|
45
|
+
pass
|
|
46
|
+
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
from radiojavanapi.helper import to_int
|
|
2
|
+
from radiojavanapi.models import (
|
|
3
|
+
Account, Album, Artist, MyPlaylists, NotificationsStatus,
|
|
4
|
+
ShortUser, Song, MusicPlaylist, Story, User, Video,
|
|
5
|
+
ShortData, Podcast, SearchResults, VideoPlaylist
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
def extract_account(data) -> Account:
|
|
9
|
+
data["default_thumbnail"] = data.pop('default_thumb')
|
|
10
|
+
data["has_subscription"] = data.pop('subscription')
|
|
11
|
+
data["has_custom_photo"] = data.pop('custom_photo')
|
|
12
|
+
data["is_verified"] = data.pop('verify')
|
|
13
|
+
data["artists_name"] = [artist["name"] for artist in data.pop('artists')]
|
|
14
|
+
data["stories"] = [extract_story(story)
|
|
15
|
+
for story in data.pop('selfies',[])]
|
|
16
|
+
return Account(**data)
|
|
17
|
+
|
|
18
|
+
def extract_user(data) -> User:
|
|
19
|
+
data["default_thumbnail"] = data.pop('default_thumb')
|
|
20
|
+
data["has_custom_photo"] = data.pop('custom_photo')
|
|
21
|
+
data["has_subscription"] = data.pop('subscription')
|
|
22
|
+
data["is_verified"] = data.pop('verify')
|
|
23
|
+
data["artists_name"] = [artist["name"] for artist in data.pop('artists')]
|
|
24
|
+
data["stories"] = [extract_story(story)
|
|
25
|
+
for story in data.pop('selfies',[])]
|
|
26
|
+
data["music_playlists"] = [extract_short_data(playlist['playlist'], MusicPlaylist)
|
|
27
|
+
for playlist in data.pop('playlists')]
|
|
28
|
+
return User(**data)
|
|
29
|
+
|
|
30
|
+
def extract_song(data) -> Song:
|
|
31
|
+
album = data.pop('album', None)
|
|
32
|
+
if type(album) == dict:
|
|
33
|
+
album = album.pop('album', None)
|
|
34
|
+
data["album"] = album if album else data.pop('album', None)
|
|
35
|
+
data["plays"] = to_int(data.pop('plays'))
|
|
36
|
+
data["name"] = data.pop('song')
|
|
37
|
+
data["likes"] = to_int(data.pop('likes'))
|
|
38
|
+
data["dislikes"] = to_int(data.pop('dislikes'))
|
|
39
|
+
data["downloads"] = to_int(data.pop('downloads'))
|
|
40
|
+
data["related_songs"] = [extract_short_data(song, Song) for song in data.pop('related',[])]
|
|
41
|
+
data["stories"] = [extract_story(story) for story in data.pop('selfies',[])]
|
|
42
|
+
return Song(**data)
|
|
43
|
+
|
|
44
|
+
def extract_video(data) -> Video:
|
|
45
|
+
data["lq_hls"] = data.get('low_web')
|
|
46
|
+
data["hq_hls"] = data.get('high_web')
|
|
47
|
+
data["name"] = data.pop('song')
|
|
48
|
+
data["views"] = to_int(data.pop('views'))
|
|
49
|
+
data["likes"] = to_int(data.pop('likes'))
|
|
50
|
+
data["dislikes"] = to_int(data.pop('dislikes'))
|
|
51
|
+
data["related_videos"] = [extract_short_data(video, Video) for video in data.pop('related',[])]
|
|
52
|
+
return Video(**data)
|
|
53
|
+
|
|
54
|
+
def extract_podcast(data) -> Podcast:
|
|
55
|
+
data["is_talk"] = data.pop('talk')
|
|
56
|
+
data["plays"] = to_int(data.pop('plays'))
|
|
57
|
+
data["likes"] = to_int(data.pop('likes'))
|
|
58
|
+
data["dislikes"] = to_int(data.pop('dislikes'))
|
|
59
|
+
data["related_podcasts"] = [extract_short_data(podcast, Podcast) for podcast in data.pop('related',[])]
|
|
60
|
+
return Podcast(**data)
|
|
61
|
+
|
|
62
|
+
def extract_artist(data) -> Artist:
|
|
63
|
+
data["photo_thumbnail"] = data.pop('photo_thumb')
|
|
64
|
+
data["latest_song"] = extract_short_data(data.pop('latest'), Song) if data.get('latest') else None
|
|
65
|
+
data['name'] = data.pop('query')
|
|
66
|
+
followers = data.pop('followers')
|
|
67
|
+
data["followers_count"] = followers['count']
|
|
68
|
+
data["following"] = followers['following']
|
|
69
|
+
data["plays"] = followers['plays']
|
|
70
|
+
data["songs"] = [extract_short_data(mp3, Song) for mp3 in data.pop('mp3s')]
|
|
71
|
+
data["albums"] = [extract_short_data(album, Album) for album in data.pop('albums')]
|
|
72
|
+
data["videos"] = [extract_short_data(video, Video) for video in data.pop('videos')]
|
|
73
|
+
data["podcasts"] = [extract_short_data(podcasts, Podcast) for podcasts in data.pop('podcasts')]
|
|
74
|
+
data["music_playlists"] = [extract_short_data(playlist['playlist'], MusicPlaylist)
|
|
75
|
+
for playlist in data.pop('playlists')]
|
|
76
|
+
return Artist(**data)
|
|
77
|
+
|
|
78
|
+
def extract_short_data(data, type) -> ShortData:
|
|
79
|
+
if type == Song or type == Video:
|
|
80
|
+
data["name"] = data["song"]
|
|
81
|
+
|
|
82
|
+
elif type == Album:
|
|
83
|
+
data["artist"] = data["album_artist"]
|
|
84
|
+
data["name"] = data["album_album"]
|
|
85
|
+
|
|
86
|
+
elif type == Podcast:
|
|
87
|
+
data["artist"] = data["podcast_artist"]
|
|
88
|
+
data["name"] = data["title"]
|
|
89
|
+
data["title"] = '{} - \"{}\"'.format(data["artist"], data["name"])
|
|
90
|
+
|
|
91
|
+
elif type == MusicPlaylist:
|
|
92
|
+
data["name"] = data["title"]
|
|
93
|
+
data["title"] = '{} - \"{}\"'.format(data["name"], data["created_by"])
|
|
94
|
+
|
|
95
|
+
elif type == VideoPlaylist:
|
|
96
|
+
data["name"] = data["title"]
|
|
97
|
+
|
|
98
|
+
elif type == 'show':
|
|
99
|
+
data["artist"] = data["date"]
|
|
100
|
+
data["name"] = data["show_title"]
|
|
101
|
+
data["title"] = '{} - \"{}\"'.format(data["artist"], data["name"])
|
|
102
|
+
data["permlink"] = data["show_permlink"]
|
|
103
|
+
|
|
104
|
+
return ShortData(**data)
|
|
105
|
+
|
|
106
|
+
def extract_search_results(data) -> SearchResults:
|
|
107
|
+
data["songs"] = [extract_short_data(mp3, Song) for mp3 in data.pop('mp3s')]
|
|
108
|
+
data["albums"] = [extract_short_data(album, Album) for album in data.pop('albums')]
|
|
109
|
+
data["videos"] = [extract_short_data(video, Video) for video in data.pop('videos')]
|
|
110
|
+
data["podcasts"] = [extract_short_data(podcasts, Podcast) for podcasts in data.pop('podcasts')]
|
|
111
|
+
data["shows"] = [extract_short_data(show, 'show') for show in data.pop('shows')]
|
|
112
|
+
data["users"] = [extract_short_user(profile) for profile in data.pop('profiles')]
|
|
113
|
+
data["artist_names"] = [artist["name"] for artist in data.pop('artists')]
|
|
114
|
+
data["music_playlists"] = [extract_short_data(playlist['playlist'], MusicPlaylist)
|
|
115
|
+
for playlist in data.pop('playlists')]
|
|
116
|
+
return SearchResults(**data)
|
|
117
|
+
|
|
118
|
+
def extract_video_playlist(data) -> VideoPlaylist:
|
|
119
|
+
data['is_my_playlist'] = data.pop('myplaylist')
|
|
120
|
+
data["videos"] = [extract_video(video) for video in data.pop('items',[])]
|
|
121
|
+
return VideoPlaylist(**data)
|
|
122
|
+
|
|
123
|
+
def extract_music_playlist(data) -> MusicPlaylist:
|
|
124
|
+
data['is_my_playlist'] = data.pop('myplaylist')
|
|
125
|
+
data['is_public'] = data.pop('public')
|
|
126
|
+
data['has_custom_photo'] = data.pop('custom_photo')
|
|
127
|
+
data["sync"] = True if data.pop('sync', None) else False
|
|
128
|
+
data["songs"] = [extract_song(song) for song in data.pop('items',[])]
|
|
129
|
+
return MusicPlaylist(**data)
|
|
130
|
+
|
|
131
|
+
def extract_short_user(data) -> Story:
|
|
132
|
+
return ShortUser(**data)
|
|
133
|
+
|
|
134
|
+
def extract_story(data) -> Story:
|
|
135
|
+
data['is_verified'] = data.pop('verified')
|
|
136
|
+
data['lq_link'] = data.pop('hls')
|
|
137
|
+
data["song_id"] = data.pop('mp3')
|
|
138
|
+
data['is_my_story'] = data.pop('myselfie',None)
|
|
139
|
+
data['user'] = extract_short_user(data.pop('user'))
|
|
140
|
+
return Story(**data)
|
|
141
|
+
|
|
142
|
+
def extract_album(data):
|
|
143
|
+
data["tracks"] = [extract_song(song)
|
|
144
|
+
for song in data.pop('album_tracks')]
|
|
145
|
+
data['name'] = data.pop('album_album')
|
|
146
|
+
data['artist'] = data.pop('album_artist')
|
|
147
|
+
data['share_link'] = data.get('album_share_link','share_link')
|
|
148
|
+
return Album(**data)
|
|
149
|
+
|
|
150
|
+
def extract_my_playlists(data):
|
|
151
|
+
return MyPlaylists(**{
|
|
152
|
+
"music_playlists": [extract_short_data(mpl, MusicPlaylist)
|
|
153
|
+
for mpl in data['mp3s']['myplaylists']],
|
|
154
|
+
"video_playlists": [extract_short_data(vpl, VideoPlaylist)
|
|
155
|
+
for vpl in data['videos']['myplaylists']]
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
def extract_notifications_status(data) -> NotificationsStatus:
|
|
159
|
+
return NotificationsStatus(**data)
|
radiojavanapi/helper.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
def url_to_id(url: str) -> str:
|
|
4
|
+
return re.findall(
|
|
5
|
+
r'.*[video|mp3|song|podcast|artist|story|preview|u]/([\d\w\-_()+\.]+)',url)[0]
|
|
6
|
+
|
|
7
|
+
def to_int(string: str) -> int:
|
|
8
|
+
return int(string.replace(',','').replace('+',''))
|
|
9
|
+
|
|
10
|
+
def extract_cookie(string: str) -> str:
|
|
11
|
+
return re.findall(r'(_rj_web=.*?;)', string)[0]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
from radiojavanapi.mixins.user import UserMixin
|
|
2
|
+
from radiojavanapi.mixins.auth import AuthMixin
|
|
3
|
+
from radiojavanapi.models import Account, MyPlaylists, NotificationsStatus, ShortUser
|
|
4
|
+
from radiojavanapi.extractors import extract_account, extract_my_playlists, extract_notifications_status
|
|
5
|
+
|
|
6
|
+
from typing import List
|
|
7
|
+
|
|
8
|
+
class AccountMixin(AuthMixin, UserMixin):
|
|
9
|
+
def account_info(self) -> Account:
|
|
10
|
+
"""
|
|
11
|
+
Get private info for your account
|
|
12
|
+
|
|
13
|
+
Returns
|
|
14
|
+
-------
|
|
15
|
+
Account: An object of Account type
|
|
16
|
+
|
|
17
|
+
"""
|
|
18
|
+
response = self.private_request('user_profile', need_login=True).json()
|
|
19
|
+
return extract_account(response)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def account_edit(self,
|
|
23
|
+
firstname: str = None,
|
|
24
|
+
lastname: str = None,
|
|
25
|
+
username: str = None,
|
|
26
|
+
email: str = None,
|
|
27
|
+
bio: str = None,
|
|
28
|
+
_remove_photo: bool = False
|
|
29
|
+
) -> Account:
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
Change profile data (e.g. email, firstname, ...).
|
|
33
|
+
Note: To remove bio, pass empty string.
|
|
34
|
+
|
|
35
|
+
Arguments
|
|
36
|
+
----------
|
|
37
|
+
firstname: Account's firstname
|
|
38
|
+
lastname : Account's lastname
|
|
39
|
+
username : Account's username
|
|
40
|
+
email : Account's email
|
|
41
|
+
|
|
42
|
+
Returns
|
|
43
|
+
-------
|
|
44
|
+
Account: An object of Account type
|
|
45
|
+
|
|
46
|
+
"""
|
|
47
|
+
account = self.account_info()
|
|
48
|
+
payload = {
|
|
49
|
+
'firstname' : firstname or account.firstname,
|
|
50
|
+
'lastname' : lastname or account.lastname,
|
|
51
|
+
'email' : email or account.email,
|
|
52
|
+
'username' : username or account.username,
|
|
53
|
+
}
|
|
54
|
+
if _remove_photo:
|
|
55
|
+
payload.update({"remove_photo": True})
|
|
56
|
+
|
|
57
|
+
if bio != None:
|
|
58
|
+
payload.update({"bio": bio})
|
|
59
|
+
|
|
60
|
+
self.private_request('user_profile_update',
|
|
61
|
+
json=payload, need_login=True)
|
|
62
|
+
return self.account_info()
|
|
63
|
+
|
|
64
|
+
def account_notifications(self) -> NotificationsStatus:
|
|
65
|
+
"""
|
|
66
|
+
Get current status of account notifications settings
|
|
67
|
+
|
|
68
|
+
Returns
|
|
69
|
+
-------
|
|
70
|
+
NotificationsStatus: An object of NotificationsStatus type which holds current settings
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
response = self.private_request('user_notifications', need_login=True).json()
|
|
74
|
+
return extract_notifications_status(response)
|
|
75
|
+
|
|
76
|
+
def account_notifications_update(self,
|
|
77
|
+
new_music: bool = None,
|
|
78
|
+
followed_artists: bool = None,
|
|
79
|
+
) -> bool:
|
|
80
|
+
|
|
81
|
+
"""
|
|
82
|
+
Update account notifications settings.
|
|
83
|
+
|
|
84
|
+
Arguments
|
|
85
|
+
----------
|
|
86
|
+
new_music: Send email notifications about new music.
|
|
87
|
+
followed_artists : Send email notifications about artists that you follow.
|
|
88
|
+
|
|
89
|
+
Returns
|
|
90
|
+
-------
|
|
91
|
+
bool: Returns true if success
|
|
92
|
+
|
|
93
|
+
"""
|
|
94
|
+
acc_notif = self.account_notifications()
|
|
95
|
+
payload = {
|
|
96
|
+
'music_email' : str(int(new_music if new_music != None else acc_notif.music_email)),
|
|
97
|
+
'artists_email' : str(int(followed_artists if followed_artists != None else acc_notif.artists_email))
|
|
98
|
+
}
|
|
99
|
+
return self.private_request('user_notifications_update',
|
|
100
|
+
json=payload, need_login=True).json()['success']
|
|
101
|
+
|
|
102
|
+
def change_password(self, password: str) -> bool:
|
|
103
|
+
"""
|
|
104
|
+
Change your account password
|
|
105
|
+
|
|
106
|
+
Arguments
|
|
107
|
+
----------
|
|
108
|
+
password: Your new password
|
|
109
|
+
|
|
110
|
+
Returns
|
|
111
|
+
-------
|
|
112
|
+
bool: Returns true if success
|
|
113
|
+
|
|
114
|
+
"""
|
|
115
|
+
response = self.private_request('user_password_update',
|
|
116
|
+
json={
|
|
117
|
+
"oldpass" : self.password,
|
|
118
|
+
"newpass1": password,
|
|
119
|
+
"newpass2": password
|
|
120
|
+
}, need_login=True)
|
|
121
|
+
|
|
122
|
+
response_json = response.json()
|
|
123
|
+
if response_json['success']:
|
|
124
|
+
self.password = password
|
|
125
|
+
self.cookie = {
|
|
126
|
+
'Cookie': '_rj_web={}'.format(
|
|
127
|
+
response.headers['Set-Cookie'].split('_rj_web=')[1].split(';')[0]
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
self.private.headers.update(self.cookie)
|
|
131
|
+
return True
|
|
132
|
+
return False
|
|
133
|
+
|
|
134
|
+
def upload_photo(self, photo_path: str) -> bool:
|
|
135
|
+
"""
|
|
136
|
+
Upload your profile photo (support jpg/png)
|
|
137
|
+
|
|
138
|
+
Arguments
|
|
139
|
+
----------
|
|
140
|
+
photo_path:
|
|
141
|
+
Path to the image you want to upload
|
|
142
|
+
|
|
143
|
+
Returns
|
|
144
|
+
-------
|
|
145
|
+
bool: Returns true if success
|
|
146
|
+
|
|
147
|
+
"""
|
|
148
|
+
account = self.account_info()
|
|
149
|
+
with open(photo_path, 'rb') as photo:
|
|
150
|
+
fields = {
|
|
151
|
+
'firstname': account.firstname,
|
|
152
|
+
'lastname': account.lastname,
|
|
153
|
+
'email': account.email,
|
|
154
|
+
'username': account.username,
|
|
155
|
+
'remove_photo': 'undefined',
|
|
156
|
+
'photo': ('0', photo, 'image/jpeg')
|
|
157
|
+
}
|
|
158
|
+
return self.private_request('user_profile_update',
|
|
159
|
+
fields=fields , need_login=True).json()['success']
|
|
160
|
+
|
|
161
|
+
def remove_photo(self) -> bool:
|
|
162
|
+
"""
|
|
163
|
+
Remove your profile photo
|
|
164
|
+
|
|
165
|
+
Returns
|
|
166
|
+
-------
|
|
167
|
+
bool: Returns true if removed successfully
|
|
168
|
+
|
|
169
|
+
"""
|
|
170
|
+
account = self.account_edit(_remove_photo = True)
|
|
171
|
+
return account.has_custom_photo != True
|
|
172
|
+
|
|
173
|
+
def deactive_account(self) -> bool:
|
|
174
|
+
"""
|
|
175
|
+
Deactivate your profile and logout
|
|
176
|
+
|
|
177
|
+
Returns
|
|
178
|
+
-------
|
|
179
|
+
bool: Returns true if success
|
|
180
|
+
|
|
181
|
+
"""
|
|
182
|
+
if self.private_request('deactivate',
|
|
183
|
+
need_login=True).json()['success'] and self.logout():
|
|
184
|
+
return True
|
|
185
|
+
return False
|
|
186
|
+
|
|
187
|
+
def following_artists(self) -> List[str]:
|
|
188
|
+
"""
|
|
189
|
+
Get list of artist names which you've followed
|
|
190
|
+
|
|
191
|
+
Returns
|
|
192
|
+
-------
|
|
193
|
+
List: names list
|
|
194
|
+
|
|
195
|
+
"""
|
|
196
|
+
return self.account_info().artists_name
|
|
197
|
+
|
|
198
|
+
def my_followers(self) -> List[ShortUser]:
|
|
199
|
+
"""
|
|
200
|
+
Get list of your followers
|
|
201
|
+
|
|
202
|
+
Returns
|
|
203
|
+
-------
|
|
204
|
+
List[ShortUser]: list of your followers as ShortUser object
|
|
205
|
+
|
|
206
|
+
"""
|
|
207
|
+
return self.get_user_followers(self.account_info().username)
|
|
208
|
+
|
|
209
|
+
def my_following(self) -> List[ShortUser]:
|
|
210
|
+
"""
|
|
211
|
+
Get list of user which you've followed
|
|
212
|
+
|
|
213
|
+
Returns
|
|
214
|
+
-------
|
|
215
|
+
List[ShortUser]: list of your following as ShortUser object
|
|
216
|
+
|
|
217
|
+
"""
|
|
218
|
+
return self.get_user_following(self.account_info().username)
|
|
219
|
+
|
|
220
|
+
def my_playlists(self) -> MyPlaylists:
|
|
221
|
+
"""
|
|
222
|
+
Get your MusicPlaylist & VideoPlaylist' shortdata as MyPlaylists Object
|
|
223
|
+
|
|
224
|
+
Returns
|
|
225
|
+
-------
|
|
226
|
+
MyPlaylists: An object of MyPlaylists type
|
|
227
|
+
|
|
228
|
+
"""
|
|
229
|
+
response = self.private_request('playlists_dash', need_login=True).json()
|
|
230
|
+
return extract_my_playlists(response)
|
|
231
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from radiojavanapi.mixins.search import SearchMixin
|
|
2
|
+
from radiojavanapi.extractors import extract_album
|
|
3
|
+
from radiojavanapi.models import Album
|
|
4
|
+
from radiojavanapi.helper import url_to_id
|
|
5
|
+
|
|
6
|
+
from typing import Union
|
|
7
|
+
from pydantic import HttpUrl
|
|
8
|
+
|
|
9
|
+
class AlbumMixin(SearchMixin):
|
|
10
|
+
def get_album_by_url(self, url: HttpUrl) -> Album:
|
|
11
|
+
"""
|
|
12
|
+
Get album info by site url (e.g. `play.radiojavan.com/album/...` or `play.radiojavan.com/redirect?r=radiojavan://mp3_album/...`)
|
|
13
|
+
|
|
14
|
+
Arguments
|
|
15
|
+
----------
|
|
16
|
+
url: Site url of album
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
Album: An object of Album type
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
query = url_to_id(url).lower().replace('-',' ')
|
|
24
|
+
albums = self.search(query).albums
|
|
25
|
+
for album in albums:
|
|
26
|
+
if album.artist.lower() in query and album.name.lower() in query:
|
|
27
|
+
return self.get_album_by_id(album.id)
|
|
28
|
+
|
|
29
|
+
def get_album_by_id(self, id: Union[int, str]) -> Album:
|
|
30
|
+
"""
|
|
31
|
+
Get album info by id
|
|
32
|
+
|
|
33
|
+
Arguments
|
|
34
|
+
----------
|
|
35
|
+
id: This id belong to one of album-tracks
|
|
36
|
+
|
|
37
|
+
Returns
|
|
38
|
+
-------
|
|
39
|
+
Album: An object of Album type
|
|
40
|
+
|
|
41
|
+
"""
|
|
42
|
+
album = self.private_request('mp3',
|
|
43
|
+
params=f'id={id}').json()
|
|
44
|
+
return extract_album(album)
|
|
45
|
+
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from radiojavanapi.mixins.private import PrivateRequest
|
|
2
|
+
from radiojavanapi.extractors import extract_artist
|
|
3
|
+
from radiojavanapi.models import Artist
|
|
4
|
+
from radiojavanapi.helper import url_to_id
|
|
5
|
+
|
|
6
|
+
from pydantic import HttpUrl
|
|
7
|
+
from urllib.parse import quote_plus
|
|
8
|
+
|
|
9
|
+
class ArtistMixin(PrivateRequest):
|
|
10
|
+
def get_artist_by_url(self, url: HttpUrl) -> Artist:
|
|
11
|
+
"""
|
|
12
|
+
Get artist info by site url (e.g. `play.radiojavan.com/artist/...` or `play.radiojavan.com/redirect?r=radiojavan://artist/...`)
|
|
13
|
+
|
|
14
|
+
Arguments
|
|
15
|
+
----------
|
|
16
|
+
url: Site url of artist
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
Artist: An object of Artist type
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
return self.get_artist_by_name(url_to_id(url))
|
|
24
|
+
|
|
25
|
+
def get_artist_by_name(self, name: str) -> Artist:
|
|
26
|
+
"""
|
|
27
|
+
Get artist info by name (must be the exact name on RadioJavan API)
|
|
28
|
+
|
|
29
|
+
Arguments
|
|
30
|
+
----------
|
|
31
|
+
name: Exact name of artist on RadioJavan API
|
|
32
|
+
|
|
33
|
+
Returns
|
|
34
|
+
-------
|
|
35
|
+
Artist: Return An object of Artist type
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
response = self.private_request(
|
|
39
|
+
'artist', params=f'query={quote_plus(name)}').json()
|
|
40
|
+
return extract_artist(response)
|
|
41
|
+
|
|
42
|
+
def follow_artist(self, name: str) -> bool:
|
|
43
|
+
"""
|
|
44
|
+
Follow an artist
|
|
45
|
+
|
|
46
|
+
Arguments
|
|
47
|
+
----------
|
|
48
|
+
name: Exact name of artist on RadioJavan API
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
bool: RJ api result
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
response = self.private_request('artist_follow',
|
|
56
|
+
params=f'artist={quote_plus(name)}',
|
|
57
|
+
need_login=True).json()
|
|
58
|
+
return response['success'] == True
|
|
59
|
+
|
|
60
|
+
def unfollow_artist(self, name: str) -> bool:
|
|
61
|
+
"""
|
|
62
|
+
UnFollow an artist
|
|
63
|
+
|
|
64
|
+
Arguments
|
|
65
|
+
----------
|
|
66
|
+
name: Exact name of artist on RadioJavan API
|
|
67
|
+
|
|
68
|
+
Returns
|
|
69
|
+
-------
|
|
70
|
+
bool: RJ api result
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
response = self.private_request('artist_unfollow',
|
|
74
|
+
params=f'artist={quote_plus(name)}',
|
|
75
|
+
need_login=True).json()
|
|
76
|
+
return response['success'] == True
|