Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added polish diacritics in non_ascii_equivalents.py #386

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 24 additions & 30 deletions plugins/non_ascii_equivalents/non_ascii_equivalents.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
# this program. If not, see <http://www.gnu.org/licenses/>.

from picard import metadata
from picard.util.textencoding import unaccent

PLUGIN_NAME = "Non-ASCII Equivalents"
PLUGIN_AUTHOR = "Anderson Mesquita <andersonvom@trysometinghere>"
PLUGIN_VERSION = "0.4"
PLUGIN_AUTHOR = "Anderson Mesquita <andersonvom@trysometinghere>, Konrad Marciniak"
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"
Expand All @@ -29,23 +30,9 @@
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.'''
Currently replaces characters on "album", "albumartist", "albumartists", "albumartistsort", "albumsort", "artist", "artists", "artistsort" 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",
phw marked this conversation as resolved.
Show resolved Hide resolved
"å": "aa",
Expand All @@ -55,12 +42,14 @@
"œ": "oe",
"ẞ": "ss",
"ß": "ss",
"Ç": "C",
"ç": "c",
"Ñ": "N",
"ñ": "n",
"Ø": "O",
"ø": "o",
"Ł": "L",
"ł": "l",
"Þ": "Th", # Thorn
"þ": "th",
"Ð": "D", # Eth
"ð": "d",

# Punctuation
"¡": "!",
Expand Down Expand Up @@ -92,10 +81,9 @@
"﹂": "|-",
"﹃": "-|",
"﹄": "|-",
""": '"',
"'": "'",
"「": "|-",
"」": "-|",
"・": ".", # Katakana middle dot

# Mathematics
"≠": "!=",
Expand All @@ -112,39 +100,45 @@
"≫": ">>", # from the quotation marks

# Misc
"ª": "a",
"º": "o",
"°": "o",
"µ": "u",
"ı": "i",
"†": "t",
"©": "(c)",
"®": "(R)",
"℠": "(SM)",
"™": "(TM)",
"♥": "<3",
"→": "-->",
"☆": "*",
"★": "*",
}

FILTER_TAGS = [
"album",
"albumartist",
"albumartists",
"albumartistsort",
"albumsort",
"artist",
"artists",
"artistsort",
"title",
]


def sanitize(char):
if char in CHAR_TABLE:
return CHAR_TABLE[char]
return char
return unaccent(char)


def ascii(word):
def to_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[name] = [to_ascii(x) for x in value]


metadata.register_track_metadata_processor(main)
Expand Down
Loading