Beispiel #1
0
    def __init__(self):
        sys.path.append('python-audio-tools')

        import audiotools
        import audiotools.accuraterip

        cd_drive = os.path.realpath('/dev/cdrom')

        names = []
        for i, track in enumerate(cd):
            md = meta[0][i]
            filename = '{1} - {0} - {2}.mp3'.format(md.track_number,
                                                    md.artist_name,
                                                    md.track_name)
            names.append(filename)

        format = audiotools.TYPE_MAP['mp3']
        quali = 'standard'

        track = cd[1]
        ripper = audiotools.accuraterip.AccurateRipReader(track)

        md = meta[0][i]

        options = OptionParser()
        msg = audiotools.Messenger('cdaudio', options)
        prog = audiotools.SingleProgressDisplay(msg, filename)
        riprog = audiotools.PCMReaderProgress(ripper,
                                              track.length() * (44100 / 75),
                                              update)  #prog.update)

        format.from_pcm(filename,
                        riprog,
                        quali,
                        total_pcm_frames=track.length() * (44100 / 75))
Beispiel #2
0
    def _open_file(self, filename):
        """Open a file for reading and wrap it in several helpers."""
        # Audiotools seems to hate unicode, so we.. don't give it that
        if isinstance(filename, unicode):
            filename = filename.encode('utf8')

        try:
            reader = audiotools.open(filename)
        except (audiotools.UnsupportedFile):
            raise AudioError("Unsupported file")

        self.file = reader
        total_frames = reader.total_frames()

        # Wrap in a PCMReader because we want PCM
        reader = reader.to_pcm()

        # Wrap in a converter
        reader = audiotools.PCMConverter(
            reader,
            sample_rate=44100,
            channels=2,
            channel_mask=audiotools.ChannelMask(0x1 | 0x2),
            bits_per_sample=24,
        )

        # And for file progress!
        reader = audiotools.PCMReaderProgress(reader, total_frames,
                                              self.progress)

        return reader
Beispiel #3
0
    def add_intro_outtro(self):
        '''
        Please add the intro and outro clips.
        http://audiotools.sourceforge.net/install.html
        prepend intro.flac
        append outro.flac
        '''

        output_filename = self.get_filename() + ".flac"
        if (os.path.exists(output_filename)):
            return

        output_filename = audiotools.Filename(output_filename)

        intro = audiotools.open_files(['intro.flac'])
        content = audiotools.open_files([self.input_file])
        outro = audiotools.open_files(['outro.flac'])

        audiofiles = [
            intro[0],
            content[0],
            outro[0],
        ]

        AudioType = audiotools.filename_to_type("intro.flac")
        metadata = content[0].get_metadata()
        output_class = AudioType
        #print audiofiles
        pcms = ([af.to_pcm() for af in audiofiles])
        #print [r.bits_per_sample for r in pcms]

        encoded = output_class.from_pcm(
            str(output_filename),
            audiotools.PCMReaderProgress(
                audiotools.PCMCat(pcms),
                sum([af.total_frames() for af in audiofiles]),
                progress_update),
            #output_quality,
            total_pcm_frames=sum([af.total_frames() for af in audiofiles]))
        encoded.set_metadata(metadata)

        self.set_intro_added()
Beispiel #4
0
def accuraterip_image_checksum(progress, track, is_first, is_last, ar_matches,
                               displayed_filename, pcm_frames_offset,
                               total_pcm_frames):
    from audiotools import (transfer_data, PCMReaderProgress, PCMReaderWindow)
    from audiotools.accuraterip import Checksum, match_offset

    reader = track.to_pcm()

    pcm_frames_offset -= PREVIOUS_TRACK_FRAMES

    # if PCMReader has seek(), use it to reduce the amount of frames to skip
    if (hasattr(reader, "seek") and callable(reader.seek)
            and (pcm_frames_offset > 0)):
        pcm_frames_offset -= reader.seek(pcm_frames_offset)

    # feed stream to checksummers
    checksummer = Checksum(total_pcm_frames=total_pcm_frames,
                           sample_rate=track.sample_rate(),
                           is_first=is_first,
                           is_last=is_last,
                           pcm_frame_range=PREVIOUS_TRACK_FRAMES + 1 +
                           NEXT_TRACK_FRAMES,
                           accurateripv2_offset=PREVIOUS_TRACK_FRAMES)

    try:
        pcmreader = audiotools.PCMReaderProgress(
            audiotools.PCMReaderWindow(
                reader, pcm_frames_offset,
                PREVIOUS_TRACK_FRAMES + total_pcm_frames + NEXT_TRACK_FRAMES),
            PREVIOUS_TRACK_FRAMES + total_pcm_frames + NEXT_TRACK_FRAMES,
            progress)

        audiotools.transfer_data(pcmreader.read, checksummer.update)
    except (IOError, ValueError) as err:
        return {
            "filename": displayed_filename,
            "error": str(err),
            "v1": {
                "checksum": None,
                "offset": None,
                "confidence": None
            },
            "v2": {
                "checksum": None,
                "offset": None,
                "confidence": None
            }
        }

    # determine checksum, confidence and offset from
    # the calculated checksums and possible AccurateRip matches
    (checksum_v2, confidence_v2,
     offset_v2) = match_offset(ar_matches=ar_matches,
                               checksums=[checksummer.checksum_v2()],
                               initial_offset=0)

    (checksum_v1, confidence_v1,
     offset_v1) = match_offset(ar_matches=ar_matches,
                               checksums=checksummer.checksums_v1(),
                               initial_offset=-PREVIOUS_TRACK_FRAMES)

    if len(ar_matches) == 0:
        return {
            "filename": displayed_filename,
            "error": None,
            "v1": {
                "checksum": checksum_v1,
                "offset": offset_v1,
                "confidence": AR_NOT_FOUND
            },
            "v2": {
                "checksum": checksum_v2,
                "offset": offset_v2,
                "confidence": AR_NOT_FOUND
            }
        }
    else:
        return {
            "filename": displayed_filename,
            "error": None,
            "v1": {
                "checksum":
                checksum_v1,
                "offset":
                offset_v1,
                "confidence": (confidence_v1 if
                               (confidence_v1 is not None) else AR_MISMATCH)
            },
            "v2": {
                "checksum":
                checksum_v2,
                "offset":
                offset_v2,
                "confidence": (confidence_v2 if
                               (confidence_v2 is not None) else AR_MISMATCH)
            }
        }
Beispiel #5
0
#statusbar.pack(fill=gui.X, side=gui.BOTTOM)

sys.exit(0)


def update(current, total):
    print '\r', current, total


format = audiotools.TYPE_MAP['mp3']
quali = 'standard'

track = cd[1]
ripper = audiotools.accuraterip.AccurateRipReader(track)

md = meta[0][i]

options = OptionParser()
msg = audiotools.Messenger('cdaudio', options)
prog = audiotools.SingleProgressDisplay(msg, filename)
riprog = audiotools.PCMReaderProgress(ripper,
                                      track.length() * (44100 / 75),
                                      update)  #prog.update)

format.from_pcm(filename,
                riprog,
                quali,
                total_pcm_frames=track.length() * (44100 / 75))

print 'done!'