def match_filename(seriesid): """ get filenames from tv_db and match them with local filenames and save them for confirmation. :param filename: :return: """ show = tvdb.Series(seriesid) info = show.info() title = info['seriesName'] episodes = tvdb.Series_Episodes(seriesid).all() for s in episodes: for k in validfiles: try: if s['absoluteNumber'] == k.episodenumber: outfilename = make_filename(title, s['airedSeason'], s['airedEpisodeNumber'], s['episodeName'], s['absoluteNumber']) src = getcwd() + '/' + k.filename dst = getcwd() + '/' + outfilename + k.extension print(src) print(dst) rename(src, dst) except IOError: print(IOError) continue return
def get_series_episodes_api(id, settings): ret = None language = settings.getSettingString('language') showeps = tvdb.Series_Episodes(id, language=language) try: ret = showeps.all() except: pass ADDON.setSetting('token', tvdb.KEYS.API_TOKEN) return ret
def __init__(self, id): self.tvdb_id = id show = tvdb.Series(tvdb_id) response = show.info() self.series_episodes = tvdb.Series_Episodes(tvdb_id) response = self.series_episodes.summary() #map converts the list of strings to integers so that the max function works self.seriesCount = max(map(int, self.series_episodes.airedSeasons)) self.posters = show.Images.poster() self.series = show
def get_series_episodes_api(show_id, settings): ret = None language = settings.getSettingString('language') ret = cache.load_show_info_from_cache(show_id, language, 'episodes') if ret is not None: return ret showeps = tvdb.Series_Episodes(show_id, language=language) try: ret = showeps.all() except: pass ADDON.setSetting('token', tvdb.KEYS.API_TOKEN) cache.cache_show_info(show_id, ret, language, 'episodes') return ret
def download_episode_data(sereisid): """dwonlaod episode data""" episodes = tvdb.Series_Episodes(sereisid).all() exts = [ '.mkv', '.mp4', '.avi', '.flv', '.mpg', '.mpeg', '.wmv', '.webm', '.vob', '.mov', '.3gp', '.ogv' ] for root, dirs, files in walk(getcwd(), topdown=False): for name in files: filename = join(root, name) if getnameextensions(filename) in exts: for s in episodes: try: if s['absoluteNumber'] == get_episodeno(filename): downlaod_file_images( s['filename'], filename.replace('./', getcwd()).replace( getnameextensions(filename), '')) except IOError as e: print(e.errno) print(e) continue return
def _get_episodes_from_season_and_episode_no(self, series: dict = None, parts: MediaNameParse = None): if not parts: return season = parts.season episode = parts.episode if series is None or season == '' or episode == '': return try: results = tvdb.Series_Episodes(id=series.get('id'), airedSeason=season, airedEpisode=episode).all() results = list(map(lambda r: dict(r, _series=series), results)) add_unique_elements(self.exact_episode_matches, results) logger.debug( f'Found {len(results)} episodes for "{series.get("seriesName")}" using season ' f'{season} and episode {episode}: {[e.get("episodeName") for e in results]}' ) except HTTPError as e: logger.debug( f'TVDB returned zero episodes for "{series.get("seriesName")}" using season ' f'{season} and episode {episode}. Error: {err_str(e)}')
def _get_episodes_from_episode_title(self, series: dict = None, parts: MediaNameParse = None): if series is None or parts is None: return ''' use free-text output from parser to match against episode titles ''' parse_tokens = [ parts.title, parts.episode_name, parts.year, parts.month, parts.day, parts.group, parts.excess ] parse_date = None if parts.year and parts.month and parts.day: parse_date = datetime(parts.year, parts.month, parts.day) if parse_tokens: logger.debug(f'Fuzzy matching against {series["seriesName"]}') logger.debug(f'Search tokens: {parse_tokens}') all_episode_list = [] try: logger.debug( f'Querying for all episodes for {series.get("seriesName")}...' ) all_episode_list = tvdb.Series_Episodes( id=series.get('id')).all() logger.debug( f'TVDB returned {len(all_episode_list)} episodes.') except HTTPError as e: logger.debug( f'TVDB returned zero episodes: Error: {err_str(e)}') for episode in (e for e in all_episode_list if e.get('episodeName')): episode['_series'] = series if parse_date and (aired_date := episode.get('firstAired')): try: aired_date = datetime.strptime(aired_date, '%Y-%m-%d') except Exception as e: logger.error( f'Failed to parse Aired Date "{aired_date}". Error: {repr(e)}' ) else: if parse_date == aired_date: logger.debug( f'Found episode "{episode.get("episodeName")}" with Aired Date ' f'{aired_date.date()} and Parse Date {parse_date.date()}' ) add_unique_elements(self.exact_episode_matches, episode) continue score = self.calculate_match_score( source=parse_tokens, target=episode.get('episodeName', ''), target_aired_date=episode.get('firstAired', '')) if score > 0: logger.debug( f'Found episode "{episode.get("episodeName")} for "{series.get("seriesName")}' ) episode['_fuzzy_score'] = score add_unique_elements(self.fuzzy_episode_matches, episode)