Skip to content

Commit

Permalink
improved artist bio, fixed mix page error, improved track ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Apr 23, 2024
1 parent 948d2a4 commit b112ced
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
1 change: 1 addition & 0 deletions data/ui/widgets/generic_track_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<property name="xalign">0</property>
<property name="use-markup">true</property>
<property name="ellipsize">3</property>
<property name="margin-bottom">6</property>
<property name="label" bind-source="artist_label" bind-property="label"></property>
</object>
</child>
Expand Down
31 changes: 31 additions & 0 deletions src/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
from tidalapi.user import Favorites

import requests
import re
import html

from pathlib import Path
from . import variables

Expand Down Expand Up @@ -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)=&quot;(\d+)&quot;\]([^[]+)\[\/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'<a href="artist:{id_value}">{label}</a>'
elif link_type == "albumId":
return f'<a href="album:{id_value}">{label}</a>'
else:
return label

# Replace <br/> with two periods
escaped_text = escaped_text.replace('&lt;br/&gt;', '\n\n')

# Use re.sub() to perform the replacement
replaced_text = re.sub(pattern, replace, escaped_text)

return replaced_text
4 changes: 2 additions & 2 deletions src/lib/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(":")
Expand Down
23 changes: 15 additions & 8 deletions src/pages/artist_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import requests
import random
import copy
import html
import re

from .page import Page

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]
# <a href="artist:3653311">Hayley Williams</a>

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()
Expand Down Expand Up @@ -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)

12 changes: 6 additions & 6 deletions src/pages/mix_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b112ced

Please sign in to comment.