def writeLog(self, discName, txt_logger): logPath = common.truncate_filename(discName + '.log') handle = open(logPath, 'w') log = txt_logger.log(self.result) handle.write(log) handle.close() self.logPath = logPath return logPath
def writeCue(self, discName): assert self.result.table.canCue() cuePath = common.truncate_filename(discName + '.cue') logger.debug('write .cue file to %s', cuePath) handle = open(cuePath, 'w') # FIXME: do we always want utf-8 ? handle.write(self.result.table.cue(cuePath)) handle.close() self.cuePath = cuePath return cuePath
def _done(self): self.setProgress(1.0) self.toc = TocFile(self.tocfile) self.toc.parse() if self.toc_path is not None: t_comp = os.path.abspath(self.toc_path).split(os.sep) t_dirn = os.sep.join(t_comp[:-1]) # If the output path doesn't exist, make it recursively os.makedirs(t_dirn, exist_ok=True) t_dst = truncate_filename(os.path.join(t_dirn, t_comp[-1] + '.toc')) shutil.copy(self.tocfile, os.path.join(t_dirn, t_dst)) os.unlink(self.tocfile) self.stop() return
def _done(self): self.setProgress(1.0) self.toc = TocFile(self.tocfile) self.toc.parse() if self.toc_path is not None: t_comp = os.path.abspath(self.toc_path).split(os.sep) t_dirn = os.sep.join(t_comp[:-1]) # If the output path doesn't exist, make it recursively try: os.makedirs(t_dirn) logger.info("creating output directory %s", t_dirn) except FileExistsError as e: logger.debug(e) t_dst = truncate_filename(os.path.join(t_dirn, t_comp[-1] + '.toc')) shutil.copy(self.tocfile, os.path.join(t_dirn, t_dst)) os.unlink(self.tocfile) self.stop() return
def write_m3u(self, discname): m3uPath = common.truncate_filename(discname + '.m3u') with open(m3uPath, 'w') as f: f.write('#EXTM3U\n') for track in self.result.tracks: if not track.filename: # false positive htoa continue if track.number == 0: length = (self.result.table.getTrackStart(1) / common.FRAMES_PER_SECOND) else: length = (self.result.table.getTrackLength(track.number) / common.FRAMES_PER_SECOND) target_path = common.getRelativePath(track.filename, m3uPath) u = '#EXTINF:%d,%s\n' % (length, target_path) f.write(u) u = '%s\n' % target_path f.write(u)
def read_toc(device, fast_toc=False, toc_path=None): """ Return cdrdao-generated table of contents for 'device'. """ # cdrdao MUST be passed a non-existing filename as its last argument # to write the TOC to; it does not support writing to stdout or # overwriting an existing file, nor does linux seem to support # locking a non-existant file. Thus, this race-condition introducing # hack is carried from morituri to whipper and will be removed when # cdrdao is fixed. fd, tocfile = tempfile.mkstemp(suffix=u'.cdrdao.read-toc.whipper') os.close(fd) os.unlink(tocfile) cmd = [CDRDAO, 'read-toc'] + (['--fast-toc'] if fast_toc else []) + [ '--device', device, tocfile] # PIPE is the closest to >/dev/null we can get logger.debug("executing %r", cmd) p = Popen(cmd, stdout=PIPE, stderr=PIPE) _, stderr = p.communicate() if p.returncode != 0: msg = 'cdrdao read-toc failed: return code is non-zero: ' + \ str(p.returncode) logger.critical(msg) # Gracefully handle missing disc if "ERROR: Unit not ready, giving up." in stderr: raise EjectError(device, "no disc detected") raise IOError(msg) toc = TocFile(tocfile) toc.parse() if toc_path is not None: t_comp = os.path.abspath(toc_path).split(os.sep) t_dirn = os.sep.join(t_comp[:-1]) # If the output path doesn't exist, make it recursively if not os.path.isdir(t_dirn): os.makedirs(t_dirn) t_dst = truncate_filename(os.path.join(t_dirn, t_comp[-1] + '.toc')) shutil.copy(tocfile, os.path.join(t_dirn, t_dst)) os.unlink(tocfile) return toc
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
def __init__(self, path, table, start, stop, overread, offset=0, device=None, taglist=None, what="track"): """ @param path: where to store the ripped track @type path: str @param table: table of contents of CD @type table: L{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') 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.truncate_filename(common.shrinkPath(path)) tmpoutpath = common.truncate_filename(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