Exemplo n.º 1
0
def album_transcode_generator(sets, targettids, allowedcodecs, targetcodec):
    copy_task = None
    copy_queue = deque()
    for album in sets:
        if all(t.type_ in allowedcodecs and t.has_replaygain() for t in album):
            copy_queue.append(FuncTask(copy_rename_files, album, op="copy"))
            if copy_task and copy_task.deferred.called:
                copy_task = None
            if copy_task is None:
                copy_task = PoolTask(deque_queue(copy_queue), jobs=1)
                copy_task.queue()
        else:
            yield album_transcode_one(album, targetcodec)
Exemplo n.º 2
0
def track_transcode_generator(sets, targettids, allowedcodecs, targetcodec):
    class album_(object):
        __slots__ = ["task_count", "album", "outfiles"]

    copy_task = None
    copy_queue = deque()
    completions = deque()

    def wrap(f):
        @wraps(getattr(f, "func", f))
        def proxy(out):
            f()
            return out

        return proxy

    for album in sets:
        if all(t.type_ in allowedcodecs and t.has_replaygain() for t in album):
            copy_queue.append(FuncTask(copy_rename_files, album, op="copy"))
            if copy_task and copy_task.deferred.called:
                copy_task = None
            if copy_task is None:
                copy_task = PoolTask(deque_queue(copy_queue), jobs=1)
                copy_task.queue()
        else:
            file_manager.create_dir()
            tasks = []
            outfiles = []
            outfiles_ext = []
            for track in album:
                outfile, = file_manager.get_files(1)
                outfile_ext = targetcodec._conv_out_filename(outfile)
                decoder = get_codec(track).to_wav_pipe(track.filename, None, track.meta)
                encoder = targetcodec.from_wav_pipe(None, outfile_ext, track.meta)
                task = CLIPipelineTask([decoder, encoder])
                task.deferred.addCallback(wrap(partial(check_output, outfile_ext)))
                if os.path.exists(outfile_ext):
                    err(consoleformat="Output file %(file)r already exists!", file=outfile_ext)
                tasks.append(task)
                outfiles.append(outfile)
                outfiles_ext.append(outfile_ext)
                yield task
            complete_task = complete_album(album, targetcodec, outfiles_ext)
            complete_task.deferred.addBoth(wrap(partial(file_manager.free_files, outfiles)))
            DeferredList([t.deferred for t in tasks], fireOnOneErrback=True).addCallback(wrap(complete_task.run))