Added plugin

This commit is contained in:
Daniele Ferone 2023-02-07 15:34:50 +01:00 committed by J0J0 Todos
parent 0e5ade4f71
commit 249b420b19
2 changed files with 67 additions and 0 deletions

40
beetsplug/substitute.py Normal file
View file

@ -0,0 +1,40 @@
# This file is part of beets.
# Copyright 2016, Adrian Sampson.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
"""Uses user-specified substituting rules to canonicalize names for path
formats without modifying the tags of the songs.
"""
from beets.plugins import BeetsPlugin
import re
_substitute_rules = []
class Substitute(BeetsPlugin):
def __init__(self):
super(Substitute, self).__init__()
self.template_funcs['substitute'] = _tmpl_substitute
for key, view in self.config.items():
value = view.as_str()
pattern = re.compile(key.lower())
_substitute_rules.append((pattern, value))
def _tmpl_substitute(text):
if text:
for pattern, replacement in _substitute_rules:
if pattern.match(text.lower()):
return replacement
return text
else:
return u''

View file

@ -0,0 +1,27 @@
Substitute Plugin
==============
The ``substitute`` plugin lets you easily substitute values in your templates and
path formats. Specifically, it is intended to let you *canonicalize* names
such as artists: for example, perhaps you want albums from The Jimi Hendrix
Experience to be sorted into the same folder as solo Hendrix albums.
To use field substituting, first enable the ``substitute`` plugin
(see :ref:`using-plugins`).
Then, make a ``substitute:`` section in your config file to contain your rules.
Each rule consists of a a regular expression pattern, and a
replacement value. Rules are written ``regex: replacement``.
For example, this line implements the Jimi Hendrix example above::
rewrite:
The Jimi Hendrix Experience: Jimi Hendrix
The pattern is a case-insensitive regular expression. This means you can use
ordinary regular expression syntax to match multiple artists. For example, you
might use::
rewrite:
.*jimi hendrix.*: Jimi Hendrix
This plugin is intented as a replacement for the ``rewrite`` plugin. Indeed, while
the ``rewrite`` plugin modifies the metadata, this plugin does not.