示例#1
0
def main(args):
    cache = SeriesCache()
    if args.get('--verbose', False):
        setlogginglevel('debug')
    logger.debug("Arguments: {args}".format(args=args))
    if args.get('<showname>', False):
        showname = getshowname(" ".join(args['<showname>']))
        if showname is None:
            print("Couldn't find a show by the name '{n}' "
                  "in your regexes!".format(n=" ".join(args['<showname>'])))
            return
        logger.info("Showname: '{name}'".format(name=showname))

    if args.get('--watch-next', False):
        watchnext(showname, cache)
    elif args.get('--watch', False):
        watch(showname, cache, args['--watch'])
    elif args.get('--next-episode', False):
        nextepisode(showname, cache)
    elif args.get('--mark-watched', False):
        markwatched(showname, cache, args['--mark-watched'], watched=True,
                    markprevious=args.get('--mark-previous', False))
    elif args.get('--mark-unwatched', False):
        markwatched(showname, cache, args['--mark-unwatched'], watched=False,
                    markprevious=args.get('--mark-previous', False))
    elif args.get('--download', False):
        download(showname, cache)
    elif args.get('--update', False):
        update(showname, cache)
    elif args.get('--rename', False):
        rename(cache, args.get('<filename>', []))
    else:
        print('Unimplemented/unknown arguments "{}".'.format(args))
示例#2
0
def rename(cache, filenames):
    logger.info("rename")
    # user didn't give an argument. he wants to run it on all files in folder.
    if filenames == []:
        filenames = listdir('.')
    for filename in filenames:
        renameepisode(filename, cache=cache)
示例#3
0
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)
示例#4
0
def nextepisode(showname, cache):
    logger.info("nextepisode")
    episode = cache.getnextepisode(showname)
    if episode is None:
        print "No episode found!"
        return
    print("Next episode is: {episode}: {date}".format(episode=episode.getprettyname(),
                                                      date=episode.getairdatestr()).encode('utf8'))
示例#5
0
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)
示例#6
0
def watchnext(showname, cache):
    logger.info("watchnext")
    episode = cache.getnextepisode(showname)
    if episode is None:
        print("Couldn't find any new episodes!")
        if yesno("Would you like to update the cache?"):
            update(showname, cache)
            watchnext(showname, cache)  # this could be an endless loop.
        return
    if watchepisode(episode):
        cache.markwatched(episode)
    askwatchnext(showname, cache)
示例#7
0
def update(showname, cache):
    logger.info("update")
    print("Updating {name}..".format(name=showname))
    cache.getshow(showname, update=True)
示例#8
0
def download(showname, cache):
    logger.info("download")
    seasonnum, episodenum = getepisodeinfo(args['--download'])
    episode = cache.getepisode(showname, seasonnum, episodenum)
    downloadepisode(episode)