Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Subsonic fixes #10

Merged
merged 2 commits into from
Dec 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions lb_content_resolver/subsonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@


class SubsonicDatabase(Database):
'''
'''
Add subsonic sync capabilities to the Database
'''

# Determined by the number of albums we can fetch in one go
BATCH_SIZE = 500

Expand Down Expand Up @@ -55,11 +55,11 @@ def run_sync(self):
albums = []
offset = 0
while True:
results = conn.getAlbumList(ltype="alphabeticalByArtist", size=self.BATCH_SIZE, offset=offset)
albums.extend(results["albumList"]["album"])
album_ids.update([r["id"] for r in results["albumList"]["album"] ])
results = conn.getAlbumList2(ltype="alphabeticalByArtist", size=self.BATCH_SIZE, offset=offset)
albums.extend(results["albumList2"]["album"])
album_ids.update([r["id"] for r in results["albumList2"]["album"] ])

album_count = len(results["albumList"]["album"])
album_count = len(results["albumList2"]["album"])
offset += album_count
if album_count < self.BATCH_SIZE:
break
Expand All @@ -70,14 +70,19 @@ def run_sync(self):
recordings = []

for album in albums:
album_info = conn.getAlbumInfo2(id=album["id"])
try:
album_mbid = album_info["albumInfo"]["musicBrainzId"]
except KeyError:
pbar.write(bcolors.FAIL + "FAIL " + bcolors.ENDC + "subsonic album '%s' by '%s' has no MBID" %
(album["album"], album["artist"]))
self.error += 1
continue
album_info = conn.getAlbum(id=album["id"])

# Some servers might already include the MBID in the list or album response
album_mbid = album_info.get("musicBrainzId", album.get("musicBrainzId"))
if not album_mbid:
album_info2 = conn.getAlbumInfo2(id=album["id"])
try:
album_mbid = album_info2["albumInfo"]["musicBrainzId"]
except KeyError:
pbar.write(bcolors.FAIL + "FAIL " + bcolors.ENDC + "subsonic album '%s' by '%s' has no MBID" %
(album_info["name"], album_info["artist"]))
self.error += 1
continue

cursor.execute(
"""SELECT recording.id
Expand All @@ -89,8 +94,6 @@ def run_sync(self):
# create index on (track_num, disc_num)
release_tracks = {(row[1], row[2]): row[0] for row in cursor.fetchall()}

album_info = conn.getAlbum(id=album["id"])

if len(release_tracks) == 0:
pbar.write("For album %s" % album_mbid)
pbar.write("loaded %d of %d expected tracks from DB." %
Expand All @@ -108,11 +111,11 @@ def run_sync(self):
continue
if msg == "":
pbar.write(bcolors.OKGREEN + "OK " + bcolors.ENDC + "album %-50s %-50s" %
(album["album"][:49], album["artist"][:49]))
(album_info["name"][:49], album_info["artist"][:49]))
self.matched += 1
else:
pbar.write(bcolors.FAIL + "FAIL " + bcolors.ENDC + "album %-50s %-50s" %
(album["album"][:49], album["artist"][:49]))
(album_info["name"][:49], album_info["artist"][:49]))
pbar.write(msg)
self.error += 1

Expand Down