def __init__(self, defaultFilters): """ WhatEpisodeIsThisQuestion """ videoDisplayType = VideoDisplayType() super(WhatEpisodeIsThisQuestion, self).__init__(videoDisplayType) show = library.getTVShows(['title', 'art']).withFilters(defaultFilters).limitTo(1).asItem() if not show: raise QuestionException('No tvshows found') season = library.getSeasons(show['tvshowid'], ['season', 'art']).limitTo(14).asItem() if not season: raise QuestionException('No seasons found') episodes = library.getEpisodes(['episode', 'title', 'file']).fromShow(show['title']).fromSeason( season['season']).limitTo(4).asList() correctIdx = random.randint(0, len(episodes) - 1) for idx, episode in enumerate(episodes): id = "%s-%s-%s" % (show['tvshowid'], season['season'], episode['episode']) self.addAnswer(id=id, text=episode['label'], image=season['art']['poster'], sortWeight=episode['episode'], correct=(idx == correctIdx)) self.answers = sorted(self.answers, key=lambda answer: int(answer.sortWeight)) self.text = strings(Q_WHAT_EPISODE_IS_THIS) % show['title'] videoDisplayType.setVideoFile(episodes[correctIdx]['file'])
def __init__(self, defaultFilters): """ WhenWasTVShowFirstAiredQuestion """ super(WhenWasTVShowFirstAiredQuestion, self).__init__() show = library.getTVShows(["title", "art"]).withFilters(defaultFilters).limitTo(1).asItem() if not show: raise QuestionException("No shows found") season = library.getSeasons(show["tvshowid"], ["season"]).limitTo(1).asItem() if not season: raise QuestionException("No seasons found") episode = ( library.getEpisodes(["firstaired"]) .withFilters(defaultFilters) .episode(1) .fromShow(show["title"]) .fromSeason(season["season"]) .limitTo(1) .asItem() ) if not episode: raise QuestionException("No episodes found") episodeYear = int(episode["firstaired"][0:4]) skew = random.randint(0, 10) minYear = episodeYear - skew maxYear = episodeYear + (10 - skew) thisYear = datetime.datetime.today().year if maxYear > thisYear: maxYear = thisYear minYear = thisYear - 10 years = list() years.append(episodeYear) while len(years) < 4: year = random.randint(minYear, maxYear) if not year in years: years.append(year) list.sort(years) for year in years: self.addAnswer( id="%s-%s" % (show["tvshowid"], season["season"]), text=str(year), correct=(year == episodeYear) ) self.text = strings(Q_WHEN_WAS_TVSHOW_FIRST_AIRED) % (show["title"] + " - " + season["label"]) self.setFanartFile(show["art"]["fanart"])
def __init__(self, defaultFilters): """ WhenWasTVShowFirstAiredQuestion """ super(WhenWasTVShowFirstAiredQuestion, self).__init__() show = library.getTVShows( ['title', 'art']).withFilters(defaultFilters).limitTo(1).asItem() if not show: raise QuestionException('No shows found') season = library.getSeasons(show['tvshowid'], ['season']).limitTo(1).asItem() if not season: raise QuestionException('No seasons found') episode = library.getEpisodes([ 'firstaired' ]).withFilters(defaultFilters).episode(1).fromShow( show['title']).fromSeason(season['season']).limitTo(1).asItem() if not episode: raise QuestionException('No episodes found') episodeYear = int(episode['firstaired'][0:4]) skew = random.randint(0, 10) minYear = episodeYear - skew maxYear = episodeYear + (10 - skew) thisYear = datetime.datetime.today().year if maxYear > thisYear: maxYear = thisYear minYear = thisYear - 10 years = list() years.append(episodeYear) while len(years) < 4: year = random.randint(minYear, maxYear) if not year in years: years.append(year) list.sort(years) for year in years: self.addAnswer(id="%s-%s" % (show['tvshowid'], season['season']), text=str(year), correct=(year == episodeYear)) self.text = strings(Q_WHEN_WAS_TVSHOW_FIRST_AIRED) % ( show['title'] + ' - ' + season['label']) self.setFanartFile(show['art']['fanart'])
def __init__(self, defaultFilters): """ WhatSeasonIsThisQuestion """ videoDisplayType = VideoDisplayType() super(WhatSeasonIsThisQuestion, self).__init__(videoDisplayType) show = library.getTVShows(["title", "art"]).withFilters(defaultFilters).limitTo(1).asItem() if not show: raise QuestionException("No tvshows found") seasons = library.getSeasons(show["tvshowid"], ["season", "art"]).limitTo(4).asList() correctIdx = random.randint(0, len(seasons) - 1) episode = ( library.getEpisodes(["file", "resume"]) .withFilters(defaultFilters) .fromShow(show["title"]) .fromSeason(seasons[correctIdx]["season"]) .limitTo(1) .asItem() ) if not episode: raise QuestionException("TVshow has no episodes") for idx, season in enumerate(seasons): self.addAnswer( "%s-%s" % (show["tvshowid"], season["season"]), season["label"], image=season["art"]["poster"], sortWeight=season["season"], correct=(idx == correctIdx), ) self.answers = sorted(self.answers, key=lambda answer: int(answer.sortWeight)) self.text = strings(Q_WHAT_SEASON_IS_THIS) % show["title"] videoDisplayType.setVideoFile(episode["file"], episode["resume"]["position"])