mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 02:26:53 -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, François-Xavier Thomas.
|
||||
#
|
||||
|
@ -16,18 +15,19 @@
|
|||
"""Use command-line tools to check for audio file corruption.
|
||||
"""
|
||||
|
||||
from __future__ import division, absolute_import, print_function
|
||||
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets.ui import Subcommand
|
||||
from beets.util import displayable_path, confit
|
||||
from beets import ui
|
||||
from subprocess import check_output, CalledProcessError, list2cmdline, STDOUT
|
||||
|
||||
import shlex
|
||||
import os
|
||||
import errno
|
||||
import sys
|
||||
import six
|
||||
import confuse
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets.ui import Subcommand
|
||||
from beets.util import displayable_path, par_map
|
||||
from beets import ui
|
||||
from beets import importer
|
||||
|
||||
|
||||
class CheckerCommandException(Exception):
|
||||
|
@ -48,8 +48,17 @@ class CheckerCommandException(Exception):
|
|||
|
||||
|
||||
class BadFiles(BeetsPlugin):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.verbose = False
|
||||
|
||||
self.register_listener('import_task_start',
|
||||
self.on_import_task_start)
|
||||
self.register_listener('import_task_before_choice',
|
||||
self.on_import_task_before_choice)
|
||||
|
||||
def run_command(self, cmd):
|
||||
self._log.debug(u"running command: {}",
|
||||
self._log.debug("running command: {}",
|
||||
displayable_path(list2cmdline(cmd)))
|
||||
try:
|
||||
output = check_output(cmd, stderr=STDOUT)
|
||||
|
@ -61,7 +70,7 @@ class BadFiles(BeetsPlugin):
|
|||
status = e.returncode
|
||||
except OSError as e:
|
||||
raise CheckerCommandException(cmd, e)
|
||||
output = output.decode(sys.getfilesystemencoding())
|
||||
output = output.decode(sys.getdefaultencoding(), 'replace')
|
||||
return status, errors, [line for line in output.split("\n") if line]
|
||||
|
||||
def check_mp3val(self, path):
|
||||
|
@ -85,68 +94,122 @@ class BadFiles(BeetsPlugin):
|
|||
ext = ext.lower()
|
||||
try:
|
||||
command = self.config['commands'].get(dict).get(ext)
|
||||
except confit.NotFoundError:
|
||||
except confuse.NotFoundError:
|
||||
command = None
|
||||
if command:
|
||||
return self.check_custom(command)
|
||||
elif ext == "mp3":
|
||||
if ext == "mp3":
|
||||
return self.check_mp3val
|
||||
elif ext == "flac":
|
||||
if ext == "flac":
|
||||
return self.check_flac
|
||||
|
||||
def check_bad(self, lib, opts, args):
|
||||
for item in lib.items(ui.decargs(args)):
|
||||
def check_item(self, item):
|
||||
# First, check whether the path exists. If not, the user
|
||||
# should probably run `beet update` to cleanup your library.
|
||||
dpath = displayable_path(item.path)
|
||||
self._log.debug("checking path: {}", dpath)
|
||||
if not os.path.exists(item.path):
|
||||
ui.print_("{}: file does not exist".format(
|
||||
ui.colorize('text_error', dpath)))
|
||||
|
||||
# First, check whether the path exists. If not, the user
|
||||
# should probably run `beet update` to cleanup your library.
|
||||
dpath = displayable_path(item.path)
|
||||
self._log.debug(u"checking path: {}", dpath)
|
||||
if not os.path.exists(item.path):
|
||||
ui.print_(u"{}: file does not exist".format(
|
||||
ui.colorize('text_error', dpath)))
|
||||
# Run the checker against the file if one is found
|
||||
ext = os.path.splitext(item.path)[1][1:].decode('utf8', 'ignore')
|
||||
checker = self.get_checker(ext)
|
||||
if not checker:
|
||||
self._log.error("no checker specified in the config for {}",
|
||||
ext)
|
||||
return []
|
||||
path = item.path
|
||||
if not isinstance(path, str):
|
||||
path = item.path.decode(sys.getfilesystemencoding())
|
||||
try:
|
||||
status, errors, output = checker(path)
|
||||
except CheckerCommandException as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
self._log.error(
|
||||
"command not found: {} when validating file: {}",
|
||||
e.checker,
|
||||
e.path
|
||||
)
|
||||
else:
|
||||
self._log.error("error invoking {}: {}", e.checker, e.msg)
|
||||
return []
|
||||
|
||||
# Run the checker against the file if one is found
|
||||
ext = os.path.splitext(item.path)[1][1:].decode('utf8', 'ignore')
|
||||
checker = self.get_checker(ext)
|
||||
if not checker:
|
||||
self._log.error(u"no checker specified in the config for {}",
|
||||
ext)
|
||||
continue
|
||||
path = item.path
|
||||
if not isinstance(path, six.text_type):
|
||||
path = item.path.decode(sys.getfilesystemencoding())
|
||||
try:
|
||||
status, errors, output = checker(path)
|
||||
except CheckerCommandException as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
self._log.error(
|
||||
u"command not found: {} when validating file: {}",
|
||||
e.checker,
|
||||
e.path
|
||||
)
|
||||
else:
|
||||
self._log.error(u"error invoking {}: {}", e.checker, e.msg)
|
||||
continue
|
||||
if status > 0:
|
||||
ui.print_(u"{}: checker exited with status {}"
|
||||
.format(ui.colorize('text_error', dpath), status))
|
||||
for line in output:
|
||||
ui.print_(u" {}".format(displayable_path(line)))
|
||||
elif errors > 0:
|
||||
ui.print_(u"{}: checker found {} errors or warnings"
|
||||
.format(ui.colorize('text_warning', dpath), errors))
|
||||
for line in output:
|
||||
ui.print_(u" {}".format(displayable_path(line)))
|
||||
elif opts.verbose:
|
||||
ui.print_(u"{}: ok".format(ui.colorize('text_success', dpath)))
|
||||
error_lines = []
|
||||
|
||||
if status > 0:
|
||||
error_lines.append(
|
||||
"{}: checker exited with status {}"
|
||||
.format(ui.colorize('text_error', dpath), status))
|
||||
for line in output:
|
||||
error_lines.append(f" {line}")
|
||||
|
||||
elif errors > 0:
|
||||
error_lines.append(
|
||||
"{}: checker found {} errors or warnings"
|
||||
.format(ui.colorize('text_warning', dpath), errors))
|
||||
for line in output:
|
||||
error_lines.append(f" {line}")
|
||||
elif self.verbose:
|
||||
error_lines.append(
|
||||
"{}: ok".format(ui.colorize('text_success', dpath)))
|
||||
|
||||
return error_lines
|
||||
|
||||
def on_import_task_start(self, task, session):
|
||||
if not self.config['check_on_import'].get(False):
|
||||
return
|
||||
|
||||
checks_failed = []
|
||||
|
||||
for item in task.items:
|
||||
error_lines = self.check_item(item)
|
||||
if error_lines:
|
||||
checks_failed.append(error_lines)
|
||||
|
||||
if checks_failed:
|
||||
task._badfiles_checks_failed = checks_failed
|
||||
|
||||
def on_import_task_before_choice(self, task, session):
|
||||
if hasattr(task, '_badfiles_checks_failed'):
|
||||
ui.print_('{} one or more files failed checks:'
|
||||
.format(ui.colorize('text_warning', 'BAD')))
|
||||
for error in task._badfiles_checks_failed:
|
||||
for error_line in error:
|
||||
ui.print_(error_line)
|
||||
|
||||
ui.print_()
|
||||
ui.print_('What would you like to do?')
|
||||
|
||||
sel = ui.input_options(['aBort', 'skip', 'continue'])
|
||||
|
||||
if sel == 's':
|
||||
return importer.action.SKIP
|
||||
elif sel == 'c':
|
||||
return None
|
||||
elif sel == 'b':
|
||||
raise importer.ImportAbort()
|
||||
else:
|
||||
raise Exception(f'Unexpected selection: {sel}')
|
||||
|
||||
def command(self, lib, opts, args):
|
||||
# Get items from arguments
|
||||
items = lib.items(ui.decargs(args))
|
||||
self.verbose = opts.verbose
|
||||
|
||||
def check_and_print(item):
|
||||
for error_line in self.check_item(item):
|
||||
ui.print_(error_line)
|
||||
|
||||
par_map(check_and_print, items)
|
||||
|
||||
def commands(self):
|
||||
bad_command = Subcommand('bad',
|
||||
help=u'check for corrupt or missing files')
|
||||
help='check for corrupt or missing files')
|
||||
bad_command.parser.add_option(
|
||||
u'-v', u'--verbose',
|
||||
'-v', '--verbose',
|
||||
action='store_true', default=False, dest='verbose',
|
||||
help=u'view results for both the bad and uncorrupted files'
|
||||
help='view results for both the bad and uncorrupted files'
|
||||
)
|
||||
bad_command.func = self.check_bad
|
||||
bad_command.func = self.command
|
||||
return [bad_command]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue