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): """ 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): """ WhoPlayedRoleInTVShowQuestion """ super(WhoPlayedRoleInTVShowQuestion, self).__init__() show = library.getTVShows(['title', 'genre', 'cast', 'art']).withFilters(defaultFilters).limitTo(1).asItem() if not show or len(show['cast']) < 4: raise QuestionException('No tvshows found') otherActors = show['cast'] actor = otherActors.pop(random.randint(0, len(otherActors) - 1)) role = actor['role'] if re.search('[|/,]', role): roles = re.split('[|/,]', role) # find random role role = roles[random.randint(0, len(roles) - 1)] self.addCorrectAnswer(id=actor['name'], text=actor['name'], image=actor.get('thumbnail')) for otherActor in otherActors: self.addAnswer(id=otherActor['name'].encode('utf-8', 'ignore'), text=otherActor['name'], image=otherActor.get('thumbnail')) if len(self.answers) == 4: break random.shuffle(self.answers) if self._isAnimationGenre(show['genre']): self.text = strings(Q_WHO_VOICES_ROLE_IN_TVSHOW) % (role, show['title']) else: self.text = strings(Q_WHO_PLAYS_ROLE_IN_TVSHOW) % (role, show['title']) self.setFanartFile(show['art']['fanart'])
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): audioDisplayType = AudioDisplayType() super(WhatTVShowIsThisThemeFromQuestion, self).__init__(audioDisplayType) items = library.getTVShows(['title', 'file', 'art']).withFilters(defaultFilters).limitTo(4).asList() show = None otherShows = list() for item in items: themeSong = os.path.join(item['file'], 'theme.mp3') if show is None and xbmcvfs.exists(themeSong): show = item else: otherShows.append(item) if show is None: raise QuestionException('Unable to find any tv shows with a theme.mp3 file') self.addCorrectAnswer(id=show['tvshowid'], text=show['title'], image=show['art']['poster']) # Fill with random episodes from other shows for otherShow in otherShows: self.addAnswer(id=otherShow['tvshowid'], text=otherShow['title'], image=otherShow['art']['poster']) random.shuffle(self.answers) audioDisplayType.setAudioFile(os.path.join(show['file'], 'theme.mp3')) self.text = strings(Q_WHAT_TVSHOW_IS_THIS_THEME_FROM)
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): """ 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"])
def __init__(self, defaultFilters): """ WhoPlayedRoleInTVShowQuestion """ super(WhoPlayedRoleInTVShowQuestion, self).__init__() show = library.getTVShows(["title", "genre", "cast", "art"]).withFilters(defaultFilters).limitTo(1).asItem() if not show or len(show["cast"]) < 4: raise QuestionException("No tvshows found") otherActors = show["cast"] actor = otherActors.pop(random.randint(0, len(otherActors) - 1)) role = actor["role"] if re.search("[|/,]", role): roles = re.split("[|/,]", role) # find random role role = roles[random.randint(0, len(roles) - 1)] self.addCorrectAnswer(id=actor["name"], text=actor["name"], image=actor.get("thumbnail")) for otherActor in otherActors: self.addAnswer( id=otherActor["name"].encode("utf-8", "ignore"), text=otherActor["name"], image=otherActor.get("thumbnail"), ) if len(self.answers) == 4: break random.shuffle(self.answers) if self._isAnimationGenre(show["genre"]): self.text = strings(Q_WHO_VOICES_ROLE_IN_TVSHOW) % (role, show["title"]) else: self.text = strings(Q_WHO_PLAYS_ROLE_IN_TVSHOW) % (role, show["title"]) self.setFanartFile(show["art"]["fanart"])