Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start using classes for Radio playlists and stations #1422

Merged
merged 12 commits into from
Feb 3, 2025
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
Loading