Skip to content

Commit

Permalink
various
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Dec 17, 2024
1 parent 65dff25 commit f09d4df
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 48 deletions.
6 changes: 2 additions & 4 deletions data/ui/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
<object class="AdwComboRow" id="_quality_row">
<property name="model">
<object class="GtkStringList">
<property name="strings">Low
High
<property name="strings">Low 96k
High 320k
Lossless
Hi-res
Hi-res Lossless</property>
</object>
</property>
<property name="subtitle">The last quality is enabled only for HiFi+ subscribers</property>
<property name="title">Quality</property>
</object>
</child>
Expand Down
5 changes: 5 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import gi

gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
gi.require_version('Gst', '1.0')
52 changes: 32 additions & 20 deletions src/lib/player_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,18 @@
# SPDX-License-Identifier: GPL-3.0-or-later

import random
import threading

from tidalapi.mix import Mix
from tidalapi.artist import Artist
from tidalapi.album import Album
from tidalapi.media import Track
from tidalapi.playlist import Playlist

from tidalapi.user import Favorites

from gi.repository import GObject
from gi.repository import Gst, GLib

from enum import IntEnum

import random
import threading


class RepeatType(IntEnum):
NONE = 0
Expand Down Expand Up @@ -70,15 +65,22 @@ def __init__(self):
self._bus = self._player.get_bus()
self._bus.add_signal_watch()

self.queue = [] # List to store queued songs (Not the next songs in an album/playlist/mix, but the ones added with play next/add to queue)
# List to store queued songs (Not the next songs in an
# album/playlist/mix, but the ones added with play next/add to queue)
self.queue = []

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

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
# 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
self.tracks_to_play = []
# Shuffled version of the next tracks to play
self._shuffled_tracks_to_play = []

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

self.shuffle_mode = False
self.is_playing = False
Expand Down Expand Up @@ -119,7 +121,8 @@ def __init__(self):
def _on_bus_eos(self, *args):
self.play_next()

def play_this(self, thing, index = 0): # Used to play albums, playlists, mixes
def play_this(self, thing, index=0):
"""Used to play albums, playlists, mixes"""
self.current_mix_album_playlist = thing
tracks = self.get_track_list(thing)
self._tracks_to_play = tracks[index:] + tracks[:index]
Expand All @@ -133,12 +136,14 @@ def play_this(self, thing, index = 0): # Used to play albums, playlists, mixes
self.play_track(track)
self.play()

def shuffle_this(self, thing): # Same as play_this, but on shuffle
def shuffle_this(self, thing):
"""Same as play_this, but on shuffle"""
tracks = self.get_track_list(thing)
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 @@ -180,7 +185,9 @@ def play_track(self, track):
th.start()

def th_play_track(self, track):
print(f"play track: {track.name} by {track.artist.name}, {track.media_metadata_tags}, {track.audio_quality}, {track.id}")
print(f"""play track: {track.name} by {track.artist.name}""" +
f"""{track.media_metadata_tags}, {track.audio_quality}""")

music_url = track.get_url()
self._player.set_state(Gst.State.NULL)

Expand All @@ -207,7 +214,8 @@ def th_play_track(self, track):
self.emit("song-changed")

def play_next(self):
"""Play the next song in the queue or from the currently playing album/mix/playlist."""
"""Play the next song in the queue or from the currently
playing album/mix/playlist."""

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

Expand All @@ -220,7 +228,8 @@ def play_next(self):
0)
return

# Appends the track that just finished playing or was skipped to the played_songs list
# 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
Expand All @@ -230,7 +239,8 @@ def play_next(self):
self.play_track(track)
return

# If the tracks_to_play list is empty it refills it with the played songs and empties the played_songs
# 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 == RepeatType.LIST:
self._tracks_to_play = self.played_songs
Expand All @@ -240,7 +250,9 @@ def play_next(self):
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 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:
track = self._shuffled_tracks_to_play[0]
self.play_track(track)
Expand Down
49 changes: 27 additions & 22 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@
# SPDX-License-Identifier: GPL-3.0-or-later

import sys
import gi

gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
gi.require_version('Gst', '1.0')

from gi.repository import Gtk, Gio, Adw, Gdk
from gi.repository import GObject
from gi.repository import Gtk, Gio, Adw
from .window import HighTideWindow
# from gi.events import GLibEventLoopPolicy

from tidalapi.media import Quality
from .lib import variables

import threading
import os
import shutil
# import asyncio

# asyncio.set_event_loop_policy(GLibEventLoopPolicy())


class TidalApplication(Adw.Application):
"""The main application singleton class."""
Expand All @@ -50,6 +46,8 @@ def __init__(self):

variables.init()

self.preferences = None

def on_download(self, *args):
th = threading.Thread(target=self.win.th_download_song)
th.deamon = True
Expand Down Expand Up @@ -77,24 +75,29 @@ def do_activate(self):
def on_about_action(self, widget, _):
"""Callback for the app.about action."""
about = Adw.AboutDialog(
application_name='High Tide',
application_icon='io.github.nokse22.HighTide',
developer_name='Nokse',
version='0.1.0',
developers=['Nokse'],
copyright='© 2023 Nokse')
application_name='High Tide',
application_icon='io.github.nokse22.HighTide',
developer_name='Nokse',
version='0.1.0',
developers=['Nokse'],
copyright='© 2023 Nokse')
about.present(self.props.active_window)

def on_preferences_action(self, widget, _):
"""Callback for the app.preferences action."""
print('app.preferences action activated')

builder = Gtk.Builder.new_from_resource("/io/github/nokse22/HighTide/ui/preferences.ui")
if not self.preferences:
builder = Gtk.Builder.new_from_resource(
"/io/github/nokse22/HighTide/ui/preferences.ui")

builder.get_object("_quality_row").connect(
"notify::selected", self.on_quality_changed)
builder.get_object("_quality_row").set_selected(
self.win.settings.get_int("quality"))

builder.get_object("_quality_row").connect("notify::selected", self.on_quality_changed)
builder.get_object("_quality_row").set_selected(self.win.settings.get_int("quality"))
self.preferences = builder.get_object("_preference_window")

builder.get_object("_preference_window").present(self.props.active_window)
self.preferences.present(self.win)

def on_quality_changed(self, widget, *args):
self.win.select_quality(widget.get_selected())
Expand All @@ -120,7 +123,9 @@ def on_shutdown(self, *args):
list_id = list_.id
# self.win.settings.set_int("last-playing-song-id", track_id)
self.win.settings.set_string("last-playing-list-id", list_id)
self.win.settings.set_string("last-playing-list-type", variables.get_type(list_))
self.win.settings.set_string(
"last-playing-list-type", variables.get_type(list_))


def main(version):
"""The application's entry point."""
Expand Down
2 changes: 0 additions & 2 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,6 @@ def select_quality(self, pos):
self.session.audio_quality = Quality.low_320k
case 2:
self.session.audio_quality = Quality.high_lossless
case 3:
self.session.audio_quality = Quality.hi_res
case 4:
self.session.audio_quality = Quality.hi_res_lossless

Expand Down

0 comments on commit f09d4df

Please sign in to comment.