Skip to content

Commit fb78b49

Browse files
authored
Fix Subsonic isDir check and add logging for another one (#1606)
Also some typing additions, as is custom
1 parent 5020a9d commit fb78b49

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/tauon/t_modules/t_main.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ def merge(self, index: int, object) -> None:
932932
class AlbumStarStore:
933933

934934
def __init__(self, tauon: Tauon) -> None:
935-
self.db = {}
935+
self.db: dict[str, int] = {}
936936
self.subsonic = SubsonicService(tauon=tauon, album_star_store=self)
937937

938938
def get_key(self, track_object: TrackClass) -> str:
@@ -941,19 +941,19 @@ def get_key(self, track_object: TrackClass) -> str:
941941
artist = track_object.artist
942942
return artist + ":" + track_object.album
943943

944-
def get_rating(self, track_object: TrackClass):
944+
def get_rating(self, track_object: TrackClass) -> int:
945945
return self.db.get(self.get_key(track_object), 0)
946946

947-
def set_rating(self, track_object: TrackClass, rating) -> None:
947+
def set_rating(self, track_object: TrackClass, rating: int) -> None:
948948
self.db[self.get_key(track_object)] = rating
949949
if track_object.file_ext == "SUB":
950950
self.db[self.get_key(track_object)] = math.ceil(rating / 2) * 2
951951
self.subsonic.set_album_rating(track_object, rating)
952952

953-
def set_rating_artist_title(self, artist: str, album: str, rating) -> None:
953+
def set_rating_artist_title(self, artist: str, album: str, rating: int) -> None:
954954
self.db[artist + ":" + album] = rating
955955

956-
def get_rating_artist_title(self, artist: str, album: str):
956+
def get_rating_artist_title(self, artist: str, album: str) -> int:
957957
return self.db.get(artist + ":" + album, 0)
958958

959959
class Fonts:
@@ -18125,7 +18125,7 @@ def get_music3(self, return_list: bool = False):
1812518125
self.scanning = True
1812618126
self.gui.to_got = 0
1812718127

18128-
existing = {}
18128+
existing: dict[str, int] = {}
1812918129

1813018130
for track_id, track in self.pctl.master_library.items():
1813118131
if track.is_network and track.file_ext == "SUB":
@@ -18139,9 +18139,12 @@ def get_music3(self, return_list: bool = False):
1813918139
self.scanning = False
1814018140
return []
1814118141

18142+
if "indexes" not in a["subsonic-response"]:
18143+
logging.critical("Failed to find expected key 'indexes', report a bug with the log below!")
18144+
logging.critical(a["subsonic-response"])
1814218145
b = a["subsonic-response"]["indexes"]["index"]
1814318146

18144-
folders = []
18147+
folders: list[tuple[str, str]] = []
1814518148

1814618149
for letter in b:
1814718150
artists = letter["artist"]
@@ -18151,14 +18154,14 @@ def get_music3(self, return_list: bool = False):
1815118154
artist["name"],
1815218155
))
1815318156

18154-
playlist = []
18155-
songsets = []
18157+
playlist: list[int] = []
18158+
songsets: list[tuple[TrackClass, str, str, int]] = []
1815618159
for i in range(len(folders)):
1815718160
songsets.append([])
1815818161
statuses = [0] * len(folders)
18159-
dupes = []
18162+
#dupes = []
1816018163

18161-
def getsongs(index, folder_id, name: str, inner: bool = False, parent=None) -> None:
18164+
def getsongs(index: int, folder_id: str, name: str, inner: bool = False, parent: dict[str, str | int] | None = None) -> None:
1816218165
try:
1816318166
d = self.r("getMusicDirectory", p={"id": folder_id})
1816418167
if "child" not in d["subsonic-response"]["directory"]:
@@ -18180,7 +18183,7 @@ def getsongs(index, folder_id, name: str, inner: bool = False, parent=None) -> N
1818018183
self.gui.update = 2
1818118184

1818218185
for item in items:
18183-
if item["isDir"]:
18186+
if "isDir" in item and item["isDir"]:
1818418187
if "userRating" in item and "artist" in item:
1818518188
rating = item["userRating"]
1818618189
if self.album_star_store.get_rating_artist_title(item["artist"], item["title"]) == 0 and rating == 0:

0 commit comments

Comments
 (0)