def get_episode(tvdbid, season, episode): """ Get episode info :param tvdbid: TVDB series ID :type tvdbid: str :param season: season # without preceding 0 :type season: str :param episode: episode # without preceding 0 :type episode: str :return: TV episode data :rtype: dict :raises TvdbError: if TheTVDB returns no data """ page = load_page( GET_EPISODE.format(apikey=APIKEY, id=tvdbid, season=season.lstrip('0'), episode=episode.lstrip('0'))) root = etree.fromstring(page) ep_info = root.find('Episode') if ep_info is None: raise TvdbError('TheTVDB returned invalid XML data!') else: return parse_items(ep_info)
def get_token(): """ Get a token to access Rarbg API The token will expire in 15 min :return: Rarbg API token :rtype: str """ params = {'get_token': 'get_token'} return load_page(API, params=params, headers={'content-type': 'application/json'})['token']
def get_series(tvdbid): """ Get series info by TheTVDB ID :param tvdbid: series ID on TheTVDB :type tvdbid: str :return: TV series data :rtype: dict :raises TvdbError: if TheTVDB returns no data """ page = load_page(GET_SERIES.format(apikey=APIKEY, id=tvdbid)) root = etree.fromstring(page) series = root.find('Series') if series is None: raise TvdbError('TheTVDB returned invalid XML data!') else: return parse_items(series)
def load_torrents(params): """ Get the list of recent TV episode torrents with extended data :param params: Rarbg API query params :type params: dict :return: the list of torrents as dicts :rtype: list :raises RarbgError: if Rarbg returns no torrent data """ params['token'] = get_token() time.sleep(2) params['format'] = 'json_extended' response = load_page(API, params=params, headers={'content-type': 'application/json'}) if 'torrent_results' not in response: plugin.log_error('Rarbg returned error: {0}'.format(response)) raise RarbgApiError return response['torrent_results']