SickGear/sickgear/indexers/indexer_api.py

120 lines
4.2 KiB
Python
Raw Normal View History

#
# This file is part of SickGear.
#
# SickGear is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SickGear is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
import os
from .indexer_config import init_config, tvinfo_config
from sg_helpers import proxy_setting
import sickgear
from lib.tvinfo_base import TVInfoBase
# noinspection PyUnreachableCode
if False:
from typing import AnyStr, Dict
class TVInfoAPI(object):
def __init__(self, tvid=None):
self.tvid = int(tvid) if tvid else None
def __del__(self):
pass
def setup(self, *args, **kwargs):
# type: (...) -> TVInfoBase
if self.tvid:
if tvinfo_config[self.tvid]['active'] or ('no_dummy' in kwargs and True is kwargs['no_dummy']):
if 'no_dummy' in kwargs:
kwargs.pop('no_dummy')
indexer_cache_dir = os.path.join(sickgear.CACHE_DIR, 'tvinfo_cache', tvinfo_config[self.tvid]['name'])
kwargs['diskcache_dir'] = indexer_cache_dir
return tvinfo_config[self.tvid]['module'](*args, **kwargs)
else:
return TVInfoBase(*args, **kwargs)
@property
def config(self):
# type: () -> Dict
if self.tvid:
return tvinfo_config[self.tvid]
return init_config
@property
def name(self):
# type: () -> AnyStr
if self.tvid:
return tvinfo_config[self.tvid]['name']
@property
def api_params(self):
# type: () -> Dict
if self.tvid:
if sickgear.CACHE_DIR:
tvinfo_config[self.tvid]['api_params']['cache'] = os.path.join(
sickgear.CACHE_DIR, 'indexers', self.name)
if sickgear.PROXY_SETTING and sickgear.PROXY_INDEXERS:
(proxy_address, pac_found) = proxy_setting(sickgear.PROXY_SETTING,
tvinfo_config[self.tvid]['base_url'],
force=True)
if proxy_address:
tvinfo_config[self.tvid]['api_params']['proxy'] = proxy_address
return tvinfo_config[self.tvid]['api_params']
@property
def cache(self):
if sickgear.CACHE_DIR:
return self.api_params['cache']
Fix py2 deprecation cleanups added exclusively by TvdbV4 code. Refactor `timestamp_near` to `SGDatetime.timestamp_near` --- Simplify enforce_type + clean_data to clean_str. Change simplified all but one enforce_type use case. --- Add tvdb, trakt slug tvinfo search test cases Change direct tvdb slug search support via new api endpoint Fix origin_countries in tvdb_api_v4. --- Add new TV_Maze id to show obj ids in tvdb_api_v4. Fix a bug parsing social ids for tvshows in tvdb_api_v4. Change add language support to search API and tvdb_api_v4. Change add `updated_at` to artwork on tvdb_api_v4. Change add `finale` type to episodes. Change add method `get_top_rated` to tvdb_api_v4. optional params... - year=... argument to get only top rated of given year, if not it's all time Change returns result for shows until same day last year. Add youtube, reddit, fansite, tiktok, linkedin, wikidata to tv.py Add tiktok to indexer_config. Add fansite to tvdb_api_v4. Aadd fansite to TVInfoSocialIDs. Add source type parsing and add linkein to tvdb_api_v4. Add linkedin. Add tiktok parser to tvdb_api_v4. Change v4 to TVInfoIDs, TVInfoSocialIDs. Change add new id data. Add contentrating. Change fill in new fields to get_person results. ---- Change implement discover endpoint in tvdb_api_v4. Change filter '0000' year for firstaired field in tvdb_api_v4. Change use the default_season_type from api for website fallback. Change remove unneeded _auth_time. Add backup fetch for episode data. Change add multiple space remove to clean_data. Change move _get_tvdb_id to central function. Change fix minor warnings, code tidy + DRY. Change remove the show-edit option `Use DVD titles and numbers` until ready with multi TVInfo source. Add try_date and use to attempt conversion of unspecified date format types birthdate, deathdate, aired. Change tweaks, remove one warn, order imports. Change tidy up of other warnings, mismatched types, typos, a strange arg issue with deepcopy, and PEP8. Bug fix, bad key in get_item for TVInfoSocialIDs. Fix ambiguities of `show` used in sg versus external uses. Fix add data sanitisation of image field. Change make set_episode code more readable. Change fix final two warnings in api v4. Fix an API can return falsy as firstaired which crashes adding a show via load_from_tv_info() (The Andrew Marr Show@tvdbv4). Add cast, crew type mappings Only take Main Actors, Hosts, Interviewers, Presenters Change increase viewagble history menu items from 13 to 15.
2021-09-05 19:10:58 +00:00
@staticmethod
def _filter(condition):
return dict([(int(x['id']), x['name']) for x in list(tvinfo_config.values()) if condition(x)])
@property
def sources(self):
# type: () -> Dict[int, AnyStr]
Fix py2 deprecation cleanups added exclusively by TvdbV4 code. Refactor `timestamp_near` to `SGDatetime.timestamp_near` --- Simplify enforce_type + clean_data to clean_str. Change simplified all but one enforce_type use case. --- Add tvdb, trakt slug tvinfo search test cases Change direct tvdb slug search support via new api endpoint Fix origin_countries in tvdb_api_v4. --- Add new TV_Maze id to show obj ids in tvdb_api_v4. Fix a bug parsing social ids for tvshows in tvdb_api_v4. Change add language support to search API and tvdb_api_v4. Change add `updated_at` to artwork on tvdb_api_v4. Change add `finale` type to episodes. Change add method `get_top_rated` to tvdb_api_v4. optional params... - year=... argument to get only top rated of given year, if not it's all time Change returns result for shows until same day last year. Add youtube, reddit, fansite, tiktok, linkedin, wikidata to tv.py Add tiktok to indexer_config. Add fansite to tvdb_api_v4. Aadd fansite to TVInfoSocialIDs. Add source type parsing and add linkein to tvdb_api_v4. Add linkedin. Add tiktok parser to tvdb_api_v4. Change v4 to TVInfoIDs, TVInfoSocialIDs. Change add new id data. Add contentrating. Change fill in new fields to get_person results. ---- Change implement discover endpoint in tvdb_api_v4. Change filter '0000' year for firstaired field in tvdb_api_v4. Change use the default_season_type from api for website fallback. Change remove unneeded _auth_time. Add backup fetch for episode data. Change add multiple space remove to clean_data. Change move _get_tvdb_id to central function. Change fix minor warnings, code tidy + DRY. Change remove the show-edit option `Use DVD titles and numbers` until ready with multi TVInfo source. Add try_date and use to attempt conversion of unspecified date format types birthdate, deathdate, aired. Change tweaks, remove one warn, order imports. Change tidy up of other warnings, mismatched types, typos, a strange arg issue with deepcopy, and PEP8. Bug fix, bad key in get_item for TVInfoSocialIDs. Fix ambiguities of `show` used in sg versus external uses. Fix add data sanitisation of image field. Change make set_episode code more readable. Change fix final two warnings in api v4. Fix an API can return falsy as firstaired which crashes adding a show via load_from_tv_info() (The Andrew Marr Show@tvdbv4). Add cast, crew type mappings Only take Main Actors, Hosts, Interviewers, Presenters Change increase viewagble history menu items from 13 to 15.
2021-09-05 19:10:58 +00:00
return self._filter(lambda x:
not x['mapped_only'] and
True is not x.get('fallback') and True is not x.get('people_only'))
@property
def search_sources(self):
# type: () -> Dict[int, AnyStr]
Fix py2 deprecation cleanups added exclusively by TvdbV4 code. Refactor `timestamp_near` to `SGDatetime.timestamp_near` --- Simplify enforce_type + clean_data to clean_str. Change simplified all but one enforce_type use case. --- Add tvdb, trakt slug tvinfo search test cases Change direct tvdb slug search support via new api endpoint Fix origin_countries in tvdb_api_v4. --- Add new TV_Maze id to show obj ids in tvdb_api_v4. Fix a bug parsing social ids for tvshows in tvdb_api_v4. Change add language support to search API and tvdb_api_v4. Change add `updated_at` to artwork on tvdb_api_v4. Change add `finale` type to episodes. Change add method `get_top_rated` to tvdb_api_v4. optional params... - year=... argument to get only top rated of given year, if not it's all time Change returns result for shows until same day last year. Add youtube, reddit, fansite, tiktok, linkedin, wikidata to tv.py Add tiktok to indexer_config. Add fansite to tvdb_api_v4. Aadd fansite to TVInfoSocialIDs. Add source type parsing and add linkein to tvdb_api_v4. Add linkedin. Add tiktok parser to tvdb_api_v4. Change v4 to TVInfoIDs, TVInfoSocialIDs. Change add new id data. Add contentrating. Change fill in new fields to get_person results. ---- Change implement discover endpoint in tvdb_api_v4. Change filter '0000' year for firstaired field in tvdb_api_v4. Change use the default_season_type from api for website fallback. Change remove unneeded _auth_time. Add backup fetch for episode data. Change add multiple space remove to clean_data. Change move _get_tvdb_id to central function. Change fix minor warnings, code tidy + DRY. Change remove the show-edit option `Use DVD titles and numbers` until ready with multi TVInfo source. Add try_date and use to attempt conversion of unspecified date format types birthdate, deathdate, aired. Change tweaks, remove one warn, order imports. Change tidy up of other warnings, mismatched types, typos, a strange arg issue with deepcopy, and PEP8. Bug fix, bad key in get_item for TVInfoSocialIDs. Fix ambiguities of `show` used in sg versus external uses. Fix add data sanitisation of image field. Change make set_episode code more readable. Change fix final two warnings in api v4. Fix an API can return falsy as firstaired which crashes adding a show via load_from_tv_info() (The Andrew Marr Show@tvdbv4). Add cast, crew type mappings Only take Main Actors, Hosts, Interviewers, Presenters Change increase viewagble history menu items from 13 to 15.
2021-09-05 19:10:58 +00:00
return self._filter(lambda x:
not x['mapped_only'] and x.get('active') and not x.get('defunct') and
True is not x.get('fallback') and True is not x.get('people_only'))
@property
def all_sources(self):
# type: () -> Dict[int, AnyStr]
"""
:return: return all indexers including mapped only indexers excluding fallback indexers
"""
Fix py2 deprecation cleanups added exclusively by TvdbV4 code. Refactor `timestamp_near` to `SGDatetime.timestamp_near` --- Simplify enforce_type + clean_data to clean_str. Change simplified all but one enforce_type use case. --- Add tvdb, trakt slug tvinfo search test cases Change direct tvdb slug search support via new api endpoint Fix origin_countries in tvdb_api_v4. --- Add new TV_Maze id to show obj ids in tvdb_api_v4. Fix a bug parsing social ids for tvshows in tvdb_api_v4. Change add language support to search API and tvdb_api_v4. Change add `updated_at` to artwork on tvdb_api_v4. Change add `finale` type to episodes. Change add method `get_top_rated` to tvdb_api_v4. optional params... - year=... argument to get only top rated of given year, if not it's all time Change returns result for shows until same day last year. Add youtube, reddit, fansite, tiktok, linkedin, wikidata to tv.py Add tiktok to indexer_config. Add fansite to tvdb_api_v4. Aadd fansite to TVInfoSocialIDs. Add source type parsing and add linkein to tvdb_api_v4. Add linkedin. Add tiktok parser to tvdb_api_v4. Change v4 to TVInfoIDs, TVInfoSocialIDs. Change add new id data. Add contentrating. Change fill in new fields to get_person results. ---- Change implement discover endpoint in tvdb_api_v4. Change filter '0000' year for firstaired field in tvdb_api_v4. Change use the default_season_type from api for website fallback. Change remove unneeded _auth_time. Add backup fetch for episode data. Change add multiple space remove to clean_data. Change move _get_tvdb_id to central function. Change fix minor warnings, code tidy + DRY. Change remove the show-edit option `Use DVD titles and numbers` until ready with multi TVInfo source. Add try_date and use to attempt conversion of unspecified date format types birthdate, deathdate, aired. Change tweaks, remove one warn, order imports. Change tidy up of other warnings, mismatched types, typos, a strange arg issue with deepcopy, and PEP8. Bug fix, bad key in get_item for TVInfoSocialIDs. Fix ambiguities of `show` used in sg versus external uses. Fix add data sanitisation of image field. Change make set_episode code more readable. Change fix final two warnings in api v4. Fix an API can return falsy as firstaired which crashes adding a show via load_from_tv_info() (The Andrew Marr Show@tvdbv4). Add cast, crew type mappings Only take Main Actors, Hosts, Interviewers, Presenters Change increase viewagble history menu items from 13 to 15.
2021-09-05 19:10:58 +00:00
return self._filter(lambda x:
True is not x.get('fallback') and True is not x.get('people_only'))
@property
def fallback_sources(self):
# type: () -> Dict[int, AnyStr]
"""
:return: return all fallback indexers
"""
Fix py2 deprecation cleanups added exclusively by TvdbV4 code. Refactor `timestamp_near` to `SGDatetime.timestamp_near` --- Simplify enforce_type + clean_data to clean_str. Change simplified all but one enforce_type use case. --- Add tvdb, trakt slug tvinfo search test cases Change direct tvdb slug search support via new api endpoint Fix origin_countries in tvdb_api_v4. --- Add new TV_Maze id to show obj ids in tvdb_api_v4. Fix a bug parsing social ids for tvshows in tvdb_api_v4. Change add language support to search API and tvdb_api_v4. Change add `updated_at` to artwork on tvdb_api_v4. Change add `finale` type to episodes. Change add method `get_top_rated` to tvdb_api_v4. optional params... - year=... argument to get only top rated of given year, if not it's all time Change returns result for shows until same day last year. Add youtube, reddit, fansite, tiktok, linkedin, wikidata to tv.py Add tiktok to indexer_config. Add fansite to tvdb_api_v4. Aadd fansite to TVInfoSocialIDs. Add source type parsing and add linkein to tvdb_api_v4. Add linkedin. Add tiktok parser to tvdb_api_v4. Change v4 to TVInfoIDs, TVInfoSocialIDs. Change add new id data. Add contentrating. Change fill in new fields to get_person results. ---- Change implement discover endpoint in tvdb_api_v4. Change filter '0000' year for firstaired field in tvdb_api_v4. Change use the default_season_type from api for website fallback. Change remove unneeded _auth_time. Add backup fetch for episode data. Change add multiple space remove to clean_data. Change move _get_tvdb_id to central function. Change fix minor warnings, code tidy + DRY. Change remove the show-edit option `Use DVD titles and numbers` until ready with multi TVInfo source. Add try_date and use to attempt conversion of unspecified date format types birthdate, deathdate, aired. Change tweaks, remove one warn, order imports. Change tidy up of other warnings, mismatched types, typos, a strange arg issue with deepcopy, and PEP8. Bug fix, bad key in get_item for TVInfoSocialIDs. Fix ambiguities of `show` used in sg versus external uses. Fix add data sanitisation of image field. Change make set_episode code more readable. Change fix final two warnings in api v4. Fix an API can return falsy as firstaired which crashes adding a show via load_from_tv_info() (The Andrew Marr Show@tvdbv4). Add cast, crew type mappings Only take Main Actors, Hosts, Interviewers, Presenters Change increase viewagble history menu items from 13 to 15.
2021-09-05 19:10:58 +00:00
return self._filter(lambda x: True is x.get('fallback'))
@property
def xem_supported_sources(self):
# type: () -> Dict[int, AnyStr]
Fix py2 deprecation cleanups added exclusively by TvdbV4 code. Refactor `timestamp_near` to `SGDatetime.timestamp_near` --- Simplify enforce_type + clean_data to clean_str. Change simplified all but one enforce_type use case. --- Add tvdb, trakt slug tvinfo search test cases Change direct tvdb slug search support via new api endpoint Fix origin_countries in tvdb_api_v4. --- Add new TV_Maze id to show obj ids in tvdb_api_v4. Fix a bug parsing social ids for tvshows in tvdb_api_v4. Change add language support to search API and tvdb_api_v4. Change add `updated_at` to artwork on tvdb_api_v4. Change add `finale` type to episodes. Change add method `get_top_rated` to tvdb_api_v4. optional params... - year=... argument to get only top rated of given year, if not it's all time Change returns result for shows until same day last year. Add youtube, reddit, fansite, tiktok, linkedin, wikidata to tv.py Add tiktok to indexer_config. Add fansite to tvdb_api_v4. Aadd fansite to TVInfoSocialIDs. Add source type parsing and add linkein to tvdb_api_v4. Add linkedin. Add tiktok parser to tvdb_api_v4. Change v4 to TVInfoIDs, TVInfoSocialIDs. Change add new id data. Add contentrating. Change fill in new fields to get_person results. ---- Change implement discover endpoint in tvdb_api_v4. Change filter '0000' year for firstaired field in tvdb_api_v4. Change use the default_season_type from api for website fallback. Change remove unneeded _auth_time. Add backup fetch for episode data. Change add multiple space remove to clean_data. Change move _get_tvdb_id to central function. Change fix minor warnings, code tidy + DRY. Change remove the show-edit option `Use DVD titles and numbers` until ready with multi TVInfo source. Add try_date and use to attempt conversion of unspecified date format types birthdate, deathdate, aired. Change tweaks, remove one warn, order imports. Change tidy up of other warnings, mismatched types, typos, a strange arg issue with deepcopy, and PEP8. Bug fix, bad key in get_item for TVInfoSocialIDs. Fix ambiguities of `show` used in sg versus external uses. Fix add data sanitisation of image field. Change make set_episode code more readable. Change fix final two warnings in api v4. Fix an API can return falsy as firstaired which crashes adding a show via load_from_tv_info() (The Andrew Marr Show@tvdbv4). Add cast, crew type mappings Only take Main Actors, Hosts, Interviewers, Presenters Change increase viewagble history menu items from 13 to 15.
2021-09-05 19:10:58 +00:00
return self._filter(lambda x: x.get('xem_origin'))