Skip to content

Commit

Permalink
Start using classes for Radio playlists and stations (#1422)
Browse files Browse the repository at this point in the history
* Radio changes WIP

* Fix ups to get it running

* Add migrations

* Convert more code

* Fix broken buttons

* Do not wipe website URL if stream URL hasn't changed

* Handle radio websocket better

* Fix indent

* Add the default station fallback URL back

* Fix up adding radio and m3u radio

* Fix if

* Fix comma
  • Loading branch information
C0rn3j authored Feb 3, 2025
1 parent e76c4e9 commit 5536d7b
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 266 deletions.
30 changes: 27 additions & 3 deletions src/tauon/t_modules/t_db_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path
from typing import TYPE_CHECKING

from tauon.t_modules.t_extra import TauonPlaylist, TauonQueueItem
from tauon.t_modules.t_extra import RadioPlaylist, RadioStation, TauonPlaylist, TauonQueueItem

if TYPE_CHECKING:
from tauon.t_modules.t_main import GuiVar, Prefs, StarStore, TrackClass
Expand All @@ -28,7 +28,7 @@ def database_migrate(
gui: GuiVar,
gen_codes: dict[int, str],
prefs: Prefs,
radio_playlists: list[TauonPlaylist],
radio_playlists: list[dict[str, int | str | list[dict[str, str]]]] | list[RadioPlaylist],
p_force_queue: list | list[TauonQueueItem],
theme: int,
) -> tuple[
Expand All @@ -40,7 +40,7 @@ def database_migrate(
Prefs,
GuiVar,
dict[int, str],
list[TauonPlaylist]]:
list[RadioPlaylist]]:
"""Migrate database to a newer version if we're behind
Returns all the objects that could've been possibly changed:
Expand Down Expand Up @@ -543,4 +543,28 @@ def database_migrate(
multi_playlist = new_multi_playlist
p_force_queue = new_queue

if db_version <= 69:
logging.info("Updating database to version 69")
new_radio_playlists: list[RadioPlaylist] = []
for playlist in radio_playlists:
stations: list[RadioStation] = []

for station in playlist["items"]:
stations.append(
RadioStation(
title=station["title"],
stream_url=station["stream_url"],
country=station["country"],
website_url=station["website_url"],
icon=station["icon"],
stream_url_fallback=station["stream_url_unresolved"] if "stream_url_unresolved" in station else ""))
new_radio_playlists.append(
RadioPlaylist(
uid=playlist["uid"],
name=playlist["name"],
scroll=playlist["scroll"] if "scroll" in playlist else 0,
stations=stations))
radio_playlists = new_radio_playlists


return master_library, multi_playlist, star_store, p_force_queue, theme, prefs, gui, gen_codes, radio_playlists
17 changes: 16 additions & 1 deletion src/tauon/t_modules/t_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import time
import urllib.parse
import zipfile
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import TYPE_CHECKING

from gi.repository import GLib
Expand All @@ -45,6 +45,21 @@

from tauon.t_modules.t_main import TrackClass

@dataclass
class RadioStation:
title: str
stream_url: str
country: str = ""
website_url: str = ""
icon: str = ""
stream_url_fallback: str = ""

@dataclass
class RadioPlaylist:
name: str
uid: int
scroll: int = 0
stations: list[RadioStation] = field(default_factory=list)

@dataclass
class TauonQueueItem:
Expand Down
Loading

0 comments on commit 5536d7b

Please sign in to comment.