def getTraktEpisodeInfo(showName, seasonNumber, episodeNumber, cache, seriesWhitelist, seriesMismatched): print showName, seasonNumber, episodeNumber if (showName.lower() in cache): showTvDbId = cache[showName.lower()]['tvdb'] showName = cache[showName.lower()]['title'] elif (showName in seriesMismatched): showRes = showName showName = seriesMismatched[showName] showTvDbId = TVShow('"' + showName + '"').tvdb cache = updateCache(cache, showRes, showName, showTvDbId) elif (showName in seriesWhitelist): showTvDbId = seriesWhitelist[showName] else: showName = showName.replace("(", "").replace(")", "").replace(":", "") showRes = TVShow.search('"' + showName + '"') for showFound in showRes: if showName.lower() == showFound.title.lower(): cache = updateCache(cache, showName, showFound.title, showFound.tvdb) showName = showFound.title showTvDbId = showFound.tvdb break else: # Cannot find exact show name in trakt.tv search results so use 1st entry cache = updateCache(cache, showName, showRes[0].title, showRes[0].tvdb) showName = showRes[0].title showTvDbId = showRes[0].tvdb print showName, showTvDbId, seasonNumber, episodeNumber episode = TVEpisode(showName, seasonNumber, episodeNumber) #print episode.show, showTvDbId, seasonNumber, episodeNumber, episode.title, episode.tvdb return (showName, showTvDbId, seasonNumber, episodeNumber, episode.title, episode.tvdb)
def _search(self, query): """Search Trakt for a TV episode matching *query*""" results = TVShow.search(query) self.filter_key = slugify(query) result = self.filter_results(query, results) if result is None: return self.context show = TVShow(result.slug) LOGGER.info('Trakt Search Result: %s', str(show)) self._apply_mapping(show) # Get general information about the show # Get episode specific data season_num = self.context.get('TV Season', None) if season_num is None: return self.context episode_num = self.context.get('TV Episode #') episode = TVEpisode(result.slug, season_num, episode_num) return self._get_episode(episode)
def update(self): """Get the latest state of the sensor.""" from trakt.calendar import MyShowCalendar from trakt.tv import TVShow import requests attributes = {} default = {} card_json = [] default['title_default'] = '$title' default['line1_default'] = '$episode' default['line2_default'] = '$release' default['line3_default'] = '$rating - $runtime' default['line4_default'] = '$number - $studio' default['icon'] = 'mdi:arrow-down-bold' card_json.append(default) calendar = MyShowCalendar(days=self._days) if not calendar: _LOGGER.error("Nothing in upcoming calendar") return False self._state = len(calendar) for show in calendar: if not show or show.show in self._exclude: continue try: show_details = TVShow.search(show.show, show.year) except AttributeError: _LOGGER.error('Unable to retrieve show details for ' + show.show) if not show_details: continue session = requests.Session() try: tmdb_url = session.get( 'http://api.tmdb.org/3/tv/{}?api_key=0eee347e2333d7a97b724106353ca42f' .format(str(show_details[0].tmdb))) tmdb_json = tmdb_url.json() except requests.exceptions.RequestException as e: _LOGGER.warning('api.themoviedb.org is not responding') return image_url = 'https://image.tmdb.org/t/p/w%s%s' if days_until(show.airs_at.isoformat() + 'Z', self._tz) <= 7: release = '$day, $time' else: release = '$day, $date $time' card_item = { 'airdate': show.airs_at.isoformat() + 'Z', 'release': release, 'flag': False, 'title': show.show, 'episode': show.title, 'number': 'S' + str(show.season) + 'E' + str(show.number), 'rating': tmdb_json.get('vote_average', ''), 'poster': image_url % ('500', tmdb_json.get('poster_path', '')), 'fanart': image_url % ('780', tmdb_json.get('backdrop_path', '')), 'runtime': tmdb_json.get('episode_run_time')[0] if len(tmdb_json.get('episode_run_time')) > 0 else '', 'studio': tmdb_json.get('networks')[0].get('name', '') if len(tmdb_json.get('networks')) > 0 else '' } card_json.append(card_item) attributes['data'] = json.dumps(card_json) self._hass.data[DATA_UPCOMING] = attributes
def test_show_search_with_year(): results = TVShow.search('batman', year=1999) assert isinstance(results, list) assert len(results) == 10 assert all(isinstance(m, TVShow) for m in results)
def test_show_search(): results = TVShow.search('batman') assert isinstance(results, list) assert all(isinstance(m, TVShow) for m in results)
def test_show_search_with_year(): results = TVShow.search('batman', year=1999) assert isinstance(results, list) assert len(results) == 1 assert all(isinstance(m, TVShow) for m in results)