mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
7852be5e3f
+ add extra fields for backup in favorites and scrobble data - not yet for the playlist tracks
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from typing import Any
|
|
from app.store.albums import AlbumStore
|
|
from app.store.artists import ArtistStore
|
|
from app.store.tracks import TrackStore
|
|
|
|
|
|
def get_extra_info(hash: str, type: str):
|
|
"""
|
|
Generates extra info for a track, album or artist, which will be stored
|
|
in the database (in favorites, playlists and scrobble data) for backup and restore.
|
|
|
|
The extra info contains all the fields needed to reconstruct the itemhash. The track contains an additional filepath field which can be used to locate the file when restoring.
|
|
"""
|
|
extra: dict[str, Any] = {}
|
|
|
|
if type == "track":
|
|
trackentry = TrackStore.trackhashmap.get(hash)
|
|
if trackentry is not None:
|
|
track = trackentry.get_best()
|
|
|
|
extra["filepath"] = track.filepath
|
|
extra["title"] = track.title
|
|
extra["artists"] = [a["name"] for a in track.artists]
|
|
extra["album"] = track.albumhash
|
|
|
|
elif type == "album":
|
|
album = AlbumStore.get_album_by_hash(hash)
|
|
if album is not None:
|
|
extra["albumartists"] = [a["name"] for a in album.albumartists]
|
|
extra["title"] = album.title
|
|
|
|
elif type == "artist":
|
|
artist = ArtistStore.get_artist_by_hash(hash)
|
|
if artist is not None:
|
|
extra["name"] = artist.name
|
|
|
|
return extra
|