Finished creating xem info provider
This commit is contained in:
1 parent
ec2facd056
commit
906a54ef09
1 file changed
+82
-19
@@ -57,7 +57,6 @@ class Xem(ShowProvider):
|
|||||||
{
|
{
|
||||||
"result": "success",
|
"result": "success",
|
||||||
"data": {
|
"data": {
|
||||||
"79604": ["Black-Lagoon", "ブラック・ラグーン", "Burakku Ragūn"],
|
|
||||||
"248812": ["Dont Trust the Bitch in Apartment 23", "Don't Trust the Bitch in Apartment 23"],
|
"248812": ["Dont Trust the Bitch in Apartment 23", "Don't Trust the Bitch in Apartment 23"],
|
||||||
"257571": ["Nazo no Kanojo X"],
|
"257571": ["Nazo no Kanojo X"],
|
||||||
"257875": ["Lupin III - Mine Fujiko to Iu Onna", "Lupin III Fujiko to Iu Onna", "Lupin the Third - Mine Fujiko to Iu Onna"]
|
"257875": ["Lupin III - Mine Fujiko to Iu Onna", "Lupin III Fujiko to Iu Onna", "Lupin the Third - Mine Fujiko to Iu Onna"]
|
||||||
@@ -67,40 +66,104 @@ class Xem(ShowProvider):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
addEvent('show.search', self.search, priority = 5)
|
|
||||||
addEvent('show.info', self.getShowInfo, priority = 5)
|
addEvent('show.info', self.getShowInfo, priority = 5)
|
||||||
addEvent('season.info', self.getSeasonInfo, priority = 5)
|
|
||||||
addEvent('episode.info', self.getEpisodeInfo, priority = 5)
|
addEvent('episode.info', self.getEpisodeInfo, priority = 5)
|
||||||
|
|
||||||
self.config = {}
|
self.config = {}
|
||||||
self.config['base_url'] = "http://thexem.de"
|
self.config['base_url'] = "http://thexem.de"
|
||||||
self.config['url_single'] = u"%(base_url)s/map/single?" % self.config
|
self.config['url_single'] = u"%(base_url)s/map/single?" % self.config
|
||||||
self.config['url_all'] = u"%(base_url)s/map/all?" % self.config
|
self.config['url_all'] = u"%(base_url)s/map/all?" % self.config
|
||||||
self.config['url_names'] = u"%(base_url)s/map/allNames?" % self.config
|
self.config['url_names'] = u"%(base_url)s/map/names?" % self.config
|
||||||
|
self.config['url_all_names'] = u"%(base_url)s/map/allNames?" % self.config
|
||||||
def search(self, q, limit = 12, language='en'):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def getShow(self, identifier = None):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
# TODO: Also get show aliases (store as titles)
|
||||||
def getShowInfo(self, identifier = None):
|
def getShowInfo(self, identifier = None):
|
||||||
if self.isDisabled():
|
if self.isDisabled():
|
||||||
return False
|
return {}
|
||||||
|
|
||||||
|
cache_key = 'xem.cache.%s' % identifier
|
||||||
|
log.debug('Getting showInfo: %s', cache_key)
|
||||||
|
result = self.getCache(cache_key) or {}
|
||||||
|
if result:
|
||||||
|
return result
|
||||||
|
|
||||||
|
# Create season/episode and absolute mappings
|
||||||
url = self.config['url_all'] + "id=%s&origin=tvdb" % tryUrlencode(identifier)
|
url = self.config['url_all'] + "id=%s&origin=tvdb" % tryUrlencode(identifier)
|
||||||
response = self.getJsonData(url)
|
response = self.getJsonData(url)
|
||||||
if response:
|
if response:
|
||||||
if response.get('result') == 'success':
|
if response.get('result') == 'success':
|
||||||
map = response.get('data', None)
|
data = response.get('data', None)
|
||||||
if map:
|
result = self._parse(data)
|
||||||
return dict(map = map)
|
|
||||||
return False
|
|
||||||
|
|
||||||
def getSeasonInfo(self, identifier=None, season_identifier=None):
|
# Create name alias mappings
|
||||||
pass
|
url = self.config['url_names'] + "id=%s&origin=tvdb" % tryUrlencode(identifier)
|
||||||
|
response = self.getJsonData(url)
|
||||||
|
if response:
|
||||||
|
if response.get('result') == 'success':
|
||||||
|
data = response.get('data', None)
|
||||||
|
result.update({'map_names': data})
|
||||||
|
|
||||||
def getEpisodeInfo(self, identifier=None, season_identifier=None, episode_identifier=None):
|
self.setCache(cache_key, result)
|
||||||
pass
|
return result
|
||||||
|
|
||||||
|
def getEpisodeInfo(self, identifier = None, params = {}):
|
||||||
|
episode = params.get('episode', None)
|
||||||
|
if episode is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
season_identifier = params.get('season_identifier', None)
|
||||||
|
if season_identifier is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
episode_identifier = params.get('episode_identifier', None)
|
||||||
|
absolute = params.get('absolute', None)
|
||||||
|
|
||||||
|
# season_identifier must contain the 'show id : season number' since there is no tvdb id
|
||||||
|
# for season and we need a reference to both the show id and season number
|
||||||
|
if season_identifier:
|
||||||
|
try:
|
||||||
|
identifier, season_identifier = season_identifier.split(':')
|
||||||
|
season = int(season_identifier)
|
||||||
|
except: return False
|
||||||
|
|
||||||
|
result = self.getShowInfo(identifier)
|
||||||
|
map = {}
|
||||||
|
if result:
|
||||||
|
map_episode = result.get('map_episode', {}).get(season, {}).get(episode, {})
|
||||||
|
if map_episode:
|
||||||
|
map.update({'map_episode': map_episode})
|
||||||
|
|
||||||
|
if absolute:
|
||||||
|
map_absolute = result.get('map_absolute', {}).get(absolute, {})
|
||||||
|
if map_absolute:
|
||||||
|
map.update({'map_absolute': map_absolute})
|
||||||
|
|
||||||
|
map_names = result.get('map_names', {}).get(season, {}).get(episode, {})
|
||||||
|
if map_names:
|
||||||
|
map.update({'map_names': map_names})
|
||||||
|
|
||||||
|
return map
|
||||||
|
|
||||||
|
|
||||||
|
def _parse(self, data, master = 'tvdb'):
|
||||||
|
'''parses xem map and returns a custom formatted dict map
|
||||||
|
|
||||||
|
To retreive map for scene:
|
||||||
|
if 'scene' in map['map_episode'][1][1]:
|
||||||
|
print map['map_episode'][1][1]['scene']['season']
|
||||||
|
'''
|
||||||
|
if not isinstance(data, list):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
map = {'map_episode': {}, 'map_absolute': {}}
|
||||||
|
for maps in data:
|
||||||
|
origin = maps.pop(master, None)
|
||||||
|
if origin is None:
|
||||||
|
continue # No master origin to map to
|
||||||
|
map.get('map_episode').setdefault(origin['season'], {}).setdefault(origin['episode'], maps.copy())
|
||||||
|
map.get('map_absolute').setdefault(origin['absolute'], maps.copy())
|
||||||
|
|
||||||
|
return map
|
||||||
|
|
||||||
def isDisabled(self):
|
def isDisabled(self):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in new issue
Block a user