Skip to content

Commit 028fcfe

Browse files
committed
Use new StarRecord class for StarStore objects
1 parent 88a36fb commit 028fcfe

File tree

2 files changed

+124
-114
lines changed

2 files changed

+124
-114
lines changed

src/tauon/t_modules/t_db_migrate.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from tauon.t_modules.t_extra import RadioPlaylist, RadioStation, TauonPlaylist, TauonQueueItem
1010

1111
if TYPE_CHECKING:
12-
from tauon.t_modules.t_main import GuiVar, Prefs, StarStore, Tauon, TrackClass
12+
from tauon.t_modules.t_main import GuiVar, Prefs, StarRecord, StarStore, Tauon, TrackClass
1313

1414

1515
def database_migrate(
@@ -18,7 +18,7 @@ def database_migrate(
1818
db_version: float,
1919
master_library: dict[int, TrackClass],
2020
install_mode: bool,
21-
multi_playlist: list | list[TauonPlaylist],
21+
multi_playlist: list[str | int | bool] | list[TauonPlaylist],
2222
star_store: StarStore,
2323
a_cache_dir: str,
2424
cache_directory: Path,
@@ -29,7 +29,7 @@ def database_migrate(
2929
gen_codes: dict[int, str],
3030
prefs: Prefs,
3131
radio_playlists: list[dict[str, int | str | list[dict[str, str]]]] | list[RadioPlaylist],
32-
p_force_queue: list | list[TauonQueueItem],
32+
p_force_queue: list[int | bool] | list[TauonQueueItem],
3333
theme: int,
3434
) -> tuple[
3535
dict[int, TrackClass],
@@ -545,7 +545,7 @@ def database_migrate(
545545
p_force_queue = new_queue
546546

547547
if db_version <= 69:
548-
logging.info("Updating database to version 69")
548+
logging.info("Updating database to version 70")
549549
new_radio_playlists: list[RadioPlaylist] = []
550550
for playlist in radio_playlists:
551551
stations: list[RadioStation] = []
@@ -567,5 +567,20 @@ def database_migrate(
567567
stations=stations))
568568
radio_playlists = new_radio_playlists
569569

570+
if db_version <= 70:
571+
logging.info("Updating database to version 71")
572+
new_starstore_db: dict[tuple[str, str, str], StarRecord] = {}
573+
old_record: list[int | str] = [] # Here just for typing
574+
for key, old_record in star_store.db.items():
575+
new_record = star_store.new_object()
576+
new_record.playtime = old_record[0]
577+
new_record.loved = "L" in old_record[1]
578+
new_record.rating = old_record[2]
579+
# There was a bug where the fourth element was not set
580+
if len(old_record) == 4:
581+
new_record.loved_timestamp = old_record[3]
582+
new_starstore_db[key] = new_record
583+
584+
star_store.db = new_starstore_db
570585

571586
return master_library, multi_playlist, star_store, p_force_queue, theme, prefs, gui, gen_codes, radio_playlists

0 commit comments

Comments
 (0)