Skip to content

Commit

Permalink
Playlist workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
rajlaud committed Sep 26, 2020
1 parent f521393 commit 69fd604
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
20 changes: 11 additions & 9 deletions pysqueezebox/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def current_track(self):
except KeyError:
pass
try:
if self.current_index:
if self.current_index is not None:
return self._status["playlist_loop"][self.current_index]
except (KeyError, IndexError):
pass
Expand Down Expand Up @@ -342,6 +342,11 @@ async def async_update(self, add_tags=None):
Return True if successful, False if update fails.
"""

# cancel pending poll if we were called manually
if self._poll and not self._poll.done():
self._poll.cancel()

tags = "acdIKlNorTux"
if add_tags:
tags = "".join(set(tags + add_tags))
Expand Down Expand Up @@ -387,17 +392,14 @@ async def async_update(self, add_tags=None):
self._property_futures = property_futures

# schedule poll if pending futures with polling interval
if self._poll and not self._poll.done():
self._poll.cancel()
if len(self._property_futures) > 0 and interval:

async def _poll(interval):
await asyncio.sleep(interval)
await self.async_update()

self._poll = asyncio.create_task(_poll(interval))
self._poll = asyncio.create_task(self._async_poll(interval))
return True

async def _async_poll(self, interval):
await asyncio.sleep(interval)
asyncio.create_task(self.async_update())

async def async_set_volume(self, volume, timeout=TIMEOUT):
"""Set volume level, range 0..100, or +/- integer."""
if isinstance(volume, str) and (
Expand Down
17 changes: 12 additions & 5 deletions pysqueezebox/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def __init__(
self.albums = None
self.titles = None
self.genres = None
self.playlists = None

def __repr__(self):
"""Return representation of Server object."""
Expand Down Expand Up @@ -246,7 +245,13 @@ async def async_query_category(self, category, limit=None, search=None):
"""Return list of entries in category, optionally filtered by search string."""
if not limit:
limit = await self.async_get_count(category)
query = [category, "0", f"{limit}", search]
if search and "playlist_id" in search:
# workaround LMS bug - playlist_id doesn't work for "titles" search
query = ["playlists", "tracks", "0", f"{limit}", search]
query.append("tags:ju")
category = "playlisttracks"
else:
query = [category, "0", f"{limit}", search]

if category == "albums":
query.append("tags:jl")
Expand All @@ -258,9 +263,10 @@ async def async_query_category(self, category, limit=None, search=None):
try:
items = result[f"{category}_loop"]
for item in items:
item["title"] = item.pop(category[:-1])
if category != "playlisttracks":
item["title"] = item.pop(category[:-1])

if category in ["albums", "titles"]:
if category in ["albums", "titles", "playlisttracks"]:
if "artwork_track_id" in item:
item["image_url"] = self.generate_image_url_from_track_id(
item["artwork_track_id"]
Expand All @@ -269,12 +275,13 @@ async def async_query_category(self, category, limit=None, search=None):

except KeyError:
_LOGGER.error("Could not find results loop for category %s", category)
_LOGGER.error("Got result %s", result)

async def async_get_category(self, category, limit=None, search=None):
"""Update cache of library category if needed and return result."""

if (
category not in ["artists", "albums", "titles", "genres", "playlists"]
category not in ["artists", "albums", "titles", "genres"]
or search is not None
):
return await self.async_query_category(category, limit, search)
Expand Down

0 comments on commit 69fd604

Please sign in to comment.