mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 13:23:18 -07:00
Update vendored beets to 1.6.0
Updates colorama to 0.4.6 Adds confuse version 1.7.0 Updates jellyfish to 0.9.0 Adds mediafile 0.10.1 Updates munkres to 1.1.4 Updates musicbrainzngs to 0.7.1 Updates mutagen to 1.46.0 Updates pyyaml to 6.0 Updates unidecode to 1.3.6
This commit is contained in:
parent
5073ec0c6f
commit
56c6773c6b
385 changed files with 25143 additions and 18080 deletions
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# This file is part of beets.
|
||||
# Copyright 2016, Adrian Sampson.
|
||||
#
|
||||
|
@ -16,19 +15,17 @@
|
|||
"""Shows file metadata.
|
||||
"""
|
||||
|
||||
from __future__ import division, absolute_import, print_function
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets import ui
|
||||
from beets import mediafile
|
||||
import mediafile
|
||||
from beets.library import Item
|
||||
from beets.util import displayable_path, normpath, syspath
|
||||
|
||||
|
||||
def tag_data(lib, args):
|
||||
def tag_data(lib, args, album=False):
|
||||
query = []
|
||||
for arg in args:
|
||||
path = normpath(arg)
|
||||
|
@ -42,15 +39,29 @@ def tag_data(lib, args):
|
|||
yield tag_data_emitter(item.path)
|
||||
|
||||
|
||||
def tag_fields():
|
||||
fields = set(mediafile.MediaFile.readable_fields())
|
||||
fields.add('art')
|
||||
return fields
|
||||
|
||||
|
||||
def tag_data_emitter(path):
|
||||
def emitter():
|
||||
fields = list(mediafile.MediaFile.readable_fields())
|
||||
fields.remove('images')
|
||||
def emitter(included_keys):
|
||||
if included_keys == '*':
|
||||
fields = tag_fields()
|
||||
else:
|
||||
fields = included_keys
|
||||
if 'images' in fields:
|
||||
# We can't serialize the image data.
|
||||
fields.remove('images')
|
||||
mf = mediafile.MediaFile(syspath(path))
|
||||
tags = {}
|
||||
for field in fields:
|
||||
tags[field] = getattr(mf, field)
|
||||
tags['art'] = mf.art is not None
|
||||
if field == 'art':
|
||||
tags[field] = mf.art is not None
|
||||
else:
|
||||
tags[field] = getattr(mf, field, None)
|
||||
|
||||
# create a temporary Item to take advantage of __format__
|
||||
item = Item.from_path(syspath(path))
|
||||
|
||||
|
@ -58,15 +69,14 @@ def tag_data_emitter(path):
|
|||
return emitter
|
||||
|
||||
|
||||
def library_data(lib, args):
|
||||
for item in lib.items(args):
|
||||
def library_data(lib, args, album=False):
|
||||
for item in lib.albums(args) if album else lib.items(args):
|
||||
yield library_data_emitter(item)
|
||||
|
||||
|
||||
def library_data_emitter(item):
|
||||
def emitter():
|
||||
data = dict(item.formatted())
|
||||
data.pop('path', None) # path is fetched from item
|
||||
def emitter(included_keys):
|
||||
data = dict(item.formatted(included_keys=included_keys))
|
||||
|
||||
return data, item
|
||||
return emitter
|
||||
|
@ -98,7 +108,7 @@ def print_data(data, item=None, fmt=None):
|
|||
formatted = {}
|
||||
for key, value in data.items():
|
||||
if isinstance(value, list):
|
||||
formatted[key] = u'; '.join(value)
|
||||
formatted[key] = '; '.join(value)
|
||||
if value is not None:
|
||||
formatted[key] = value
|
||||
|
||||
|
@ -106,7 +116,7 @@ def print_data(data, item=None, fmt=None):
|
|||
return
|
||||
|
||||
maxwidth = max(len(key) for key in formatted)
|
||||
lineformat = u'{{0:>{0}}}: {{1}}'.format(maxwidth)
|
||||
lineformat = f'{{0:>{maxwidth}}}: {{1}}'
|
||||
|
||||
if path:
|
||||
ui.print_(displayable_path(path))
|
||||
|
@ -114,7 +124,7 @@ def print_data(data, item=None, fmt=None):
|
|||
for field in sorted(formatted):
|
||||
value = formatted[field]
|
||||
if isinstance(value, list):
|
||||
value = u'; '.join(value)
|
||||
value = '; '.join(value)
|
||||
ui.print_(lineformat.format(field, value))
|
||||
|
||||
|
||||
|
@ -129,7 +139,7 @@ def print_data_keys(data, item=None):
|
|||
if len(formatted) == 0:
|
||||
return
|
||||
|
||||
line_format = u'{0}{{0}}'.format(u' ' * 4)
|
||||
line_format = '{0}{{0}}'.format(' ' * 4)
|
||||
if path:
|
||||
ui.print_(displayable_path(path))
|
||||
|
||||
|
@ -140,24 +150,28 @@ def print_data_keys(data, item=None):
|
|||
class InfoPlugin(BeetsPlugin):
|
||||
|
||||
def commands(self):
|
||||
cmd = ui.Subcommand('info', help=u'show file metadata')
|
||||
cmd = ui.Subcommand('info', help='show file metadata')
|
||||
cmd.func = self.run
|
||||
cmd.parser.add_option(
|
||||
u'-l', u'--library', action='store_true',
|
||||
help=u'show library fields instead of tags',
|
||||
'-l', '--library', action='store_true',
|
||||
help='show library fields instead of tags',
|
||||
)
|
||||
cmd.parser.add_option(
|
||||
u'-s', u'--summarize', action='store_true',
|
||||
help=u'summarize the tags of all files',
|
||||
'-a', '--album', action='store_true',
|
||||
help='show album fields instead of tracks (implies "--library")',
|
||||
)
|
||||
cmd.parser.add_option(
|
||||
u'-i', u'--include-keys', default=[],
|
||||
'-s', '--summarize', action='store_true',
|
||||
help='summarize the tags of all files',
|
||||
)
|
||||
cmd.parser.add_option(
|
||||
'-i', '--include-keys', default=[],
|
||||
action='append', dest='included_keys',
|
||||
help=u'comma separated list of keys to show',
|
||||
help='comma separated list of keys to show',
|
||||
)
|
||||
cmd.parser.add_option(
|
||||
u'-k', u'--keys-only', action='store_true',
|
||||
help=u'show only the keys',
|
||||
'-k', '--keys-only', action='store_true',
|
||||
help='show only the keys',
|
||||
)
|
||||
cmd.parser.add_format_option(target='item')
|
||||
return [cmd]
|
||||
|
@ -176,7 +190,7 @@ class InfoPlugin(BeetsPlugin):
|
|||
dictionary and only prints that. If two files have different values
|
||||
for the same tag, the value is set to '[various]'
|
||||
"""
|
||||
if opts.library:
|
||||
if opts.library or opts.album:
|
||||
data_collector = library_data
|
||||
else:
|
||||
data_collector = tag_data
|
||||
|
@ -184,18 +198,21 @@ class InfoPlugin(BeetsPlugin):
|
|||
included_keys = []
|
||||
for keys in opts.included_keys:
|
||||
included_keys.extend(keys.split(','))
|
||||
key_filter = make_key_filter(included_keys)
|
||||
# Drop path even if user provides it multiple times
|
||||
included_keys = [k for k in included_keys if k != 'path']
|
||||
|
||||
first = True
|
||||
summary = {}
|
||||
for data_emitter in data_collector(lib, ui.decargs(args)):
|
||||
for data_emitter in data_collector(
|
||||
lib, ui.decargs(args),
|
||||
album=opts.album,
|
||||
):
|
||||
try:
|
||||
data, item = data_emitter()
|
||||
except (mediafile.UnreadableFileError, IOError) as ex:
|
||||
self._log.error(u'cannot read file: {0}', ex)
|
||||
data, item = data_emitter(included_keys or '*')
|
||||
except (mediafile.UnreadableFileError, OSError) as ex:
|
||||
self._log.error('cannot read file: {0}', ex)
|
||||
continue
|
||||
|
||||
data = key_filter(data)
|
||||
if opts.summarize:
|
||||
update_summary(summary, data)
|
||||
else:
|
||||
|
@ -210,33 +227,3 @@ class InfoPlugin(BeetsPlugin):
|
|||
|
||||
if opts.summarize:
|
||||
print_data(summary)
|
||||
|
||||
|
||||
def make_key_filter(include):
|
||||
"""Return a function that filters a dictionary.
|
||||
|
||||
The returned filter takes a dictionary and returns another
|
||||
dictionary that only includes the key-value pairs where the key
|
||||
glob-matches one of the keys in `include`.
|
||||
"""
|
||||
if not include:
|
||||
return identity
|
||||
|
||||
matchers = []
|
||||
for key in include:
|
||||
key = re.escape(key)
|
||||
key = key.replace(r'\*', '.*')
|
||||
matchers.append(re.compile(key + '$'))
|
||||
|
||||
def filter_(data):
|
||||
filtered = dict()
|
||||
for key, value in data.items():
|
||||
if any([m.match(key) for m in matchers]):
|
||||
filtered[key] = value
|
||||
return filtered
|
||||
|
||||
return filter_
|
||||
|
||||
|
||||
def identity(val):
|
||||
return val
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue