コード例 #1
0
ファイル: metadata.py プロジェクト: audiolog/audiolog
def handleMetadata(directoryPath, audioFilePaths):
    """Create and run a ReleaseManager object."""
    
    releaseManager = Manager.ReleaseManager(directoryPath, audioFilePaths)
    try:
        releaseManager.run()
    except Manager.ReleaseManagerError, e:
        log("\nCould not identify and tag audio.")
        log(str(e))
        functions.rejectItem(directoryPath)
コード例 #2
0
def handleMetadata(directoryPath, audioFilePaths):
    """Create and run a ReleaseManager object."""

    releaseManager = Manager.ReleaseManager(directoryPath, audioFilePaths)
    try:
        releaseManager.run()
    except Manager.ReleaseManagerError, e:
        log("\nCould not identify and tag audio.")
        log(str(e))
        functions.rejectItem(directoryPath)
コード例 #3
0
ファイル: convert.py プロジェクト: audiolog/audiolog
def convert(audioFilePaths):
    """Convert undesirable audio formats into ogg.
    
    Takes a list of audio files and converts each to ogg using appropriate
    commands. These commands (mac, oggenc, mpc123) must be present."""

    for audioFilePath in audioFilePaths:
        fileName = os.path.basename(audioFilePath)
        with logSection("Converting %s." % quote(fileName)):
            filePathWithoutExtension, extension = os.path.splitext(
                audioFilePath)
            commands = convertorCommands[extension]

            success = True
            for command in commands:
                cmd = [
                    arg.replace("$$", filePathWithoutExtension)
                    for arg in command
                ]

                log(" ".join(cmd))
                try:
                    p = subprocess.Popen(cmd)
                    p.wait()
                except OSError:
                    log("% command not found." % cmd[0])
                    success = False
                    break

                if p.returncode != 0:
                    success = False
                    break

            if not success:
                # FIXME: Should we reject this file or this entire directory?
                log("Unable to convert %s." % quote(fileName))
                functions.rejectItem(audioFilePath)
            else:
                functions.deleteItem(audioFilePath)

            if len(commands) > 1:  # If we created an intermediate wav file
                functions.deleteItem(filePathWithoutExtension + ".wav", True)
コード例 #4
0
def extract(archivePaths):
    """Extract archives using appropriate utility.
    
    Takes a list of paths to archives and for each:
    Creates a directory with the same name as the archive, without extension.
    Chooses the utility to use for extraction based on the archive's extension.
    Attempts to extract the archive into the newly created directory.
    If the extraction fails, the directory is deleted and the archive rejected.
    If the extraction succeeds, the archive is discarded."""

    for archivePath in archivePaths:
        fileName = os.path.basename(archivePath)
        with logSection("Extracting %s." % quote(fileName)):
            destDirectoryPath, ext = os.path.splitext(archivePath)
            if not os.path.exists(destDirectoryPath):
                os.mkdir(destDirectoryPath)

            command = extractorCommands[ext.lower()][:]
            for (i, arg) in enumerate(command):
                if arg == "$a":
                    command[i] = archivePath
                elif arg == "$d":
                    command[i] = destDirectoryPath

            log(" ".join(command))

            try:
                p = subprocess.Popen(command)
                p.wait()
                success = p.returncode == 0
            except OSError:
                log("%s command not found." % command[0])
                success = False

            if not success:
                log("Unable to extract %s." % quote(archivePath))
                functions.deleteItem(destDirectoryPath)
                functions.rejectItem(archivePath)
            else:
                functions.deleteItem(archivePath)
コード例 #5
0
ファイル: extract.py プロジェクト: audiolog/audiolog
def extract(archivePaths):
    """Extract archives using appropriate utility.
    
    Takes a list of paths to archives and for each:
    Creates a directory with the same name as the archive, without extension.
    Chooses the utility to use for extraction based on the archive's extension.
    Attempts to extract the archive into the newly created directory.
    If the extraction fails, the directory is deleted and the archive rejected.
    If the extraction succeeds, the archive is discarded."""
    
    for archivePath in archivePaths:
        fileName = os.path.basename(archivePath)
        with logSection("Extracting %s." % quote(fileName)):
            destDirectoryPath, ext = os.path.splitext(archivePath)
            if not os.path.exists(destDirectoryPath):
                os.mkdir(destDirectoryPath)   
            
            command = extractorCommands[ext.lower()][:]
            for (i, arg) in enumerate(command):
                if arg == "$a":
                    command[i] = archivePath
                elif arg == "$d":
                    command[i] = destDirectoryPath
            
            log(" ".join(command))
            
            try:
                p = subprocess.Popen(command)
                p.wait()
                success = p.returncode == 0
            except OSError:
                log("%s command not found." % command[0])
                success = False
            
            if not success:
                log("Unable to extract %s." % quote(archivePath))
                functions.deleteItem(destDirectoryPath)
                functions.rejectItem(archivePath)
            else:
                functions.deleteItem(archivePath)
コード例 #6
0
ファイル: convert.py プロジェクト: audiolog/audiolog
def convert(audioFilePaths):
    """Convert undesirable audio formats into ogg.
    
    Takes a list of audio files and converts each to ogg using appropriate
    commands. These commands (mac, oggenc, mpc123) must be present."""

    for audioFilePath in audioFilePaths:
        fileName = os.path.basename(audioFilePath)
        with logSection("Converting %s." % quote(fileName)):
            filePathWithoutExtension, extension = os.path.splitext(audioFilePath)
            commands = convertorCommands[extension]

            success = True
            for command in commands:
                cmd = [arg.replace("$$", filePathWithoutExtension) for arg in command]

                log(" ".join(cmd))
                try:
                    p = subprocess.Popen(cmd)
                    p.wait()
                except OSError:
                    log("% command not found." % cmd[0])
                    success = False
                    break

                if p.returncode != 0:
                    success = False
                    break

            if not success:
                # FIXME: Should we reject this file or this entire directory?
                log("Unable to convert %s." % quote(fileName))
                functions.rejectItem(audioFilePath)
            else:
                functions.deleteItem(audioFilePath)

            if len(commands) > 1:  # If we created an intermediate wav file
                functions.deleteItem(filePathWithoutExtension + ".wav", True)
コード例 #7
0
def split(cuePaths, audioFilePaths):
    """Split audio files based on cue files.
    
    Takes a list of cue paths and a list of audio file paths.
    Rejects the folder if there are inequal numbers of audio and cue files.
    If there is one cue/audio pair, it is split using mp3splt. 
    If there are multiple pairs, they are moved into their own folders."""

    numCues = len(cuePaths)
    directoryPath = os.path.dirname(cuePaths[0])

    if numCues != len(audioFilePaths):
        log("There are unequal numbers of cues and audio files in %s." %
            quote(directoryPath))
        functions.rejectItem(directoryPath)
        return

    if numCues == 1:
        cuePath = cuePaths[0]
        audioFilePath = audioFilePaths[0]

        log("Splitting %s based on %s." %
            (quote(os.path.basename(audioFilePath)),
             quote(os.path.basename(cuePath))))

        command = [
            'mp3splt', '-d', directoryPath, '-c', cuePath, audioFilePath
        ]
        log(" ".join(command))

        try:
            p = subprocess.Popen(command)
            p.wait()
            success = p.returncode == 0
        except OSError:
            log("%s command not found." % command[0])
            success = False

        if success:
            log("Successfully split %s." % quote(audioFilePath))
            functions.deleteItem(cuePath)
            functions.deleteItem(audioFilePath)

        else:
            log("Unable to split %s." % quote(audioFilePath))
            functions.rejectItem(cuePath)
            functions.rejectItem(audioFilePath)

    else:
        log("Multiple cue/audio pairs in %s." % quote(directoryName))
        pairs = [(audioFilePaths[i], cuePaths[i]) for i in range(numCues)]
        functions.moveDiscsIntoFolders(pairs)
コード例 #8
0
ファイル: split.py プロジェクト: audiolog/audiolog
def split(cuePaths, audioFilePaths):
    """Split audio files based on cue files.
    
    Takes a list of cue paths and a list of audio file paths.
    Rejects the folder if there are inequal numbers of audio and cue files.
    If there is one cue/audio pair, it is split using mp3splt. 
    If there are multiple pairs, they are moved into their own folders."""
    
    numCues = len(cuePaths)
    directoryPath = os.path.dirname(cuePaths[0])
    
    if numCues != len(audioFilePaths):
        log("There are unequal numbers of cues and audio files in %s." % 
            quote(directoryPath))
        functions.rejectItem(directoryPath)
        return

    if numCues == 1:
        cuePath = cuePaths[0]
        audioFilePath = audioFilePaths[0]
        
        log("Splitting %s based on %s." % 
            (quote(os.path.basename(audioFilePath)), 
             quote(os.path.basename(cuePath))))
        
        command = ['mp3splt', '-d', directoryPath, '-c', cuePath, audioFilePath]
        log(" ".join(command))
        
        try:
            p = subprocess.Popen(command)
            p.wait()
            success = p.returncode == 0
        except OSError:
            log("%s command not found." % command[0])
            success = False

        if success:
            log("Successfully split %s." % quote(audioFilePath))
            functions.deleteItem(cuePath)
            functions.deleteItem(audioFilePath)

        else:
            log("Unable to split %s." % quote(audioFilePath))
            functions.rejectItem(cuePath)
            functions.rejectItem(audioFilePath)
                           
    else: 
        log("Multiple cue/audio pairs in %s." % quote(directoryName))
        pairs = [(audioFilePaths[i], cuePaths[i]) for i in range(numCues)]
        functions.moveDiscsIntoFolders(pairs)