forked from phil65/script.extendedinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDaemon.py
253 lines (234 loc) · 13.6 KB
/
Daemon.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import sys
import os, datetime
import xbmc, xbmcgui, 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__ )
xbmc.executebuiltin('SetProperty(extendedinfo_backend_running,True,home)')
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.musicvideos = []
self.movies = []
self.id = None
self.dbid = None
self.type = False
self.tag = ""
self.silent = True
self.prop_prefix = ""
self.Artist_mbid = None
self.window.clearProperty('SongToMusicVideo.Path')
def run_backend(self):
self._stop = False
self.previousitem = ""
self.previousartist = ""
self.previoussong = ""
log("starting backend")
self.musicvideos = create_musicvideo_list()
self.movies = create_movie_list()
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)] + !Container.Scrolling"):
self.selecteditem = xbmc.getInfoLabel("ListItem.DBID")
if (self.selecteditem != self.previousitem):
self.previousitem = self.selecteditem
if xbmc.getCondVisibility("!IsEmpty(ListItem.DBID) + Container.Content(artists)"):
self._set_artist_details(xbmc.getInfoLabel("ListItem.DBID"))
log("setting movieset labels")
elif xbmc.getCondVisibility("!IsEmpty(ListItem.DBID) + Container.Content(albums)"):
self._set_album_details(xbmc.getInfoLabel("ListItem.DBID"))
log("setting movieset labels")
elif xbmc.getCondVisibility("!IsEmpty(ListItem.DBID) + SubString(ListItem.Path,videodb://movies/sets/,left)"):
self._set_movieset_details(xbmc.getInfoLabel("ListItem.DBID"))
elif xbmc.getCondVisibility("!IsEmpty(ListItem.DBID) + Container.Content(movies)"):
self._set_movie_details(xbmc.getInfoLabel("ListItem.DBID"))
elif xbmc.getCondVisibility("!IsEmpty(ListItem.DBID) + Container.Content(episodes)"):
self._set_episode_details(xbmc.getInfoLabel("ListItem.DBID"))
elif xbmc.getCondVisibility("!IsEmpty(ListItem.DBID) + Container.Content(musicvideos)"):
self._set_musicvideo_details(xbmc.getInfoLabel("ListItem.DBID"))
else:
clear_properties()
elif xbmc.getCondVisibility("Container.Content(years)"):
self._detail_selector("year")
elif xbmc.getCondVisibility("Container.Content(genres)"):
self._detail_selector("genre")
elif xbmc.getCondVisibility("Container.Content(directors)"):
self._detail_selector("director")
elif xbmc.getCondVisibility("Container.Content(actors)"):
self._detail_selector("cast")
elif xbmc.getCondVisibility("Container.Content(studios)"):
self._detail_selector("studio")
elif xbmc.getCondVisibility("Container.Content(countries)"):
self._detail_selector("country")
elif xbmc.getCondVisibility("Container.Content(tags)"):
self._detail_selector("tag")
elif xbmc.getCondVisibility('Container.Content(songs)') and self.musicvideos:
# get artistname and songtitle of the selected item
self.selecteditem = xbmc.getInfoLabel('ListItem.DBID')
# check if we've focussed a new song
if self.selecteditem != self.previousitem:
self.previousitem = self.selecteditem
# clear the window property
self.window.clearProperty('SongToMusicVideo.Path')
# iterate through our musicvideos
for musicvideo in self.musicvideos:
if self.selecteditem == musicvideo[0]:#needs fixing
# match found, set the window property
self.window.setProperty('SongToMusicVideo.Path', musicvideo[2])
xbmc.sleep(100)
# stop iterating
break
elif xbmc.getCondVisibility("Window.IsActive(visualisation)"):
self.selecteditem = xbmc.getInfoLabel('MusicPlayer.Artist')
if (self.selecteditem != self.previousitem) and self.selecteditem:
self.previousitem = self.selecteditem
from MusicBrainz import GetMusicBrainzIdFromNet
log("Daemon updating SimilarArtists")
Artist_mbid = GetMusicBrainzIdFromNet(self.selecteditem)
passDataToSkin('SimilarArtistsInLibrary', None, self.prop_prefix)
passDataToSkin('SimilarArtists', GetSimilarArtistsInLibrary(Artist_mbid), self.prop_prefix)
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(extendedinfo_backend_running))"):
clear_properties()
self._stop = True
xbmc.sleep(100)
def _set_song_details( self, dbid ): #unused, needs fixing
try:
b = ""
a = datetime.datetime.now()
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": {"properties": ["artist", "file"], "sort": { "method": "artist" } }, "id": 1}')
json_query = unicode(json_query, 'utf-8', errors='ignore')
json_query = simplejson.loads(json_query)
clear_properties()
if "result" in json_query and json_query['result'].has_key('musicvideos'):
set_movie_properties(json_query)
b = datetime.datetime.now() - a
log('Total time needed to request JSON and set properties for song: %s' % b)
except Exception, e:
log(e)
def _set_artist_details( self, dbid ):
try:
b = ""
a = datetime.datetime.now()
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": {"properties": ["title", "year", "albumlabel", "playcount", "thumbnail"], "sort": { "method": "label" }, "filter": {"artistid": %s} }, "id": 1}' % dbid)
json_query = unicode(json_query, 'utf-8', errors='ignore')
json_query = simplejson.loads(json_query)
clear_properties()
if json_query['result'].has_key('albums'):
set_artist_properties(json_query)
b = datetime.datetime.now() - a
log('Total time needed to request JSON and set properties for artist: %s' % b)
except Exception, e:
log(e)
def _set_movie_details( self, dbid ):
try:
if xbmc.getCondVisibility('Container.Content(movies)') or self.type == "movie":
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"properties": ["streamdetails","set","setid","cast"], "movieid":%s }, "id": 1}' % dbid)
json_query = unicode(json_query, 'utf-8', errors='ignore')
log(json_query)
json_response = simplejson.loads(json_query)
if json_response['result'].has_key('moviedetails'):
self._set_properties(json_response)
except Exception, e:
log(e)
def _set_episode_details( self, dbid ):
try:
if xbmc.getCondVisibility('Container.Content(episodes)') or self.type == "episode":
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"properties": ["streamdetails"], "episodeid":%s }, "id": 1}' % dbid)
json_query = unicode(json_query, 'utf-8', errors='ignore')
log(json_query)
json_response = simplejson.loads(json_query)
if json_response['result'].has_key('episodedetails'):
self._set_properties(json_response['result']['episodedetails']['streamdetails']['audio'], json_response['result']['episodedetails']['streamdetails']['subtitle'])
except Exception, e:
log(e)
def _set_musicvideo_details( self, dbid ):
try:
if xbmc.getCondVisibility('Container.Content(musicvideos)') or self.type == "musicvideo":
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideoDetails", "params": {"properties": ["streamdetails"], "musicvideoid":%s }, "id": 1}' % dbid)
json_query = unicode(json_query, 'utf-8', errors='ignore')
log(json_query)
json_response = simplejson.loads(json_query)
if json_response['result'].has_key('musicvideodetails'):
self._set_properties(json_response['result']['musicvideodetails']['streamdetails']['audio'], json_response['result']['musicvideodetails']['streamdetails']['subtitle'])
except Exception, e:
log(e)
def _set_album_details( self, dbid ):
try:
b = ""
a = datetime.datetime.now()
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetSongs", "params": {"properties": ["title", "track", "duration", "file", "lastplayed", "disc"], "sort": { "method": "label" }, "filter": {"albumid": %s} }, "id": 1}' % dbid)
json_query = unicode(json_query, 'utf-8', errors='ignore')
json_query = simplejson.loads(json_query)
clear_properties()
if "result" in json_query and json_query['result'].has_key('songs'):
set_album_properties(json_query)
b = datetime.datetime.now() - a
log('Total time needed to request JSON and set properties for album: %s' % b)
except Exception, e:
log(e)
def _set_movieset_details( self, dbid ):
try:
b = ""
a = datetime.datetime.now()
json_query = xbmc.executeJSONRPC('{"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)
json_query = unicode(json_query, 'utf-8', errors='ignore')
json_query = simplejson.loads(json_query)
clear_properties()
if "result" in json_query and json_query['result'].has_key('setdetails'):
set_movie_properties(json_query)
b = datetime.datetime.now() - a
log('Total time needed to request JSON and set properties for set: %s' % b)
except Exception, e:
log("Exception in _set_movieset_details:")
log(e)
def _detail_selector( self, comparator):
self.selecteditem = xbmc.getInfoLabel("ListItem.Label")
if (self.selecteditem != self.previousitem):
if xbmc.getCondVisibility("!Stringcompare(ListItem.Label,..)"):
self.previousitem = self.selecteditem
clear_properties()
count = 1
for movie in self.movies["result"]["movies"]:
log(comparator)
if self.selecteditem in str(movie[comparator]):
log(movie)
self._set_detail_properties(movie,count)
count +=1
if count > 19:
break
else:
clear_properties()
def _set_properties( self, results ):
# Set language properties
count = 1
audio = results['result']['moviedetails']['streamdetails']['audio']
subtitles = results['result']['moviedetails']['streamdetails']['subtitle']
# Clear properties before setting new ones
clear_properties()
for item in audio:
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:
self.wnd.setProperty('SubtitleLanguage.%d' % count, item['language'])
count += 1
# self.cleared = False