Skip to content

Commit

Permalink
ogg: Always search for the last page finishing a packet to get the la…
Browse files Browse the repository at this point in the history
…st abolsute granule position. Fixes quodlibet#308

This fixes cases where the length of the ogg stream was reported as some small negative value.
  • Loading branch information
lazka committed Jun 1, 2017
1 parent da39c1e commit b09768e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion mutagen/oggflac.py
Expand Up @@ -79,7 +79,9 @@ def __init__(self, fileobj):
def _post_tags(self, fileobj):
if self.length:
return
page = OggPage.find_last(fileobj, self.serial)
page = OggPage.find_last(fileobj, self.serial, finishing=True)
if page is None:
raise OggFLACHeaderError
self.length = page.position / float(self.sample_rate)

def pprint(self):
Expand Down
2 changes: 1 addition & 1 deletion mutagen/oggopus.py
Expand Up @@ -69,7 +69,7 @@ def __init__(self, fileobj):
raise OggOpusHeaderError("version %r unsupported" % major)

def _post_tags(self, fileobj):
page = OggPage.find_last(fileobj, self.serial)
page = OggPage.find_last(fileobj, self.serial, finishing=True)
if page is None:
raise OggOpusHeaderError
self.length = (page.position - self.__pre_skip) / float(48000)
Expand Down
2 changes: 1 addition & 1 deletion mutagen/oggspeex.py
Expand Up @@ -64,7 +64,7 @@ def __init__(self, fileobj):
self.serial = page.serial

def _post_tags(self, fileobj):
page = OggPage.find_last(fileobj, self.serial)
page = OggPage.find_last(fileobj, self.serial, finishing=True)
if page is None:
raise OggSpeexHeaderError
self.length = page.position / float(self.sample_rate)
Expand Down
2 changes: 1 addition & 1 deletion mutagen/oggtheora.py
Expand Up @@ -67,7 +67,7 @@ def __init__(self, fileobj):
self.serial = page.serial

def _post_tags(self, fileobj):
page = OggPage.find_last(fileobj, self.serial)
page = OggPage.find_last(fileobj, self.serial, finishing=True)
if page is None:
raise OggTheoraHeaderError
position = page.position
Expand Down
2 changes: 1 addition & 1 deletion mutagen/oggvorbis.py
Expand Up @@ -83,7 +83,7 @@ def __init__(self, fileobj):
def _post_tags(self, fileobj):
"""Raises ogg.error"""

page = OggPage.find_last(fileobj, self.serial)
page = OggPage.find_last(fileobj, self.serial, finishing=True)
if page is None:
raise OggVorbisHeaderError
self.length = page.position / float(self.sample_rate)
Expand Down

0 comments on commit b09768e

Please sign in to comment.