forked from vially/googlemusic-xbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.py
82 lines (64 loc) · 2.39 KB
/
default.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import sys, xbmc, xbmcgui, xbmcplugin, xbmcaddon
# plugin constants
version = "0.8exp14"
plugin = "GoogleMusic-" + version
# xbmc hooks
settings = xbmcaddon.Addon(id='plugin.audio.googlemusic')
__info__ = settings.getAddonInfo
__icon__ = __info__('icon')
dbg = settings.getSetting( "debug" ) == "true"
dbglevel = 3
# plugin variables
storage = ""
# utility functions
def parameters_string_to_dict(parameters):
''' Convert parameters encoded in a URL to a dict. '''
paramDict = {}
if parameters:
paramPairs = parameters[1:].split("&")
for paramsPair in paramPairs:
paramSplits = paramsPair.split('=')
if (len(paramSplits)) == 2:
paramDict[paramSplits[0]] = paramSplits[1]
return paramDict
def log(message):
if dbg:
print "[%s] %s" % (plugin, message)
if (__name__ == "__main__" ):
if dbg:
print plugin + " ARGV: " + repr(sys.argv)
else:
print plugin
import GoogleMusicStorage
storage = GoogleMusicStorage.GoogleMusicStorage()
import GoogleMusicPlaySong
song = GoogleMusicPlaySong.GoogleMusicPlaySong()
params = parameters_string_to_dict(sys.argv[2])
get = params.get
if (get("action") == "play_song"):
song.play(get("song_id"),params)
else:
import GoogleMusicLogin
login = GoogleMusicLogin.GoogleMusicLogin()
import GoogleMusicNavigation
if (not params):
# check for initing cookies, db and library only on main menu
storage.checkDbInit()
login.checkCredentials()
login.checkCookie()
login.initDevice()
navigation = GoogleMusicNavigation.GoogleMusicNavigation()
if not storage.isPlaylistFetched('all_songs'):
xbmc.executebuiltin("XBMC.Notification("+plugin+",'Loading library',5000,"+__icon__ +")")
log('Loading library')
navigation.api.updatePlaylistSongs('all_songs')
navigation.listMenu()
elif (get("action")):
navigation = GoogleMusicNavigation.GoogleMusicNavigation()
navigation.executeAction(params)
elif (get("path")):
navigation = GoogleMusicNavigation.GoogleMusicNavigation()
navigation.listMenu(params)
else:
print plugin + " ARGV Nothing done.. verify params " + repr(params)
login.logout()