mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-22 08:53:59 +01:00
pathrender.py: Add module for extended path formatting
The pattern matching is loosely based on foobar2000 pattern syntax, i.e. the notion of escaping characters with ' and optional elements enclosed in square brackets [] is taken from there while the substitution variable names are Perl-ish or sh-ish. The following syntax elements are supported: * escaped literal strings, that is everything that is enclosed within single quotes (like 'this'); * substitution variables, which start with dollar sign ($) and extend until next non-alphanumeric+underscore character (like $This and $5_that). * optional elements enclosed in square brackets, which render nonempty value only if any variable or optional inside returned nonempty value, ignoring literals (like ['['$That']' ]).
This commit is contained in:
@@ -191,11 +191,13 @@ def piratesize(size):
|
||||
|
||||
|
||||
def replace_all(text, dic, normalize=False):
|
||||
from headphones import pathrender
|
||||
if not text:
|
||||
return ''
|
||||
|
||||
for i, j in dic.iteritems():
|
||||
if normalize:
|
||||
if normalize:
|
||||
new_dic = {}
|
||||
for i, j in dic.iteritems():
|
||||
try:
|
||||
if sys.platform == 'darwin':
|
||||
j = unicodedata.normalize('NFD', j)
|
||||
@@ -203,8 +205,9 @@ def replace_all(text, dic, normalize=False):
|
||||
j = unicodedata.normalize('NFC', j)
|
||||
except TypeError:
|
||||
j = unicodedata.normalize('NFC', j.decode(headphones.SYS_ENCODING, 'replace'))
|
||||
text = text.replace(i, j)
|
||||
return text
|
||||
new_dic[i] = j
|
||||
dic = new_dic
|
||||
return pathrender.render(text, dic)
|
||||
|
||||
|
||||
def replace_illegal_chars(string, type="file"):
|
||||
|
||||
Reference in New Issue
Block a user