def __init__(self, image): task.MultiSeparateTask.__init__(self) self._image = image cue = image.cue self._tasks = [] self.lengths = {} try: htoa = cue.table.tracks[0].indexes[0] track = cue.table.tracks[0] path = image.getRealPath(htoa.path) assert type(path) is unicode, "%r is not unicode" % path logger.debug('schedule scan of audio length of %r', path) taskk = AudioLengthTask(path) self.addTask(taskk) self._tasks.append((0, track, taskk)) except (KeyError, IndexError): logger.debug('no htoa track') for trackIndex, track in enumerate(cue.table.tracks): logger.debug('verifying track %d', trackIndex + 1) index = track.indexes[1] length = cue.getTrackLength(track) if length == -1: path = image.getRealPath(index.path) assert type(path) is unicode, "%r is not unicode" % path logger.debug('schedule scan of audio length of %r', path) taskk = AudioLengthTask(path) self.addTask(taskk) self._tasks.append((trackIndex + 1, track, taskk)) else: logger.debug('track %d has length %d', trackIndex + 1, length)
def __init__(self, image): task.MultiSeparateTask.__init__(self) self._image = image # XXX: Pylint, redefining name 'cue' from outer scope (import) cue = image.cue self._tasks = [] self.lengths = {} try: htoa = cue.table.tracks[0].indexes[0] track = cue.table.tracks[0] path = image.getRealPath(htoa.path) assert isinstance(path, str), "%r is not str" % path logger.debug('schedule scan of audio length of %r', path) taskk = AudioLengthTask(path) self.addTask(taskk) self._tasks.append((0, track, taskk)) except (KeyError, IndexError): logger.debug('no HTOA track') for trackIndex, track in enumerate(cue.table.tracks): logger.debug('verifying track %d', trackIndex + 1) index = track.indexes[1] length = cue.getTrackLength(track) if length == -1: path = image.getRealPath(index.path) assert isinstance(path, str), "%r is not str" % path logger.debug('schedule scan of audio length of %r', path) taskk = AudioLengthTask(path) self.addTask(taskk) self._tasks.append((trackIndex + 1, track, taskk)) else: logger.debug('track %d has length %d', trackIndex + 1, length)
def testAbsentFile(self): tempdir = tempfile.mkdtemp() path = os.path.join(tempdir, "nonexistent.flac") t = AudioLengthTask(path) runner = task.SyncRunner() self.assertRaises(task.TaskException, runner.run, t, verbose=False) os.rmdir(tempdir)
def _testSuffix(self, suffix): fd, path = tempfile.mkstemp(suffix=suffix) with os.fdopen(fd, "wb") as temptrack: temptrack.write(open(base_track_file, "rb").read()) t = AudioLengthTask(path) runner = task.SyncRunner() runner.run(t, verbose=False) self.assertEquals(t.length, base_track_length) os.unlink(path)
def testLength(self): path = base_track_file t = AudioLengthTask(path) runner = task.SyncRunner() runner.run(t, verbose=False) self.assertEqual(t.length, base_track_length)