mirror of
https://github.com/beetbox/beets.git
synced 2026-01-01 13:33:02 +01:00
Delete 'format' variables that shadow the built-in
Also cleanup the 'the' plugin a bit: delete unused variables. Relates to #1300.
This commit is contained in:
parent
54abd1a510
commit
d267741ff3
5 changed files with 21 additions and 28 deletions
|
|
@ -1296,11 +1296,11 @@ class DefaultTemplateFunctions(object):
|
|||
return unidecode(s)
|
||||
|
||||
@staticmethod
|
||||
def tmpl_time(s, format):
|
||||
def tmpl_time(s, fmt):
|
||||
"""Format a time value using `strftime`.
|
||||
"""
|
||||
cur_fmt = beets.config['time_format'].get(unicode)
|
||||
return time.strftime(format, time.strptime(s, cur_fmt))
|
||||
return time.strftime(fmt, time.strptime(s, cur_fmt))
|
||||
|
||||
def tmpl_aunique(self, keys=None, disam=None):
|
||||
"""Generate a string that is guaranteed to be unique among all
|
||||
|
|
|
|||
|
|
@ -438,8 +438,8 @@ def summarize_items(items, singleton):
|
|||
summary_parts.append(items[0].format)
|
||||
else:
|
||||
# Enumerate all the formats.
|
||||
for format, count in format_counts.iteritems():
|
||||
summary_parts.append('{0} {1}'.format(format, count))
|
||||
for fmt, count in format_counts.iteritems():
|
||||
summary_parts.append('{0} {1}'.format(fmt, count))
|
||||
|
||||
average_bitrate = sum([item.bitrate for item in items]) / len(items)
|
||||
total_duration = sum([item.length for item in items])
|
||||
|
|
|
|||
|
|
@ -49,25 +49,25 @@ def replace_ext(path, ext):
|
|||
return os.path.splitext(path)[0] + b'.' + ext
|
||||
|
||||
|
||||
def get_format(format=None):
|
||||
def get_format(fmt=None):
|
||||
"""Return the command tempate and the extension from the config.
|
||||
"""
|
||||
if not format:
|
||||
format = config['convert']['format'].get(unicode).lower()
|
||||
format = ALIASES.get(format, format)
|
||||
if not fmt:
|
||||
fmt = config['convert']['format'].get(unicode).lower()
|
||||
fmt = ALIASES.get(fmt, fmt)
|
||||
|
||||
try:
|
||||
format_info = config['convert']['formats'][format].get(dict)
|
||||
format_info = config['convert']['formats'][fmt].get(dict)
|
||||
command = format_info['command']
|
||||
extension = format_info['extension']
|
||||
except KeyError:
|
||||
raise ui.UserError(
|
||||
u'convert: format {0} needs "command" and "extension" fields'
|
||||
.format(format)
|
||||
.format(fmt)
|
||||
)
|
||||
except ConfigTypeError:
|
||||
command = config['convert']['formats'][format].get(bytes)
|
||||
extension = format
|
||||
command = config['convert']['formats'][fmt].get(bytes)
|
||||
extension = fmt
|
||||
|
||||
# Convenience and backwards-compatibility shortcuts.
|
||||
keys = config['convert'].keys()
|
||||
|
|
@ -84,7 +84,7 @@ def get_format(format=None):
|
|||
return (command.encode('utf8'), extension.encode('utf8'))
|
||||
|
||||
|
||||
def should_transcode(item, format):
|
||||
def should_transcode(item, fmt):
|
||||
"""Determine whether the item should be transcoded as part of
|
||||
conversion (i.e., its bitrate is high or it has the wrong format).
|
||||
"""
|
||||
|
|
@ -92,7 +92,7 @@ def should_transcode(item, format):
|
|||
not (item.format.lower() in LOSSLESS_FORMATS):
|
||||
return False
|
||||
maxbr = config['convert']['max_bitrate'].get(int)
|
||||
return format.lower() != item.format.lower() or \
|
||||
return fmt.lower() != item.format.lower() or \
|
||||
item.bitrate >= 1000 * maxbr
|
||||
|
||||
|
||||
|
|
@ -209,9 +209,9 @@ class ConvertPlugin(BeetsPlugin):
|
|||
self._log.info(u'Finished encoding {0}',
|
||||
util.displayable_path(source))
|
||||
|
||||
def convert_item(self, dest_dir, keep_new, path_formats, format,
|
||||
def convert_item(self, dest_dir, keep_new, path_formats, fmt,
|
||||
pretend=False):
|
||||
command, ext = get_format(format)
|
||||
command, ext = get_format(fmt)
|
||||
item, original, converted = None, None, None
|
||||
while True:
|
||||
item = yield (item, original, converted)
|
||||
|
|
@ -224,11 +224,11 @@ class ConvertPlugin(BeetsPlugin):
|
|||
if keep_new:
|
||||
original = dest
|
||||
converted = item.path
|
||||
if should_transcode(item, format):
|
||||
if should_transcode(item, fmt):
|
||||
converted = replace_ext(converted, ext)
|
||||
else:
|
||||
original = item.path
|
||||
if should_transcode(item, format):
|
||||
if should_transcode(item, fmt):
|
||||
dest = replace_ext(dest, ext)
|
||||
converted = dest
|
||||
|
||||
|
|
@ -254,7 +254,7 @@ class ConvertPlugin(BeetsPlugin):
|
|||
util.displayable_path(original))
|
||||
util.move(item.path, original)
|
||||
|
||||
if should_transcode(item, format):
|
||||
if should_transcode(item, fmt):
|
||||
try:
|
||||
self.encode(command, original, converted, pretend)
|
||||
except subprocess.CalledProcessError:
|
||||
|
|
@ -386,8 +386,8 @@ class ConvertPlugin(BeetsPlugin):
|
|||
"""Transcode a file automatically after it is imported into the
|
||||
library.
|
||||
"""
|
||||
format = self.config['format'].get(unicode).lower()
|
||||
if should_transcode(item, format):
|
||||
fmt = self.config['format'].get(unicode).lower()
|
||||
if should_transcode(item, fmt):
|
||||
command, ext = get_format()
|
||||
fd, dest = tempfile.mkstemp('.' + ext)
|
||||
os.close(fd)
|
||||
|
|
|
|||
|
|
@ -30,12 +30,6 @@ FORMAT = u'{0}, {1}'
|
|||
|
||||
class ThePlugin(BeetsPlugin):
|
||||
|
||||
_instance = None
|
||||
|
||||
the = True
|
||||
a = True
|
||||
format = u''
|
||||
strip = False
|
||||
patterns = []
|
||||
|
||||
def __init__(self):
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ class ThePluginTest(_common.TestCase):
|
|||
|
||||
def test_template_function_with_defaults(self):
|
||||
ThePlugin().patterns = [PATTERN_THE, PATTERN_A]
|
||||
ThePlugin().format = FORMAT
|
||||
self.assertEqual(ThePlugin().the_template_func('The The'), 'The, The')
|
||||
self.assertEqual(ThePlugin().the_template_func('An A'), 'A, An')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue