Skip to content

Commit

Permalink
strip emojis from nfo output strings, resolves #495
Browse files Browse the repository at this point in the history
  • Loading branch information
meeb committed Apr 28, 2024
1 parent 8c0c6ad commit f897e0f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ yt-dlp = "*"
redis = "*"
hiredis = "*"
requests = {extras = ["socks"], version = "*"}
emoji = "*"
7 changes: 7 additions & 0 deletions tubesync/common/utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions tubesync/sync/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f897e0f

Please sign in to comment.