From f897e0fa505a86e0739b7662f45b4764b400dc6e Mon Sep 17 00:00:00 2001 From: meeb Date: Mon, 29 Apr 2024 01:49:37 +1000 Subject: [PATCH] strip emojis from nfo output strings, resolves #495 --- Pipfile | 1 + tubesync/common/utils.py | 7 +++++++ tubesync/sync/models.py | 10 +++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Pipfile b/Pipfile index bb2f9550..af67a7a1 100644 --- a/Pipfile +++ b/Pipfile @@ -23,3 +23,4 @@ yt-dlp = "*" redis = "*" hiredis = "*" requests = {extras = ["socks"], version = "*"} +emoji = "*" diff --git a/tubesync/common/utils.py b/tubesync/common/utils.py index 4cb9f935..1c7b42e5 100644 --- a/tubesync/common/utils.py +++ b/tubesync/common/utils.py @@ -1,6 +1,7 @@ import string from datetime import datetime from urllib.parse import urlunsplit, urlencode, urlparse +import emoji from yt_dlp.utils import LazyList from .errors import DatabaseConnectionError @@ -123,6 +124,12 @@ def clean_filename(filename): return clean_filename.strip() +def clean_emoji(s): + if not isinstance(s, str): + raise ValueError(f'parameter must be a str, got {type(s)}') + return emoji.replace_emoji(s) + + def json_serial(obj): if isinstance(obj, datetime): return obj.isoformat() diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index cdadb16e..47346c83 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -15,7 +15,7 @@ from django.utils import timezone from django.utils.translation import gettext_lazy as _ from common.errors import NoFormatException -from common.utils import clean_filename +from common.utils import clean_filename, clean_emoji from .youtube import (get_media_info as get_youtube_media_info, download_media as download_youtube_media, get_channel_image_info as get_youtube_channel_image_info) @@ -1275,12 +1275,12 @@ def nfoxml(self): nfo.text = '\n ' # title = media metadata title title = nfo.makeelement('title', {}) - title.text = str(self.name).strip() + title.text = clean_emoji(str(self.name).strip()) title.tail = '\n ' nfo.append(title) # showtitle = source name showtitle = nfo.makeelement('showtitle', {}) - showtitle.text = str(self.source.name).strip() + showtitle.text = clean_emoji(str(self.source.name).strip()) showtitle.tail = '\n ' nfo.append(showtitle) # season = upload date year @@ -1322,7 +1322,7 @@ def nfoxml(self): nfo.append(ratings) # plot = media metadata description plot = nfo.makeelement('plot', {}) - plot.text = str(self.description).strip() + plot.text = clean_emoji(str(self.description).strip()) plot.tail = '\n ' nfo.append(plot) # thumb = local path to media thumbnail @@ -1355,7 +1355,7 @@ def nfoxml(self): nfo.append(uniqueid) # studio = media metadata uploader studio = nfo.makeelement('studio', {}) - studio.text = str(self.uploader).strip() + studio.text = clean_emoji(str(self.uploader).strip()) studio.tail = '\n ' nfo.append(studio) # aired = media metadata uploaded date