Skip to content

Commit eef9d83

Browse files
committed
some pep8, some golf
1 parent 38d5782 commit eef9d83

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tinytag/tinytag.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
2-
#!/usr/bin/env python
32
# -*- coding: utf-8 -*-
4-
#
3+
54
# tinytag - an audio meta info reader
65
# Copyright (c) 2014-2018 Tom Wallroth
76
#
@@ -43,7 +42,7 @@
4342
from io import BytesIO
4443
import re
4544

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
4746

4847

4948
class TinyTagException(LookupError): # inherit LookupError for backwards compat
@@ -74,7 +73,7 @@ def _bytes_to_int(b):
7473
class TinyTag(object):
7574
def __init__(self, filehandler, filesize, ignore_errors=False):
7675
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)`')
7877
self._filehandler = filehandler
7978
self.filesize = filesize
8079
self.album = None
@@ -141,7 +140,7 @@ def _get_parser_for_file_handle(cls, fh):
141140

142141
@classmethod
143142
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
145144
return cls # otherwise use the class on which `get` was invoked
146145
parser_class = cls._get_parser_for_filename(filename)
147146
if parser_class is not None:
@@ -605,8 +604,8 @@ def _determine_duration(self, fh):
605604

606605
def _parse_tag(self, fh):
607606
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)
610609
if not has_all_tags and self.filesize > 128:
611610
fh.seek(-128, os.SEEK_END) # try parsing id3v1 in last 128 bytes
612611
self._parse_id3v1(fh)
@@ -948,7 +947,7 @@ def _determine_duration(self, fh, skip_tags=False):
948947
# | <5> (bits per sample)-1.
949948
# | <36> Total samples in stream.
950949
# 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]
952951
# min_frm = _bytes_to_int(struct.unpack('3B', min_frm))
953952
# max_frm = _bytes_to_int(struct.unpack('3B', max_frm))
954953
# channels--. bits total samples

0 commit comments

Comments
 (0)