-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
29 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,36 +31,36 @@ | |
except ImportError: | ||
pass | ||
|
||
HEADERS = ( | ||
('User-Agent', 'Kodi TV Show scraper by Team Kodi/; contact [email protected]'), | ||
('Accept', 'application/json'), | ||
) | ||
SESSION = requests.Session() | ||
SESSION.headers.update(dict(HEADERS)) | ||
|
||
|
||
def set_headers(headers): | ||
SESSION.headers.update(headers) | ||
|
||
|
||
def load_info(url, params=None, default=None): | ||
def load_info(url, params=None, default=None, resp_type = 'json'): | ||
# type: (Text, Optional[Dict[Text, Union[Text, List[Text]]]]) -> Union[dict, list] | ||
""" | ||
Load info from external api | ||
:param url: API endpoint URL | ||
:param params: URL query params | ||
:default: object to return if there is an error | ||
:resp_type: what to return to the calling function | ||
:return: API response or default on error | ||
""" | ||
logger.debug('Calling URL "{}" with params {}'.format(url, params)) | ||
try: | ||
response = SESSION.get(url, params=params) | ||
except HTTPError as exc: | ||
logger.error('themoviedb returned an error: {}'.format(exc)) | ||
logger.error('the site returned an error: {}'.format(exc)) | ||
response = None | ||
if response is None: | ||
return default | ||
json_response = response.json() | ||
resp = default | ||
elif resp_type.lower() == 'json': | ||
resp = response.json() | ||
else: | ||
resp = response.text | ||
if settings.VERBOSELOG: | ||
logger.debug('the api response:\n{}'.format(pformat(json_response))) | ||
return json_response | ||
logger.debug('the api response:\n{}'.format(pformat(resp))) | ||
return resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,12 @@ | |
except ImportError: | ||
pass | ||
|
||
HEADERS = ( | ||
('User-Agent', 'Kodi TV Show scraper by Team Kodi; contact [email protected]'), | ||
('Accept', 'application/json'), | ||
) | ||
api_utils.set_headers(HEADERS) | ||
|
||
BASE_URL = 'https://api.themoviedb.org/3/{}?api_key=%s&language=%s' % (settings.TMDB_CLOWNCAR, settings.LANG) | ||
EPISODE_GROUP_URL = BASE_URL.format('tv/episode_group/{}') | ||
SEARCH_URL = BASE_URL.format('search/tv') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,15 +28,19 @@ | |
except ImportError: | ||
pass | ||
|
||
BASE_URL = 'https://api.trakt.tv/shows/{}' | ||
SHOW_URL = BASE_URL + '?extended=full' | ||
EP_URL = BASE_URL + '/seasons/{}/episodes/{}/ratings' | ||
|
||
HEADERS = ( | ||
('User-Agent', 'Kodi TV Show scraper by Team Kodi; contact [email protected]'), | ||
('Accept', 'application/json'), | ||
('trakt-api-key', settings.TRAKT_CLOWNCAR), | ||
('trakt-api-version', '2'), | ||
('Content-Type', 'application/json'), | ||
) | ||
api_utils.set_headers(dict(HEADERS)) | ||
api_utils.set_headers(HEADERS) | ||
|
||
BASE_URL = 'https://api.trakt.tv/shows/{}' | ||
SHOW_URL = BASE_URL + '?extended=full' | ||
EP_URL = BASE_URL + '/seasons/{}/episodes/{}/ratings' | ||
|
||
|
||
def get_details(imdb_id, season=None, episode=None): | ||
|