3434 ('User-Agent' , 'Kodi TV Show scraper by Team Kodi; contact pkscout@kodi.tv' ),
3535 ('Accept' , 'application/json' ),
3636)
37- api_utils .set_headers (HEADERS )
37+ api_utils .set_headers (dict ( HEADERS ) )
3838
39- BASE_URL = 'https://api.themoviedb.org/3/{}?api_key=%s&language=%s' % (settings .TMDB_CLOWNCAR , settings .LANG )
39+ TMDB_PARAMS = {'api_key' : settings .TMDB_CLOWNCAR , 'language' : settings .LANG }
40+ BASE_URL = 'https://api.themoviedb.org/3/{}'
4041EPISODE_GROUP_URL = BASE_URL .format ('tv/episode_group/{}' )
4142SEARCH_URL = BASE_URL .format ('search/tv' )
4243FIND_URL = BASE_URL .format ('find/{}' )
4344SHOW_URL = BASE_URL .format ('tv/{}' )
4445SEASON_URL = BASE_URL .format ('tv/{}/season/{}' )
4546EPISODE_URL = BASE_URL .format ('tv/{}/season/{}/episode/{}' )
47+ FANARTTV_URL = 'https://webservice.fanart.tv/v3/tv/{}'
48+ FANARTTV_PARAMS = {'api_key' : settings .FANARTTV_CLOWNCAR }
4649if settings .FANARTTV_CLIENTKEY :
47- FANARTTV_URL = 'https://webservice.fanart.tv/v3/tv/{}?api_key=%s&client_key=%s' % (settings .FANARTTV_CLOWNCAR , settings .FANARTTV_CLIENTKEY )
48- else :
49- FANARTTV_URL = 'https://webservice.fanart.tv/v3/tv/{}?api_key=%s' % settings .FANARTTV_CLOWNCAR
50+ FANARTTV_PARAMS ['client_key' ] = settings .FANARTTV_CLIENTKEY
5051
5152
5253def search_show (title , year = None ):
@@ -58,23 +59,23 @@ def search_show(title, year=None):
5859 : param year: the year to search (optional)
5960 :return: a list with found TV shows
6061 """
62+ params = TMDB_PARAMS
6163 results = []
6264 ext_media_id = data_utils .parse_media_id (title )
6365 if ext_media_id :
6466 logger .debug ('using %s of %s to find show' % (ext_media_id ['type' ], ext_media_id ['title' ]))
6567 if ext_media_id ['type' ] == 'tmdb_id' :
6668 search_url = SHOW_URL .format (ext_media_id ['title' ])
67- params = {}
6869 else :
6970 search_url = FIND_URL .format (ext_media_id ['title' ])
70- params = { 'external_source' : ext_media_id ['type' ]}
71+ params [ 'external_source' ] = ext_media_id ['type' ]
7172 else :
7273 logger .debug ('using title of %s to find show' % title )
7374 search_url = SEARCH_URL
74- params = { 'query' : title }
75+ params [ 'query' ] = title
7576 if year :
76- params . update ({ 'first_air_date_year' : str (year )} )
77- resp = api_utils .load_info (search_url , params )
77+ params [ 'first_air_date_year' ] = str (year )
78+ resp = api_utils .load_info (search_url , params = params )
7879 if resp is not None :
7980 if ext_media_id :
8081 if ext_media_id ['type' ] == 'tmdb_id' :
@@ -96,7 +97,7 @@ def load_episode_list(show_info, season_map, ep_grouping):
9697 if ep_grouping is not None :
9798 logger .debug ('Getting episodes with episode grouping of ' + ep_grouping )
9899 episode_group_url = EPISODE_GROUP_URL .format (ep_grouping )
99- custom_order = api_utils .load_info (episode_group_url )
100+ custom_order = api_utils .load_info (episode_group_url , params = TMDB_PARAMS )
100101 if custom_order is not None :
101102 show_info ['seasons' ] = []
102103 season_num = 1
@@ -143,19 +144,17 @@ def load_show_info(show_id, ep_grouping=None):
143144 if show_info is None :
144145 logger .debug ('no cache file found, loading from scratch' )
145146 show_url = SHOW_URL .format (show_id )
146- params = {}
147+ params = TMDB_PARAMS
147148 params ['append_to_response' ] = 'credits,content_ratings,external_ids,images'
148149 params ['include_image_language' ] = '%s,en,null' % settings .LANG [0 :2 ]
149- show_info = api_utils .load_info (show_url , params )
150+ show_info = api_utils .load_info (show_url , params = params )
150151 if show_info is None :
151152 return None
152153 season_map = {}
154+ params ['append_to_response' ] = 'credits,images'
153155 for season in show_info .get ('seasons' , []):
154156 season_url = SEASON_URL .format (show_id , season ['season_number' ])
155- params = {}
156- params ['append_to_response' ] = 'credits,images'
157- params ['include_image_language' ] = '%s,en,null' % settings .LANG [0 :2 ]
158- season_info = api_utils .load_info (season_url , params , default = {})
157+ season_info = api_utils .load_info (season_url , params = params , default = {})
159158 season_info ['images' ] = _sort_image_types (season_info .get ('images' , {}))
160159 season_map [str (season ['season_number' ])] = season_info
161160 show_info = load_episode_list (show_info , season_map , ep_grouping )
@@ -197,10 +196,10 @@ def load_episode_info(show_id, episode_id):
197196 return None
198197 # this ensures we are using the season/ep from the episode grouping if provided
199198 ep_url = EPISODE_URL .format (show_info ['id' ], episode_info ['org_seasonnum' ], episode_info ['org_epnum' ])
200- params = {}
199+ params = TMDB_PARAMS
201200 params ['append_to_response' ] = 'credits,external_ids,images'
202201 params ['include_image_language' ] = '%s,en,null' % settings .LANG [0 :2 ]
203- ep_return = api_utils .load_info (ep_url , params )
202+ ep_return = api_utils .load_info (ep_url , params = params )
204203 if ep_return is None :
205204 return None
206205 ep_return ['images' ] = _sort_image_types (ep_return .get ('images' , {}))
@@ -256,7 +255,7 @@ def load_fanarttv_art(show_info):
256255 break
257256 if tvdb_id and artwork_enabled :
258257 fanarttv_url = FANARTTV_URL .format (tvdb_id )
259- artwork = api_utils .load_info (fanarttv_url )
258+ artwork = api_utils .load_info (fanarttv_url , params = FANARTTV_PARAMS )
260259 if artwork is None :
261260 return show_info
262261 for fanarttv_type , tmdb_type in settings .FANARTTV_MAPPING .items ():
0 commit comments