Commits

Virgil Dupras  committed d81119f

Support values like "1/8" in OGG's TRACKNUMBER field. Fixes #1.

  • Participants
  • Parent commits a592010

Comments (0)

Files changed (3)

File hsaudiotag/ogg.py

 # http://www.hardcoded.net/licenses/bsd_license
 
 from struct import unpack
+import re
 
 from .util import FileOrPath
 
+RE_STARTS_WITH_DIGIT = re.compile(r"^\d+")
+
 class InvalidFileError(Exception):
     pass
 
         self.album = get_field(b'ALBUM')
         self.title = get_field(b'TITLE')
         self.genre = get_field(b'GENRE')
-        self.track = int(meta_data.get(b'TRACKNUMBER', 0))
+        track_str = get_field(b'TRACKNUMBER')
+        m = RE_STARTS_WITH_DIGIT.match(track_str)
+        self.track = int(m.group(0)) if m else 0
         self.comment = get_field(b'COMMENT')
         self.year = get_field(b'DATE')
         if not self.year:

File hsaudiotag/tests/ogg_test.py

     eq_(o.album, 'The White Stripes')
     eq_(o.title, 'Astro')
 
+def test_track_with_slash():
+    # A track number field with a slash (for example, 1/20) is supported and will return the first
+    # number of the field.
+    # FILE NOTE: Because I had added 4 bytes to the TRACKNUMBER field in the test file and that I
+    # wasn't sure where I had to adjust the vorbis comment offset other than just in front of the
+    # field, I removed 4 bytes in the otherwise unused TRACKTOTAL (now TRACKT) field.
+    o = ogg.Vorbis(TestData.filepath('ogg/track_with_slash.ogg'))
+    eq_(o.track, 18)
+
 def verify_emptyness(o):
     eq_(0, o.bitrate)
     eq_(0, o.sample_rate)

File hsaudiotag/tests/testdata/ogg/track_with_slash.ogg

Binary file added.