예제 #1
0
def cron_run(conn):
    """
    This function will be called when the script is executed by cron. This will
    read the jobs and try to find sub downloads for each of them
    """
    # get all eps
    all_eps = db.get_all_eps(conn)
    return find_subs(all_eps)
예제 #2
0
파일: sicksubs.py 프로젝트: Jarcol/sicksubs
def cron_run(conn):
    '''
    This function will be called when the script is executed by cron. This will
    read the jobs and try to find sub downloads for each of them
    '''
    # get all eps
    all_eps = db.get_all_eps(conn)

    to_download = []
    for ep in all_eps:
        if ep.sid and ep.season and ep.ep:
            sublinks = bierdopje.get_subs(ep.sid, SUB_LANG, ep.season, ep.ep)
            sub = nameparser.find_link(ep.job_name, sublinks)
            if sub and os.path.exists(ep.final_loc):
                ep.sub = sub
                to_download.append(ep)
            else:
                ep_name = os.path.splitext(os.path.expanduser(ep.final_loc))[0]
                if os.path.exists(ep_name + '.srt'):
                    # Mabe user downloaded sub for this ep manually?
                    db.remove_single(conn, ep)
                    print(u'Cleaned up db because ' + ep_name + ' already has '
                    'subs!')
                elif not os.path.exists(ep.final_loc):
                    db.remove_single(conn, ep)
                    print(u'Cleaned up db because ' + ep_name + ' is no '
                    'longer available on disk!')

    if not to_download:
        if not quiet:
            print "No subs available for any of your eps yet!"
        return True
    for d in to_download:
        d.result = download(d)
    # remove successfully downloaded files from db
    successful = filter(lambda x: x.result, to_download)
    db.remove_downloaded(conn, successful)
    # check if all files are parsed successfully
    result = all([ep.result for ep in to_download])
    # call post-processing for successfully downloaded files
    if not POST_CALL:
        return result

    for d in successful:
        for script in POST_CALL.split(','):
            to_call = shlex.split(script)
            to_call.append(d.final_loc)
            subprocess.call(to_call)
    # return result
    return result
예제 #3
0
def cron_run(conn):
    """
    This function will be called when the script is executed by cron. This will
    read the jobs and try to find sub downloads for each of them
    """
    # get all eps
    all_eps = db.get_all_eps(conn)

    to_download = {}
    subdl = periscope.Periscope("cache")
    for ep in all_eps:
        subs = subdl.listSubtitles(ep.final_loc, [SUB_LANG])

        if subs and os.path.exists(ep.final_loc):
            to_download[ep] = subs
        else:
            ep_name = os.path.splitext(os.path.expanduser(ep.final_loc))[0]
            if os.path.exists(ep_name + ".srt"):
                # Mabe user downloaded sub for this ep manually?
                db.remove_single(conn, ep)
                print (u"Cleaned up db because " + ep_name + " already has subs!")
            elif not os.path.exists(ep.final_loc):
                db.remove_single(conn, ep)
                print (u"Cleaned up db because " + ep_name + " is no longer available on disk!")
            time.sleep(3)

    if not to_download:
        if not quiet:
            print "No subs available for any of your eps yet!"
        return True
    successful = []
    for d in to_download:
        if subdl.attemptDownloadSubtitle(to_download[d], [SUB_LANG]) is not None:
            successful.append(d)

    # remove successfully downloaded files from db
    db.remove_downloaded(conn, successful)
    # call post-processing for successfully downloaded files
    if POST_CALL:
        for d in successful:
            for script in POST_CALL.split(","):
                to_call = shlex.split(script)
                to_call.append(d.final_loc)
                subprocess.call(to_call)