def _do_encode(self, track): src = 'track%02d.wav' % track dst = 'track%02d.flac' % track ret = subprocess.call(self.FLAC + ['-o', dst, src]) if ret != 0: self.ui.error('flac exited with code %d' % ret) raise error.Abort()
def get_release(self, disc_info): self.ui.status('Disc ID: %s\n' % disc_info.id) self.ui.status('Searching for release info...') try: release_info = musicbrainz.get_releases_by_discid( disc_info.id, includes=['artists', 'recordings', 'labels']) except urllib2.HTTPError, ex: if ex.getcode() == 404: submit = disc.getSubmissionUrl(disc_info) self.ui.error('Release info not found!') self.ui.info('Submit info at: %s' % submit) raise error.Abort() raise
def _get_metadata(self): q = query.Query(self.opt, self.ui) disc = q.get_disc() if self.tracks: last = len(disc.tracks) bad = [str(i) for i in xrange(len(disc.tracks)) if i > last] if bad: self.ui.error('Invalid track numbers: %s' % ' '.join(bad)) raise error.Abort() else: self.tracks = range(len(disc.tracks)) return q.get_release(disc)
def _rip_track(self, track): path = 'track%02d.wav' % track cmd = ['cdparanoia', '-d', self.opt.device] if self.opt.disable_paranoia: cmd.append('--disable-paranoia') if self.opt.abort_on_skip: cmd.append('--abort-on-skip') cmd.append(str(track)) cmd.append(path) ret = subprocess.call(cmd) if ret != 0: self.ui.error('cdparanoia exited with code %d' % ret) raise error.Abort() return path
def rip(self): self.metadata = self._get_metadata() self._pre_summary() if not self.ui.yesno('OK?'): raise error.Abort() analyzer = replaygain.ReplayGain() encoders = [flac.FlacEncoder(self.opt, self.ui)] for track in self.tracks: track_data = self.metadata.disc['track-dict'][track] self.ui.status('Ripping track %02d. %s...' % (track, track_data['recording']['title'])) path = self._rip_track(track) track_gain = analyzer.analyze_track(path) track_data['replaygain-track-gain'] = track_gain.gain track_data['replaygain-track-peak'] = track_gain.peak self.ui.status('Encoding track %02d. %s...' % (track, track_data['recording']['title'])) for encoder in encoders: encoder.encode(track) album_gain = analyzer.analyze_album() self.metadata['replaygain-album-gain'] = album_gain.gain self.metadata['replaygain-album-peak'] = album_gain.peak self.metadata['replaygain-reference-loudness'] = \ replaygain.REFERENCE_LOUDNESS self.ui.status('Waiting for encoder(s) to finish...') for encoder in encoders: encoder.wait() for track in self.tracks: track_data = self.metadata.disc['track-dict'][track] self.ui.status('Tagging track %02d. %s...' % (track, track_data['recording']['title'])) for encoder in encoders: encoder.tag(track, self.metadata) import pprint, os pprint.pprint(self.metadata) os.system("ls -la")
class Query(object): @classmethod def add_options(cls, parser): pass def __init__(self, opt, ui): self.ui = ui self.device = opt.device def get_disc(self): self.ui.status('Reading %s TOC...' % self.device) return disc.readDisc(self.device) def get_release(self, disc_info): self.ui.status('Disc ID: %s\n' % disc_info.id) self.ui.status('Searching for release info...') try: release_info = musicbrainz.get_releases_by_discid( disc_info.id, includes=['artists', 'recordings', 'labels']) except urllib2.HTTPError, ex: if ex.getcode() == 404: submit = disc.getSubmissionUrl(disc_info) self.ui.error('Release info not found!') self.ui.info('Submit info at: %s' % submit) raise error.Abort() raise releases = release_info['disc']['release-list'] # Version 1 of the API provided partial results from # CDDB but I'm not sure about version 2 yet... assert all(r['id'] for r in releases) releases.sort(key=self._fmt_release) self.ui.status("Found %s possible release(s)" % len(releases)) chosen = self.ui.choose('Release', releases, self._fmt_release) info = ReleaseInfo(disc_info.id, chosen['id']) # XXX: does the disc info include data tracks? if len(info.disc['track-list']) != len(disc_info.tracks): self.ui.error('Disc and metadata mismatch!') raise error.Abort() return info