Commits

Virgil Dupras  committed ba19cc5

Fix reading of small (<64kb) OGG files. Fixes #2.

  • Participants
  • Parent commits 373e824

Comments (0)

Files changed (3)

File hsaudiotag/ogg.py

         
         #Seek last page to get sample count. It's impossible to not have at least one page in
         #the last 64kb.
-        fp.seek(-0x10000, 2)
+        SEEK_OFFSET = min(0x10000, self.size)
+        fp.seek(-SEEK_OFFSET, 2)
         last_data = fp.read()
         last_offset = last_data.rfind(VorbisPage.OGG_PAGE_ID)
-        to_seek = 0x10000 - last_offset
+        to_seek = SEEK_OFFSET - last_offset
         fp.seek(-to_seek, 2)
         page = VorbisPage(fp)
         if not page.valid:

File hsaudiotag/tests/ogg_test.py

     o = ogg.Vorbis(TestData.filepath('ogg/track_with_slash.ogg'))
     eq_(o.track, 18)
 
+def test_small():
+    # Previously, a small (<64kb) OGG file couldn't be read due to a hardcoded 64kb offset. Tix #2.
+    o = ogg.Vorbis(TestData.filepath('ogg/small.ogg'))
+    eq_(o.bitrate, 60)
+    eq_(o.duration, 4)
+
 def verify_emptyness(o):
     eq_(0, o.bitrate)
     eq_(0, o.sample_rate)

File hsaudiotag/tests/testdata/ogg/small.ogg

Binary file added.