mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
add asciify function
This commit is contained in:
parent
b493bc7004
commit
8fde981b1d
2 changed files with 11 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
from unidecode import unidecode
|
||||||
from beets.mediafile import MediaFile
|
from beets.mediafile import MediaFile
|
||||||
from beets import plugins
|
from beets import plugins
|
||||||
from beets import util
|
from beets import util
|
||||||
|
|
@ -1301,6 +1302,10 @@ def _tmpl_if(condition, trueval, falseval=u''):
|
||||||
return trueval
|
return trueval
|
||||||
else:
|
else:
|
||||||
return falseval
|
return falseval
|
||||||
|
def _tmpl_asciify(s):
|
||||||
|
"""Translate non-ASCII characters to their ASCII equivalents.
|
||||||
|
"""
|
||||||
|
return unidecode(s)
|
||||||
|
|
||||||
TEMPLATE_FUNCTIONS = {
|
TEMPLATE_FUNCTIONS = {
|
||||||
'lower': _tmpl_lower,
|
'lower': _tmpl_lower,
|
||||||
|
|
@ -1309,4 +1314,5 @@ TEMPLATE_FUNCTIONS = {
|
||||||
'left': _tmpl_left,
|
'left': _tmpl_left,
|
||||||
'right': _tmpl_right,
|
'right': _tmpl_right,
|
||||||
'if': _tmpl_if,
|
'if': _tmpl_if,
|
||||||
|
'asciify': _tmpl_asciify,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,11 @@ These functions are built in to beets:
|
||||||
``condition`` is nonempty (or nonzero, if it's a number), then returns
|
``condition`` is nonempty (or nonzero, if it's a number), then returns
|
||||||
the second argument. Otherwise, returns the third argument if specified (or
|
the second argument. Otherwise, returns the third argument if specified (or
|
||||||
nothing if ``falsetext`` is left off).
|
nothing if ``falsetext`` is left off).
|
||||||
|
* ``%asciify{text}``: Convert non-ASCII characters to their ASCII equivalents.
|
||||||
|
For example, "café" becomes "cafe". Uses the mapping provided by the
|
||||||
|
`unidecode module`_.
|
||||||
|
|
||||||
|
.. _unidecode module: http://pypi.python.org/pypi/Unidecode
|
||||||
|
|
||||||
Plugins can extend beets with more template functions (see
|
Plugins can extend beets with more template functions (see
|
||||||
:ref:`writing-plugins`).
|
:ref:`writing-plugins`).
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue