Skip to content

Commit

Permalink
added posters + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sualfred committed Sep 24, 2019
1 parent 68061bc commit 37c8a1f
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 79 deletions.
2 changes: 1 addition & 1 deletion addon.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.embuary.info" name="Embuary Info" version="1.0.14" provider-name="sualfred">
<addon id="script.embuary.info" name="Embuary Info" version="1.0.15" provider-name="sualfred">
<requires>
<import addon="xbmc.python" version="2.26.0"/>
<import addon="script.module.requests" version="2.9.1"/>
Expand Down
15 changes: 12 additions & 3 deletions resources/lib/main.py
Expand Up @@ -134,7 +134,8 @@ def fetch_video(self):
crew=data['crew'],
similar=data['similar'],
youtube=data['youtube'],
backdrops=data['images'],
backdrops=data['backdrops'],
posters=data['posters'],
collection=data['collection'],
seasons=data['seasons'],
tmdb_id=self.tmdb_id
Expand All @@ -150,6 +151,7 @@ def fetch_season(self):
details=data['details'],
cast=data['cast'],
gueststars=data['gueststars'],
posters=data['posters'],
tmdb_id=self.tmdb_id
)
return dialog
Expand Down Expand Up @@ -201,8 +203,6 @@ def quit(self):
del self.call_params
del self.window_stack
del self.dialog_cache
winprop('script.embuary.info-language_code', clear=True)
winprop('script.embuary.info-country_code', clear=True)
quit()


Expand Down Expand Up @@ -287,6 +287,7 @@ def __init__(self,*args,**kwargs):
self.similar = kwargs['similar']
self.youtube = kwargs['youtube']
self.backdrops = kwargs['backdrops']
self.posters = kwargs['posters']
self.seasons = kwargs['seasons']
self.collection = kwargs['collection']

Expand Down Expand Up @@ -318,6 +319,8 @@ def add_items(self):
self.cont6.addItems(self.collection)
self.cont7 = self.getControl(10058)
self.cont7.addItems(self.seasons)
self.cont8 = self.getControl(10059)
self.cont8.addItems(self.posters)

def onAction(self,action):
if action.getId() in [92,10]:
Expand Down Expand Up @@ -370,6 +373,7 @@ def __init__(self,*args,**kwargs):
self.details = kwargs['details']
self.cast = kwargs['cast']
self.gueststars = kwargs['gueststars']
self.posters = kwargs['posters']

def __getitem__(self,key):
return self.action[key]
Expand All @@ -389,6 +393,8 @@ def add_items(self):
self.cont1.addItems(self.cast)
self.cont2 = self.getControl(10056)
self.cont2.addItems(self.gueststars)
self.cont3 = self.getControl(10059)
self.cont3.addItems(self.posters)

def onAction(self,action):
if action.getId() in [92,10]:
Expand All @@ -407,6 +413,9 @@ def onClick(self,controlId):
self.action['season'] = ''
self.quit()

elif next_call == 'image':
FullScreenImage(controlId)

def quit(self):
close_action = self.getProperty('onclose')
onback_action = self.getProperty('onback_%s' % self.getFocusId())
Expand Down
17 changes: 10 additions & 7 deletions resources/lib/person.py
Expand Up @@ -30,15 +30,16 @@ def __init__(self,call_request):
self.details = get_cache(cache_key)

if not self.details:
self.details = tmdb_item_details('person',self.tmdb_id,append_to_response='translations,movie_credits,tv_credits,images')
self.details = tmdb_query(action='person',
call=self.tmdb_id,
params={'append_to_response': 'translations,movie_credits,tv_credits,images'}
)

write_cache(cache_key,self.details)

if not self.details:
return

self.movies = self.details['movie_credits']['cast']
self.tvshows = self.details['tv_credits']['cast']
self.images = self.details['images']['profiles']
self.local_movie_count = 0
self.local_tv_count = 0

Expand All @@ -62,7 +63,8 @@ def get_person_details(self):
return li

def get_movie_list(self):
movies = sort_dict(self.movies,'release_date',True)
movies = self.details['movie_credits']['cast']
movies = sort_dict(movies,'release_date',True)
li = list()
duplicate_handler = list()

Expand All @@ -88,7 +90,8 @@ def get_movie_list(self):
return li

def get_tvshow_list(self):
tvshows = sort_dict(self.tvshows,'first_air_date',True)
tvshows = self.details['tv_credits']['cast']
tvshows = sort_dict(tvshows,'first_air_date',True)
li = list()
duplicate_handler = list()

Expand Down Expand Up @@ -119,7 +122,7 @@ def get_tvshow_list(self):
def get_person_images(self):
li = list()

for item in self.images:
for item in self.details['images']['profiles']:
list_item = tmdb_handle_images(item)
li.append(list_item)

Expand Down
47 changes: 42 additions & 5 deletions resources/lib/season.py
Expand Up @@ -16,7 +16,6 @@
class TMDBSeasons(object):
def __init__(self,call_request):
self.result = {}
self.call = call_request['call']
self.tmdb_id = call_request['tmdb_id']
self.season = call_request['season']

Expand All @@ -25,13 +24,24 @@ def __init__(self,call_request):
self.details = get_cache(cache_key)

if not self.details:
self.details = tmdb_item_details('tv',self.tmdb_id,'season',self.season,append_to_response='credits')
self.details = tmdb_query(action='tv',
call=self.tmdb_id,
get='season',
season=self.season,
params={'append_to_response': 'credits'}
)

if not self.details:
return

if DEFAULT_LANGUAGE != FALLBACK_LANGUAGE and not self.details['overview']:
fallback_details = tmdb_item_details('tv',self.tmdb_id,'season',self.season,use_language=False)
fallback_details = tmdb_query(action='tv',
call=self.tmdb_id,
get='season',
season=self.season,
use_language=False
)

self.details['overview'] = fallback_details.get('overview')

write_cache(cache_key,self.details)
Expand All @@ -42,16 +52,21 @@ def __init__(self,call_request):
self.result['details'] = self.get_details()
self.result['cast'] = self.get_cast()
self.result['gueststars'] = self.get_gueststars()
self.result['posters'] = self.get_images()

def __getitem__(self, key):
return self.result.get(key,'')

def get_tvshow_details(self):
tvshow_cache_key = self.call + str(self.tmdb_id)
tvshow_cache_key = 'tv' + str(self.tmdb_id)
tvshow_details = get_cache(tvshow_cache_key)

if not tvshow_details:
tvshow_details = tmdb_item_details('tv',self.tmdb_id,append_to_response='release_dates,content_ratings,external_ids,credits,videos,translations')
tvshow_details = tmdb_query(action='tv',
call=self.tmdb_id,
params={'append_to_response': 'release_dates,content_ratings,external_ids,credits,videos,translations'}
)

write_cache(tvshow_cache_key,tvshow_details)

return tvshow_details
Expand Down Expand Up @@ -87,4 +102,26 @@ def get_gueststars(self):
li.append(list_item)
self.person_duplicate_handler.append(item['id'])

return li

def get_images(self):
cache_key = 'images' + str(self.tmdb_id) + 'season' + str(self.season)
images = get_cache(cache_key)
li = list()

if not images:
images = tmdb_query(action='tv',
call=self.tmdb_id,
get='season',
season=self.season,
season_get='images',
params={'include_image_language': '%s,en,null' % DEFAULT_LANGUAGE}
)

write_cache(cache_key,images)

for item in images['posters']:
list_item = tmdb_handle_images(item)
li.append(list_item)

return li
70 changes: 25 additions & 45 deletions resources/lib/utils.py
Expand Up @@ -162,48 +162,45 @@ def tmdb_call(request_url,error_check=False,error=ADDON.getLocalizedString(32019
tmdb_error(error)


def tmdb_query(action=None,call=None,get=None,season=None,use_language=True,language=DEFAULT_LANGUAGE,error_check=False,**kwargs):
kwargs['api_key'] = API_KEY
def tmdb_query(action,call=None,get=None,season=None,season_get=None,params=None,use_language=True,language=DEFAULT_LANGUAGE,error_check=False):
args = {}
args['api_key'] = API_KEY

if use_language:
kwargs['language'] = language
args['language'] = language

season = '/' + str(season) if season else ''
if params:
args.update(params)

call = '/' + str(call) if call else ''
get = '/' + get if get else ''
call = '/' + call if call else ''
season = '/' + str(season) if season else ''
season_get = '/' + season_get if season_get else ''

url = API_URL + action + call + get + season
url = '{0}?{1}'.format(url, urlencode(kwargs))
url = API_URL + action + call + get + season + season_get
url = '{0}?{1}'.format(url, urlencode(args))

return tmdb_call(url,error_check)


def tmdb_search(call,query,year=None,include_adult='false'):
#/search/{call}?api_key=&language=&query={query}&page=1&include_adult=false
if call == 'person':
result = tmdb_query(action='search',
call=call,
query=query,
include_adult=include_adult,
error_check=True
)
params = {'query': query, 'include_adult': include_adult}

elif call == 'movie':
result = tmdb_query(action='search',
call=call,
query=query,
year=year,
include_adult=include_adult,
error_check=True
)
params = {'query': query, 'year': year, 'include_adult': include_adult}

elif call == 'tv':
result = tmdb_query(action='search',
call=call,
query=query,
first_air_date_year=year,
error_check=True
)
params = {'query': query, 'year': year}

else:
return ''

result = tmdb_query(action='search',
call=call,
params=params,
error_check=True
)

try:
return result['results']
Expand All @@ -212,15 +209,14 @@ def tmdb_search(call,query,year=None,include_adult='false'):


def tmdb_find(call,external_id):
#/find/{id}?api_key=&language=en-US&external_source=tvdb_id
if external_id.startswith('tt'):
external_source = 'imdb_id'
else:
external_source = 'tvdb_id'

result = tmdb_query(action='find',
call=str(external_id),
external_source=external_source,
params={'external_source': external_source},
use_language=False
)

Expand All @@ -234,22 +230,6 @@ def tmdb_find(call,external_id):

return result


def tmdb_item_details(action,tmdb_id,get=None,season=None,append_to_response=None,use_language=True,include_image_language=None):
#{action}/{id}?api_key=&language=
#{action}/{id}/{get}?api_key=&language=
result = tmdb_query(action=action,
call=str(tmdb_id),
get=get,
season=season,
append_to_response=append_to_response,
use_language=use_language,
include_image_language=include_image_language
)

return result


def tmdb_select_dialog(list,call):
indexlist = []
selectionlist = []
Expand Down

0 comments on commit 37c8a1f

Please sign in to comment.