Skip to content

Commit

Permalink
RIFF parser WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnd committed Jul 24, 2018
1 parent 164a90f commit 1bcf9da
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tinytag/tinytag.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,14 @@ def _parse_pages(self, fh):


class Wave(TinyTag):
riff_mapping = {
'INAM': 'title',
'IART': 'artist',
'ICMT': 'comment',
'ICRD': 'year',
'IGNR': 'genre',
}

def __init__(self, filehandler, filesize):
TinyTag.__init__(self, filehandler, filesize)
self._duration_parsed = False
Expand All @@ -811,6 +819,21 @@ def _determine_duration(self, fh):
self.duration = float(subchunksize)/channels/self.samplerate/(bitdepth/8)
self.audio_offest = fh.tell() - 8 # rewind to data header
fh.seek(subchunksize, 1)
elif subchunkid == b'LIST':
is_info = fh.read(4) # check INFO header
if is_info != b'INFO': # jump over non-INFO sections
fh.seek(subchunksize - 4, os.SEEK_CUR)
continue
sub_fh = BytesIO(fh.read(subchunksize - 4))
field = sub_fh.read(4)
while len(field):
data_length = struct.unpack('I', sub_fh.read(4))[0]
data = sub_fh.read(data_length).split(b'\x00', 1)[0] # strip zero-byte
data = codecs.decode(data, 'utf-8')
fieldname = self.riff_mapping.get(field)
if fieldname:
self._set_field(fieldname, data)
field = sub_fh.read(4)
elif subchunkid == b'id3 ' or subchunkid == b'ID3 ':
id3 = ID3(fh, 0)
id3._parse_id3v2(fh)
Expand Down

0 comments on commit 1bcf9da

Please sign in to comment.