From 5133b22c9d520f2c4a517c5d1f63e91a7b1ae505 Mon Sep 17 00:00:00 2001 From: Echelon666 <151920667+Echelon666@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:46:53 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Strengthening=20an=20existing=20plugin=20?= =?UTF-8?q?=E2=80=9CNon-ASCII=20Equivalents=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I added 41 new characters to the existing “Non-ASCII Equivalents” plugin: 18 Polish diacritics 23 "My others" special characters that were junk in the ID3 tag of my MP3 collection. Co-Authored-By: Anderson Mesquita <69922+andersonvom@users.noreply.github.com> --- .../non_ascii_equivalents_enhanced.py | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py diff --git a/plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py b/plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py new file mode 100644 index 00000000..9029695d --- /dev/null +++ b/plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py @@ -0,0 +1,196 @@ +# -*- coding: utf-8 -*- + +# Copyright (C) 2016 Anderson Mesquita +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . + +from picard import metadata + +PLUGIN_NAME = "Expanded Non-ASCII Equivalents" +PLUGIN_AUTHOR = "Anderson Mesquita , Peter69" +PLUGIN_VERSION = "0.5" +PLUGIN_API_VERSIONS = ["0.9", "0.10", "0.11", "0.15", "2.0"] +PLUGIN_LICENSE = "GPL-3.0-or-later" +PLUGIN_LICENSE_URL = "https://gnu.org/licenses/gpl.html" +PLUGIN_DESCRIPTION = '''Replaces accented and otherwise non-ASCII characters +with a somewhat equivalent version of their ASCII counterparts. This allows old +devices to be able to display song artists and titles somewhat correctly, +instead of displaying weird or blank symbols. It's an attempt to do a little +better than Musicbrainz's native "Replace non-ASCII characters" option. + +Currently replaces characters on "album", "artist", and "title" tags.''' + +CHAR_TABLE = { + # Acute # Grave # Umlaut # Circumflex + "Á": "A", "À": "A", "Ä": "A", "Â": "A", + "É": "E", "È": "E", "Ë": "E", "Ê": "E", + "Í": "I", "Ì": "I", "Ï": "I", "Î": "I", + "Ó": "O", "Ò": "O", "Ö": "O", "Ô": "O", + "Ú": "U", "Ù": "U", "Ü": "U", "Û": "U", + "Ý": "Y", "Ỳ": "Y", "Ÿ": "Y", "Ŷ": "Y", + "á": "a", "à": "a", "ä": "a", "â": "a", + "é": "e", "è": "e", "ë": "e", "ê": "e", + "í": "i", "ì": "i", "ï": "i", "î": "i", + "ó": "o", "ò": "o", "ö": "o", "ô": "o", + "ú": "u", "ù": "u", "ü": "u", "û": "u", + "ý": "y", "ỳ": "y", "ÿ": "y", "ŷ": "y", + + # Misc Letters + "Å": "AA", + "å": "aa", + "Æ": "AE", + "æ": "ae", + "Œ": "OE", + "œ": "oe", + "ẞ": "ss", + "ß": "ss", + "Ç": "C", + "ç": "c", + "Ñ": "N", + "ñ": "n", + "Ø": "O", + "ø": "o", + + # Punctuation + "¡": "!", + "¿": "?", + "–": "--", + "—": "--", + "―": "--", + "«": "<<", + "»": ">>", + "‘": "'", + "’": "'", + "‚": ",", + "‛": "'", + "“": '"', + "”": '"', + "„": ",,", + "‟": '"', + "‹": "<", + "›": ">", + "⹂": ",,", + "「": "|-", + "」": "-|", + "『": "|-", + "』": "-|", + "〝": '"', + "〞": '"', + "〟": ",,", + "﹁": "-|", + "﹂": "|-", + "﹃": "-|", + "﹄": "|-", + """: '"', + "'": "'", + "「": "|-", + "」": "-|", + + # Mathematics + "≠": "!=", + "≤": "<=", + "≥": ">=", + "±": "+-", + "∓": "-+", + "×": "x", + "·": ".", + "÷": "/", + "√": "\\/", + "∑": "E", + "≪": "<<", # these are different + "≫": ">>", # from the quotation marks + + # Misc + "ª": "a", + "º": "o", + "°": "o", + "µ": "u", + "ı": "i", + "†": "t", + "©": "(c)", + "®": "(R)", + "℠": "(SM)", + "™": "(TM)", + + # Polish + "Ą": "A", + "ą": "a", + "Ć": "C", + "ć": "c", + "Ę": "E", + "ę": "e", + "Ł": "L", + "ł": "l", + "Ń": "N", + "ń": "n", + "Ó": "O", + "ó": "o", + "Ś": "S", + "ś": "s", + "Ź": "Z", + "ź": "z", + "Ż": "Z", + "ż": "z", + + # My others + "μ": "u", + "õ": "o", + "ọ": "o", + "ő": "o", + "Ž": "Z", + "þ": "p", + "Þ": "P", + "ð": "d", + "č": "c", + "š": "s", + "ș": "s", + "♥": "-", + "ã": "a", + "ŵ": "w", + "→": "-", + "・": "-", + "☆": "-", + "★": "-", + "/": ",", + "*": ".", + ":": "-", + ">": "(", + "<": ")", +} + +FILTER_TAGS = [ + "album", + "artist", + "title", +] + + +def sanitize(char): + if char in CHAR_TABLE: + return CHAR_TABLE[char] + return char + + +def ascii(word): + return "".join(sanitize(char) for char in word) + + +def main(tagger, metadata, *args): + for name, value in metadata.rawitems(): + if name in FILTER_TAGS: + metadata[name] = [ascii(x) for x in value] + + +metadata.register_track_metadata_processor(main) +metadata.register_album_metadata_processor(main) From 2731b393ea38e6945e7875ada14a6b660b931976 Mon Sep 17 00:00:00 2001 From: Echelon666 <151920667+Echelon666@users.noreply.github.com> Date: Wed, 6 Nov 2024 23:11:11 +0100 Subject: [PATCH 2/3] Update non_ascii_equivalents_enhanced.py Co-Authored-By: Anderson Mesquita <69922+andersonvom@users.noreply.github.com> --- .../non_ascii_equivalents_enhanced.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py b/plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py index 9029695d..84ee7f27 100644 --- a/plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py +++ b/plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py @@ -122,7 +122,7 @@ "®": "(R)", "℠": "(SM)", "™": "(TM)", - + # Polish "Ą": "A", "ą": "a", @@ -134,8 +134,7 @@ "ł": "l", "Ń": "N", "ń": "n", - "Ó": "O", - "ó": "o", + "Ś": "S", "ś": "s", "Ź": "Z", From 5524f952825f60b6cb5831c957787a39d52394a0 Mon Sep 17 00:00:00 2001 From: Echelon666 <151920667+Echelon666@users.noreply.github.com> Date: Wed, 6 Nov 2024 23:15:43 +0100 Subject: [PATCH 3/3] Update non_ascii_equivalents_enhanced.py Co-Authored-By: Anderson Mesquita <69922+andersonvom@users.noreply.github.com> --- .../non_ascii_equivalents_enhanced.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py b/plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py index 84ee7f27..dd85f64f 100644 --- a/plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py +++ b/plugins/non_ascii_equivalents_enhanced/non_ascii_equivalents_enhanced.py @@ -141,7 +141,7 @@ "ź": "z", "Ż": "Z", "ż": "z", - + # My others "μ": "u", "õ": "o",