def watch(showname, cache, episodestring):
    logger.info("watch({name}, {epstring})".format(name=showname, epstring=episodestring))
    seasonnum, episodenum = getepisodeinfo(episodestring)
    assert(seasonnum is not None and episodenum is not None)
    episode = cache.getepisode(showname, seasonnum, episodenum)
    if watchepisode(episode):
        cache.markwatched(episode)
    askwatchnext(showname, cache)
def markwatched(showname, cache, episodestring, markprevious, watched):
    logger.info("markwatched")
    # shortcut so that you don't need to know the name of the next episode.
    if episodestring == "next":
        episode = cache.getnextepisode(showname)
    else:
        seasonnum, episodenum = getepisodeinfo(episodestring)
        episode = cache.getepisode(showname, seasonnum, episodenum)
    cache.markwatched(episode, markprevious=markprevious, watched=watched)
def renameepisode(filename, cache):
    """ Rename a file by guessing what series and episode it is,
    from its' current file name
    """
    print("Analyzing {}".format(filename))
    seasonnumber, episodenumber = getepisodeinfo(filename)
    if None in (seasonnumber, episodenumber):
        print("Couldn't find episode information!".format(filename))
        return False
    showname = getshowname(filename)
    if showname is None:
        print("Didn't match any series")
        return False
    print("Found to be part of {}".format(showname))
    episode = cache.getepisode(showname, seasonnumber, episodenumber)
    if episode is None:
        print("Couldn't find any information on {} S{}E{}".format(showname, seasonnumber, episodenumber))
        return
    __, ext = path.splitext(filename)
    newfilename = episode.getprettyname() + ext
    newfilename = newfilename.replace("/", "-").replace("'", "")
    print("Moving to {}".format(newfilename.encode('utf8')))
    _movefile(filename, newfilename, showname)
def download(showname, cache):
    logger.info("download")
    seasonnum, episodenum = getepisodeinfo(args['--download'])
    episode = cache.getepisode(showname, seasonnum, episodenum)
    downloadepisode(episode)