Skip to content

Commit

Permalink
fixed playlist repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Oct 17, 2024
1 parent 49d1931 commit 59fa8a2
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 47 deletions.
15 changes: 3 additions & 12 deletions data/io.github.nokse22.HighTide.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="tidal">
<schema id="io.github.nokse22.HighTide" path="/io/github/nokse22/tidal/">
<key name="token-type" type="s">
<default>""</default>
</key>
<key name="access-token" type="s">
<default>""</default>
</key>
<key name="refresh-token" type="s">
<default>""</default>
</key>
<key name="expiry-time" type="s">
<default>""</default>
</key>
<key name="window-width" type="i">
<default>1000</default>
</key>
Expand All @@ -33,6 +21,9 @@
</key>
<key name="last-volume" type="i">
<default>10</default>
</key>
<key name="repeat" type="b">
<default>false</default>
</key>
</schema>
</schemalist>
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 @@ -174,3 +174,4 @@
<!-- </submenu> -->
</menu>
</interface>

3 changes: 2 additions & 1 deletion data/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ flat</property>
</object>
</child>
<child>
<object class="GtkToggleButton" id="repeat_button">
<object class="GtkButton" id="repeat_button">
<property name="css-classes">circular
flat</property>
<property name="icon-name">media-playlist-repeat-symbolic</property>
Expand All @@ -481,6 +481,7 @@ flat</property>
<property name="margin-end">6</property>
<property name="margin-top">6</property>
<property name="opacity">0.6</property>
<signal name="clicked" handler="on_repeat_clicked"/>
</object>
</child>
</object>
Expand Down
18 changes: 12 additions & 6 deletions src/lib/player_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,19 @@ def __init__(self):

self.current_mix_album_playlist = None # Information about the currently playing mix/album

self._tracks_to_play = [] # The tracks to play in the correct order
self.tracks_to_play = [] # List of all the tracks to play in the current album/mix/playlist EXPOSED
self._tracks_to_play = [] # The tracks to play in the correct order
self.tracks_to_play = [] # List of all the tracks to play in the current album/mix/playlist EXPOSED
self._shuffled_tracks_to_play = [] # Shuffled version of the next tracks to play

self.played_songs = [] # List of played songs when not shuffling
self.played_songs = [] # List of played songs when not shuffling

self.shuffle_mode = False
self.is_playing = False
self.playing_track = None
self.song_album = None

self.repeat = True

self.duration = self.query_duration()

self.can_next = False
Expand Down Expand Up @@ -127,7 +129,7 @@ def shuffle_this(self, thing): # Same as play_this, but on shuffle
self.play_this(tracks, random.randint(0, len(tracks)))
self.shuffle(True)

def get_track_list(self, thing): # Converts albums, playlists, mixes in a list of tracks
def get_track_list(self, thing): # Converts albums, playlists, mixes in a list of tracks
if isinstance(thing, Mix):
tracks = thing.items()
elif isinstance(thing, Album):
Expand Down Expand Up @@ -214,8 +216,12 @@ def play_next(self):

# If the tracks_to_play list is empty it refills it with the played songs and empties the played_songs
if self._tracks_to_play == []:
self._tracks_to_play = self.played_songs
self.played_songs = []
if self.repeat:
self._tracks_to_play = self.played_songs
self.played_songs = []
else:
self.pause()
return

# If it's shuffling it plays the first song in the shuffled_tracks_to_play. If it's not on shuffle it will play the first song from tracks_to_play
if self.shuffle_mode:
Expand Down
8 changes: 4 additions & 4 deletions src/lib/secret_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def save(self):
expiry_time = self.session.expiry_time

self.token_dictionary = {
"token-type" : token_type,
"access-token" : access_token,
"refresh-token" : refresh_token,
"expiry-time" : str(expiry_time)
"token-type": token_type,
"access-token": access_token,
"refresh-token": refresh_token,
"expiry-time": str(expiry_time)
}

json_data = json.dumps(self.token_dictionary, indent=2)
Expand Down
1 change: 1 addition & 0 deletions src/widgets/carousel_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,4 @@ def __on_unrealized(self, *args):

def __del__(self, *args):
print(f"DELETING {self}")

82 changes: 58 additions & 24 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,56 @@ class HighTideWindow(Adw.ApplicationWindow):
queue_widget = Gtk.Template.Child()
mobile_stack = Gtk.Template.Child()
lyrics_label = Gtk.Template.Child()
repeat_button = Gtk.Template.Child()

def __init__(self, **kwargs):
super().__init__(**kwargs)

self.settings = Gio.Settings.new('io.github.nokse22.HighTide')

self.settings.bind("window-width", self, "default-width", Gio.SettingsBindFlags.DEFAULT)
self.settings.bind("window-height", self, "default-height", Gio.SettingsBindFlags.DEFAULT)
self.settings.bind(
"window-width", self,
"default-width", Gio.SettingsBindFlags.DEFAULT)
self.settings.bind(
"window-height", self,
"default-height", Gio.SettingsBindFlags.DEFAULT)

self.player_object = playerObject()
variables.player_object = self.player_object
# variables.search_entry = self.search_entry

self.volume_button.get_adjustment().set_value(self.settings.get_int("last-volume")/10)
self.volume_button.get_adjustment().set_value(
self.settings.get_int("last-volume")/10)

self.shuffle_button.connect("toggled", self.on_shuffle_button_toggled)

self.player_object.connect("shuffle-changed", self.on_shuffle_changed)
self.player_object.connect("update-slider", self.update_slider)
self.player_object.connect("song-changed", self.on_song_changed)
self.player_object.connect("song-added-to-queue", self.on_song_added_to_queue)
self.player_object.connect(
"shuffle-changed", self.on_shuffle_changed)
self.player_object.connect(
"update-slider", self.update_slider)
self.player_object.connect(
"song-changed", self.on_song_changed)
self.player_object.connect(
"song-added-to-queue", self.on_song_added_to_queue)
self.player_object.connect("play-changed", self.update_controls)

self.queue_widget.connect("map", self.on_queue_widget_mapped)
self.player_object.repeat = self.settings.get_boolean("repeat")
if not self.player_object.repeat:
self.repeat_button.set_icon_name(
"media-playlist-consecutive-symbolic")
else:
self.repeat_button.set_icon_name(
"media-playlist-repeat-symbolic")

self.queue_widget.connect(
"map", self.on_queue_widget_mapped)

self.artist_label.connect("activate-link", variables.open_uri)
self.mobile_artist_label.connect("activate-link", variables.open_uri)
self.mobile_artist_label.connect("activate-link", self.toggle_mobile_view)
self.artist_label.connect(
"activate-link", variables.open_uri)
self.mobile_artist_label.connect(
"activate-link", variables.open_uri)
self.mobile_artist_label.connect(
"activate-link", self.toggle_mobile_view)

self.session = tidalapi.Session()

Expand All @@ -130,12 +152,6 @@ def __init__(self, **kwargs):

self.secret_store = SecretStore(self.session)

# TO REMOVE UNSECURED TOKENS set in early development
self.settings.set_string("token-type", "")
self.settings.set_string("access-token", "")
self.settings.set_string("refresh-token", "")
self.settings.set_string("expiry-time", "")

page = startUpPage(None, "Loading")
page.load()
self.navigation_view.push(page)
Expand Down Expand Up @@ -170,8 +186,8 @@ def on_login_failed(self):
page.load()
self.navigation_view.replace([page])

def on_create_new_playlist_requested(self, window, playlist_title, playlist_description):
self.session.user.create_playlist(playlist_title, playlist_description)
def on_create_new_playlist_requested(self, window, p_title, p_description):
self.session.user.create_playlist(p_title, p_description)
self.update_my_playlists()
window.close()

Expand Down Expand Up @@ -235,14 +251,20 @@ def on_song_changed(self, *args):
self.explicit_label.set_visible(track.explicit)

if variables.is_favourited(track):
self.in_my_collection_button.set_icon_name("heart-filled-symbolic")
self.in_my_collection_button.set_icon_name(
"heart-filled-symbolic")
else:
self.in_my_collection_button.set_icon_name("heart-outline-thick-symbolic")
self.in_my_collection_button.set_icon_name(
"heart-outline-thick-symbolic")

self.settings.set_int("last-playing-song-id", track.id)

threading.Thread(target=utils.add_image, args=(self.playing_track_image, album)).start()
threading.Thread(target=utils.add_picture, args=(self.current_carousel_picture, album)).start()
threading.Thread(
target=utils.add_image,
args=(self.playing_track_image, album)).start()
threading.Thread(
target=utils.add_picture,
args=(self.current_carousel_picture, album)).start()

# next_track = self.player_object.get_next_track()
# if next_track:
Expand Down Expand Up @@ -530,8 +552,20 @@ def toggle_mobile_view(self, *args):

return True

def on_song_added_to_queue(self, *args):
@Gtk.Template.Callback("on_repeat_clicked")
def on_repeat_clicked(self, *args):
if self.player_object.repeat:
self.repeat_button.set_icon_name(
"media-playlist-consecutive-symbolic")
self.player_object.repeat = False
else:
self.repeat_button.set_icon_name(
"media-playlist-repeat-symbolic")
self.player_object.repeat = True

self.settings.set_boolean("repeat", self.player_object.repeat)

def on_song_added_to_queue(self, *args):
if (self.main_view_stack.get_visible_child_name() == "mobile_view" and
self.mobile_stack.get_visible_child_name() == "queue_page"):
self.queue_widget.update_queue(self.player_object)
Expand Down

0 comments on commit 59fa8a2

Please sign in to comment.