def get_show_by_key(epguides_name): epguides_name = str(epguides_name).lower().replace(" ", "") if epguides_name.startswith("the"): epguides_name = epguides_name[3:] show = Show(epguides_name) add_epguides_key_to_redis(epguides_name) return show
def view_show(show): log_event(request, "ViewShow") add_epguides_key_to_redis(show) try: return json_response(get_show_by_key(show).get_show_data()) except EpisodeNotFoundException: return json_response({'error': 'Show not found'}, 404) except SeasonNotFoundException: return json_response({'error': 'Season not found'}, 404)
def last(show): log_event(request, "ViewShowLastEpisode") add_epguides_key_to_redis(show) try: return json_response({'episode': get_show_by_key(show).last_episode()}) except EpisodeNotFoundException: return json_response({'error': 'Show not found'}, 404) except SeasonNotFoundException: return json_response({'error': 'Season not found'}, 404)
def next_from_given_episode(show, season, episode): log_event(request, "ViewNextFromGivenEpisode") add_epguides_key_to_redis(show) try: show = get_show_by_key(show) return json_response( {'episode': show.get_episode(int(season), int(episode)).next()}) except EpisodeNotFoundException: return json_response({'error': 'Show not found'}, 404) except SeasonNotFoundException: return json_response({'error': 'Season not found'}, 404)
def released(show, season, episode): log_event(request, "ViewReleased") add_epguides_key_to_redis(show) try: show = get_show_by_key(show) return json_response( {'status': show.episode_released(int(season), int(episode))}) except EpisodeNotFoundException: return json_response({'error': 'Show not found'}, 404) except SeasonNotFoundException: return json_response({'error': 'Season not found'}, 404)
def episode(show, season, episode): log_event(request, "ViewEpisode") add_epguides_key_to_redis(show) try: return json_response({ 'episode': get_show_by_key(show).get_episode(int(season), int(episode)) }) except EpisodeNotFoundException: return json_response({'error': 'Show not found'}, 404) except SeasonNotFoundException: return json_response({'error': 'Season not found'}, 404)
def next_released_from_given_episode(show, season, episode): log_event(request, "ViewNextReleasedFromGivenEpisode") add_epguides_key_to_redis(show) try: show = get_show_by_key(show) next_episode = show.get_episode(season, episode).next() if not next_episode: raise EpisodeNotFoundException return json_response({'status': next_episode.released()}) except EpisodeNotFoundException: return json_response({'error': 'Show not found'}, 404) except SeasonNotFoundException: return json_response({'error': 'Season not found'}, 404)