def test_find_last_none_finishing_mux(self): page1 = OggPage() page1.last = True page1.position = -1 page2 = OggPage() page2.serial = page1.serial + 1 pages = [page1, page2] data = BytesIO(b"".join([page.write() for page in pages])) assert OggPage.find_last(data, page1.serial, finishing=True) is None assert OggPage.find_last(data, page2.serial, finishing=True) == page2
def test_find_last_last_empty(self): # https://github.com/quodlibet/mutagen/issues/308 pages = [OggPage() for i in xrange(10)] for i, page in enumerate(pages): page.sequence = i page.position = i pages[-1].last = True pages[-1].position = -1 data = BytesIO(b"".join([page.write() for page in pages])) page = OggPage.find_last(data, pages[-1].serial, finishing=True) assert page is not None assert page.position == 8 page = OggPage.find_last(data, pages[-1].serial, finishing=False) assert page is not None assert page.position == -1
def test_find_last_really_last(self): pages = [OggPage() for i in range(10)] pages[-1].last = True for i, page in enumerate(pages): page.sequence = i data = BytesIO(bytearray().join([page.write() for page in pages])) self.failUnlessEqual( OggPage.find_last(data, pages[0].serial), pages[-1])
def _post_tags(self, fileobj): if self.length: return page = OggPage.find_last(fileobj, self.serial, finishing=True) if page is None: raise OggFLACHeaderError self.length = page.position / float(self.sample_rate)
def _post_tags(self, fileobj): """Raises ogg.error""" page = OggPage.find_last(fileobj, self.serial, finishing=True) if page is None: raise OggVorbisHeaderError self.length = page.position / float(self.sample_rate)
def _post_tags(self, fileobj): """Raises ogg.error""" page = OggPage.find_last(fileobj, self.serial) if page is None: raise OggVorbisHeaderError self.length = page.position / float(self.sample_rate)
def test_find_last(self): pages = [OggPage() for i in range(10)] for i, page in enumerate(pages): page.sequence = i data = BytesIO(b"".join([page.write() for page in pages])) self.failUnlessEqual(OggPage.find_last(data, pages[0].serial), pages[-1])
def test_find_last(self): pages = [OggPage() for i in xrange(10)] for i, page in enumerate(pages): page.sequence = i data = BytesIO(b"".join([page.write() for page in pages])) self.failUnlessEqual( OggPage.find_last(data, pages[0].serial), pages[-1])
def test_find_last_single_muxed(self): page1 = OggPage() page1.last = True page2 = OggPage() page2.serial = page1.serial + 1 pages = [page1, page2] data = BytesIO(b"".join([page.write() for page in pages])) assert OggPage.find_last(data, page2.serial).serial == page2.serial
def _post_tags(self, fileobj): page = OggPage.find_last(fileobj, self.serial) if page is None: raise OggTheoraHeaderError position = page.position mask = (1 << self.granule_shift) - 1 frames = (position >> self.granule_shift) + (position & mask) self.length = frames / float(self.fps)
def test_find_last_muxed(self): pages = [OggPage() for i in range(10)] for i, page in enumerate(pages): page.sequence = i pages[-2].last = True pages[-1].serial = pages[0].serial + 1 data = StringIO("".join([page.write() for page in pages])) self.failUnlessEqual( OggPage.find_last(data, pages[0].serial), pages[-2])
def test_find_last_really_last(self): pages = [OggPage() for i in range(10)] pages[-1].last = True for i, page in enumerate(pages): page.sequence = i data = StringIO("".join([page.write() for page in pages])) self.failUnlessEqual(OggPage.find_last(data, pages[0].serial), pages[-1])
def _post_tags(self, fileobj): page = OggPage.find_last(fileobj, self.serial, finishing=True) if page is None: raise OggTheoraHeaderError position = page.position mask = (1 << self.granule_shift) - 1 frames = (position >> self.granule_shift) + (position & mask) self.length = frames / float(self.fps)
def load(self, fp): self.filename = fp.name fileobj = fp try: try: self.info = self._Info(fileobj) self.tags = self._Tags(fileobj, self.info) if self.info.length: return last_page = OggPage.find_last(fileobj, self.info.serial) samples = last_page.position try: denom = self.info.sample_rate except AttributeError: denom = self.info.fps self.info.length = samples / float(denom) except OggError, e: raise self._Error, e, sys.exc_info()[2] except EOFError: raise self._Error, "no appropriate stream found"
def test_find_last_none_finishing(self): page = OggPage() page.position = -1 data = BytesIO(page.write()) assert OggPage.find_last(data, page.serial, finishing=True) is None
def _post_tags(self, fileobj): page = OggPage.find_last(fileobj, self.serial) self.length = (page.position - self.__pre_skip) / float(48000)
def _post_tags(self, fileobj): page = OggPage.find_last(fileobj, self.serial) position = page.position mask = (1 << self.granule_shift) - 1 frames = (position >> self.granule_shift) + (position & mask) self.length = frames / float(self.fps)
def test_find_last_no_serial(self): pages = [OggPage() for i in xrange(10)] for i, page in enumerate(pages): page.sequence = i data = BytesIO(b"".join([page.write() for page in pages])) self.failUnless(OggPage.find_last(data, pages[0].serial + 1) is None)
def _post_tags(self, fileobj): page = OggPage.find_last(fileobj, self.serial) self.length = page.position / float(self.sample_rate)
def _post_tags(self, fileobj): page = OggPage.find_last(fileobj, self.serial) if page is None: raise OggSpeexHeaderError self.length = page.position / float(self.sample_rate)
def test_find_last_invalid_sync(self): data = BytesIO(b"if you think this is an OggS, you're crazy") page = OggPage.find_last(data, 0) self.failIf(page)
def _post_tags(self, fileobj): if self.length: return page = OggPage.find_last(fileobj, self.serial) self.length = page.position / self.sample_rate
def _post_tags(self, fileobj): page = OggPage.find_last(fileobj, self.serial) if page is None: raise OggOpusHeaderError self.length = (page.position - self.__pre_skip) / float(48000)
def _post_tags(self, fileobj): page = OggPage.find_last(fileobj, self.serial, finishing=True) if page is None: raise OggOpusHeaderError self.length = (page.position - self.__pre_skip) / float(48000)
def test_find_last_no_serial(self): pages = [OggPage() for i in range(10)] for i, page in enumerate(pages): page.sequence = i data = BytesIO(bytearray().join([page.write() for page in pages])) self.failUnless(OggPage.find_last(data, pages[0].serial + 1) is None)