commit 1bd9180df2f104c45e5c5c8472dce8ea26d84f31
parent 3963fb2492ee6ba15a319b388b6dab94bbd072f9
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date: Tue, 21 Jul 2020 13:13:42 -0700
Improve support for unicode characters.
Diffstat:
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/Songs2Slides/core.py b/Songs2Slides/core.py
@@ -6,6 +6,7 @@ from pptx.enum.text import MSO_ANCHOR, PP_ALIGN
from pptx.util import Inches, Pt
import re
import requests
+from unidecode import unidecode
@@ -16,12 +17,16 @@ def GetLyrics(title, artist):
title = title.lower()
# Replace invalid characters
- old = [" ", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "+", "=", "'", "?", "/", "|", "\\", ".", ",", "á", "é", "í", "ó", "ñ", "ú"]
- new = ["-", "", "", "", "s", "", "-", "-and-", "", "", "", "-", "-", "", "", "", "", "", "", "", "a", "e", "i", "o", "n", "u"]
+ old = [" ", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "+", "=", "'", "?", "/", "|", "\\", ".", ","]
+ new = ["-", "", "", "", "s", "", "-", "-and-", "", "", "", "-", "-", "", "", "", "", "", "", ""]
for i in range(0, len(old)):
artist = artist.replace(old[i], new[i])
title = title.replace(old[i], new[i])
+ # Replace unicode characters
+ artist = unidecode(artist)
+ title = unidecode(title)
+
# Remove unnecessary dashes
artist = "-".join(list(filter(lambda a: a != "", artist.split("-"))))
title = "-".join(list(filter(lambda a: a != "", title.split("-"))))
diff --git a/requirements.txt b/requirements.txt
@@ -1,4 +1,5 @@
bs4
python-pptx
requests
-flask
-\ No newline at end of file
+flask
+unidecode
+\ No newline at end of file