Skip to content

Commit

Permalink
Add migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
C0rn3j committed Jan 29, 2025
1 parent 67ce5df commit cde7fc7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 31 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:
uid: int
name: str
scroll: int = 0
stations: list[RadioStation] = field(default_factory=list)

@dataclass
class TauonQueueItem:
Expand Down
45 changes: 18 additions & 27 deletions src/tauon/t_modules/t_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@
TauonQueueItem,
TestTimer,
Timer,
RadioPlaylist,
RadioStation,
alpha_blend,
alpha_mod,
archive_file_scan,
Expand Down Expand Up @@ -23224,22 +23226,6 @@ def bk_tracks(self, pl_index: int, indis) -> None:
def bk_playtime_transfer(self, fr, fr_s, fr_scr, so, to_s, to_scr) -> None:
self.e.append(("ptt", fr, fr_s, fr_scr, so, to_s, to_scr))

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

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

class GetSDLInput:

def __init__(self):
Expand Down Expand Up @@ -38309,19 +38295,15 @@ def save_state() -> None:
view_prefs["append-date"] = prefs.append_date

tauonplaylist_jar = []
radioplaylist_jar = []
tauonqueueitem_jar = []
#if db_version > 68:
trackclass_jar = []
for v in pctl.multi_playlist:
# logging.warning(f"Playlist: {v}")
tauonplaylist_jar.append(v.__dict__)
for v in pctl.radio_playlists:
radioplaylist_jar.append(v.__dict__)
for v in pctl.force_queue:
# logging.warning(f"Queue: {v}")
tauonqueueitem_jar.append(v.__dict__)
#else:
# tauonplaylist_jar = pctl.multi_playlist
# tauonqueueitem_jar = pctl.track_queue

trackclass_jar = []
for v in pctl.master_library.values():
trackclass_jar.append(v.__dict__)

Expand Down Expand Up @@ -38491,7 +38473,7 @@ def save_state() -> None:
trackclass_jar,
prefs.premium,
gui.radio_view,
pctl.radio_playlists,
radioplaylist_jar, # pctl.radio_playlists,
pctl.radio_playlist_viewing,
prefs.radio_thumb_bans,
prefs.playlist_exports,
Expand Down Expand Up @@ -39458,7 +39440,7 @@ def drop_file(target: str):

folder_image_offsets: dict[str, int] = {}
db_version: float = 0.0
latest_db_version: float = 69
latest_db_version: float = 70

albums = []
album_position = 0
Expand Down Expand Up @@ -39961,7 +39943,14 @@ def drop_file(target: str):
if save[164] is not None:
gui.restore_radio_view = save[164]
if save[165] is not None:
radio_playlists = save[165]
if db_version > 69:
radio_playlists = []
radioplaylist_jar = save[165]
for d in radioplaylist_jar:
nt = RadioPlaylist(**d)
radio_playlists.append(nt)
else:
radio_playlists = save[165]
if save[166] is not None:
radio_playlist_viewing = save[166]
if save[167] is not None:
Expand Down Expand Up @@ -40052,8 +40041,10 @@ def drop_file(target: str):
)
except ValueError:
logging.exception("That should not happen")
sys.exit(42)
except Exception:
logging.exception("Unknown error running database migration!")
sys.exit(42)

playing_in_queue = min(playing_in_queue, len(track_queue) - 1)

Expand Down

0 comments on commit cde7fc7

Please sign in to comment.