From b112cedd4cc24ed44bfa25e328710e1f39c88ce7 Mon Sep 17 00:00:00 2001 From: Nokse22 Date: Tue, 23 Apr 2024 21:56:51 +0200 Subject: [PATCH] improved artist bio, fixed mix page error, improved track ui --- data/ui/widgets/generic_track_widget.ui | 1 + src/lib/utils.py | 31 +++++++++++++++++++++++++ src/lib/variables.py | 4 ++-- src/pages/artist_page.py | 23 +++++++++++------- src/pages/mix_page.py | 12 +++++----- src/window.py | 12 ++++++++++ 6 files changed, 67 insertions(+), 16 deletions(-) diff --git a/data/ui/widgets/generic_track_widget.ui b/data/ui/widgets/generic_track_widget.ui index e6c1d5c..47b356f 100644 --- a/data/ui/widgets/generic_track_widget.ui +++ b/data/ui/widgets/generic_track_widget.ui @@ -126,6 +126,7 @@ 0 true 3 + 6 diff --git a/src/lib/utils.py b/src/lib/utils.py index bfb2a94..53a0c37 100644 --- a/src/lib/utils.py +++ b/src/lib/utils.py @@ -33,6 +33,9 @@ from tidalapi.user import Favorites import requests +import re +import html + from pathlib import Path from . import variables @@ -105,3 +108,31 @@ def _add_image_to_avatar(avatar_widget, file_path): file.write(image_data) GLib.idle_add(_add_image_to_avatar, avatar_widget, str(file_path)) + +def replace_links(text): + # Define regular expression pattern to match escaped [wimpLink ...]...[/wimpLink] tags + pattern = r'\[wimpLink (artistId|albumId)="(\d+)"\]([^[]+)\[\/wimpLink\]' + + # Escape HTML in the entire text + escaped_text = html.escape(text) + + # Define a function to replace the matched pattern with the desired format + def replace(match): + link_type = match.group(1) + id_value = match.group(2) + label = match.group(3) + + if link_type == "artistId": + return f'{label}' + elif link_type == "albumId": + return f'{label}' + else: + return label + + # Replace
with two periods + escaped_text = escaped_text.replace('<br/>', '\n\n') + + # Use re.sub() to perform the replacement + replaced_text = re.sub(pattern, replace, escaped_text) + + return replaced_text diff --git a/src/lib/variables.py b/src/lib/variables.py index b4d69c2..0c8469e 100644 --- a/src/lib/variables.py +++ b/src/lib/variables.py @@ -33,11 +33,11 @@ def init(): global favourite_tracks -def open_uri(label, uri): +def open_uri(label, uri, turn=True): print(uri) th= threading.Thread(target=_load_object, args=(uri,)) th.start() - return True + return turn def _open_uri(uri, loaded_object): uri_parts = uri.split(":") diff --git a/src/pages/artist_page.py b/src/pages/artist_page.py index 8b3bcc9..1a7c622 100644 --- a/src/pages/artist_page.py +++ b/src/pages/artist_page.py @@ -39,6 +39,8 @@ import requests import random import copy +import html +import re from .page import Page @@ -78,16 +80,14 @@ def _load_page(self): artist_picture = builder.get_object("_avatar") - th = threading.Thread(target=utils.add_image_to_avatar, args=(artist_picture, self.artist)) - th.deamon = True - th.start() + threading.Thread(target=utils.add_image_to_avatar, args=(artist_picture, self.artist)).start() roles_str = "" for role in self.artist.roles: print(role) roles_str += " " + role.main.value - builder.get_object("_first_subtitle_label").set_label(roles_str) + builder.get_object("_first_subtitle_label").set_label("Artist") tracks_list_widget = TracksListWidget("Top Tracks") tracks_list_widget.set_function(self.artist.get_top_tracks) @@ -145,15 +145,21 @@ def _load_page(self): artist_card = self.get_artist_card(artist) carousel.append_card(artist_card) + # [wimpLink artistId="3653311"]Hayley Williams[/wimpLink] + # Hayley Williams + try: bio = self.artist.get_bio() except: pass else: - expander = Gtk.Expander(label="Bio", css_classes=["title-3"], margin_bottom=50) - label = Gtk.Label(label=bio, wrap=True, css_classes=[]) - expander.set_child(label) - content_box.append(expander) + bio = utils.replace_links(bio) + # expander = Gtk.Expander(label="Bio", css_classes=["title-3"], margin_bottom=50) + label = Gtk.Label(wrap=True, css_classes=[]) + label.set_markup(bio) + # expander.set_child(label) + content_box.append(label) + label.connect("activate-link", variables.open_uri) self.page_content.append(page_content) self._page_loaded() @@ -184,3 +190,4 @@ def on_artist_radio_button_clicked(self, btn): page = trackRadioPage(self.artist, f"Radio of {self.artist.name}") page.load() variables.navigation_view.push(page) + diff --git a/src/pages/mix_page.py b/src/pages/mix_page.py index 4a7b17c..397f7ed 100644 --- a/src/pages/mix_page.py +++ b/src/pages/mix_page.py @@ -64,12 +64,12 @@ def _load_page(self): th.deamon = True th.start() - for favourite_track in variables.favourite_tracks: - if favourite_track.isrc == track.isrc: - self.in_my_collection_button.set_icon_name("heart-filled-symbolic") - break - else: - self.in_my_collection_button.set_icon_name("heart-outline-thick-symbolic") + # for favourite_track in variables.favourite_tracks: + # if favourite_track.isrc == track.isrc: + # self.in_my_collection_button.set_icon_name("heart-filled-symbolic") + # break + # else: + # self.in_my_collection_button.set_icon_name("heart-outline-thick-symbolic") for index, track in enumerate(self.item.items()): listing = self.get_track_listing(track) diff --git a/src/window.py b/src/window.py index e4f28e4..abb97ce 100644 --- a/src/window.py +++ b/src/window.py @@ -78,6 +78,7 @@ class HighTideWindow(Adw.ApplicationWindow): song_title_label = Gtk.Template.Child() playing_track_image = Gtk.Template.Child() artist_label = Gtk.Template.Child() + mobile_artist_label = Gtk.Template.Child() sidebar_collection = Gtk.Template.Child() right_sidebar_split_view = Gtk.Template.Child() lyrics_label = Gtk.Template.Child() @@ -111,6 +112,8 @@ def __init__(self, **kwargs): self.player_object.connect("play-changed", self.update_controls) self.artist_label.connect("activate-link", variables.open_uri) + self.mobile_artist_label.connect("activate-link", variables.open_uri, False) + self.mobile_artist_label.connect("activate-link", self.toggle_mobile_view) self.search_entry.connect("activate", self.on_search_activated) @@ -282,6 +285,15 @@ def update_queue(self, *args): # print("REMOVED") self.queue_list.set_child(box) + def toggle_mobile_view(self, *args): + name = self.main_view_stack.get_visible_child_name() + if name == "normal_view": + self.main_view_stack.set_visible_child_name("mobile_view") + elif name == "mobile_view": + self.main_view_stack.set_visible_child_name("normal_view") + + return True + def on_search_activated(self, *args): page = searchPage(None, "Search") page.load()