Skip to content

Commit

Permalink
Merge 26e7750 into 2d4f9bb
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnd committed Oct 4, 2018
2 parents 2d4f9bb + 26e7750 commit 4e2cd73
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -6,7 +6,6 @@

language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
Expand All @@ -16,7 +15,6 @@ python:
# command to install dependencies
install:
- "pip install coveralls"
- "if [[ $TRAVIS_PYTHON_VERSION = 2.6 ]]; then pip install unittest2; fi"

# command to run tests
script:
Expand Down
Binary file added tinytag/tests/samples/test-riff-tags.wav
Binary file not shown.
4 changes: 2 additions & 2 deletions tinytag/tests/test.py
Expand Up @@ -53,7 +53,8 @@
# WAV
('samples/test.wav', {'duration': 1.0, 'filesize': 176444, 'bitrate': 1378.125, 'samplerate': 44100, 'audio_offest': 36}),
('samples/test3sMono.wav', {'duration': 3.0, 'filesize': 264644, 'bitrate': 689.0625, 'duration': 3.0, 'samplerate': 44100, 'audio_offest': 36}),
('samples/test-tagged.wav', {'duration': 1.0, 'filesize': 176688, 'album': 'thealbum', 'artist': 'theartisst', 'bitrate': 1378.125, 'genre': 'Acid', 'samplerate': 44100, 'title': 'thetitle', 'track': '66', 'audio_offest': 36}),
('samples/test-tagged.wav', {'duration': 1.0, 'filesize': 176688, 'album': 'thealbum', 'artist': 'theartisst', 'bitrate': 1378.125, 'genre': 'Acid', 'samplerate': 44100, 'title': 'thetitle', 'track': '66', 'audio_offest': 36, 'comment': 'hello', 'year': '2014'}),
('samples/test-riff-tags.wav', {'duration': 1.0, 'filesize': 176540, 'album': None, 'artist': 'theartisst', 'bitrate': 1378.125, 'genre': 'Acid', 'samplerate': 44100, 'title': 'thetitle', 'track': None, 'audio_offest': 36, 'comment': 'hello', 'year': '2014'}),
('samples/silence-22khz-mono-1s.wav', {'duration': 1.0, 'filesize': 48160, 'bitrate': 344.53125, 'samplerate': 22050, 'audio_offest': 4088}),

# FLAC
Expand Down Expand Up @@ -149,7 +150,6 @@ def test_unsubclassed_tinytag_parse_tag():
def test_mp3_length_estimation():
ID3.set_estimation_precision(0.7)
tag = TinyTag.get(os.path.join(testfolder, 'samples/silence-44-s-v1.mp3'))
print(tag.duration)
assert 3.5 < tag.duration < 4.0

@raises(TinyTagException)
Expand Down
28 changes: 28 additions & 0 deletions tinytag/tinytag.py
Expand Up @@ -794,6 +794,19 @@ def _parse_pages(self, fh):


class Wave(TinyTag):
riff_mapping = {
b'INAM': 'title',
b'TITL': 'title',
b'IART': 'artist',
b'ICMT': 'comment',
b'ICRD': 'year',
b'IGNR': 'genre',
b'TRCK': 'track',
b'PRT1': 'track',
b'PRT2': 'track_number',
b'YEAR': 'year',
}

def __init__(self, filehandler, filesize):
TinyTag.__init__(self, filehandler, filesize)
self._duration_parsed = False
Expand All @@ -816,6 +829,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 4e2cd73

Please sign in to comment.