forked from phil65/script.skin.info.service
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdefault.py
204 lines (185 loc) · 12 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
204
import sys
import xbmc
import xbmcgui
import xbmcaddon
from Utils import *
ADDON = xbmcaddon.Addon()
ADDON_VERSION = ADDON.getAddonInfo('version')
WND = xbmcgui.Window(12003) # Video info dialog
HOME = xbmcgui.Window(10000) # Home Window
class Daemon:
def __init__(self):
log("version %s started" % ADDON_VERSION)
self._init_vars()
self.ssis_monitor = xbmc.Monitor()
self.run_backend()
def _init_vars(self):
self.id = None
self.type = False
self.Artist_mbid = None
def run_backend(self):
self._stop = False
self.previousitem = ""
log("starting backend")
while (not self._stop) and (not self.ssis_monitor.abortRequested()):
if xbmc.getCondVisibility("[Window.IsActive(videoosd) + Skin.String(SkinInfo.AutoCloseVideoOSD)] | [Window.IsActive(musicosd) + Skin.String(SkinInfo.AutoCloseMusicOSD)]"):
if xbmc.getCondVisibility("Window.IsActive(videoosd)"):
seconds = xbmc.getInfoLabel("Skin.String(SkinInfo.AutoCloseVideoOSD)")
window = "videoosd"
elif xbmc.getCondVisibility("Window.IsActive(musicosd)"):
seconds = xbmc.getInfoLabel("Skin.String(SkinInfo.AutoCloseMusicOSD)")
window = "musicosd"
else:
seconds = ""
if seconds and seconds != "0" and xbmc.getCondVisibility("System.IdleTime(%s)" % seconds) and xbmc.getCondVisibility("Window.IsActive(%s)" % window):
xbmc.executebuiltin("Dialog.Close(%s)" % window)
if xbmc.getCondVisibility("Container.Content(movies) | Container.Content(sets) | ListItem.IsCollection | String.IsEqual(ListItem.DBTYPE,set) | 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 != ""):
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("ListItem.IsCollection | String.IsEqual(ListItem.DBTYPE,set)"):
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)"):
HOME.setProperty("SeasonPoster", xbmc.getInfoLabel("ListItem.Icon"))
HOME.setProperty("SeasonID", xbmc.getInfoLabel("ListItem.DBID"))
HOME.setProperty("SeasonNumber", xbmc.getInfoLabel("ListItem.Season"))
elif xbmc.getCondVisibility("Window.IsActive(videos) + [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 xbmc.getCondVisibility("!ListItem.IsParentFolder"):
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 xbmc.getCondVisibility("!ListItem.IsParentFolder"):
self.setMusicDetailsforCategory()
elif xbmc.getCondVisibility('Window.IsActive(screensaver)'):
xbmc.Monitor().waitForAbort(1)
else:
self.previousitem = ""
self.selecteditem = ""
clear_properties()
xbmc.sleep(500)
if xbmc.getCondVisibility("String.IsEmpty(Window(home).Property(skininfos_daemon_running))"):
clear_properties()
self._stop = True
xbmc.sleep(100)
def _set_artist_details(self, dbid):
json_response = Get_JSON_response('{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": {"properties": ["title", "year", "albumlabel", "playcount", "art"], "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):
HOME.setProperty('SkinInfo.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", "mpaa", "plotoutline", "plot", "country", "streamdetails"], "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.getCondVisibility("!ListItem.IsParentFolder"):
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"]:
HOME.setProperty('SkinInfo.Detail.Movie.%i.Path' % (count), movie["file"])
HOME.setProperty('SkinInfo.Detail.Movie.%i.Art(fanart)' % (count), movie["art"].get('fanart', ''))
HOME.setProperty('SkinInfo.Detail.Movie.%i.Art(poster)' % (count), movie["art"].get('poster', ''))
count += 1
if count > 19:
break
def setMusicDetailsforCategory(self):
if xbmc.getCondVisibility("!ListItem.IsParentFolder"):
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:
HOME.setProperty('SkinInfo.Detail.Music.%i.DBID' % (count), str(artist["id"]))
HOME.setProperty('SkinInfo.Detail.Music.%i.Art(fanart)' % (count), artist["fanart"])
HOME.setProperty('SkinInfo.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']))
WND.setProperty('SkinInfo.AudioLanguage.%d' % count, item['language'])
WND.setProperty('SkinInfo.AudioCodec.%d' % count, item['codec'])
WND.setProperty('SkinInfo.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']))
WND.setProperty('SkinInfo.SubtitleLanguage.%d' % count, item['language'])
count += 1
WND.setProperty('SkinInfo.SubtitleLanguage', " / ".join(subs))
WND.setProperty('SkinInfo.AudioLanguage', " / ".join(streams))
WND.setProperty('SkinInfo.SubtitleLanguage.Count', str(len(subs)))
WND.setProperty('SkinInfo.AudioLanguage.Count', str(len(streams)))
try:
params = dict(arg.split("=") for arg in sys.argv[1].split("&"))
except:
params = {}
if xbmc.getCondVisibility("String.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')