Example #1
0
def open (name, fh=0):
    name = os.path.normpath(name)
    if not os.path.exists(name):
        raise IOError, (2, "No such file or directory: '%s'" % name)
    ext = os.path.splitext(name)[1][1:].lower()
    if ext in ("mp4", "m4a", "m4b", "aac"):
        if os.name=="nt": cline = [faad, "-q", "-w", name]
        else: cline = [faad, "-q", "-f", "2", "-w", name]
        po = Popen(cline, shell=0, stdout=PIPE, stdin=PIPE, stderr=PIPE, creationflags=noWindow)
        po.stdin.close(); po.stderr.close()
        po.filename = name
        wf = fakewave(po, fh)
    elif ext=="ogg":
        if os.name=="nt": cline = [oggdec, "--stdout", name]
        else: cline = [oggdec, "-q", "-o", "-", name]
        po = Popen(cline, shell=0, stdout=PIPE, stdin=PIPE, stderr=PIPE, creationflags=noWindow)
        po.stdin.close(); po.stderr.close()
        po.filename = name
        wf = fakewave(po, fh)
    elif ext in ("wav", "wave"):
        wf = wave.open(name, "r")
    elif ext in ("aiff", "aif"):
        wf = aifc.open(name, "r")
    elif ext in ("mp1", "mp2", "mp3"):
        cline = [lame, "--quiet", "--decode", name, "-"]
        po = Popen(cline, shell=0, stdout=PIPE, stdin=PIPE, stderr=PIPE, creationflags=noWindow)
        po.stdin.close(); po.stderr.close()
        po.filename = name
        wf = fakewave(po, fh)
    elif ext in ("flac", "oga"):
        cline = [flac, "--silent", "--stdout", "-d", name]
        po = Popen(cline, shell=0, stdout=PIPE, stdin=PIPE, stderr=PIPE, creationflags=noWindow)
        po.stdin.close(); po.stderr.close()
        po.filename = name
        wf = fakewave(po, fh)
    elif ext=="wma":
        if os.name=="nt": cline = [wmadec, "-w", name]
        else: cline = [ffmpeg, "-i", name, "-f", "wav", "-"]
        po = Popen(cline, shell=0, stdout=PIPE, stdin=PIPE, stderr=PIPE, creationflags=noWindow)
        po.stdin.close(); po.stderr.close()
        po.filename = name
        wf = fakewave(po, fh)
    else: wf = None
    return wf