Skip to content

Commit

Permalink
updated library, fixed some bugs, added song repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Nov 4, 2024
1 parent 59fa8a2 commit dc43d90
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 81 deletions.
1 change: 1 addition & 0 deletions data/HighTide.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<file preprocess="xml-stripblanks">icons/16x16/actions/explore2-large-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/16x16/actions/library-music-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/16x16/actions/music-note-single-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/16x16/actions/playlist-repeat-song-symbolic.svg</file>
<!-- <file preprocess="xml-stripblanks">icons/16x16/actions/music-note-single-symbolic.svg</file> -->
</gresource>
</gresources>
Expand Down
2 changes: 2 additions & 0 deletions data/icons/16x16/actions/playlist-repeat-song-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions data/io.github.nokse22.HighTide.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<key name="last-volume" type="i">
<default>10</default>
</key>
<key name="repeat" type="b">
<default>false</default>
<key name="repeat" type="i">
<default>0</default>
</key>
</schema>
</schemalist>
126 changes: 63 additions & 63 deletions io.github.nokse22.HighTide.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,69 +62,69 @@
]
},
{
"name": "python3-tidalapi",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"tidalapi\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ba/06/a07f096c664aeb9f01624f858c3add0a4e913d6c96257acb4fce61e7de14/certifi-2024.2.2-py3-none-any.whl",
"sha256": "dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/63/09/c1bc53dab74b1816a00d8d030de5bf98f724c52c1635e07681d312f20be8/charset-normalizer-3.3.2.tar.gz",
"sha256": "f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/e5/3e/741d8c82801c347547f8a2a06aa57dbb1992be9e948df2ea0eda2c8b79e8/idna-3.7-py3-none-any.whl",
"sha256": "82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/b6/85/7882d311924cbcfc70b1890780763e36ff0b140c7e51c110fc59a532f087/isodate-0.6.1-py2.py3-none-any.whl",
"sha256": "0751eece944162659049d35f4f549ed815792b38793f07cf73381c1c87cbed96"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ab/1a/5be778993af7c2079e7a24dc208424af6fe1b6392dfaac268a8cf42ba842/mpegdash-0.4.0-py3-none-any.whl",
"sha256": "d07f6e1f2a67ddce1be501e3ad7abc29a2d6a7b1830b4da974b49c2ebe99cf2a"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl",
"sha256": "a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ab/38/ff60c8fc9e002d50d48822cc5095deb8ebbc5f91a6b8fdd9731c87a147c9/ratelimit-2.2.1.tar.gz",
"sha256": "af8a9b64b821529aca09ebaf6d8d279100d766f19e90b5059ac6a718ca6dee42"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/c3/20/748e38b466e0819491f0ce6e90ebe4184966ee304fe483e2c414b0f4ef07/requests-2.32.2-py3-none-any.whl",
"sha256": "fc06670dd0ed212426dfeb94fc1b983d917c4f9847c863f313c9dfaaffb7c23c"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/8d/dd/6669a0deae9808320416793f7111b6cb0c80a1a65c9be0f1ed66f2c0a201/tidalapi-0.7.6-py3-none-any.whl",
"sha256": "ac9afe91296d2db71381e70470a710c052ce45b5014c4735bd1908ca3938f233"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/e1/4d/d612de852a0bc64a64418e1cef25fe1914c5b1611e34cc271ed7e36174c8/typing_extensions-4.12.0-py3-none-any.whl",
"sha256": "b349c66bea9016ac22978d800cfff206d5f9816951f12a7d0ec5578b0a819594"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/a2/73/a68704750a7679d0b6d3ad7aa8d4da8e14e151ae82e6fee774e6e0d05ec8/urllib3-2.2.1-py3-none-any.whl",
"sha256": "450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d"
}
]
},
"name": "python3-tidalapi",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"tidalapi\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/12/90/3c9ff0512038035f59d279fddeb79f5f1eccd8859f06d6163c58798b9487/certifi-2024.8.30-py3-none-any.whl",
"sha256": "922820b53db7a7257ffbda3f597266d435245903d80737e34f8a45ff3e3230d8"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/f2/4f/e1808dc01273379acc506d18f1504eb2d299bd4131743b9fc54d7be4df1e/charset_normalizer-3.4.0.tar.gz",
"sha256": "223217c3d4f82c3ac5e29032b3f1c2eb0fb591b72161f86d93f5719079dae93e"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl",
"sha256": "946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/15/aa/0aca39a37d3c7eb941ba736ede56d689e7be91cab5d9ca846bde3999eba6/isodate-0.7.2-py3-none-any.whl",
"sha256": "28009937d8031054830160fce6d409ed342816b543597cece116d966c6d99e15"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ab/1a/5be778993af7c2079e7a24dc208424af6fe1b6392dfaac268a8cf42ba842/mpegdash-0.4.0-py3-none-any.whl",
"sha256": "d07f6e1f2a67ddce1be501e3ad7abc29a2d6a7b1830b4da974b49c2ebe99cf2a"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl",
"sha256": "a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ab/38/ff60c8fc9e002d50d48822cc5095deb8ebbc5f91a6b8fdd9731c87a147c9/ratelimit-2.2.1.tar.gz",
"sha256": "af8a9b64b821529aca09ebaf6d8d279100d766f19e90b5059ac6a718ca6dee42"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/f9/9b/335f9764261e915ed497fcdeb11df5dfd6f7bf257d4a6a2a686d80da4d54/requests-2.32.3-py3-none-any.whl",
"sha256": "70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/24/d9/b321e540044b67e1382976445418da17eb81ac62ffd91b670cca2449fa9e/tidalapi-0.8.0-py3-none-any.whl",
"sha256": "114b8cf127bb9d6f02796b446f9202571989fbd5c3c62b69b58c43d9ada77e38"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/26/9f/ad63fc0248c5379346306f8668cda6e2e2e9c95e01216d2b8ffd9ff037d0/typing_extensions-4.12.2-py3-none-any.whl",
"sha256": "04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ce/d9/5f4c13cecde62396b0d3fe530a50ccea91e7dfc1ccf0e09c228841bb5ba8/urllib3-2.2.3-py3-none-any.whl",
"sha256": "ca899ca043dcb1bafa3e262d73aa25c465bfb49e0bd9dd5d59f1d0acba2f8fac"
}
]
},
{
"name": "HighTide",
"builddir": true,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .player_object import playerObject
from .player_object import playerObject, RepeatType
from .utils import *
from .secret_storage import SecretStore
29 changes: 23 additions & 6 deletions src/lib/player_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@
from gi.repository import GObject
from gi.repository import Gst, GLib

from enum import IntEnum

import random
import threading


class RepeatType(IntEnum):
NONE = 0
SONG = 1
LIST = 2


class playerObject(GObject.GObject):
"""This class handles all the player logic, queue, shuffle..."""

Expand Down Expand Up @@ -76,7 +85,7 @@ def __init__(self):
self.playing_track = None
self.song_album = None

self.repeat = True
self.repeat = RepeatType.NONE

self.duration = self.query_duration()

Expand Down Expand Up @@ -200,13 +209,20 @@ def th_play_track(self, track):
def play_next(self):
"""Play the next song in the queue or from the currently playing album/mix/playlist."""

# Appends the track that just finished playing or was skipped to the played_songs list
self.played_songs.append(self.playing_track)

print(f"Shuffle mode is {self.shuffle_mode}")

print(f"The queue is {len(self.queue)} long and the tracks to play are {len(self._tracks_to_play)}")

if self.repeat == RepeatType.SONG:
self.seek(
Gst.Format.TIME,
Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT,
0)
return

# Appends the track that just finished playing or was skipped to the played_songs list
self.played_songs.append(self.playing_track)

# If the queue is not empty it plays the first song in the queue
if len(self.queue) != 0:
track = self.queue[0]
Expand All @@ -216,10 +232,11 @@ 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 == []:
if self.repeat:
if self.repeat == RepeatType.LIST:
self._tracks_to_play = self.played_songs
self.tracks_to_play = self._tracks_to_play
self.played_songs = []
else:
elif self.repeat == RepeatType.NONE:
self.pause()
return

Expand Down
25 changes: 16 additions & 9 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from tidalapi.media import Quality

from .lib import playerObject
from .lib import playerObject, RepeatType
from .lib import utils

from .login import LoginDialog
Expand Down Expand Up @@ -114,13 +114,16 @@ def __init__(self, **kwargs):
"song-added-to-queue", self.on_song_added_to_queue)
self.player_object.connect("play-changed", self.update_controls)

self.player_object.repeat = self.settings.get_boolean("repeat")
if not self.player_object.repeat:
self.player_object.repeat = self.settings.get_int("repeat")
if self.player_object.repeat == RepeatType.NONE:
self.repeat_button.set_icon_name(
"media-playlist-consecutive-symbolic")
else:
elif self.player_object.repeat == RepeatType.LIST:
self.repeat_button.set_icon_name(
"media-playlist-repeat-symbolic")
elif self.player_object.repeat == RepeatType.SONG:
self.repeat_button.set_icon_name(
"playlist-repeat-song-symbolic")

self.queue_widget.connect(
"map", self.on_queue_widget_mapped)
Expand Down Expand Up @@ -554,16 +557,20 @@ def toggle_mobile_view(self, *args):

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

self.settings.set_boolean("repeat", self.player_object.repeat)
self.settings.set_int("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
Expand Down

0 comments on commit dc43d90

Please sign in to comment.