def __init__(self, defaultFilters): """ WhatTVShowIsThisQuestion """ videoDisplayType = VideoDisplayType() super(WhatTVShowIsThisQuestion, self).__init__(videoDisplayType) show = library.getTVShows(['title', 'art']).withFilters(defaultFilters).limitTo(1).asItem() if not show: raise QuestionException('No tvshows found') self.addCorrectAnswer(id=show['tvshowid'], text=show['title'], image=show['art']['poster']) episode = library.getEpisodes(['file']).withFilters(defaultFilters).fromShow(show['title']).limitTo( 1).asItem() if not episode: raise QuestionException('TVshow has no episodes') otherShows = library.getTVShows(['title', 'art']).withFilters(defaultFilters).excludeTitles( [show['title']]).limitTo(3).asList() for otherShow in otherShows: self.addAnswer(id=otherShow['tvshowid'], text=otherShow['title'], image=otherShow['art']['poster']) random.shuffle(self.answers) self.text = strings(Q_WHAT_TVSHOW_IS_THIS) videoDisplayType.setVideoFile(episode['file'])
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): """ WhatTVShowIsThisQuoteFrom """ quoteDisplayType = QuoteDisplayType() super(WhatTVShowIsThisQuoteFrom, self).__init__(quoteDisplayType) episode = library.getEpisodes(['showtitle', 'season', 'episode', 'art']).withFilters(defaultFilters).limitTo( 1).asItem() if not episode: raise QuestionException('No episodes found') quoteText = IMDB.getRandomQuote(episode['showtitle'], season=episode['season'], episode=episode['episode'], maxLength=128) if quoteText is None: raise QuestionException('Did not find any quotes') self.addCorrectAnswer(id=episode['showtitle'], text=episode['showtitle'], image=episode['art']['tvshow.poster']) otherShows = library.getTVShows(['title', 'art']).withFilters(defaultFilters).excludeTitles( [episode['showtitle']]).limitTo(3).asList() for otherShow in otherShows: self.addAnswer(id=otherShow['title'].encode('utf-8', 'ignore'), text=otherShow['title'], image=otherShow['art']['poster']) random.shuffle(self.answers) quoteDisplayType.setQuoteText(quoteText) self.text = strings(Q_WHAT_TVSHOW_IS_THIS_QUOTE_FROM)
def __init__(self, defaultFilters): """ WhatTVShowIsThisQuestion """ videoDisplayType = VideoDisplayType() super(WhatTVShowIsThisQuestion, self).__init__(videoDisplayType) show = library.getTVShows(["title", "art"]).withFilters(defaultFilters).limitTo(1).asItem() if not show: raise QuestionException("No tvshows found") self.addCorrectAnswer(id=show["tvshowid"], text=show["title"], image=show["art"]["poster"]) episode = ( library.getEpisodes(["file", "resume"]) .withFilters(defaultFilters) .fromShow(show["title"]) .limitTo(1) .asItem() ) if not episode: raise QuestionException("TVshow has no episodes") otherShows = ( library.getTVShows(["title", "art"]) .withFilters(defaultFilters) .excludeTitles([show["title"]]) .limitTo(3) .asList() ) for otherShow in otherShows: self.addAnswer(id=otherShow["tvshowid"], text=otherShow["title"], image=otherShow["art"]["poster"]) random.shuffle(self.answers) self.text = strings(Q_WHAT_TVSHOW_IS_THIS) videoDisplayType.setVideoFile(episode["file"], episode["resume"]["position"])
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): """ WhatTVShowIsThisQuoteFrom """ quoteDisplayType = QuoteDisplayType() super(WhatTVShowIsThisQuoteFrom, self).__init__(quoteDisplayType) episode = ( library.getEpisodes(["showtitle", "season", "episode", "art"]) .withFilters(defaultFilters) .limitTo(1) .asItem() ) if not episode: raise QuestionException("No episodes found") quoteText = IMDB.getRandomQuote( episode["showtitle"], season=episode["season"], episode=episode["episode"], maxLength=128 ) if quoteText is None: raise QuestionException("Did not find any quotes") self.addCorrectAnswer(id=episode["showtitle"], text=episode["showtitle"], image=episode["art"]["tvshow.poster"]) otherShows = ( library.getTVShows(["title", "art"]) .withFilters(defaultFilters) .excludeTitles([episode["showtitle"]]) .limitTo(3) .asList() ) for otherShow in otherShows: self.addAnswer( id=otherShow["title"].encode("utf-8", "ignore"), text=otherShow["title"], image=otherShow["art"]["poster"], ) random.shuffle(self.answers) quoteDisplayType.setQuoteText(quoteText) self.text = strings(Q_WHAT_TVSHOW_IS_THIS_QUOTE_FROM)
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"])