Advertisement
Guest User

Untitled

a guest
Mar 16th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 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 _normalize_string as normalize_string
  15. from resources.lib.utils import _log as log
  16. from elementtree import ElementTree as ET
  17. # Commoncache plugin import
  18. try:
  19. import StorageServer
  20. except:
  21. import storageserverdummy as StorageServer
  22.  
  23. cacheMedia = StorageServer.StorageServer("ArtworkDownloader",1)
  24. #cacheMedia.timeout = 600 # In seconds
  25.  
  26. # Retrieve JSON data from cache function
  27. def _media_listing_(media_type):
  28. result = cacheMedia.cacheFunction( _media_listing_new, media_type )
  29. if len(result) == 0 or result == 'Empty':
  30. result = []
  31. return result
  32. else:
  33. return result
  34.  
  35. ### get list of all tvshows and movies with their imdbnumber from library
  36. # Retrieve JSON list
  37.  
  38. def _media_listing(media_type):
  39. log('Using JSON for retrieving %s info' %media_type)
  40. Medialist = []
  41. try:
  42. if media_type == 'tvshow':
  43. json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["file", "imdbnumber"], "sort": { "method": "label" } }, "id": 1}')
  44. json_response.decode('utf-8')
  45. jsonobject = simplejson.loads(json_response)
  46. if jsonobject['result'].has_key('tvshows'):
  47. for item in jsonobject['result']['tvshows']:
  48. Media = {}
  49. Media['name'] = item['label']
  50. Media['path'] = media_path(item['file'])
  51. Media['id'] = item['imdbnumber']
  52. Media['tvshowid'] = item['tvshowid']
  53.  
  54. # Search for season information
  55. json_response_season = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetSeasons", "params": {"properties": ["season"], "sort": { "method": "label" }, "tvshowid":%s }, "id": 1}' %Media['tvshowid'])
  56. jsonobject_season = simplejson.loads(json_response_season)
  57. # Get start/end and total seasons
  58. if jsonobject_season['result'].has_key('limits'):
  59. limits = jsonobject_season['result']['limits']
  60. Media['seasontotal'] = limits['total']
  61. Media['seasonstart'] = limits['start']
  62. Media['seasonend'] = limits['end']
  63. # Get the season numbers
  64. if jsonobject_season['result'].has_key('seasons'):
  65. seasons = jsonobject_season['result']['seasons']
  66. Media['seasons'] =[]
  67. for season in seasons:
  68. Media['seasons'].append(season['season'])
  69. '''
  70. # Retrieve season folder path
  71. i = Media['seasonstart']
  72. Media['seasonpaths'] = []
  73. while( i <= Media['seasonend'] and not xbmc.abortRequested ):
  74. json_response_episode = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid":%s, "season":%s, "properties": ["file"] }, "id": 1}' %(Media['tvshowid'],i) )
  75. jsonobject_episode = simplejson.loads(json_response_episode)
  76. itempath = ''
  77. Seasonitem = {}
  78. if jsonobject_episode['result'].has_key('episodes'):
  79. for item in jsonobject_episode['result']['episodes']:
  80. itempath = ( media_path(item['file']) )
  81. if itempath:
  82. break
  83. Seasonitem['seasonpath'] = itempath
  84. Seasonitem['seasonnumber'] = str( i )
  85. #log('Path: %s' %Seasonitem['seasonpath'] )
  86. #log('Number: %s'%Seasonitem['seasonnumber'] )
  87. if Seasonitem['seasonpath']:
  88. Media['seasonpaths'].append(Seasonitem)
  89. i += 1
  90. '''
  91. #log(Media)
  92. Medialist.append(Media)
  93.  
  94. elif media_type == 'movie':
  95. json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["file", "imdbnumber", "year", "trailer"], "sort": { "method": "label" } }, "id": 1}')
  96. json_response.decode('utf-8')
  97. jsonobject = simplejson.loads(json_response)
  98. if jsonobject['result'].has_key('movies'):
  99. for item in jsonobject['result']['movies']:
  100. Media = {}
  101. Media['movieid'] = item['movieid']
  102. Media['name'] = item['label']
  103. Media['year'] = item['year']
  104. Media['path'] = media_path(item['file'])
  105. Media['trailer'] = item['trailer']
  106. Media['id'] = item['imdbnumber']
  107. Medialist.append(Media)
  108.  
  109. elif media_type == 'musicvideo':
  110. json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": {"properties": ["file", "artist", "album", "track", "runtime", "year", "genre"], "sort": { "method": "album" } }, "id": 1}')
  111. json_response.decode('utf-8')
  112. jsonobject = simplejson.loads(json_response)
  113. if jsonobject['result'].has_key('musicvideos'):
  114. for item in jsonobject['result']['musicvideos']:
  115. Media = {}
  116. Media['id'] = ''
  117. Media['movieid'] = item['musicvideoid']
  118. Media['name'] = item['label']
  119. Media['artist'] = item['artist']
  120. Media['album'] = item['album']
  121. Media['track'] = item['track']
  122. Media['runtime'] = item['runtime']
  123. Media['year'] = item['year']
  124. Media['path'] = media_path(item['file'])
  125. Medialist.append(Media)
  126. else:
  127. log('No JSON results found')
  128. except Exception, NoneType:
  129. Medialist = 'Empty'
  130. log('No %s found in your library' %media_type)
  131. except Exception, e:
  132. Medialist = 'Empty'
  133. log( str( e ), xbmc.LOGERROR )
  134. return Medialist
  135.  
  136.  
  137. def media_path(path):
  138. # Check for stacked movies
  139. log(path)
  140. try:
  141. path = os.path.split(path)[0].rsplit(' , ', 1)[1]
  142. except:
  143. path = os.path.split(path)[0]
  144. # Fixes problems with rared movies
  145. if path.startswith("rar"):
  146. path = os.path.split(urllib.url2pathname(path.replace("rar://","")))[0]
  147. log(path)
  148. return path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement