sampsyo/beets — pull request #556 by geigerzaehler (2014-02-23 18:13:26+00:00)
Title: Allow for custom path separator replacement

Second stab at this after c82b31e. See also #323.

Kinda hard to explain, its probably best to look at the code, but here we go.

Before, path sanitation took place in two places. `Model.format` and `Item.destination`. The first method made sure no path separators occured in when evaluating variables in a template. Then `Item.destination` applied additional sanitization: Unicode normalization, applying user defined (or default) replacements and truncation. This made it impossible to specify the path separtor in the `replace` configuration.

With this commit we remove any path sanitization logic from `Model`. Instead, we add the `Model.evaluate_path_template` method that evaluates the components of a template separately, but does not sanitize the components. This allows us to sanitize each component in `Item.destination` and then join them. Sanitization in `Item.destination` has two steps: First user defined replacements are performed. These are passed to the `Library` constructor as the `replacements` keyword and default to those given in `default_config.yaml`. Secondly, we call the `beets.util.sanitize_path_component` to replace all path separators and truncate the components. The function does not replace reserved characters such as `:`, but this is consistent with previous behaviour where the user set the `replace` configuration.

There is still an issue with `Model.evalutate_path_template`. The method splits the template before parsing it. This may not be correct when some custom function conatin a path separator. It would appreciate suggestions on how to fix this, since I don't know the internals of `Template`.