mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
per-plugin configuration defaults in __init__()
This uses the new BeetsPlugin.config convenience view heavily. Things are slowly getting less verbose.
This commit is contained in:
parent
4a5594bec6
commit
6d68a4855e
17 changed files with 152 additions and 188 deletions
|
|
@ -28,17 +28,6 @@ log = logging.getLogger('beets')
|
||||||
DEVNULL = open(os.devnull, 'wb')
|
DEVNULL = open(os.devnull, 'wb')
|
||||||
_fs_lock = threading.Lock()
|
_fs_lock = threading.Lock()
|
||||||
|
|
||||||
config.add({
|
|
||||||
'convert': {
|
|
||||||
u'dest': None,
|
|
||||||
u'threads': util.cpu_count(),
|
|
||||||
u'ffmpeg': u'ffmpeg',
|
|
||||||
u'opts': u'-aq 2',
|
|
||||||
u'max_bitrate': 500,
|
|
||||||
u'embed': True,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
def encode(source, dest):
|
def encode(source, dest):
|
||||||
log.info(u'Started encoding {0}'.format(util.displayable_path(source)))
|
log.info(u'Started encoding {0}'.format(util.displayable_path(source)))
|
||||||
|
|
@ -117,6 +106,17 @@ def convert_func(lib, opts, args):
|
||||||
|
|
||||||
|
|
||||||
class ConvertPlugin(BeetsPlugin):
|
class ConvertPlugin(BeetsPlugin):
|
||||||
|
def __init__(self):
|
||||||
|
super(ConvertPlugin, self).__init__()
|
||||||
|
self.config.add({
|
||||||
|
u'dest': None,
|
||||||
|
u'threads': util.cpu_count(),
|
||||||
|
u'ffmpeg': u'ffmpeg',
|
||||||
|
u'opts': u'-aq 2',
|
||||||
|
u'max_bitrate': 500,
|
||||||
|
u'embed': True,
|
||||||
|
})
|
||||||
|
|
||||||
def commands(self):
|
def commands(self):
|
||||||
cmd = ui.Subcommand('convert', help='convert to external location')
|
cmd = ui.Subcommand('convert', help='convert to external location')
|
||||||
cmd.parser.add_option('-a', '--album', action='store_true',
|
cmd.parser.add_option('-a', '--album', action='store_true',
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,6 @@ import pyechonest.song
|
||||||
# Global logger.
|
# Global logger.
|
||||||
log = logging.getLogger('beets')
|
log = logging.getLogger('beets')
|
||||||
|
|
||||||
config.add({
|
|
||||||
'echonest_tempo': {
|
|
||||||
'apikey': u'NY2KTZHQ0QDSHBAP6',
|
|
||||||
'auto': True,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
def fetch_item_tempo(lib, loglevel, item, write):
|
def fetch_item_tempo(lib, loglevel, item, write):
|
||||||
"""Fetch and store tempo for a single item. If ``write``, then the
|
"""Fetch and store tempo for a single item. If ``write``, then the
|
||||||
tempo will also be written to the file itself in the bpm field. The
|
tempo will also be written to the file itself in the bpm field. The
|
||||||
|
|
@ -76,9 +69,13 @@ class EchoNestTempoPlugin(BeetsPlugin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(EchoNestTempoPlugin, self).__init__()
|
super(EchoNestTempoPlugin, self).__init__()
|
||||||
self.import_stages = [self.imported]
|
self.import_stages = [self.imported]
|
||||||
|
self.config.add({
|
||||||
|
'apikey': u'NY2KTZHQ0QDSHBAP6',
|
||||||
|
'auto': True,
|
||||||
|
})
|
||||||
|
|
||||||
pyechonest.config.ECHO_NEST_API_KEY = \
|
pyechonest.config.ECHO_NEST_API_KEY = \
|
||||||
config['echonest_tempo']['apikey'].get(unicode)
|
self.config['apikey'].get(unicode)
|
||||||
|
|
||||||
def commands(self):
|
def commands(self):
|
||||||
cmd = ui.Subcommand('tempo', help='fetch song tempo (bpm)')
|
cmd = ui.Subcommand('tempo', help='fetch song tempo (bpm)')
|
||||||
|
|
@ -99,6 +96,6 @@ class EchoNestTempoPlugin(BeetsPlugin):
|
||||||
|
|
||||||
# Auto-fetch tempo on import.
|
# Auto-fetch tempo on import.
|
||||||
def imported(self, config, task):
|
def imported(self, config, task):
|
||||||
if config['echonest_tempo']['auto']:
|
if self.config['auto']:
|
||||||
for item in task.imported_items():
|
for item in task.imported_items():
|
||||||
fetch_item_tempo(config.lib, logging.DEBUG, item, False)
|
fetch_item_tempo(config.lib, logging.DEBUG, item, False)
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,6 @@ from beets import config
|
||||||
|
|
||||||
log = logging.getLogger('beets')
|
log = logging.getLogger('beets')
|
||||||
|
|
||||||
config.add({
|
|
||||||
'embedart': {
|
|
||||||
'maxwidth': 0,
|
|
||||||
'auto': True,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
def _embed(path, items):
|
def _embed(path, items):
|
||||||
"""Embed an image file, located at `path`, into each item.
|
"""Embed an image file, located at `path`, into each item.
|
||||||
"""
|
"""
|
||||||
|
|
@ -65,9 +58,13 @@ class EmbedCoverArtPlugin(BeetsPlugin):
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(EmbedCoverArtPlugin, self).__init__()
|
super(EmbedCoverArtPlugin, self).__init__()
|
||||||
if config['embedart']['maxwidth'].get(int) and \
|
self.config.add({
|
||||||
|
'maxwidth': 0,
|
||||||
|
'auto': True,
|
||||||
|
})
|
||||||
|
if self.config['maxwidth'].get(int) and \
|
||||||
not ArtResizer.shared.local:
|
not ArtResizer.shared.local:
|
||||||
config['embedart']['maxwidth'] = 0
|
self.config['maxwidth'] = 0
|
||||||
log.warn("embedart: ImageMagick or PIL not found; "
|
log.warn("embedart: ImageMagick or PIL not found; "
|
||||||
"'maxwidth' option ignored")
|
"'maxwidth' option ignored")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,6 @@ DOWNLOAD_EXTENSION = '.jpg'
|
||||||
|
|
||||||
log = logging.getLogger('beets')
|
log = logging.getLogger('beets')
|
||||||
|
|
||||||
config.add({
|
|
||||||
'fetchart': {
|
|
||||||
'auto': True,
|
|
||||||
'maxwidth': 0,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
def _fetch_image(url):
|
def _fetch_image(url):
|
||||||
"""Downloads an image from a URL and checks whether it seems to
|
"""Downloads an image from a URL and checks whether it seems to
|
||||||
|
|
@ -216,15 +209,17 @@ class FetchArtPlugin(BeetsPlugin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(FetchArtPlugin, self).__init__()
|
super(FetchArtPlugin, self).__init__()
|
||||||
|
|
||||||
self.autofetch = True
|
self.config.add({
|
||||||
self.maxwidth = 0
|
'auto': True,
|
||||||
|
'maxwidth': 0,
|
||||||
|
})
|
||||||
|
|
||||||
# Holds paths to downloaded images between fetching them and
|
# Holds paths to downloaded images between fetching them and
|
||||||
# placing them in the filesystem.
|
# placing them in the filesystem.
|
||||||
self.art_paths = {}
|
self.art_paths = {}
|
||||||
|
|
||||||
self.autofetch = config['fetchart']['auto'].get(bool)
|
self.maxwidth = self.config['maxwidth'].get(int)
|
||||||
self.maxwidth = config['fetchart']['maxwidth'].get(int)
|
if self.config['auto']:
|
||||||
if self.autofetch:
|
|
||||||
# Enable two import hooks when fetching is enabled.
|
# Enable two import hooks when fetching is enabled.
|
||||||
self.import_stages = [self.fetch_art]
|
self.import_stages = [self.fetch_art]
|
||||||
self.register_listener('import_task_files', self.assign_art)
|
self.register_listener('import_task_files', self.assign_art)
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,6 @@ from beets.util.functemplate import Template
|
||||||
from beets import config
|
from beets import config
|
||||||
import difflib
|
import difflib
|
||||||
|
|
||||||
config.add({
|
|
||||||
'fuzzy': {
|
|
||||||
'threshold': 0.7,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
# THRESHOLD = 0.7
|
|
||||||
|
|
||||||
|
|
||||||
def fuzzy_score(queryMatcher, item):
|
def fuzzy_score(queryMatcher, item):
|
||||||
queryMatcher.set_seq1(item)
|
queryMatcher.set_seq1(item)
|
||||||
|
|
@ -96,5 +87,11 @@ fuzzy_cmd.func = fuzzy_list
|
||||||
|
|
||||||
|
|
||||||
class Fuzzy(BeetsPlugin):
|
class Fuzzy(BeetsPlugin):
|
||||||
|
def __init__(self):
|
||||||
|
super(Fuzzy, self).__init__('fuzzy')
|
||||||
|
self.config.add({
|
||||||
|
'threshold': 0.7,
|
||||||
|
})
|
||||||
|
|
||||||
def commands(self):
|
def commands(self):
|
||||||
return [fuzzy_cmd]
|
return [fuzzy_cmd]
|
||||||
|
|
|
||||||
|
|
@ -25,20 +25,6 @@ __author__ = 'baobab@heresiarch.info'
|
||||||
__version__ = '1.0'
|
__version__ = '1.0'
|
||||||
|
|
||||||
|
|
||||||
config.add({
|
|
||||||
'ihate': {
|
|
||||||
'warn_genre': [],
|
|
||||||
'warn_artist': [],
|
|
||||||
'warn_album': [],
|
|
||||||
'warn_whitelist': [],
|
|
||||||
'skip_genre': [],
|
|
||||||
'skip_artist': [],
|
|
||||||
'skip_album': [],
|
|
||||||
'skip_whitelist': [],
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
class IHatePlugin(BeetsPlugin):
|
class IHatePlugin(BeetsPlugin):
|
||||||
|
|
||||||
_instance = None
|
_instance = None
|
||||||
|
|
@ -58,6 +44,20 @@ class IHatePlugin(BeetsPlugin):
|
||||||
cls._instance = super(IHatePlugin,
|
cls._instance = super(IHatePlugin,
|
||||||
cls).__new__(cls, *args, **kwargs)
|
cls).__new__(cls, *args, **kwargs)
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(IHatePlugin, self).__init__()
|
||||||
|
self.config.add({
|
||||||
|
'warn_genre': [],
|
||||||
|
'warn_artist': [],
|
||||||
|
'warn_album': [],
|
||||||
|
'warn_whitelist': [],
|
||||||
|
'skip_genre': [],
|
||||||
|
'skip_artist': [],
|
||||||
|
'skip_album': [],
|
||||||
|
'skip_whitelist': [],
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def match_patterns(cls, s, patterns):
|
def match_patterns(cls, s, patterns):
|
||||||
|
|
@ -94,28 +94,28 @@ class IHatePlugin(BeetsPlugin):
|
||||||
|
|
||||||
def job_to_do(self):
|
def job_to_do(self):
|
||||||
"""Return True if at least one pattern is defined."""
|
"""Return True if at least one pattern is defined."""
|
||||||
return any(config['ihate'][l].get(list) for l in
|
return any(self.config[l].get(list) for l in
|
||||||
('warn_genre', 'warn_artist', 'warn_album',
|
('warn_genre', 'warn_artist', 'warn_album',
|
||||||
'skip_genre', 'skip_artist', 'skip_album'))
|
'skip_genre', 'skip_artist', 'skip_album'))
|
||||||
|
|
||||||
def import_task_choice_event(self, task, config):
|
def import_task_choice_event(self, task):
|
||||||
if task.choice_flag == action.APPLY:
|
if task.choice_flag == action.APPLY:
|
||||||
if self.job_to_do():
|
if self.job_to_do():
|
||||||
self._log.debug('[ihate] processing your hate')
|
self._log.debug('[ihate] processing your hate')
|
||||||
if self.do_i_hate_this(task,
|
if self.do_i_hate_this(task,
|
||||||
config['ihate']['skip_genre'].get(list),
|
self.config['skip_genre'].get(list),
|
||||||
config['ihate']['skip_artist'].get(list),
|
self.config['skip_artist'].get(list),
|
||||||
config['ihate']['skip_album'].get(list),
|
self.config['skip_album'].get(list),
|
||||||
config['ihate']['skip_whitelist'].get(list)):
|
self.config['skip_whitelist'].get(list)):
|
||||||
task.choice_flag = action.SKIP
|
task.choice_flag = action.SKIP
|
||||||
self._log.info(u'[ihate] skipped: {0} - {1}'
|
self._log.info(u'[ihate] skipped: {0} - {1}'
|
||||||
.format(task.cur_artist, task.cur_album))
|
.format(task.cur_artist, task.cur_album))
|
||||||
return
|
return
|
||||||
if self.do_i_hate_this(task,
|
if self.do_i_hate_this(task,
|
||||||
config['ihate']['warn_genre'].get(list),
|
self.config['warn_genre'].get(list),
|
||||||
config['ihate']['warn_artist'].get(list),
|
self.config['warn_artist'].get(list),
|
||||||
config['ihate']['warn_album'].get(list),
|
self.config['warn_album'].get(list),
|
||||||
config['ihate']['warn_whitelist'].get(list)):
|
self.config['warn_whitelist'].get(list)):
|
||||||
self._log.info(u'[ihate] you maybe hate this: {0} - {1}'
|
self._log.info(u'[ihate] you maybe hate this: {0} - {1}'
|
||||||
.format(task.cur_artist, task.cur_album))
|
.format(task.cur_artist, task.cur_album))
|
||||||
else:
|
else:
|
||||||
|
|
@ -126,4 +126,4 @@ class IHatePlugin(BeetsPlugin):
|
||||||
|
|
||||||
@IHatePlugin.listen('import_task_choice')
|
@IHatePlugin.listen('import_task_choice')
|
||||||
def ihate_import_task_choice(task, session):
|
def ihate_import_task_choice(task, session):
|
||||||
IHatePlugin().import_task_choice_event(task, config)
|
IHatePlugin().import_task_choice_event(task)
|
||||||
|
|
|
||||||
|
|
@ -25,22 +25,19 @@ from beets import config
|
||||||
|
|
||||||
M3U_DEFAULT_NAME = 'imported.m3u'
|
M3U_DEFAULT_NAME = 'imported.m3u'
|
||||||
|
|
||||||
config.add({
|
|
||||||
'importfeeds': {
|
|
||||||
'formats': [],
|
|
||||||
'm3u_name': u'imported.m3u',
|
|
||||||
'dir': None,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
class ImportFeedsPlugin(BeetsPlugin):
|
class ImportFeedsPlugin(BeetsPlugin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ImportFeedsPlugin, self).__init__()
|
super(ImportFeedsPlugin, self).__init__()
|
||||||
|
|
||||||
|
self.config.add({
|
||||||
|
'formats': [],
|
||||||
|
'm3u_name': u'imported.m3u',
|
||||||
|
'dir': None,
|
||||||
|
})
|
||||||
|
|
||||||
feeds_dir = config['importfeeds']['dir'].get()
|
feeds_dir = self.config['dir'].get()
|
||||||
if feeds_dir:
|
if feeds_dir:
|
||||||
config['importfeeds']['dir'] = \
|
self.config['dir'] = os.path.expanduser(bytestring_path(feeds_dir))
|
||||||
os.path.expanduser(bytestring_path(feeds_dir))
|
|
||||||
if not os.path.exists(syspath(feeds_dir)):
|
if not os.path.exists(syspath(feeds_dir)):
|
||||||
os.makedirs(syspath(feeds_dir))
|
os.makedirs(syspath(feeds_dir))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,6 @@ import traceback
|
||||||
from beets.plugins import BeetsPlugin
|
from beets.plugins import BeetsPlugin
|
||||||
from beets import config
|
from beets import config
|
||||||
|
|
||||||
config.add({
|
|
||||||
'pathfields': [],
|
|
||||||
})
|
|
||||||
|
|
||||||
log = logging.getLogger('beets')
|
log = logging.getLogger('beets')
|
||||||
|
|
||||||
class InlineError(Exception):
|
class InlineError(Exception):
|
||||||
|
|
@ -62,6 +58,10 @@ class InlinePlugin(BeetsPlugin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(InlinePlugin, self).__init__()
|
super(InlinePlugin, self).__init__()
|
||||||
|
|
||||||
|
config.add({
|
||||||
|
'pathfields': [],
|
||||||
|
})
|
||||||
|
|
||||||
# Add field expressions.
|
# Add field expressions.
|
||||||
for key, view in config['pathfields'].items():
|
for key, view in config['pathfields'].items():
|
||||||
log.debug(u'adding template field %s' % key)
|
log.debug(u'adding template field %s' % key)
|
||||||
|
|
|
||||||
|
|
@ -34,14 +34,6 @@ from beets import ui
|
||||||
from beets.util import normpath
|
from beets.util import normpath
|
||||||
from beets import config
|
from beets import config
|
||||||
|
|
||||||
config.add({
|
|
||||||
'lastgenre': {
|
|
||||||
'whitelist': os.path.join(os.path.dirname(__file__), 'genres.txt'),
|
|
||||||
'fallback': None,
|
|
||||||
'canonical': None,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
log = logging.getLogger('beets')
|
log = logging.getLogger('beets')
|
||||||
|
|
||||||
LASTFM = pylast.LastFMNetwork(api_key=plugins.LASTFM_KEY)
|
LASTFM = pylast.LastFMNetwork(api_key=plugins.LASTFM_KEY)
|
||||||
|
|
@ -138,8 +130,15 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
||||||
super(LastGenrePlugin, self).__init__()
|
super(LastGenrePlugin, self).__init__()
|
||||||
self.import_stages = [self.imported]
|
self.import_stages = [self.imported]
|
||||||
|
|
||||||
|
self.config.add({
|
||||||
|
'whitelist': os.path.join(os.path.dirname(__file__), 'genres.txt'),
|
||||||
|
'fallback': None,
|
||||||
|
'canonical': None,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# Read the whitelist file.
|
# Read the whitelist file.
|
||||||
wl_filename = config['lastgenre']['whitelist'].as_filename()
|
wl_filename = self.config['whitelist'].as_filename()
|
||||||
whitelist = set()
|
whitelist = set()
|
||||||
with open(wl_filename) as f:
|
with open(wl_filename) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
|
|
@ -149,7 +148,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
||||||
options['whitelist'] = whitelist
|
options['whitelist'] = whitelist
|
||||||
|
|
||||||
# Read the genres tree for canonicalization if enabled.
|
# Read the genres tree for canonicalization if enabled.
|
||||||
c14n_filename = config['lastgenre']['canonical'].get()
|
c14n_filename = self.config['canonical'].get()
|
||||||
if c14n_filename is not None:
|
if c14n_filename is not None:
|
||||||
c14n_filename = c14n_filename.strip()
|
c14n_filename = c14n_filename.strip()
|
||||||
if not c14n_filename:
|
if not c14n_filename:
|
||||||
|
|
@ -164,7 +163,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
||||||
|
|
||||||
def commands(self):
|
def commands(self):
|
||||||
lastgenre_cmd = ui.Subcommand('lastgenre', help='fetch genres')
|
lastgenre_cmd = ui.Subcommand('lastgenre', help='fetch genres')
|
||||||
def lastgenre_func(lib, config, opts, args):
|
def lastgenre_func(lib, opts, args):
|
||||||
# The "write to files" option corresponds to the
|
# The "write to files" option corresponds to the
|
||||||
# import_write config value.
|
# import_write config value.
|
||||||
write = config['import']['write'].get(bool)
|
write = config['import']['write'].get(bool)
|
||||||
|
|
@ -177,7 +176,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
||||||
tags.extend(_tags_for(lastfm_obj))
|
tags.extend(_tags_for(lastfm_obj))
|
||||||
genre = _tags_to_genre(tags)
|
genre = _tags_to_genre(tags)
|
||||||
|
|
||||||
fallback_str = config['lastgenre']['fallback'].get()
|
fallback_str = self.config['fallback'].get()
|
||||||
if not genre and fallback_str != None:
|
if not genre and fallback_str != None:
|
||||||
genre = fallback_str
|
genre = fallback_str
|
||||||
log.debug(u'no last.fm genre found: fallback to %s' % genre)
|
log.debug(u'no last.fm genre found: fallback to %s' % genre)
|
||||||
|
|
@ -207,7 +206,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
||||||
tags.extend(_tags_for(lastfm_obj))
|
tags.extend(_tags_for(lastfm_obj))
|
||||||
genre = _tags_to_genre(tags)
|
genre = _tags_to_genre(tags)
|
||||||
|
|
||||||
fallback_str = config['lastgenre']['fallback'].get()
|
fallback_str = self.config['fallback'].get()
|
||||||
if not genre and fallback_str != None:
|
if not genre and fallback_str != None:
|
||||||
genre = fallback_str
|
genre = fallback_str
|
||||||
log.debug(u'no last.fm genre found: fallback to %s' % genre)
|
log.debug(u'no last.fm genre found: fallback to %s' % genre)
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,6 @@ from beets.plugins import BeetsPlugin
|
||||||
from beets import ui
|
from beets import ui
|
||||||
from beets import config
|
from beets import config
|
||||||
|
|
||||||
config.add({
|
|
||||||
'lyrics': {
|
|
||||||
'auto': True,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
# Global logger.
|
# Global logger.
|
||||||
|
|
||||||
|
|
@ -203,6 +197,9 @@ class LyricsPlugin(BeetsPlugin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(LyricsPlugin, self).__init__()
|
super(LyricsPlugin, self).__init__()
|
||||||
self.import_stages = [self.imported]
|
self.import_stages = [self.imported]
|
||||||
|
self.config.add({
|
||||||
|
'auto': True,
|
||||||
|
})
|
||||||
|
|
||||||
def commands(self):
|
def commands(self):
|
||||||
cmd = ui.Subcommand('lyrics', help='fetch song lyrics')
|
cmd = ui.Subcommand('lyrics', help='fetch song lyrics')
|
||||||
|
|
@ -222,6 +219,6 @@ class LyricsPlugin(BeetsPlugin):
|
||||||
|
|
||||||
# Auto-fetch lyrics on import.
|
# Auto-fetch lyrics on import.
|
||||||
def imported(self, session, task):
|
def imported(self, session, task):
|
||||||
if config['lyrics']['auto']:
|
if self.config['auto']:
|
||||||
for item in task.imported_items():
|
for item in task.imported_items():
|
||||||
fetch_item_lyrics(session.lib, logging.DEBUG, item, False)
|
fetch_item_lyrics(session.lib, logging.DEBUG, item, False)
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,6 @@ from beets.plugins import BeetsPlugin
|
||||||
import socket
|
import socket
|
||||||
from beets import config
|
from beets import config
|
||||||
|
|
||||||
config.add({
|
|
||||||
'mpdupdate': {
|
|
||||||
'host': u'localhost',
|
|
||||||
'port': 6600,
|
|
||||||
'password': u'',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
# No need to introduce a dependency on an MPD library for such a
|
# No need to introduce a dependency on an MPD library for such a
|
||||||
# simple use case. Here's a simple socket abstraction to make things
|
# simple use case. Here's a simple socket abstraction to make things
|
||||||
# easier.
|
# easier.
|
||||||
|
|
@ -97,7 +89,13 @@ def update_mpd(host='localhost', port=6600, password=None):
|
||||||
print('... updated.')
|
print('... updated.')
|
||||||
|
|
||||||
class MPDUpdatePlugin(BeetsPlugin):
|
class MPDUpdatePlugin(BeetsPlugin):
|
||||||
pass
|
def __init__(self):
|
||||||
|
super(MPDUpdatePlugin, self).__init__()
|
||||||
|
self.config.add({
|
||||||
|
'host': u'localhost',
|
||||||
|
'port': 6600,
|
||||||
|
'password': u'',
|
||||||
|
})
|
||||||
|
|
||||||
@MPDUpdatePlugin.listen('import')
|
@MPDUpdatePlugin.listen('import')
|
||||||
def update(lib=None, paths=None):
|
def update(lib=None, paths=None):
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,6 @@ from beets.plugins import BeetsPlugin
|
||||||
from beets.util import syspath, command_output
|
from beets.util import syspath, command_output
|
||||||
from beets import config
|
from beets import config
|
||||||
|
|
||||||
config.add({
|
|
||||||
'replaygain': {
|
|
||||||
'overwrite': False,
|
|
||||||
'albumgain': False,
|
|
||||||
'noclip': True,
|
|
||||||
'apply_gain': False,
|
|
||||||
'targetlevel': 89,
|
|
||||||
'auto': True,
|
|
||||||
'command': u'',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
log = logging.getLogger('beets')
|
log = logging.getLogger('beets')
|
||||||
|
|
||||||
SAMPLE_MAX = 1 << 15
|
SAMPLE_MAX = 1 << 15
|
||||||
|
|
@ -79,14 +67,24 @@ class ReplayGainPlugin(BeetsPlugin):
|
||||||
super(ReplayGainPlugin, self).__init__()
|
super(ReplayGainPlugin, self).__init__()
|
||||||
self.import_stages = [self.imported]
|
self.import_stages = [self.imported]
|
||||||
|
|
||||||
self.overwrite = config['replaygain']['overwrite'].get(bool)
|
self.config.add({
|
||||||
self.albumgain = config['replaygain']['albumgain'].get(bool)
|
'overwrite': False,
|
||||||
self.noclip = config['replaygain']['noclip'].get(bool)
|
'albumgain': False,
|
||||||
self.apply_gain = config['replaygain']['apply_gain'].get(bool)
|
'noclip': True,
|
||||||
target_level = config['replaygain']['targetlevel'].as_number()
|
'apply_gain': False,
|
||||||
|
'targetlevel': 89,
|
||||||
|
'auto': True,
|
||||||
|
'command': u'',
|
||||||
|
})
|
||||||
|
|
||||||
|
self.overwrite = self.config['overwrite'].get(bool)
|
||||||
|
self.albumgain = self.config['albumgain'].get(bool)
|
||||||
|
self.noclip = self.config['noclip'].get(bool)
|
||||||
|
self.apply_gain = self.config['apply_gain'].get(bool)
|
||||||
|
target_level = self.config['targetlevel'].as_number()
|
||||||
self.gain_offset = int(target_level - 89)
|
self.gain_offset = int(target_level - 89)
|
||||||
self.automatic = config['replaygain']['auto'].get(bool)
|
self.automatic = self.config['auto'].get(bool)
|
||||||
self.command = config['replaygain']['command'].get(unicode)
|
self.command = self.config['command'].get(unicode)
|
||||||
|
|
||||||
if self.command:
|
if self.command:
|
||||||
# Explicit executable path.
|
# Explicit executable path.
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,6 @@ from beets import ui
|
||||||
from beets import library
|
from beets import library
|
||||||
from beets import config
|
from beets import config
|
||||||
|
|
||||||
config.add({
|
|
||||||
'rewrite': {},
|
|
||||||
})
|
|
||||||
|
|
||||||
log = logging.getLogger('beets')
|
log = logging.getLogger('beets')
|
||||||
|
|
||||||
def rewriter(field, rules):
|
def rewriter(field, rules):
|
||||||
|
|
@ -50,9 +46,11 @@ class RewritePlugin(BeetsPlugin):
|
||||||
super(BeetsPlugin, self).__init__()
|
super(BeetsPlugin, self).__init__()
|
||||||
BeetsPlugin.template_fields = {}
|
BeetsPlugin.template_fields = {}
|
||||||
|
|
||||||
|
self.config.add({})
|
||||||
|
|
||||||
# Gather all the rewrite rules for each field.
|
# Gather all the rewrite rules for each field.
|
||||||
rules = defaultdict(list)
|
rules = defaultdict(list)
|
||||||
for key, value in config['rewrite'].items():
|
for key, value in self.config.items():
|
||||||
try:
|
try:
|
||||||
fieldname, pattern = key.split(None, 1)
|
fieldname, pattern = key.split(None, 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,6 @@ from beets import ui
|
||||||
from beets import util
|
from beets import util
|
||||||
from beets import config
|
from beets import config
|
||||||
|
|
||||||
config.add({
|
|
||||||
'scrub': {
|
|
||||||
'auto': True,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
log = logging.getLogger('beets')
|
log = logging.getLogger('beets')
|
||||||
|
|
||||||
_MUTAGEN_FORMATS = {
|
_MUTAGEN_FORMATS = {
|
||||||
|
|
@ -50,6 +44,12 @@ scrubbing = False
|
||||||
|
|
||||||
class ScrubPlugin(BeetsPlugin):
|
class ScrubPlugin(BeetsPlugin):
|
||||||
"""Removes extraneous metadata from files' tags."""
|
"""Removes extraneous metadata from files' tags."""
|
||||||
|
def __init__(self):
|
||||||
|
super(ScrubPlugin, self).__init__()
|
||||||
|
self.config.add({
|
||||||
|
'auto': True,
|
||||||
|
})
|
||||||
|
|
||||||
def commands(self):
|
def commands(self):
|
||||||
def scrub_func(lib, opts, args):
|
def scrub_func(lib, opts, args):
|
||||||
# This is a little bit hacky, but we set a global flag to
|
# This is a little bit hacky, but we set a global flag to
|
||||||
|
|
|
||||||
|
|
@ -17,18 +17,6 @@
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
from beets.plugins import BeetsPlugin
|
from beets.plugins import BeetsPlugin
|
||||||
from beets import config
|
|
||||||
|
|
||||||
config.add({
|
|
||||||
'the': {
|
|
||||||
'the': True,
|
|
||||||
'a': True,
|
|
||||||
'format': u'{0}, {1}',
|
|
||||||
'strip': False,
|
|
||||||
'patterns': [],
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
__author__ = 'baobab@heresiarch.info'
|
__author__ = 'baobab@heresiarch.info'
|
||||||
__version__ = '1.1'
|
__version__ = '1.1'
|
||||||
|
|
@ -57,7 +45,15 @@ class ThePlugin(BeetsPlugin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ThePlugin, self).__init__()
|
super(ThePlugin, self).__init__()
|
||||||
|
|
||||||
self.patterns = config['the']['patterns'].get(list)
|
self.config.add({
|
||||||
|
'the': True,
|
||||||
|
'a': True,
|
||||||
|
'format': u'{0}, {1}',
|
||||||
|
'strip': False,
|
||||||
|
'patterns': [],
|
||||||
|
})
|
||||||
|
|
||||||
|
self.patterns = self.config['patterns'].get(list)
|
||||||
for p in self.patterns:
|
for p in self.patterns:
|
||||||
if p:
|
if p:
|
||||||
try:
|
try:
|
||||||
|
|
@ -68,9 +64,9 @@ class ThePlugin(BeetsPlugin):
|
||||||
if not (p.startswith('^') or p.endswith('$')):
|
if not (p.startswith('^') or p.endswith('$')):
|
||||||
self._log.warn(u'[the] warning: \"{0}\" will not '
|
self._log.warn(u'[the] warning: \"{0}\" will not '
|
||||||
'match string start/end'.format(p))
|
'match string start/end'.format(p))
|
||||||
if config['the']['a']:
|
if self.config['a']:
|
||||||
self.patterns = [PATTERN_A] + self.patterns
|
self.patterns = [PATTERN_A] + self.patterns
|
||||||
if config['the']['the']:
|
if self.config['the']:
|
||||||
self.patterns = [PATTERN_THE] + self.patterns
|
self.patterns = [PATTERN_THE] + self.patterns
|
||||||
if not self.patterns:
|
if not self.patterns:
|
||||||
self._log.warn(u'[the] no patterns defined!')
|
self._log.warn(u'[the] no patterns defined!')
|
||||||
|
|
@ -92,10 +88,10 @@ class ThePlugin(BeetsPlugin):
|
||||||
return text
|
return text
|
||||||
else:
|
else:
|
||||||
r = re.sub(r, '', text).strip()
|
r = re.sub(r, '', text).strip()
|
||||||
if config['the']['strip']:
|
if self.config['strip']:
|
||||||
return r
|
return r
|
||||||
else:
|
else:
|
||||||
fmt = config['the']['format'].get(unicode)
|
fmt = self.config['format'].get(unicode)
|
||||||
return fmt.format(r, t.strip()).strip()
|
return fmt.format(r, t.strip()).strip()
|
||||||
else:
|
else:
|
||||||
return u''
|
return u''
|
||||||
|
|
|
||||||
|
|
@ -16,19 +16,11 @@
|
||||||
from beets.plugins import BeetsPlugin
|
from beets.plugins import BeetsPlugin
|
||||||
from beets import ui
|
from beets import ui
|
||||||
from beets import util
|
from beets import util
|
||||||
from beets import config
|
|
||||||
import beets.library
|
import beets.library
|
||||||
import flask
|
import flask
|
||||||
from flask import g
|
from flask import g
|
||||||
import os
|
import os
|
||||||
|
|
||||||
config.add({
|
|
||||||
'web': {
|
|
||||||
'host': u'',
|
|
||||||
'port': 8337,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
# Utilities.
|
# Utilities.
|
||||||
|
|
||||||
|
|
@ -127,19 +119,26 @@ def home():
|
||||||
# Plugin hook.
|
# Plugin hook.
|
||||||
|
|
||||||
class WebPlugin(BeetsPlugin):
|
class WebPlugin(BeetsPlugin):
|
||||||
|
def __init__(self):
|
||||||
|
super(WebPlugin, self).__init__()
|
||||||
|
self.config.add({
|
||||||
|
'host': u'',
|
||||||
|
'port': 8337,
|
||||||
|
})
|
||||||
|
|
||||||
def commands(self):
|
def commands(self):
|
||||||
cmd = ui.Subcommand('web', help='start a Web interface')
|
cmd = ui.Subcommand('web', help='start a Web interface')
|
||||||
cmd.parser.add_option('-d', '--debug', action='store_true',
|
cmd.parser.add_option('-d', '--debug', action='store_true',
|
||||||
default=False, help='debug mode')
|
default=False, help='debug mode')
|
||||||
def func(lib, opts, args):
|
def func(lib, opts, args):
|
||||||
if args:
|
if args:
|
||||||
config['web']['host'] = args.pop(0)
|
self.config['host'] = args.pop(0)
|
||||||
if args:
|
if args:
|
||||||
config['web']['port'] = int(args.pop(0))
|
self.config['port'] = int(args.pop(0))
|
||||||
|
|
||||||
app.config['lib'] = lib
|
app.config['lib'] = lib
|
||||||
app.run(host=config['web']['host'].get(unicode),
|
app.run(host=self.config['host'].get(unicode),
|
||||||
port=config['web']['port'].get(int),
|
port=self.config['port'].get(int),
|
||||||
debug=opts.debug, threaded=True)
|
debug=opts.debug, threaded=True)
|
||||||
cmd.func = func
|
cmd.func = func
|
||||||
return [cmd]
|
return [cmd]
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,8 @@ import logging
|
||||||
from beets.plugins import BeetsPlugin
|
from beets.plugins import BeetsPlugin
|
||||||
from beets.library import ITEM_KEYS
|
from beets.library import ITEM_KEYS
|
||||||
from beets.importer import action
|
from beets.importer import action
|
||||||
from beets import config
|
|
||||||
from beets.util import confit
|
from beets.util import confit
|
||||||
|
|
||||||
config.add({
|
|
||||||
'zero': {
|
|
||||||
'fields': [],
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
__author__ = 'baobab@heresiarch.info'
|
__author__ = 'baobab@heresiarch.info'
|
||||||
__version__ = '0.10'
|
__version__ = '0.10'
|
||||||
|
|
||||||
|
|
@ -47,17 +39,21 @@ class ZeroPlugin(BeetsPlugin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ZeroPlugin, self).__init__()
|
super(ZeroPlugin, self).__init__()
|
||||||
|
|
||||||
|
self.config.add({
|
||||||
|
'fields': [],
|
||||||
|
})
|
||||||
|
|
||||||
self.fields = []
|
self.fields = []
|
||||||
self.patterns = {}
|
self.patterns = {}
|
||||||
self.warned = False
|
self.warned = False
|
||||||
|
|
||||||
for f in config['zero']['fields'].get(list):
|
for f in self.config['fields'].get(list):
|
||||||
if f not in ITEM_KEYS:
|
if f not in ITEM_KEYS:
|
||||||
self._log.error('[zero] invalid field: {0}'.format(f))
|
self._log.error('[zero] invalid field: {0}'.format(f))
|
||||||
else:
|
else:
|
||||||
self.fields.append(f)
|
self.fields.append(f)
|
||||||
try:
|
try:
|
||||||
self.patterns[f] = config['zero'][f].get(list)
|
self.patterns[f] = self.config[f].get(list)
|
||||||
except confit.NotFoundError:
|
except confit.NotFoundError:
|
||||||
self.patterns[f] = [u'']
|
self.patterns[f] = [u'']
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue