ampache / ampache-xbmc-plugin

KODI plugin for Ampache
Other
8 stars 3 forks source link

Random Playlists not working properly #20

Closed paulijar closed 3 years ago

paulijar commented 3 years ago

The feature "Explore > Random > Random Playlists" doesn't seem to work properly. For me, it always shows an empty result. Looking at the server logs, it seems to repeatedly call the action=playlist with some random small values on the argument filter. This is not a working pattern because if you just guess a playlist ID (given in the filter), then more likely than not such playlist will not exist. For example, on my account, I currently have 5 playlist with IDs 56, 156, 118, 45, and 63.

An actually working scheme could be to use the action=playlists, and pass arguments offset=<some_random_index> and limit=1.

Edit: I also noticed from the logs that sometimes in this use case the Kodi plugin requests the action=playlist without supplying the filter argument at all. This is a malformed request.

lusum commented 3 years ago

it seems to repeatedly call the action=playlist with some random small values on the argument filter

correct

An actually working scheme could be to use the action=playlists, and pass arguments offset= and limit=1.

I need to check older ampache versions before change this behaviour, like test on dogzmatic server, it takes some time.

I also noticed from the logs that sometimes in this use case the Kodi plugin requests the action=playlist without supplying the filter argument at all. This is a malformed request.

I will check

paulijar commented 3 years ago

An actually working scheme could be to use the action=playlists, and pass arguments offset= and limit=1.

Or probably even more sensible option would be to just fetch all the playlists and do the random picking locally. Unless the user has thousands of playlists (which I doubt), it is likely more efficient to do one a bit larger remote operation than it is to do 5 small ones.

lusum commented 3 years ago

Unless the user has thousands of playlists (which I doubt)

Dogzmazic has more than 8600 playlists, so i cannot fetch all the playlists 'a priori'

lusum commented 3 years ago

I have implemented your suggestion in master and it works, tell me if something is wrong

paulijar commented 3 years ago

I just downloaded the head of the master branch. I now see playlists in the view, but the result doesn't seem to be random at all. Instead, looking at the server log, I now see that the client just requests the 5 first playlists: <server_url>/server/xml.server.php?action=playlists&auth=c24745...&limit=5.

lusum commented 3 years ago

If you have few playlists this is the normal behaviour. How many playlists you have in your server?

This is the code:

if num_items > tot_items:

if tot_items are less than num_itmes, return all items

   get_items(object_type, limit=tot_items)
  return
paulijar commented 3 years ago

I first had 5 playlists, but I added 9 more to test this feature. But still the feature was returning only the 5 first playlists. Maybe the tot_items in the code above did not get updated then. So might be that it would work after restarting Kodi.

paulijar commented 3 years ago

So might be that it would work after restarting Kodi.

I can confirm that this was the case. Today the feature is working properly.

lusum commented 3 years ago

If you simply reconnect the server clicking switch server and selecting your same server, the playlists count will be updated. For performance reason, i reconnect to the server only when necessary.