|
1 | 1 | #!/usr/bin/env python |
2 | | -#!/usr/bin/env python |
3 | 2 | # -*- coding: utf-8 -*- |
4 | | -# |
| 3 | + |
5 | 4 | # tinytag - an audio meta info reader |
6 | 5 | # Copyright (c) 2014-2018 Tom Wallroth |
7 | 6 | # |
|
43 | 42 | from io import BytesIO |
44 | 43 | import re |
45 | 44 |
|
46 | | -DEBUG = os.environ.get('DEBUG', False) # some of the parsers will print some debug info when set to True |
| 45 | +DEBUG = os.environ.get('DEBUG', False) # some of the parsers can print debug info |
47 | 46 |
|
48 | 47 |
|
49 | 48 | class TinyTagException(LookupError): # inherit LookupError for backwards compat |
@@ -74,7 +73,7 @@ def _bytes_to_int(b): |
74 | 73 | class TinyTag(object): |
75 | 74 | def __init__(self, filehandler, filesize, ignore_errors=False): |
76 | 75 | if isinstance(filehandler, str): |
77 | | - raise Exception('Please use `TinyTag.get(filepath)` instead of `TinyTag(filepath)` to pass a filepath') |
| 76 | + raise Exception('Use `TinyTag.get(filepath)` instead of `TinyTag(filepath)`') |
78 | 77 | self._filehandler = filehandler |
79 | 78 | self.filesize = filesize |
80 | 79 | self.album = None |
@@ -141,7 +140,7 @@ def _get_parser_for_file_handle(cls, fh): |
141 | 140 |
|
142 | 141 | @classmethod |
143 | 142 | def get_parser_class(cls, filename, filehandle): |
144 | | - if cls != TinyTag: # if `get` is invoked on TinyTag, find parser by ext |
| 143 | + if cls != TinyTag: # if `get` is invoked on TinyTag, find parser by ext |
145 | 144 | return cls # otherwise use the class on which `get` was invoked |
146 | 145 | parser_class = cls._get_parser_for_filename(filename) |
147 | 146 | if parser_class is not None: |
@@ -605,8 +604,8 @@ def _determine_duration(self, fh): |
605 | 604 |
|
606 | 605 | def _parse_tag(self, fh): |
607 | 606 | self._parse_id3v2(fh) |
608 | | - has_all_tags = all((self.track, self.track_total, self.title, |
609 | | - self.artist, self.album, self.albumartist, self.year, self.genre)) |
| 607 | + attrs = ['track', 'track_total', 'title', 'artist', 'album', 'albumartist', 'year', 'genre'] |
| 608 | + has_all_tags = all(getattr(self, attr) for attr in attrs) |
610 | 609 | if not has_all_tags and self.filesize > 128: |
611 | 610 | fh.seek(-128, os.SEEK_END) # try parsing id3v1 in last 128 bytes |
612 | 611 | self._parse_id3v1(fh) |
@@ -948,7 +947,7 @@ def _determine_duration(self, fh, skip_tags=False): |
948 | 947 | # | <5> (bits per sample)-1. |
949 | 948 | # | <36> Total samples in stream. |
950 | 949 | # 16s| <128> MD5 signature |
951 | | - min_blk, max_blk, min_frm, max_frm = header[0:4] |
| 950 | + # min_blk, max_blk, min_frm, max_frm = header[0:4] |
952 | 951 | # min_frm = _bytes_to_int(struct.unpack('3B', min_frm)) |
953 | 952 | # max_frm = _bytes_to_int(struct.unpack('3B', max_frm)) |
954 | 953 | # channels--. bits total samples |
|
0 commit comments