mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
fix is_favorite setter on populate
This commit is contained in:
+11
-4
@@ -137,7 +137,7 @@ class Populate:
|
||||
unmodified_paths.add(track.filepath)
|
||||
continue
|
||||
except (FileNotFoundError, OSError) as e:
|
||||
log.warning(e) # REVIEW More informations = good
|
||||
log.warning(e) # REVIEW More informations = good
|
||||
TrackStore.remove_track_obj(track)
|
||||
remove_tracks_by_filepaths(track.filepath)
|
||||
|
||||
@@ -155,8 +155,14 @@ class Populate:
|
||||
tagged_tracks: deque[dict] = deque()
|
||||
tagged_count = 0
|
||||
|
||||
fav_tracks = favdb.get_fav_tracks()
|
||||
fav_tracks = set(t[1] for t in fav_tracks)
|
||||
favs = favdb.get_fav_tracks()
|
||||
|
||||
records = dict()
|
||||
|
||||
for fav in favs:
|
||||
r = records.setdefault(fav[1], set())
|
||||
r.add(fav[4])
|
||||
|
||||
|
||||
for file in tqdm(untagged, desc="Reading files"):
|
||||
if POPULATE_KEY != key:
|
||||
@@ -168,7 +174,8 @@ class Populate:
|
||||
if tags is not None:
|
||||
tagged_tracks.append(tags)
|
||||
track = Track(**tags)
|
||||
track.is_favorite = track.trackhash in fav_tracks
|
||||
|
||||
track.fav_userids = list(records.get(track.trackhash, set()))
|
||||
|
||||
TrackStore.add_track(track)
|
||||
|
||||
|
||||
+4
-16
@@ -31,27 +31,15 @@ class TrackStore:
|
||||
records = dict()
|
||||
|
||||
for fav in favs:
|
||||
if fav[1] not in records:
|
||||
# if trackhash not in dict, add it
|
||||
# and set the value to a set containing the userid
|
||||
records[fav[1]] = {fav[4]}
|
||||
|
||||
# if trackhash is in dict, add the userid to the set
|
||||
records[fav[1]].add(fav[4])
|
||||
r = records.setdefault(fav[1], set())
|
||||
r.add(fav[4])
|
||||
|
||||
for track in cls.tracks:
|
||||
if instance_key != TRACKS_LOAD_KEY:
|
||||
return
|
||||
|
||||
try:
|
||||
track.fav_userids = list(records[track.trackhash])
|
||||
except KeyError:
|
||||
track.fav_userids = []
|
||||
|
||||
# if track.trackhash in fav_hashes:
|
||||
# fav = [t for t in favs if t["hash"] == track.trackhash][0]
|
||||
# print(fav)
|
||||
# track.favorite_data = [i["userid"] for i in fav]
|
||||
userids = records.get(track.trackhash, set())
|
||||
track.fav_userids = list(userids)
|
||||
|
||||
print("Done!")
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ description = ""
|
||||
authors = ["geoffrey45 <geoffreymungai45@gmail.com>"]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.11,<3.12"
|
||||
python = ">=3.10,<3.12"
|
||||
Flask = "^2.0.2"
|
||||
Flask-Cors = "^3.0.10"
|
||||
requests = "^2.27.1"
|
||||
|
||||
Reference in New Issue
Block a user