Пример #1
0
    def do(self):
        from whipper.common import encode

        try:
            fromPath = unicode(self.options.input)
        except IndexError:
            # unexercised after BaseCommand
            sys.stdout.write('Please specify an input file.\n')
            return 3

        try:
            toPath = unicode(self.options.output)
        except IndexError:
            toPath = fromPath + '.flac'

        runner = task.SyncRunner()

        logger.debug('Encoding %s to %s', fromPath.encode('utf-8'),
                     toPath.encode('utf-8'))
        encodetask = encode.FlacEncodeTask(fromPath, toPath)

        runner.run(encodetask)

        # I think we want this to be
        # fromPath, not toPath, since the sox peak task, afaik, works on wave
        # files
        peaktask = encode.SoxPeakTask(fromPath)
        runner.run(peaktask)

        sys.stdout.write('Peak level: %r\n' % peaktask.peak)
        sys.stdout.write('Encoded to %s\n' % toPath.encode('utf-8'))
Пример #2
0
    def __init__(self,
                 path,
                 table,
                 start,
                 stop,
                 overread,
                 offset=0,
                 device=None,
                 taglist=None,
                 what="track"):
        task.MultiSeparateTask.__init__(self)

        logger.debug('Creating read and verify task on %r', path)

        if taglist:
            logger.debug('read and verify with taglist %r', taglist)
        # FIXME: choose a dir on the same disk/dir as the final path
        fd, tmppath = tempfile.mkstemp(suffix='.whipper.wav')
        tmppath = unicode(tmppath)
        os.close(fd)
        self._tmpwavpath = tmppath

        from whipper.common import checksum

        self.tasks = []
        self.tasks.append(
            ReadTrackTask(tmppath,
                          table,
                          start,
                          stop,
                          overread,
                          offset=offset,
                          device=device,
                          what=what))
        self.tasks.append(checksum.CRC32Task(tmppath))
        t = ReadTrackTask(tmppath,
                          table,
                          start,
                          stop,
                          overread,
                          offset=offset,
                          device=device,
                          action="Verifying",
                          what=what)
        self.tasks.append(t)
        self.tasks.append(checksum.CRC32Task(tmppath))

        # encode to the final path + '.part'
        try:
            tmpoutpath = path + u'.part'
            open(tmpoutpath, 'wb').close()
        except IOError as e:
            if errno.ENAMETOOLONG != e.errno:
                raise
            path = common.shrinkPath(path)
            tmpoutpath = path + u'.part'
            open(tmpoutpath, 'wb').close()
        self._tmppath = tmpoutpath
        self.path = path

        from whipper.common import encode

        self.tasks.append(encode.FlacEncodeTask(tmppath, tmpoutpath))

        # MerlijnWajer: XXX: We run the CRC32Task on the wav file, because it's
        # in general stupid to run the CRC32 on the flac file since it already
        # has --verify. We should just get rid of this CRC32 step.
        # make sure our encoding is accurate
        self.tasks.append(checksum.CRC32Task(tmppath))
        self.tasks.append(encode.SoxPeakTask(tmppath))

        # TODO: Move tagging outside of cdparanoia
        self.tasks.append(encode.TaggingTask(tmpoutpath, taglist))

        self.checksum = None
Пример #3
0
    def __init__(self,
                 path,
                 table,
                 start,
                 stop,
                 overread,
                 offset=0,
                 device=None,
                 taglist=None,
                 what="track",
                 coverArtPath=None):
        """
        Init ReadVerifyTrackTask.

        :param path: where to store the ripped track
        :type path: str
        :param table: table of contents of CD
        :type table: table.Table
        :param start: first frame to rip
        :type start: int
        :param stop: last frame to rip (inclusive)
        :type stop: int
        :param offset: read offset, in samples
        :type offset: int
        :param device: the device to rip from
        :type device: str
        :param taglist: a dict of tags
        :type taglist: dict
        """
        task.MultiSeparateTask.__init__(self)

        logger.debug('creating read and verify task on %r', path)

        if taglist:
            logger.debug('read and verify with taglist %r', taglist)
        # FIXME: choose a dir on the same disk/dir as the final path
        fd, tmppath = tempfile.mkstemp(suffix='.whipper.wav')
        os.fchmod(fd, 0o644)
        os.close(fd)
        self._tmpwavpath = tmppath

        from whipper.common import checksum

        self.tasks = []
        self.tasks.append(
            ReadTrackTask(tmppath,
                          table,
                          start,
                          stop,
                          overread,
                          offset=offset,
                          device=device,
                          what=what))
        self.tasks.append(checksum.CRC32Task(tmppath))
        t = ReadTrackTask(tmppath,
                          table,
                          start,
                          stop,
                          overread,
                          offset=offset,
                          device=device,
                          action="Verifying",
                          what=what)
        self.tasks.append(t)
        self.tasks.append(checksum.CRC32Task(tmppath))

        # encode to the final path + '.part'
        try:
            tmpoutpath = path + '.part'
            open(tmpoutpath, 'wb').close()
        except IOError as e:
            if errno.ENAMETOOLONG != e.errno:
                raise
            path = common.truncate_filename(common.shrinkPath(path))
            tmpoutpath = common.truncate_filename(path + '.part')
            open(tmpoutpath, 'wb').close()
        self._tmppath = tmpoutpath
        self.path = path

        from whipper.common import encode

        self.tasks.append(encode.FlacEncodeTask(tmppath, tmpoutpath))

        # MerlijnWajer: XXX: We run the CRC32Task on the wav file, because it's
        # in general stupid to run the CRC32 on the flac file since it already
        # has --verify. We should just get rid of this CRC32 step.
        # make sure our encoding is accurate
        self.tasks.append(checksum.CRC32Task(tmppath))
        self.tasks.append(encode.SoxPeakTask(tmppath))

        # TODO: Move tagging and embed picture outside of cdparanoia
        self.tasks.append(encode.TaggingTask(tmpoutpath, taglist))
        self.tasks.append(encode.EmbedPictureTask(tmpoutpath, coverArtPath))

        self.checksum = None