Exemplo n.º 1
0
 def __init__(self):
     zpc = ZpCacher()
     zpc.load_cache()
     
     self.cache = zpc.cache
     self.load_state()
Exemplo n.º 2
0
def main():
    zpc = ZpCacher()
    zpc.load_cache()

    state = DoneState()
    done = state.done()

    for counter, vid in enumerate(sort_nicely(zpc.cache.keys())):
        if vid in done:
            # Skip, already done
            continue
    
        cur = zpc.cache[vid]
        
        # Get filename part of URL, as we need it for transcoding,
        # Explicitly extracting and downloading to this should prevent
        # any unexpected weirdness.
        urlpath = urlparse(cur['flv']).path
        _, urlfilename = os.path.split(urlpath)
        
        # Generate wget command
        grab_command = ["curl", "-L", "-A", "\"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)\"", "-C", "-", cur['flv'], "-o", urlfilename]
        print "Getting FLV file:"
        print grab_command
        gproc = subprocess.Popen(grab_command)
        gproc.communicate()
        if gproc.returncode != 0:
            print "Non-zero exit code: %s" % gproc.returncode
            continue
        print

        if not os.path.isfile(urlfilename):
            print "Downloaded file \"%s\" not found, not transcoding" % urlfilename
            continue

        transcoded_name = "Zero Punctuation - [%02d] - %s.mp4" % (counter, cur['title'])

        transcoded_name = transcoded_name.replace(": ", " - ")

        transcoded_name = makeValidFilename(transcoded_name)


        print "Transcoding:"
        t = Transcoder(urlfilename)
        transcode_cmd = t.getcommand(transcoded_name)
        tproc = subprocess.Popen(transcode_cmd)
        tproc.communicate()
        if tproc.returncode != 0:
            print "Non-zero exit code: %s" % tproc.returncode
            continue
        print

        print "Tagging:"
        tag_command = ["AtomicParsley", transcoded_name, "--TVShowName", "Zero Punctuation", "--TVSeasonNum", "1", "--TVEpisodeNum", str(counter), "--stik", "TV Show", "--overWrite"]
        print tag_command
        try:
            tagproc = subprocess.Popen(tag_command)
        except OSError, e:
            print "Error while launching AtomicParsley, may not be installed?"
            print e
        else:
            tagproc.communicate()
            if tagproc.returncode != 0:
                print "Non-zero exit code while tagging: %s" % tagproc.returncode
                print
        
        # Mark as done, as save
        state.add_done(vid)
        state.save_state()