Guest User

Untitled

a guest
Dec 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.60 KB | None | 0 0
  1. #import modules
  2. import os
  3. import xbmc
  4. import urllib
  5. import sys
  6.  
  7. # Use json instead of simplejson when python v2.7 or greater
  8. if sys.version_info < (2, 7):
  9. import json as simplejson
  10. else:
  11. import simplejson
  12.  
  13. ### import libraries
  14. from resources.lib.utils import log
  15. # Commoncache plugin import
  16. try:
  17. import StorageServer
  18. except:
  19. import storageserverdummy as StorageServer
  20.  
  21. cacheMedia = StorageServer.StorageServer("ArtworkDownloader",1)
  22. cacheMedia.timeout = 600 # In seconds
  23.  
  24. # Retrieve JSON data from cache function
  25. def _media_listing(media_type):
  26. result = cacheMedia.cacheFunction( _media_listing_new, media_type )
  27. if len(result) == 0:
  28. result = []
  29. return result
  30. else:
  31. return result
  32.  
  33. ### get list of all tvshows and movies with their imdbnumber from library
  34. # Retrieve JSON list
  35.  
  36. def _media_listing_new(media_type):
  37. log('Using JSON for retrieving %s info' %media_type)
  38. Medialist = []
  39. if media_type == 'tvshow':
  40. json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["file", "imdbnumber"], "sort": { "method": "label" } }, "id": 1}')
  41. json_response = unicode(json_response, 'utf-8', errors='ignore')
  42. jsonobject = simplejson.loads(json_response)
  43. if jsonobject['result'].has_key('tvshows'):
  44. for item in jsonobject['result']['tvshows']:
  45. # Search for season information
  46. json_response_season = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetSeasons", "params": {"properties": ["season"], "sort": { "method": "label" }, "tvshowid":%s }, "id": 1}' %item.get('tvshowid',''))
  47. jsonobject_season = simplejson.loads(json_response_season)
  48. # Get start/end and total seasons
  49. if jsonobject_season['result'].has_key('limits'):
  50. season_limit = jsonobject_season['result']['limits']
  51. # Get the season numbers
  52. seasons_list =[]
  53. if jsonobject_season['result'].has_key('seasons'):
  54. seasons = jsonobject_season['result']['seasons']
  55. for season in seasons:
  56. seasons_list.append(season.get('season'))
  57. Medialist.append({'id': item.get('imdbnumber',''),
  58. 'tvshowid': item.get('tvshowid',''),
  59. 'name': item.get('label',''),
  60. 'path': media_path(item.get('file','')),
  61. 'seasontotal': season_limit.get('total',''),
  62. 'seasonstart': season_limit.get('start',''),
  63. 'seasonend': season_limit.get('end',''),
  64. 'seasons': seasons_list})
  65.  
  66. elif media_type == 'movie':
  67. json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["file", "imdbnumber", "year", "trailer", "streamdetails"], "sort": { "method": "label" } }, "id": 1}')
  68. json_response = unicode(json_response, 'utf-8', errors='ignore')
  69. jsonobject = simplejson.loads(json_response)
  70. if jsonobject['result'].has_key('movies'):
  71. for item in jsonobject['result']['movies']:
  72. filename = item.get('file','').encode('utf-8').lower()
  73. if (('dvd') in filename and not ('hddvd' or 'hd-dvd') in filename) or (filename.endswith('.vob' or '.ifo')):
  74. disctype = 'dvd'
  75. elif '3d' in filename:
  76. disctype = '3d'
  77. elif (('bluray' or 'blu-ray' or 'brrip' or 'bdrip') in filename):
  78. disctype = 'bluray'
  79. elif item.get('streamdetails') and item.get('streamdetails') != None and item.get('streamdetails').has_key('video'):
  80. videowidth = item['streamdetails']['video'][0]['width']
  81. videoheight = item['streamdetails']['video'][0]['height']
  82. if videowidth <= 720 and videoheight <= 480:
  83. disctype = 'dvd'
  84. else:
  85. disctype = 'bluray'
  86. else:
  87. disctype = 'n/a'
  88. Medialist.append({'movieid': item.get('movieid',''),
  89. 'id': item.get('imdbnumber',''),
  90. 'name': item.get('label',''),
  91. 'year': item.get('year',''),
  92. 'file': item.get('file',''),
  93. 'path': media_path(item.get('file','')),
  94. 'trailer': item.get('trailer',''),
  95. 'disctype': disctype})
  96.  
  97. elif media_type == 'musicvideo':
  98. json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": {"properties": ["file", "artist", "album", "track", "runtime", "year", "genre"], "sort": { "method": "album" } }, "id": 1}')
  99. json_response = unicode(json_response, 'utf-8', errors='ignore')
  100. jsonobject = simplejson.loads(json_response)
  101. if jsonobject['result'].has_key('musicvideos'):
  102. for item in jsonobject['result']['musicvideos']:
  103. Medialist.append({'id': '',
  104. 'movieid': item.get('musicvideoid',''),
  105. 'name': item.get('label',''),
  106. 'artist': item.get('artist',''),
  107. 'album': item.get('album',''),
  108. 'track': item.get('track',''),
  109. 'runtime': item.get('runtime',''),
  110. 'year': item.get('year',''),
  111. 'path': media_path(item.get('file',''))})
  112. else:
  113. log('No JSON results found')
  114. return Medialist
  115.  
  116.  
  117. def media_path(path):
  118. # Check for stacked movies
  119. try:
  120. path = os.path.split(path)[0].rsplit(' , ', 1)[1].replace(",,",",")
  121. except:
  122. path = os.path.split(path)[0]
  123. # Fixes problems with rared movies and multipath
  124. if path.startswith("rar://"):
  125. path = [os.path.split(urllib.url2pathname(path.replace("rar://","")))[0]]
  126. elif path.startswith("multipath://"):
  127. temp_path = path.replace("multipath://","").split('%2f/')
  128. path = []
  129. for item in temp_path:
  130. path.append(urllib.url2pathname(item))
  131. print path
  132. else:
  133. path = [path]
  134. return path
Add Comment
Please, Sign In to add comment