forked from phil65/script.skin.info.service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.py
203 lines (185 loc) · 11.5 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import sys
import xbmc
import xbmcgui
import xbmcaddon
from Utils import *
if sys.version_info < (2, 7):
import simplejson
else:
import json as simplejson
__addon__ = xbmcaddon.Addon()
__addonid__ = __addon__.getAddonInfo('id')
__addonversion__ = __addon__.getAddonInfo('version')
__language__ = __addon__.getLocalizedString
class Daemon:
def __init__(self):
log("version %s started" % __addonversion__)
self._init_vars()
self.run_backend()
def _init_vars(self):
self.window = xbmcgui.Window(10000) # Home Window
self.wnd = xbmcgui.Window(12003) # Video info dialog
self.id = None
self.type = False
self.Artist_mbid = None
self.window.clearProperty('SongToMusicVideo.Path')
def run_backend(self):
self._stop = False
self.previousitem = ""
log("starting backend")
while (not self._stop) and (not xbmc.abortRequested):
if xbmc.getCondVisibility("Container.Content(movies) | Container.Content(sets) | Container.Content(artists) | Container.Content(albums) | Container.Content(episodes) | Container.Content(musicvideos)"):
self.selecteditem = xbmc.getInfoLabel("ListItem.DBID")
if (self.selecteditem != self.previousitem):
self.previousitem = self.selecteditem
if (self.selecteditem is not "") and (self.selecteditem > -1):
if xbmc.getCondVisibility("Container.Content(artists)"):
self._set_artist_details(self.selecteditem)
elif xbmc.getCondVisibility("Container.Content(albums)"):
self._set_album_details(self.selecteditem)
elif xbmc.getCondVisibility("SubString(ListItem.Path,videodb://movies/sets/,left)"):
self._set_movieset_details(self.selecteditem)
elif xbmc.getCondVisibility("Container.Content(movies)"):
self._set_movie_details(self.selecteditem)
elif xbmc.getCondVisibility("Container.Content(episodes)"):
self._set_episode_details(self.selecteditem)
elif xbmc.getCondVisibility("Container.Content(musicvideos)"):
self._set_musicvideo_details(self.selecteditem)
else:
clear_properties()
else:
clear_properties()
elif xbmc.getCondVisibility("Container.Content(seasons) + !Window.IsActive(movieinformation)"):
self.window.setProperty("SeasonPoster", xbmc.getInfoLabel("ListItem.Icon"))
self.window.setProperty("SeasonID", xbmc.getInfoLabel("ListItem.DBID"))
self.window.setProperty("SeasonNumber", xbmc.getInfoLabel("ListItem.Season"))
elif xbmc.getCondVisibility("Window.IsActive(videolibrary) + [Container.Content(directors) | Container.Content(actors) | Container.Content(genres) | Container.Content(years) | Container.Content(studios) | Container.Content(countries) | Container.Content(tags)]"):
self.selecteditem = xbmc.getInfoLabel("ListItem.Label")
if (self.selecteditem != self.previousitem):
clear_properties()
self.previousitem = self.selecteditem
if (self.selecteditem != "") and (self.selecteditem != ".."):
self.setMovieDetailsforCategory()
elif xbmc.getCondVisibility("Container.Content(years) | Container.Content(genres)"):
self.selecteditem = xbmc.getInfoLabel("ListItem.Label")
if (self.selecteditem != self.previousitem):
clear_properties()
self.previousitem = self.selecteditem
if (self.selecteditem != "") and (self.selecteditem != ".."):
self.setMusicDetailsforCategory()
elif xbmc.getCondVisibility('Window.IsActive(screensaver)'):
xbmc.sleep(1000)
else:
self.previousitem = ""
self.selecteditem = ""
clear_properties()
xbmc.sleep(500)
if xbmc.getCondVisibility("IsEmpty(Window(home).Property(skininfos_daemon_running))"):
clear_properties()
self._stop = True
xbmc.sleep(100)
def _set_song_details(self, dbid): # unused, needs fixing
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": {"properties": ["artist", "file"], "sort": { "method": "artist" } }, "id": 1}')
clear_properties()
if ("result" in json_response) and ('musicvideos' in json_response['result']):
set_movie_properties(json_query)
def _set_artist_details(self, dbid):
json_response = Get_JSON_response('{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": {"properties": ["title", "year", "albumlabel", "playcount", "thumbnail"], "sort": { "method": "label" }, "filter": {"artistid": %s} }, "id": 1}' % dbid)
clear_properties()
if ("result" in json_response) and ('albums' in json_response['result']):
set_artist_properties(json_response)
def _set_movie_details(self, dbid):
json_response = Get_JSON_response('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"properties": ["streamdetails","set","setid","cast"], "movieid":%s }, "id": 1}' % dbid)
clear_properties()
if ("result" in json_response) and ('moviedetails' in json_response['result']):
self._set_properties(json_response['result']['moviedetails'])
def _set_episode_details(self, dbid):
json_response = Get_JSON_response('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"properties": ["streamdetails","tvshowid","season"], "episodeid":%s }, "id": 1}' % dbid)
clear_properties()
if ('result' in json_response) and ('episodedetails' in json_response['result']):
self._set_properties(json_response['result']['episodedetails'])
seasonnumber = json_response['result']['episodedetails']['season']
tvshowid = json_response['result']['episodedetails']['tvshowid']
json_response = Get_JSON_response('{"jsonrpc": "2.0", "method": "VideoLibrary.GetSeasons", "params": {"properties": ["thumbnail"], "tvshowid":%s }, "id": 1}' % tvshowid)
for season in json_response["result"]["seasons"]:
if season["label"].split(" ")[-1] == str(seasonnumber):
self.window.setProperty('SeasonPoster', season["thumbnail"])
def _set_musicvideo_details(self, dbid):
json_response = Get_JSON_response('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideoDetails", "params": {"properties": ["streamdetails"], "musicvideoid":%s }, "id": 1}' % dbid)
clear_properties()
if ("result" in json_response) and ('musicvideodetails' in json_response['result']):
self._set_properties(json_response['result']['musicvideodetails'])
def _set_album_details(self, dbid):
json_response = Get_JSON_response('{"jsonrpc": "2.0", "method": "AudioLibrary.GetSongs", "params": {"properties": ["title", "track", "duration", "file", "lastplayed", "disc"], "sort": { "method": "label" }, "filter": {"albumid": %s} }, "id": 1}' % dbid)
clear_properties()
if ("result" in json_response) and ('songs' in json_response['result']):
set_album_properties(json_response)
def _set_movieset_details(self, dbid):
json_response = Get_JSON_response('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieSetDetails", "params": {"setid": %s, "properties": [ "thumbnail" ], "movies": { "properties": [ "rating", "art", "file", "year", "director", "writer","genre" , "thumbnail", "runtime", "studio", "plotoutline", "plot", "country"], "sort": { "order": "ascending", "method": "year" }} },"id": 1 }' % dbid)
clear_properties()
if ("result" in json_response) and ('setdetails' in json_response['result']):
set_movie_properties(json_response)
def setMovieDetailsforCategory(self):
if xbmc.getInfoLabel("ListItem.Label") != "..":
count = 1
path = xbmc.getInfoLabel("ListItem.FolderPath")
json_response = Get_JSON_response('{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "%s", "media": "video", "properties": ["art"]}, "id": 1}' % (path))
if ("result" in json_response) and ("files" in json_response["result"]):
for movie in json_response["result"]["files"]:
self.window.setProperty('Detail.Movie.%i.Path' % (count), movie["file"])
self.window.setProperty('Detail.Movie.%i.Art(fanart)' % (count), movie["art"].get('fanart', ''))
self.window.setProperty('Detail.Movie.%i.Art(poster)' % (count), movie["art"].get('poster', ''))
count += 1
if count > 19:
break
def setMusicDetailsforCategory(self):
if xbmc.getInfoLabel("ListItem.Label") != "..":
count = 1
path = xbmc.getInfoLabel("ListItem.FolderPath")
json_response = Get_JSON_response('{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "%s", "media": "music", "properties": ["fanart", "thumbnail"]}, "id": 1}' % (path))
if ("result" in json_response) and ("files" in json_response["result"]):
for artist in json_response["result"]["files"]:
if "id" in artist:
self.window.setProperty('Detail.Music.%i.DBID' % (count), str(artist["id"]))
self.window.setProperty('Detail.Music.%i.Art(fanart)' % (count), artist["fanart"])
self.window.setProperty('Detail.Music.%i.Art(thumb)' % (count), artist["thumbnail"])
count += 1
if count > 19:
break
def _set_properties(self, results):
# Set language properties
count = 1
audio = results['streamdetails']['audio']
subtitles = results['streamdetails']['subtitle']
subs = []
streams = []
# Clear properties before setting new ones
clear_properties()
for item in audio:
if str(item['language']) not in streams:
streams.append(str(item['language']))
self.wnd.setProperty('AudioLanguage.%d' % count, item['language'])
self.wnd.setProperty('AudioCodec.%d' % count, item['codec'])
self.wnd.setProperty('AudioChannels.%d' % count, str(item['channels']))
count += 1
count = 1
for item in subtitles:
if str(item['language']) not in subtitles:
subs.append(str(item['language']))
self.wnd.setProperty('SubtitleLanguage.%d' % count, item['language'])
count += 1
wnd.setProperty('SubtitleLanguage', " / ".join(subs))
wnd.setProperty('AudioLanguage', " / ".join(streams))
# self.cleared = False
if (__name__ == "__main__"):
try:
params = dict( arg.split("=") for arg in sys.argv[1].split("&"))
except:
params = {}
if xbmc.getCondVisibility("IsEmpty(Window(home).Property(skininfos_daemon_running))"):
xbmc.executebuiltin('SetProperty(skininfos_daemon_running,True,home)')
log("starting daemon")
Daemon()
else:
log("Daemon already active")
log('finished')