Writing a find-and-replace rule to fix HTML encoding
February 13, 2019 in bliss by Dan Gravell
You can write a generic "find and replace" rule in bliss using custom rules.
In this example I'll take this idea to remove HTML encoding from tags and implement it as a custom rule. HTML encoding is a way of writing certain characters such as <
or &
in a way that does not affect the rendering of Web pages. The respective special characters for those two examples are <
and &
.
Unfortunately this text can sometimes be copied outside of an HTML context which leads to gibberish that makes little sense. In our case, it can sometimes make its way into our music tags (maybe caused by copy-and-paste gone bad, or software using data which has been HTML encoded). This then might mean the same gibberish showing up in your music player!
Custom regex rules are basically ways of finding and replacing text in your music tags. Think of them as "find and replace rules". Starting a find and replace rule can be a case of just copying and pasting the following template:
We need to replace everything in square brackets. But before you do that, I'll fill in some of the brackets...
For finding and replacing HTML encoding, we can make a good start:
# Find HTML encoding and replace with the decoded value rule find_replace_html_encoding with label "Find and replace HTML encoding" has alternatives HTML_DECODED { find /[find regex, may include groups]/ replace with "[Substitution string, may include group references]" } applies to album_artist, album_name, track_name, artist, comment
So that leaves the find
line. What should we put here? It turns out there are a few lists of HTML special characters available on a web. Here's a good one!
Using those, we can add multiple find-and-replace lines:
find /"/ replace with "\"" find /#/ replace with "#" find /$/ replace with "$"
This doesn't scale particularly well; there are a lot of lines in the linked table! However we can pretty easily implement all the common ones.
Here's the completed rule:
Now, to use it:
- Download the above completed script and save it as
find-and-replace_html-encoding.regexrule
- Move the file to the bliss settings folder, into the
regex-rules
folder. The bliss settings folder is in:Windows XP C:\Documents and Settings\[username]\.bliss Windows Vista, 7, 8 and 10 C:\Users\[username]\.bliss Mac OS X (see below) /Users/[username]/Library/Application Support/bliss Linux /home/[username]/.bliss Docker /config (within the container); find where this is mounted from in the run
commandSynology /var/packages/bliss/target/var/.bliss QNAP `getcfg SHARE_DEF defVolMP -f /etc/config/def_share.info`/.qpkg/bliss/.bliss VortexBox /root/.bliss C:\Documents and Settings\[username]\.bliss\regex-rules\find-and-replace_html-encoding.regexrule
- Restart bliss.
- Visit the settings page, and your rule should be there.
Once you've added the rule, click Apply rules and any special characters should be found:
Click the one-click fix or use the Inbox to click en-masse.
Let me know if you think of further good find-and-replace rules!
Thanks to rawpixel for the image above.