def get_previous_episode_id(tvshow_id, season, episode):
    previous_episode_id = None
    if episode > 1:
        previous_episode_id = kodi_rpc.get_episodeid(tvshow_id, season,
                                                     episode - 1)
    elif season > 1:
        previous_episode_id = kodi_rpc.get_last_episodeid(
            tvshow_id, season - 1)

    return previous_episode_id
def play_tvshow(tvshow, season, episode):
    logger.debug('Playing tv show: {}, season: {}, episode: {}'.format(
        tvshow['title'], season, episode))

    if season and episode:
        episode_id = kodi_rpc.get_episodeid(tvshow['tvshowid'], int(season),
                                            int(episode))
    else:
        episode_id = kodi_rpc.get_next_unwatched_episode(tvshow['tvshowid'])

    if episode_id:
        logger.debug('Playing episodeid: {}'.format(episode_id))
        play_episodeid(episode_id)
def get_next_episode_id(tvshow_id, season, episode):
    next_episode_id = kodi_rpc.get_episodeid(tvshow_id, season, episode + 1)
    if not next_episode_id:
        next_episode_id = kodi_rpc.get_episodeid(tvshow_id, season + 1, 1)

    return next_episode_id