From e814f5024eb85e7916ec5da864d73b1b9bb20335 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 29 Feb 2024 18:24:08 +0100 Subject: [PATCH] decode unicode when rendering AdaptiveFeedItems, viewing playlists or channels --- README.md | 2 +- melon/browse/channel.py | 7 ++++--- melon/browse/playlist.py | 5 +++-- melon/widgets/feeditem.py | 21 +++++++++++++-------- requirements.txt | 4 ++++ 5 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 requirements.txt diff --git a/README.md b/README.md index 8626c97..80276c6 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Of course, you are welcome to send issues and pull requests via email as well: - `py3-beautifulsoup4` - `py3-lxml` - `py3-requests` -- `py3-sqlite3` +- `py3-unidecode` - `gtk4.0` - `libadwaita` - `webkit2gtk-6.0` diff --git a/melon/browse/channel.py b/melon/browse/channel.py index fbd5787..bb4658c 100644 --- a/melon/browse/channel.py +++ b/melon/browse/channel.py @@ -12,6 +12,7 @@ from melon.widgets.preferencerow import PreferenceRow, PreferenceType, Preferenc from melon.widgets.iconbutton import IconButton from melon.models import get_app_settings from melon.models import is_subscribed_to_channel, ensure_subscribed_to_channel, ensure_unsubscribed_from_channel +from unidecode import unidecode class BrowseChannelScreen(Adw.NavigationPage): def fetch_page(self, page=1): @@ -51,7 +52,7 @@ class BrowseChannelScreen(Adw.NavigationPage): # obtain channel information channel = self.instance.get_channel_info(channel_id) self.channel = channel - self.set_title(channel.name) + self.set_title(unidecode(channel.name)) self.header_bar = Adw.HeaderBar() self.external_btn = IconButton("","modem-symbolic") @@ -65,8 +66,8 @@ class BrowseChannelScreen(Adw.NavigationPage): self.scrollview = Gtk.ScrolledWindow() self.box = Adw.PreferencesPage() self.about = Adw.PreferencesGroup() - self.about.set_title(channel.name.replace("&", "&")) - self.about.set_description(channel.bio.replace("&", "&")) + self.about.set_title(unidecode(channel.name).replace("&", "&")) + self.about.set_description(unidecode(channel.bio).replace("&", "&")) self.results = None diff --git a/melon/browse/playlist.py b/melon/browse/playlist.py index d752971..96031f8 100644 --- a/melon/browse/playlist.py +++ b/melon/browse/playlist.py @@ -3,6 +3,7 @@ import gi gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') from gi.repository import Gtk, Adw, Gio, Gdk, GLib +from unidecode import unidecode from melon.servers.utils import get_server_instance, get_servers_list from melon.servers.utils import pixbuf_from_url @@ -51,8 +52,8 @@ class BrowsePlaylistScreen(Adw.NavigationPage): self.scrollview = Gtk.ScrolledWindow() self.box = Adw.PreferencesPage() self.about = Adw.PreferencesGroup() - self.about.set_title(self.playlist.title) - self.about.set_description(self.playlist.description) + self.about.set_title(unidecode(self.playlist.title)) + self.about.set_description(unidecode(self.playlist.description)) bookmark_pref = Preference( "bookmark-playlist", diff --git a/melon/widgets/feeditem.py b/melon/widgets/feeditem.py index 2aa337f..aa01dab 100644 --- a/melon/widgets/feeditem.py +++ b/melon/widgets/feeditem.py @@ -9,6 +9,7 @@ from melon.widgets.iconbutton import IconButton from melon.models import PlaylistWrapperType,PlaylistWrapper import threading from melon.background import queue +from unidecode import unidecode class AdaptiveFeedItem(Adw.ActionRow): """ @@ -35,25 +36,29 @@ class AdaptiveFeedItem(Adw.ActionRow): thumb_url = None if isinstance(resource, Video): thumb_url = resource.thumbnail - self.set_title(resource.title.replace("&","&")) - self.set_subtitle(resource.channel[0].replace("&","&")) + self.set_title(unidecode(resource.title).replace("&","&")) + self.set_subtitle(unidecode(resource.channel[0]).replace("&","&")) self.set_action_name("win.player") elif isinstance(resource, Playlist): thumb_url = resource.thumbnail - self.set_title(resource.title.replace("&","&")) + self.set_title(unidecode(resource.title).replace("&","&")) pad = "" if len(resource.description) > 80: pad = "..." - sub = resource.description[:80] + pad + # NOTE: this might be a bad idea + # because it could possibly cut the unicode in half? I think? + sub = unidecode(resource.description)[:80] + pad self.set_subtitle(sub.replace("&","&")) self.set_action_name("win.browse_playlist") elif isinstance(resource, Channel): thumb_url = resource.avatar - self.set_title(resource.name.replace("&","&")) + self.set_title(unidecode(resource.name).replace("&","&")) pad = "" if len(resource.bio) > 80: pad = "..." - sub = resource.bio[:80] + pad + # NOTE: this might be a bad idea + # because it could possibly cut the unicode in half? I think? + sub = unidecode(resource.bio)[:80] + pad self.set_subtitle(sub.replace("&","&")) self.set_action_name("win.browse_channel") self.preview = Adw.Avatar() @@ -81,8 +86,8 @@ class AdaptivePlaylistFeedItem(Adw.ActionRow): pixbuf = None if show_preview: pixbuf = pixbuf_from_url(playlist.inner.thumbnail) - self.set_title(playlist.inner.title.replace("&","&")) - self.set_subtitle(playlist.inner.description.replace("&","&")) + self.set_title(unidecode(playlist.inner.title).replace("&","&")) + self.set_subtitle(unidecode(playlist.inner.description).replace("&","&")) if playlist.type == PlaylistWrapperType.EXTERNAL: self.set_action_name("win.browse_playlist") self.set_action_target_value( diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..93c3943 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +beautifulsoup4 +lxml +requests +Unidecode -- 2.38.5