Advertisement
Guest User

Untitled

a guest
Apr 6th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.53 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (C) 2012 Team-XBMC
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # This script is based on script.randomitems & script.wacthlist
  20. # Thanks to their original authors
  21.  
  22. import os
  23. import sys
  24. import xbmc
  25. import xbmcgui
  26. import xbmcaddon
  27. import random
  28. import datetime
  29. import _strptime
  30. import urllib
  31.  
  32. if sys.version_info < (2, 7):
  33. import simplejson
  34. else:
  35. import json as simplejson
  36.  
  37. __addon__ = xbmcaddon.Addon()
  38. __addonversion__ = __addon__.getAddonInfo('version')
  39. __addonid__ = __addon__.getAddonInfo('id')
  40. __addonname__ = __addon__.getAddonInfo('name')
  41. __localize__ = __addon__.getLocalizedString
  42.  
  43. def log(txt):
  44. message = '%s: %s' % (__addonname__, txt.encode('ascii', 'ignore'))
  45. xbmc.log(msg=message, level=xbmc.LOGDEBUG)
  46.  
  47. class Main:
  48. def __init__(self):
  49. self._parse_argv()
  50. # check how we were executed
  51. if self.MOVIEID:
  52. xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "movieid": %d }, "options":{ "resume": %s } }, "id": 1 }' % (int(self.MOVIEID), self.RESUME))
  53. elif self.EPISODEID:
  54. xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "episodeid": %d }, "options":{ "resume": %s } }, "id": 1 }' % (int(self.EPISODEID), self.RESUME))
  55. elif self.MUSICVIDEOID:
  56. xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "musicvideoid": %d } }, "id": 1 }' % int(self.MUSICVIDEOID))
  57. elif self.ALBUMID:
  58. xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "albumid": %d } }, "id": 1 }' % int(self.ALBUMID))
  59. elif self.SONGID:
  60. xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "songid": %d } }, "id": 1 }' % int(self.SONGID))
  61. else:
  62. self._init_vars()
  63. self._init_property()
  64. # clear our property, if another instance is already running it should stop now
  65. self.WINDOW.clearProperty('SkinWidgets_Running')
  66. a_total = datetime.datetime.now()
  67. self._fetch_info_randomitems()
  68. self._fetch_info_recommended()
  69. self._fetch_info_recentitems()
  70. b_total = datetime.datetime.now()
  71. c_total = b_total - a_total
  72. log('Total time needed for all queries: %s' % c_total)
  73. # give a possible other instance some time to notice the empty property
  74. self.WINDOW.setProperty('SkinWidgets_Running', 'true')
  75. self._daemon()
  76.  
  77. def _init_vars(self):
  78. self.WINDOW = xbmcgui.Window(10000)
  79. self.Player = Widgets_Player(action = self._update)
  80. self.Monitor = Widgets_Monitor(update_listitems = self._update, update_settings = self._init_property)
  81. self.LIMIT = 20
  82.  
  83. def _init_property(self):
  84. self.WINDOW.setProperty('SkinWidgets_Recommended', '%s' % __addon__.getSetting("recommended_enable"))
  85. self.WINDOW.setProperty('SkinWidgets_RandomItems', '%s' % __addon__.getSetting("randomitems_enable"))
  86. self.WINDOW.setProperty('SkinWidgets_RecentItems', '%s' % __addon__.getSetting("recentitems_enable"))
  87. self.WINDOW.setProperty('SkinWidgets_RandomItems_Update', 'false')
  88. self.RANDOMITEMS_UPDATE_METHOD = int(__addon__.getSetting("randomitems_method"))
  89. self.RECENTITEMS_HOME_UPDATE = __addon__.getSetting("recentitems_homeupdate")
  90. self.PLOT_ENABLE = __addon__.getSetting("plot_enable") == 'true'
  91. # convert time to seconds, times 2 for 0,5 second sleep compensation
  92. self.RANDOMITEMS_TIME = int(float(__addon__.getSetting("randomitems_time"))) * 60 * 2
  93.  
  94. def _parse_argv( self ):
  95. try:
  96. params = dict( arg.split( "=" ) for arg in sys.argv[ 1 ].split( "&" ) )
  97. except:
  98. params = {}
  99. self.MOVIEID = params.get( "movieid", "" )
  100. self.EPISODEID = params.get( "episodeid", "" )
  101. self.MUSICVIDEOID = params.get( "musicvideoid", "" )
  102. self.ALBUMID = params.get( "albumid", "" )
  103. self.SONGID = params.get( "songid", "" )
  104. self.RESUME = "true"
  105. for arg in sys.argv:
  106. param = str(arg)
  107. if 'resume=' in param:
  108. if param.replace('resume=', '') == "false":
  109. self.RESUME = "false"
  110.  
  111. def _fetch_info_recommended(self):
  112. a = datetime.datetime.now()
  113. if __addon__.getSetting("recommended_enable") == 'true':
  114. self._fetch_movies('RecommendedMovie')
  115. self._fetch_tvshows_recommended('RecommendedEpisode')
  116. self._fetch_albums('RecommendedAlbum')
  117. self._fetch_musicvideo('RecommendedMusicVideo')
  118. b = datetime.datetime.now()
  119. c = b - a
  120. log('Total time needed to request recommended queries: %s' % c)
  121.  
  122. def _fetch_info_randomitems(self):
  123. a = datetime.datetime.now()
  124. if __addon__.getSetting("randomitems_enable") == 'true':
  125. self.RANDOMITEMS_UNPLAYED = __addon__.getSetting("randomitems_unplayed") == 'true'
  126. self._fetch_movies('RandomMovie')
  127. self._fetch_tvshows('RandomEpisode')
  128. self._fetch_musicvideo('RandomMusicVideo')
  129. self._fetch_albums('RandomAlbum')
  130. self._fetch_artist('RandomArtist')
  131. self._fetch_song('RandomSong')
  132. self._fetch_addon('RandomAddon')
  133. b = datetime.datetime.now()
  134. c = b - a
  135. log('Total time needed to request random queries: %s' % c)
  136.  
  137. def _fetch_info_recentitems(self):
  138. a = datetime.datetime.now()
  139. if __addon__.getSetting("recentitems_enable") == 'true':
  140. self.RECENTITEMS_UNPLAYED = __addon__.getSetting("recentitems_unplayed") == 'true'
  141. self._fetch_movies('RecentMovie')
  142. self._fetch_tvshows('RecentEpisode')
  143. self._fetch_musicvideo('RecentMusicVideo')
  144. self._fetch_albums('RecentAlbum')
  145. b = datetime.datetime.now()
  146. c = b - a
  147. log('Total time needed to request recent items queries: %s' % c)
  148.  
  149. def _fetch_movies(self, request):
  150. if not xbmc.abortRequested:
  151. json_string = '{"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "originaltitle", "playcount", "year", "genre", "studio", "country", "tagline", "plot", "runtime", "file", "plotoutline", "lastplayed", "trailer", "rating", "resume", "art", "streamdetails", "mpaa", "director"], "limits": {"end": %d},' %self.LIMIT
  152. if request == 'RecommendedMovie':
  153. json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "lastplayed"}, "filter": {"field": "inprogress", "operator": "true", "value": ""}}}' %json_string)
  154. elif request == 'RecentMovie' and self.RECENTITEMS_UNPLAYED:
  155. json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "dateadded"}, "filter": {"field": "playcount", "operator": "is", "value": "0"}}}' %json_string)
  156. elif request == 'RecentMovie':
  157. json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "dateadded"}}}' %json_string)
  158. elif request == "RandomMovie" and self.RANDOMITEMS_UNPLAYED:
  159. json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random" }, "filter": {"field": "playcount", "operator": "lessthan", "value": "1"}}}' %json_string)
  160. else:
  161. json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random" } }}' %json_string)
  162. json_query = unicode(json_query, 'utf-8', errors='ignore')
  163. json_query = simplejson.loads(json_query)
  164. if json_query.has_key('result') and json_query['result'].has_key('movies'):
  165. self._clear_properties(request)
  166. count = 0
  167. for item in json_query['result']['movies']:
  168. count += 1
  169. if (item['resume']['position'] and item['resume']['total'])> 0:
  170. resume = "true"
  171. played = '%s%%'%int((float(item['resume']['position']) / float(item['resume']['total'])) * 100)
  172. else:
  173. resume = "false"
  174. played = '0%'
  175. if item['playcount'] >= 1:
  176. watched = "true"
  177. else:
  178. watched = "false"
  179. if not self.PLOT_ENABLE and watched == "false":
  180. plot = __localize__(32014)
  181. else:
  182. plot = item['plot']
  183. art = item['art']
  184. path = media_path(item['file'])
  185. play = 'XBMC.RunScript(' + __addonid__ + ',movieid=' + str(item.get('movieid')) + ')'
  186. streaminfo = media_streamdetails(item['file'].encode('utf-8').lower(),
  187. item['streamdetails'])
  188. self.WINDOW.setProperty("%s.%d.DBID" % (request, count), str(item.get('movieid')))
  189. self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['title'])
  190. self.WINDOW.setProperty("%s.%d.OriginalTitle" % (request, count), item['originaltitle'])
  191. self.WINDOW.setProperty("%s.%d.Year" % (request, count), str(item['year']))
  192. self.WINDOW.setProperty("%s.%d.Genre" % (request, count), " / ".join(item['genre']))
  193. self.WINDOW.setProperty("%s.%d.Studio" % (request, count), item['studio'][0])
  194. self.WINDOW.setProperty("%s.%d.Country" % (request, count), item['country'][0])
  195. self.WINDOW.setProperty("%s.%d.Plot" % (request, count), plot)
  196. self.WINDOW.setProperty("%s.%d.PlotOutline" % (request, count), item['plotoutline'])
  197. self.WINDOW.setProperty("%s.%d.Tagline" % (request, count), item['tagline'])
  198. self.WINDOW.setProperty("%s.%d.Runtime" % (request, count), str(int((item['runtime'] / 60) + 0.5)))
  199. self.WINDOW.setProperty("%s.%d.Rating" % (request, count), str(round(float(item['rating']),1)))
  200. self.WINDOW.setProperty("%s.%d.mpaa" % (request, count), item['mpaa'])
  201. self.WINDOW.setProperty("%s.%d.Director" % (request, count), " / ".join(item['director']))
  202. self.WINDOW.setProperty("%s.%d.Trailer" % (request, count), item['trailer'])
  203. self.WINDOW.setProperty("%s.%d.Art(poster)" % (request, count), art.get('poster',''))
  204. self.WINDOW.setProperty("%s.%d.Art(fanart)" % (request, count), art.get('fanart',''))
  205. self.WINDOW.setProperty("%s.%d.Art(clearlogo)" % (request, count), art.get('clearlogo',''))
  206. self.WINDOW.setProperty("%s.%d.Art(clearart)" % (request, count), art.get('clearart',''))
  207. self.WINDOW.setProperty("%s.%d.Art(landscape)" % (request, count), art.get('landscape',''))
  208. self.WINDOW.setProperty("%s.%d.Art(banner)" % (request, count), art.get('banner',''))
  209. self.WINDOW.setProperty("%s.%d.Art(discart)" % (request, count), art.get('discart',''))
  210. self.WINDOW.setProperty("%s.%d.Resume" % (request, count), resume)
  211. self.WINDOW.setProperty("%s.%d.PercentPlayed" % (request, count), played)
  212. self.WINDOW.setProperty("%s.%d.Watched" % (request, count), watched)
  213. self.WINDOW.setProperty("%s.%d.File" % (request, count), item['file'])
  214. self.WINDOW.setProperty("%s.%d.Path" % (request, count), path)
  215. self.WINDOW.setProperty("%s.%d.Play" % (request, count), play)
  216. self.WINDOW.setProperty("%s.%d.VideoCodec" % (request, count), streaminfo['videocodec'])
  217. self.WINDOW.setProperty("%s.%d.VideoResolution" % (request, count), streaminfo['videoresolution'])
  218. self.WINDOW.setProperty("%s.%d.VideoAspect" % (request, count), streaminfo['videoaspect'])
  219. self.WINDOW.setProperty("%s.%d.AudioCodec" % (request, count), streaminfo['audiocodec'])
  220. self.WINDOW.setProperty("%s.%d.AudioChannels" % (request, count), str(streaminfo['audiochannels']))
  221. del json_query
  222.  
  223. def _fetch_tvshows_recommended(self, request):
  224. if not xbmc.abortRequested:
  225. # First unplayed episode of recent played tvshows
  226. json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["title", "studio", "mpaa", "file", "art"], "sort": {"order": "descending", "method": "lastplayed"}, "filter": {"field": "inprogress", "operator": "true", "value": ""}, "limits": {"end": %d}}, "id": 1}' %self.LIMIT)
  227. json_query = unicode(json_query, 'utf-8', errors='ignore')
  228. json_query = simplejson.loads(json_query)
  229. if json_query.has_key('result') and json_query['result'].has_key('tvshows'):
  230. self._clear_properties(request)
  231. count = 0
  232. for item in json_query['result']['tvshows']:
  233. if xbmc.abortRequested:
  234. break
  235. count += 1
  236. json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "plot", "season", "episode", "showtitle", "file", "lastplayed", "rating", "resume", "art", "streamdetails", "firstaired", "runtime"], "sort": {"method": "episode"}, "filter": {"field": "playcount", "operator": "is", "value": "0"}, "limits": {"end": 1}}, "id": 1}' %item['tvshowid'])
  237. json_query2 = unicode(json_query2, 'utf-8', errors='ignore')
  238. json_query2 = simplejson.loads(json_query2)
  239. if json_query2.has_key('result') and json_query2['result'] != None and json_query2['result'].has_key('episodes'):
  240. for item2 in json_query2['result']['episodes']:
  241. episode = ("%.2d" % float(item2['episode']))
  242. season = "%.2d" % float(item2['season'])
  243. rating = str(round(float(item2['rating']),1))
  244. episodeno = "s%se%s" %(season,episode)
  245. art2 = item2['art']
  246. #seasonthumb = ''
  247. if (item2['resume']['position'] and item2['resume']['total']) > 0:
  248. resume = "true"
  249. played = '%s%%'%int((float(item2['resume']['position']) / float(item2['resume']['total'])) * 100)
  250. else:
  251. resume = "false"
  252. played = '0%'
  253. if item2['playcount'] >= 1:
  254. watched = "true"
  255. else:
  256. watched = "false"
  257. if not self.PLOT_ENABLE and watched == "false":
  258. plot = __localize__(32014)
  259. else:
  260. plot = item2['plot']
  261. art = item['art']
  262. path = media_path(item['file'])
  263. play = 'XBMC.RunScript(' + __addonid__ + ',episodeid=' + str(item2.get('episodeid')) + ')'
  264. streaminfo = media_streamdetails(item['file'].encode('utf-8').lower(),
  265. item2['streamdetails'])
  266. self.WINDOW.setProperty("%s.%d.DBID" % (request, count), str(item2.get('episodeid')))
  267. self.WINDOW.setProperty("%s.%d.Title" % (request, count), item2['title'])
  268. self.WINDOW.setProperty("%s.%d.Episode" % (request, count), episode)
  269. self.WINDOW.setProperty("%s.%d.EpisodeNo" % (request, count), episodeno)
  270. self.WINDOW.setProperty("%s.%d.Season" % (request, count), season)
  271. self.WINDOW.setProperty("%s.%d.Plot" % (request, count), plot)
  272. self.WINDOW.setProperty("%s.%d.TVshowTitle" % (request, count), item2['showtitle'])
  273. self.WINDOW.setProperty("%s.%d.Rating" % (request, count), rating)
  274. self.WINDOW.setProperty("%s.%d.Runtime" % (request, count), str(int((item2['runtime'] / 60) + 0.5)))
  275. self.WINDOW.setProperty("%s.%d.Premiered" % (request, count), item2['firstaired'])
  276. self.WINDOW.setProperty("%s.%d.Art(thumb)" % (request, count), art2.get('thumb',''))
  277. self.WINDOW.setProperty("%s.%d.Art(tvshow.fanart)" % (request, count), art2.get('tvshow.fanart',''))
  278. self.WINDOW.setProperty("%s.%d.Art(tvshow.poster)" % (request, count), art2.get('tvshow.poster',''))
  279. self.WINDOW.setProperty("%s.%d.Art(tvshow.banner)" % (request, count), art2.get('tvshow.banner',''))
  280. self.WINDOW.setProperty("%s.%d.Art(tvshow.clearlogo)"% (request, count), art2.get('tvshow.clearlogo',''))
  281. self.WINDOW.setProperty("%s.%d.Art(tvshow.clearart)" % (request, count), art2.get('tvshow.clearart',''))
  282. self.WINDOW.setProperty("%s.%d.Art(tvshow.landscape)"% (request, count), art2.get('tvshow.landscape',''))
  283. self.WINDOW.setProperty("%s.%d.Art(tvshow.characterart)"% (request, count), art2.get('tvshow.characterart',''))
  284. #self.WINDOW.setProperty("%s.%d.Art(season.poster)" % (request, count), seasonthumb)
  285. self.WINDOW.setProperty("%s.%d.Studio" % (request, count), item['studio'][0])
  286. self.WINDOW.setProperty("%s.%d.mpaa" % (request, count), item['mpaa'])
  287. self.WINDOW.setProperty("%s.%d.Resume" % (request, count), resume)
  288. self.WINDOW.setProperty("%s.%d.PercentPlayed" % (request, count), played)
  289. self.WINDOW.setProperty("%s.%d.Watched" % (request, count), watched)
  290. self.WINDOW.setProperty("%s.%d.File" % (request, count), item2['file'])
  291. self.WINDOW.setProperty("%s.%d.Path" % (request, count), path)
  292. self.WINDOW.setProperty("%s.%d.Play" % (request, count), play)
  293. self.WINDOW.setProperty("%s.%d.VideoCodec" % (request, count), streaminfo['videocodec'])
  294. self.WINDOW.setProperty("%s.%d.VideoResolution" % (request, count), streaminfo['videoresolution'])
  295. self.WINDOW.setProperty("%s.%d.VideoAspect" % (request, count), streaminfo['videoaspect'])
  296. self.WINDOW.setProperty("%s.%d.AudioCodec" % (request, count), streaminfo['audiocodec'])
  297. self.WINDOW.setProperty("%s.%d.AudioChannels" % (request, count), str(streaminfo['audiochannels']))
  298. del json_query
  299.  
  300. def _fetch_tvshows(self, request):
  301. if not xbmc.abortRequested:
  302. season_folders = __addon__.getSetting("randomitems_seasonfolders")
  303. json_string = '{"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.GetEpisodes", "params": { "properties": ["title", "playcount", "season", "episode", "showtitle", "plot", "file", "rating", "resume", "tvshowid", "art", "streamdetails", "firstaired", "runtime"], "limits": {"end": %d},' %self.LIMIT
  304. if request == 'RecentEpisode' and self.RECENTITEMS_UNPLAYED:
  305. json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "dateadded"}, "filter": {"field": "playcount", "operator": "lessthan", "value": "1"}}}' %json_string)
  306. elif request == 'RecentEpisode':
  307. json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "dateadded"}}}' %json_string)
  308. elif request == 'RandomEpisode' and self.RANDOMITEMS_UNPLAYED:
  309. json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random" }, "filter": {"field": "playcount", "operator": "lessthan", "value": "1"}}}' %json_string)
  310. else:
  311. json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random" }}}' %json_string)
  312. json_query = unicode(json_query, 'utf-8', errors='ignore')
  313. json_query = simplejson.loads(json_query)
  314. if json_query.has_key('result') and json_query['result'].has_key('episodes'):
  315. self._clear_properties(request)
  316. count = 0
  317. for item in json_query['result']['episodes']:
  318. count += 1
  319. '''
  320. # This part is commented out because it takes 1.5second extra on my system to request these which doubles the total time.
  321. # Hence the ugly path hack that will require users to have season folders.
  322. json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShowDetails", "params": {"properties": ["file", "studio"], "tvshowid":%s}, "id": 1}' %item['tvshowid'])
  323. json_query2 = unicode(json_query2, 'utf-8', errors='ignore')
  324. json_query2 = simplejson.loads(json_query2)
  325. path = json_query2['result']['tvshowdetails']['file']
  326. studio = json_query2['result']['tvshowdetails']['studio'][0]
  327. '''
  328. if season_folders == 'true':
  329. path = os.path.split(media_path(item['file']))[0]
  330. else:
  331. path = media_path(item['file'])
  332. episode = ("%.2d" % float(item['episode']))
  333. season = "%.2d" % float(item['season'])
  334. episodeno = "s%se%s" %(season,episode)
  335. #seasonthumb = ''
  336. rating = str(round(float(item['rating']),1))
  337. if (item['resume']['position'] and item['resume']['total']) > 0:
  338. resume = "true"
  339. played = '%s%%'%int((float(item['resume']['position']) / float(item['resume']['total'])) * 100)
  340. else:
  341. resume = "false"
  342. played = '0%'
  343. if item['playcount'] >= 1:
  344. watched = "true"
  345. else:
  346. watched = "false"
  347. if not self.PLOT_ENABLE and watched == "false":
  348. plot = __localize__(32014)
  349. else:
  350. plot = item['plot']
  351. art = item['art']
  352. path = media_path(item['file'])
  353. play = 'XBMC.RunScript(' + __addonid__ + ',episodeid=' + str(item.get('episodeid')) + ')'
  354. streaminfo = media_streamdetails(item['file'].encode('utf-8').lower(),
  355. item['streamdetails'])
  356. self.WINDOW.setProperty("%s.%d.DBID" % (request, count), str(item.get('episodeid')))
  357. self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['title'])
  358. self.WINDOW.setProperty("%s.%d.Episode" % (request, count), episode)
  359. self.WINDOW.setProperty("%s.%d.EpisodeNo" % (request, count), episodeno)
  360. self.WINDOW.setProperty("%s.%d.Season" % (request, count), season)
  361. self.WINDOW.setProperty("%s.%d.Plot" % (request, count), plot)
  362. self.WINDOW.setProperty("%s.%d.TVshowTitle" % (request, count), item['showtitle'])
  363. self.WINDOW.setProperty("%s.%d.Rating" % (request, count), rating)
  364. self.WINDOW.setProperty("%s.%d.Runtime" % (request, count), str(int((item['runtime'] / 60) + 0.5)))
  365. self.WINDOW.setProperty("%s.%d.Premiered" % (request, count), item['firstaired'])
  366. self.WINDOW.setProperty("%s.%d.Art(thumb)" % (request, count), art.get('thumb',''))
  367. self.WINDOW.setProperty("%s.%d.Art(tvshow.fanart)" % (request, count), art.get('tvshow.fanart',''))
  368. self.WINDOW.setProperty("%s.%d.Art(tvshow.poster)" % (request, count), art.get('tvshow.poster',''))
  369. self.WINDOW.setProperty("%s.%d.Art(tvshow.banner)" % (request, count), art.get('tvshow.banner',''))
  370. self.WINDOW.setProperty("%s.%d.Art(tvshow.clearlogo)"% (request, count), art.get('tvshow.clearlogo',''))
  371. self.WINDOW.setProperty("%s.%d.Art(tvshow.clearart)" % (request, count), art.get('tvshow.clearart',''))
  372. self.WINDOW.setProperty("%s.%d.Art(tvshow.landscape)"% (request, count), art.get('tvshow.landscape',''))
  373. self.WINDOW.setProperty("%s.%d.Art(tvshow.characterart)"% (request, count), art.get('tvshow.characterart',''))
  374. self.WINDOW.setProperty("%s.%d.Resume" % (request, count), resume)
  375. self.WINDOW.setProperty("%s.%d.PercentPlayed" % (request, count), played)
  376. self.WINDOW.setProperty("%s.%d.Watched" % (request, count), watched)
  377. self.WINDOW.setProperty("%s.%d.File" % (request, count), item['file'])
  378. self.WINDOW.setProperty("%s.%d.Path" % (request, count), path)
  379. self.WINDOW.setProperty("%s.%d.Play" % (request, count), play)
  380. self.WINDOW.setProperty("%s.%d.VideoCodec" % (request, count), streaminfo['videocodec'])
  381. self.WINDOW.setProperty("%s.%d.VideoResolution" % (request, count), streaminfo['videoresolution'])
  382. self.WINDOW.setProperty("%s.%d.VideoAspect" % (request, count), streaminfo['videoaspect'])
  383. self.WINDOW.setProperty("%s.%d.AudioCodec" % (request, count), streaminfo['audiocodec'])
  384. self.WINDOW.setProperty("%s.%d.AudioChannels" % (request, count), str(streaminfo['audiochannels']))
  385. del json_query
  386.  
  387. def _fetch_seasonthumb(self, tvshowid, seasonnumber):
  388. json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetSeasons", "params": {"properties": ["season", "thumbnail"], "tvshowid":%s }, "id": 1}' % tvshowid)
  389. json_query = unicode(json_query, 'utf-8', errors='ignore')
  390. json_query = simplejson.loads(json_query)
  391. if json_query.has_key('result') and json_query['result'].has_key('seasons'):
  392. for item in json_query['result']['seasons']:
  393. season = "%.2d" % float(item['season'])
  394. if season == seasonnumber:
  395. thumbnail = item['thumbnail']
  396. return thumbnail
  397.  
  398. def _fetch_musicvideo(self, request):
  399. if not xbmc.abortRequested:
  400. json_string = '{"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.GetMusicVideos", "params": {"properties": ["title", "artist", "playcount", "year", "plot", "genre", "runtime", "fanart", "thumbnail", "file", "streamdetails", "resume"], "limits": {"end": %d},' %self.LIMIT
  401. if request == 'RecommendedMusicVideo':
  402. json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "playcount" }}}' %json_string)
  403. elif request == 'RecentMusicVideo':
  404. json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "dateadded"}}}' %json_string)
  405. else:
  406. json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random"}}}' %json_string)
  407. json_query = unicode(json_query, 'utf-8', errors='ignore')
  408. json_query = simplejson.loads(json_query)
  409. if json_query.has_key('result') and json_query['result'].has_key('musicvideos'):
  410. self._clear_properties(request)
  411. count = 0
  412. for item in json_query['result']['musicvideos']:
  413. count += 1
  414. if (item['resume']['position'] and item['resume']['total'])> 0:
  415. resume = "true"
  416. played = '%s%%'%int((float(item['resume']['position']) / float(item['resume']['total'])) * 100)
  417. else:
  418. resume = "false"
  419. played = '0%'
  420. if item['playcount'] >= 1:
  421. watched = "true"
  422. else:
  423. watched = "false"
  424. play = 'XBMC.RunScript(' + __addonid__ + ',musicvideoid=' + str(item.get('musicvideoid')) + ')'
  425. path = media_path(item['file'])
  426. streaminfo = media_streamdetails(item['file'].encode('utf-8').lower(),
  427. item['streamdetails'])
  428. self.WINDOW.setProperty("%s.%d.DBID" % (request, count), str(item.get('musicvideoid')))
  429. self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['title'])
  430. self.WINDOW.setProperty("%s.%d.Artist" % (request, count), " / ".join(item['artist']))
  431. self.WINDOW.setProperty("%s.%d.Year" % (request, count), str(item['year']))
  432. self.WINDOW.setProperty("%s.%d.Plot" % (request, count), item['plot'])
  433. self.WINDOW.setProperty("%s.%d.Genre" % (request, count), " / ".join(item['genre']))
  434. self.WINDOW.setProperty("%s.%d.Runtime" % (request, count), str(int((item['runtime'] / 60) + 0.5)))
  435. self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail']) #remove
  436. self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart']) #remove
  437. self.WINDOW.setProperty("%s.%d.Art(thumb)" % (request, count), item['thumbnail'])
  438. self.WINDOW.setProperty("%s.%d.Art(fanart)" % (request, count), item['fanart'])
  439. self.WINDOW.setProperty("%s.%d.File" % (request, count), item['file'])
  440. self.WINDOW.setProperty("%s.%d.Path" % (request, count), path)
  441. self.WINDOW.setProperty("%s.%d.Resume" % (request, count), resume)
  442. self.WINDOW.setProperty("%s.%d.PercentPlayed" % (request, count), played)
  443. self.WINDOW.setProperty("%s.%d.Watched" % (request, count), watched)
  444. self.WINDOW.setProperty("%s.%d.Play" % (request, count), play)
  445. self.WINDOW.setProperty("%s.%d.VideoCodec" % (request, count), streaminfo['videocodec'])
  446. self.WINDOW.setProperty("%s.%d.VideoResolution" % (request, count), streaminfo['videoresolution'])
  447. self.WINDOW.setProperty("%s.%d.VideoAspect" % (request, count), streaminfo['videoaspect'])
  448. self.WINDOW.setProperty("%s.%d.AudioCodec" % (request, count), streaminfo['audiocodec'])
  449. self.WINDOW.setProperty("%s.%d.AudioChannels" % (request, count), str(streaminfo['audiochannels']))
  450. del json_query
  451.  
  452. def _fetch_albums(self, request):
  453. if not xbmc.abortRequested:
  454. json_string = '{"jsonrpc": "2.0", "id": 1, "method": "AudioLibrary.GetAlbums", "params": {"properties": ["title", "description", "albumlabel", "theme", "mood", "style", "type", "artist", "genre", "year", "thumbnail", "fanart", "rating", "playcount"], "limits": {"end": %d},' %self.LIMIT
  455. if request == 'RecommendedAlbum':
  456. json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "playcount" }}}' %json_string)
  457. elif request == 'RecentAlbum':
  458. json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "dateadded" }}}' %json_string)
  459. else:
  460. json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random"}}}' %json_string)
  461. json_query = unicode(json_query, 'utf-8', errors='ignore')
  462. json_query = simplejson.loads(json_query)
  463. if json_query.has_key('result') and json_query['result'].has_key('albums'):
  464. self._clear_properties(request)
  465. count = 0
  466. for item in json_query['result']['albums']:
  467. count += 1
  468. rating = str(item['rating'])
  469. if rating == '48':
  470. rating = ''
  471. play = 'XBMC.RunScript(' + __addonid__ + ',albumid=' + str(item.get('albumid')) + ')'
  472. self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['title'])
  473. self.WINDOW.setProperty("%s.%d.Label" % (request, count), item['title']) #needs to be removed
  474. self.WINDOW.setProperty("%s.%d.Artist" % (request, count), " / ".join(item['artist']))
  475. self.WINDOW.setProperty("%s.%d.Genre" % (request, count), " / ".join(item['genre']))
  476. self.WINDOW.setProperty("%s.%d.Theme" % (request, count), " / ".join(item['theme']))
  477. self.WINDOW.setProperty("%s.%d.Mood" % (request, count), " / ".join(item['mood']))
  478. self.WINDOW.setProperty("%s.%d.Style" % (request, count), " / ".join(item['style']))
  479. self.WINDOW.setProperty("%s.%d.Type" % (request, count), " / ".join(item['type']))
  480. self.WINDOW.setProperty("%s.%d.Year" % (request, count), str(item['year']))
  481. self.WINDOW.setProperty("%s.%d.RecordLabel" % (request, count), item['albumlabel'])
  482. self.WINDOW.setProperty("%s.%d.Description" % (request, count), item['description'])
  483. self.WINDOW.setProperty("%s.%d.Rating" % (request, count), rating)
  484. self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail']) #remove
  485. self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart']) #remove
  486. self.WINDOW.setProperty("%s.%d.Art(thumb)" % (request, count), item['thumbnail'])
  487. self.WINDOW.setProperty("%s.%d.Art(fanart)" % (request, count), item['fanart'])
  488. self.WINDOW.setProperty("%s.%d.Play" % (request, count), play)
  489. del json_query
  490.  
  491. def _fetch_artist(self, request):
  492. if not xbmc.abortRequested:
  493. # Random artist
  494. json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetArtists", "params": {"properties": ["genre", "description", "mood", "style", "born", "died", "formed", "disbanded", "yearsactive", "instrument", "fanart", "thumbnail"], "sort": {"method": "random"}, "limits": {"end": %d}}, "id": 1}' %self.LIMIT)
  495. json_query = unicode(json_query, 'utf-8', errors='ignore')
  496. json_query = simplejson.loads(json_query)
  497. if json_query.has_key('result') and json_query['result'].has_key('artists'):
  498. self._clear_properties(request)
  499. count = 0
  500. for item in json_query['result']['artists']:
  501. count += 1
  502. path = 'musicdb://2/' + str(item['artistid']) + '/'
  503. self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['label'])
  504. self.WINDOW.setProperty("%s.%d.Genre" % (request, count), " / ".join(item['genre']))
  505. self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail']) #remove
  506. self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart']) #remove
  507. self.WINDOW.setProperty("%s.%d.Art(thumb)" % (request, count), item['thumbnail'])
  508. self.WINDOW.setProperty("%s.%d.Art(fanart)" % (request, count), item['fanart'])
  509. self.WINDOW.setProperty("%s.%d.Description" % (request, count), item['description'])
  510. self.WINDOW.setProperty("%s.%d.Born" % (request, count), item['born'])
  511. self.WINDOW.setProperty("%s.%d.Died" % (request, count), item['died'])
  512. self.WINDOW.setProperty("%s.%d.Formed" % (request, count), item['formed'])
  513. self.WINDOW.setProperty("%s.%d.Disbanded" % (request, count), item['disbanded'])
  514. self.WINDOW.setProperty("%s.%d.YearsActive" % (request, count), " / ".join(item['yearsactive']))
  515. self.WINDOW.setProperty("%s.%d.Style" % (request, count), " / ".join(item['style']))
  516. self.WINDOW.setProperty("%s.%d.Mood" % (request, count), " / ".join(item['mood']))
  517. self.WINDOW.setProperty("%s.%d.Instrument" % (request, count), " / ".join(item['instrument']))
  518. self.WINDOW.setProperty("%s.%d.LibraryPath" % (request, count), path)
  519.  
  520. def _fetch_song(self, request):
  521. if not xbmc.abortRequested:
  522. json_string = '{"jsonrpc": "2.0", "id": 1, "method": "AudioLibrary.GetSongs", "params": {"properties": ["title", "playcount", "artist", "album", "year", "file", "thumbnail", "fanart", "rating"], "filter": {"field": "playcount", "operator": "lessthan", "value": "1"}, "limits": {"end": %d},' %self.LIMIT
  523. if request == 'RandomSong' and self.RANDOMITEMS_UNPLAYED == "True":
  524. json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random"}}}' %json_string)
  525. else:
  526. json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random"}}}' %json_string)
  527. json_query = unicode(json_query, 'utf-8', errors='ignore')
  528. json_query = simplejson.loads(json_query)
  529. if json_query.has_key('result') and json_query['result'].has_key('songs'):
  530. self._clear_properties(request)
  531. count = 0
  532. for item in json_query['result']['songs']:
  533. count += 1
  534. play = 'XBMC.RunScript(' + __addonid__ + ',songid=' + str(item.get('songid')) + ')'
  535. path = media_path(item['file'])
  536. self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['title'])
  537. self.WINDOW.setProperty("%s.%d.Artist" % (request, count), " / ".join(item['artist']))
  538. self.WINDOW.setProperty("%s.%d.Year" % (request, count), str(item['year']))
  539. self.WINDOW.setProperty("%s.%d.Rating" % (request, count), str(int(item['rating'])-48))
  540. self.WINDOW.setProperty("%s.%d.Album" % (request, count), item['album'])
  541. self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail']) #remove
  542. self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart']) #remove
  543. self.WINDOW.setProperty("%s.%d.Art(thumb)" % (request, count), item['thumbnail'])
  544. self.WINDOW.setProperty("%s.%d.Art(fanart)" % (request, count), item['fanart'])
  545. self.WINDOW.setProperty("%s.%d.File" % (request, count), item['file'])
  546. self.WINDOW.setProperty("%s.%d.Path" % (request, count), path)
  547. self.WINDOW.setProperty("%s.%d.Play" % (request, count), play)
  548. del json_query
  549.  
  550. def _fetch_addon(self, request):
  551. if not xbmc.abortRequested:
  552. json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Addons.GetAddons", "params": {"properties": ["name", "author", "summary", "version", "fanart", "thumbnail"]}, "id": 1}')
  553. json_query = unicode(json_query, 'utf-8', errors='ignore')
  554. json_query = simplejson.loads(json_query)
  555. if json_query.has_key('result') and json_query['result'].has_key('addons'):
  556. # find plugins and scripts
  557. addonlist = []
  558. for item in json_query['result']['addons']:
  559. if item['type'] == 'xbmc.python.script' or item['type'] == 'xbmc.python.pluginsource':
  560. addonlist.append(item)
  561. # randomize the list
  562. random.shuffle(addonlist)
  563. self._clear_properties(request)
  564. count = 0
  565. for item in addonlist:
  566. count += 1
  567. self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['name'])
  568. self.WINDOW.setProperty("%s.%d.Author" % (request, count), item['author'])
  569. self.WINDOW.setProperty("%s.%d.Summary" % (request, count), item['summary'])
  570. self.WINDOW.setProperty("%s.%d.Version" % (request, count), item['version'])
  571. self.WINDOW.setProperty("%s.%d.Path" % (request, count), item['addonid'])
  572. self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail']) #remove
  573. self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart']) #remove
  574. self.WINDOW.setProperty("%s.%d.Art(thumb)" % (request, count), item['thumbnail'])
  575. self.WINDOW.setProperty("%s.%d.Art(fanart)" % (request, count), item['fanart'])
  576. self.WINDOW.setProperty("%s.%d.Type" % (request, count), item['type'])
  577. # stop if we've reached the number of items we need
  578. if count == self.LIMIT:
  579. break
  580. self.WINDOW.setProperty("%s.Count" % (request), str(json_query['result']['limits']['total']))
  581. del json_query
  582.  
  583. def _daemon(self):
  584. # deamon is meant to keep script running at all time
  585. count = 0
  586. home_update = False
  587. while (not xbmc.abortRequested) and self.WINDOW.getProperty('SkinWidgets_Running') == 'true':
  588. xbmc.sleep(500)
  589. if not xbmc.Player().isPlayingVideo():
  590. if self.RANDOMITEMS_UPDATE_METHOD == 0:
  591. count += 1
  592. if count == self.RANDOMITEMS_TIME:
  593. self._fetch_info_randomitems()
  594. count = 0 # reset counter
  595. if self.WINDOW.getProperty('SkinWidgets_RandomItems_Update') == 'true':
  596. count = 0
  597. self.WINDOW.setProperty('SkinWidgets_RandomItems_Update','false')
  598. self._fetch_info_randomitems()
  599. if self.RECENTITEMS_HOME_UPDATE == 'true' and home_update and xbmcgui.getCurrentWindowId() == 10000:
  600. self._fetch_info_recentitems()
  601. home_update = False
  602. elif self.RECENTITEMS_HOME_UPDATE == 'true' and not home_update and xbmcgui.getCurrentWindowId() != 10000:
  603. home_update = True
  604.  
  605. def _clear_properties(self, request):
  606. count = 0
  607. for count in range(int(self.LIMIT)):
  608. count += 1
  609. self.WINDOW.clearProperty("%s.%d.Title" % (request, count))
  610.  
  611. def _update(self, type):
  612. xbmc.sleep(1000)
  613. if type == 'movie':
  614. self._fetch_movies('RecommendedMovie')
  615. self._fetch_movies('RecentMovie')
  616. elif type == 'episode':
  617. self._fetch_tvshows_recommended('RecommendedEpisode')
  618. self._fetch_tvshows('RecentEpisode')
  619. elif type == 'video':
  620. xbmc.sleep(2000)
  621. #only on db update
  622. self._fetch_movies('RecommendedMovie')
  623. self._fetch_tvshows_recommended('RecommendedEpisode')
  624. self._fetch_movies('RecentMovie')
  625. self._fetch_tvshows('RecentEpisode')
  626. self._fetch_musicvideo('RecentMusicVideo')
  627. elif type == 'music':
  628. self._fetch_albums('RecommendedAlbum')
  629. self._fetch_albums('RecentAlbum')
  630. if self.RANDOMITEMS_UPDATE_METHOD == 1:
  631. # update random if db update is selected instead of timer
  632. if type == 'video':
  633. self._fetch_movies('RandomMovie')
  634. self._fetch_tvshows('RandomEpisode')
  635. self._fetch_musicvideo('RandomMusicVideo')
  636. elif type == 'music':
  637. self._fetch_albums('RandomAlbum')
  638. self._fetch_artist('RandomArtist')
  639. self._fetch_song('RandomSong')
  640. self._fetch_addon('RandomAddon')
  641.  
  642. def media_path(path):
  643. # Check for stacked movies
  644. try:
  645. path = os.path.split(path)[0].rsplit(' , ', 1)[1].replace(",,",",")
  646. except:
  647. path = os.path.split(path)[0]
  648. # Fixes problems with rared movies and multipath
  649. if path.startswith("rar://"):
  650. path = [os.path.split(urllib.url2pathname(path.replace("rar://","")))[0]]
  651. elif path.startswith("multipath://"):
  652. temp_path = path.replace("multipath://","").split('%2f/')
  653. path = []
  654. for item in temp_path:
  655. path.append(urllib.url2pathname(item))
  656. else:
  657. path = [path]
  658. return path[0]
  659.  
  660. def media_streamdetails(filename, streamdetails):
  661. info = {}
  662. video = streamdetails['video']
  663. audio = streamdetails['audio']
  664. if '3d' in filename:
  665. info['videoresolution'] = '3d'
  666. elif video:
  667. videowidth = video[0]['width']
  668. videoheight = video[0]['height']
  669. if (video[0]['width'] <= 720 and video[0]['height'] <= 480):
  670. info['videoresolution'] = "480"
  671. elif (video[0]['width'] <= 768 and video[0]['height'] <= 576):
  672. info['videoresolution'] = "576"
  673. elif (video[0]['width'] <= 960 and video[0]['height'] <= 544):
  674. info['videoresolution'] = "540"
  675. elif (video[0]['width'] <= 1280 and video[0]['height'] <= 720):
  676. info['videoresolution'] = "720"
  677. elif (video[0]['width'] >= 1281 or video[0]['height'] >= 721):
  678. info['videoresolution'] = "1080"
  679. else:
  680. info['videoresolution'] = ""
  681. elif (('dvd') in filename and not ('hddvd' or 'hd-dvd') in filename) or (filename.endswith('.vob' or '.ifo')):
  682. info['videoresolution'] = '576'
  683. elif (('bluray' or 'blu-ray' or 'brrip' or 'bdrip' or 'hddvd' or 'hd-dvd') in filename):
  684. info['videoresolution'] = '1080'
  685. else:
  686. info['videoresolution'] = '1080'
  687. if video:
  688. info['videocodec'] = video[0]['codec']
  689. if (video[0]['aspect'] < 1.4859):
  690. info['videoaspect'] = "1.33"
  691. elif (video[0]['aspect'] < 1.7190):
  692. info['videoaspect'] = "1.66"
  693. elif (video[0]['aspect'] < 1.8147):
  694. info['videoaspect'] = "1.78"
  695. elif (video[0]['aspect'] < 2.0174):
  696. info['videoaspect'] = "1.85"
  697. elif (video[0]['aspect'] < 2.2738):
  698. info['videoaspect'] = "2.20"
  699. else:
  700. info['videoaspect'] = "2.35"
  701. else:
  702. info['videocodec'] = ''
  703. info['videoaspect'] = ''
  704. if audio:
  705. info['audiocodec'] = audio[0]['codec']
  706. info['audiochannels'] = audio[0]['channels']
  707. else:
  708. info['audiocodec'] = ''
  709. info['audiochannels'] = ''
  710. return info
  711.  
  712.  
  713. class Widgets_Monitor(xbmc.Monitor):
  714. def __init__(self, *args, **kwargs):
  715. xbmc.Monitor.__init__(self)
  716. self.update_listitems = kwargs['update_listitems']
  717. self.update_settings = kwargs['update_settings']
  718.  
  719. def onDatabaseUpdated(self, database):
  720. self.update_listitems(database)
  721.  
  722. def onSettingsChanged(self):
  723. self.update_settings()
  724.  
  725. class Widgets_Player(xbmc.Player):
  726. def __init__(self, *args, **kwargs):
  727. xbmc.Player.__init__(self)
  728. self.type = ""
  729. self.action = kwargs[ "action" ]
  730. self.substrings = [ '-trailer', 'http://' ]
  731.  
  732. def onPlayBackStarted(self):
  733. xbmc.sleep(1000)
  734. # Set values based on the file content
  735. if (self.isPlayingAudio()):
  736. self.type = "music"
  737. else:
  738. if xbmc.getCondVisibility('VideoPlayer.Content(movies)'):
  739. filename = ''
  740. isMovie = True
  741. try:
  742. filename = self.getPlayingFile()
  743. except:
  744. pass
  745. if filename != '':
  746. for string in self.substrings:
  747. if string in filename:
  748. isMovie = False
  749. break
  750. if isMovie:
  751. self.type = "movie"
  752. elif xbmc.getCondVisibility('VideoPlayer.Content(episodes)'):
  753. # Check for tv show title and season to make sure it's really an episode
  754. if xbmc.getInfoLabel('VideoPlayer.Season') != "" and xbmc.getInfoLabel('VideoPlayer.TVShowTitle') != "":
  755. self.type = "episode"
  756.  
  757. def onPlayBackEnded(self):
  758. self.onPlayBackStopped()
  759.  
  760. def onPlayBackStopped(self):
  761. if self.type == 'movie':
  762. self.action('movie')
  763. elif self.type == 'episode':
  764. self.action('episode')
  765. elif self.type == 'music':
  766. self.action('music')
  767. self.type = ""
  768.  
  769. if (__name__ == "__main__"):
  770. log('script version %s started' % __addonversion__)
  771. Main()
  772. del Widgets_Monitor
  773. del Widgets_Player
  774. del Main
  775. log('script version %s stopped' % __addonversion__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement