forked from vially/googlemusic-xbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoogleMusicApi.py
63 lines (47 loc) · 2.21 KB
/
GoogleMusicApi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys
import GoogleMusicLogin
from gmusicapi.api import Api
class GoogleMusicApi():
def __init__(self):
self.xbmc = sys.modules["__main__"].xbmc
self.xbmcgui = sys.modules["__main__"].xbmcgui
self.xbmcplugin = sys.modules["__main__"].xbmcplugin
self.settings = sys.modules["__main__"].settings
self.language = sys.modules["__main__"].language
self.dbg = sys.modules["__main__"].dbg
self.common = sys.modules["__main__"].common
self.storage = sys.modules["__main__"].storage
self.gmusicapi = Api()
self.login = GoogleMusicLogin.GoogleMusicLogin(self.gmusicapi)
def getPlaylistSongs(self, playlist_id, forceRenew=False):
if not self.storage.isPlaylistFetched(playlist_id) or forceRenew:
self.updatePlaylistSongs(playlist_id)
songs = self.storage.getPlaylistSongs(playlist_id)
return songs
def getPlaylistsByType(self, playlist_type, forceRenew=False):
if forceRenew:
self.updatePlaylists(playlist_type)
playlists = self.storage.getPlaylistsByType(playlist_type)
if len(playlists) == 0 and not forceRenew:
self.updatePlaylists(playlist_type)
playlists = self.storage.getPlaylistsByType(playlist_type)
return playlists
def getSong(self, song_id):
return self.storage.getSong(song_id)
def updatePlaylistSongs(self, playlist_id):
api_songs = []
self.login.login()
if playlist_id == 'all_songs':
api_songs = self.gmusicapi.get_all_songs()
else:
api_songs = self.gmusicapi.get_playlist_songs(playlist_id)
self.storage.storeApiSongs(api_songs, playlist_id)
def updatePlaylists(self, playlist_type):
self.login.login()
playlists = self.gmusicapi.get_all_playlist_ids(playlist_type=="auto", playlist_type=="instant", playlist_type=="user", always_id_lists=True)
self.storage.storePlaylists(playlists[playlist_type], playlist_type)
def getSongStreamUrl(self, song_id):
self.login.login()
stream_url = self.gmusicapi.get_stream_url(song_id)
#self.storage.updateSongStreamUrl(song_id, stream_url)
return stream_url