Skip to content

Commit

Permalink
fix format & cleanup codes in tinytag.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace-Radom committed Nov 30, 2023
1 parent 2354ae5 commit 92ca484
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tinytag/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@
# APE
('samples/ape-44100-16-1.ape',
{'extra': {'Copyright': 'nope'}, 'channels': 1,
'duration': 1.131, 'filesize': 22990, 'bitrate': 162.666399261963, 'samplerate': 44100,
'duration': 1.131, 'filesize': 22990, 'bitrate': 162.666399261963, 'samplerate': 44100,
'bitdepth': 16,
'title': 'ape-44100-16-1', 'artist': 'Ace-Radom', 'album': 'ar', 'albumartist': 'nope',
'comment': 'Only one sample for tinytag, all metadatas are nonsense',
Expand Down
39 changes: 17 additions & 22 deletions tinytag/tinytag.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,12 +1479,25 @@ def _determine_duration(self, fh):


class APE(TinyTag):
apetag_mapping = {
'title': 'title',
'artist': 'artist',
'album': 'album',
'album artist': 'albumartist',
'comment': 'comment',
'composer': 'composer',
'disc': 'disc',
'discnumber': 'disc',
'genre': 'genre',
'track': 'track',
'tracknumber': 'track',
'year': 'year'
}

def __init__(self, filehandler, filesize, *args, **kwargs):
TinyTag.__init__(self, filehandler, filesize, *args, **kwargs)
self._tags_parsed = False

_fver = -1
_header_parsed = False
self._fver = -1
self._header_parsed = False

def _parse_header(self, fh):
fh.seek(0, os.SEEK_SET)
Expand Down Expand Up @@ -1561,7 +1574,6 @@ def _parse_tag(self, fh):
pos -= 1024
# find APETAG footer begin pos.
if pos < 0:
self._tags_parsed = True
return
# not found

Expand Down Expand Up @@ -1592,23 +1604,6 @@ def _parse_tag(self, fh):
# same as before: decode with utf-8 for compatibility
self._update_meta(this_item_key, this_item_value)

self._tags_parsed = True

apetag_mapping = {
'title': 'title',
'artist': 'artist',
'album': 'album',
'album artist': 'albumartist',
'comment': 'comment',
'composer': 'composer',
'disc': 'disc',
'discnumber': 'disc',
'genre': 'genre',
'track': 'track',
'tracknumber': 'track',
'year': 'year'
}

def _update_meta(self, key, value):
# the key name of apetag (especially apev2) is really casual
# there's no restrictive rules so far as I know
Expand Down

0 comments on commit 92ca484

Please sign in to comment.