mdhiggins / PlexAutoSkip

Automatically skip content in Plex
MIT License
205 stars 11 forks source link

Up next skip restarts last episode if there are no others to play #26

Closed joshali1990 closed 1 year ago

joshali1990 commented 1 year ago

If there are no episodes left in a series, plex auto skip continues to restart the last few seconds of the last episode. Is there any way to change this behavior?

mdhiggins commented 1 year ago

There's logic in the code to prevent this

            if pq.items[-1] == mediaWrapper.media:
                self.log.debug("Seek target is the end but no more items in the playQueue, using seekTo to prevent loop")
                player.seekTo(mediaWrapper.media.duration)

The skipNext feature checks if its the last item in your playQueue and just skips to the end instead of going next if it is

If your player isn't returning a playQueue or there's an error this check might not work, please post some relevant logs and I can take a look

Also just some bare minimum information about what player and version of plex you're using would probably be helpful

Edit: I also just tested this feature quickly on one of my home devices (iOS specifically) and it worked as intended

INFO - Found ended 1244 [41199] (Bob's Burgers s13e06 - Apple Gore-chard! (But Not Gory)) iPhone|E1CDEB36-A35F-4B61-89A8-8DE037CA0F42 session that has reached the end of its duration 1287978 with viewOffset 1287870 with skip-next enabled, will skip to next
DEBUG - Deleting session 1244 [41199] (Bob's Burgers s13e06 - Apple Gore-chard! (But Not Gory)) iPhone|E1CDEB36-A35F-4B61-89A8-8DE037CA0F42, sessions: 0
DEBUG - Ignoring session 1244 [41199] (Bob's Burgers s13e06 - Apple Gore-chard! (But Not Gory)) iPhone|E1CDEB36-A35F-4B61-89A8-8DE037CA0F42 mhiggins, ignored: 2
DEBUG - Seek target is the end but no more items in the playQueue, using seekTo to prevent loop
joshali1990 commented 1 year ago

Here's what I'm getting:

INFO - Found new session 70 [66973] (Shark Tank s14e06 - TBA) Apple TV|6BD43681-2C1B-4919-88F2-7D4F4E398DE3 viewOffset 2584288 joshali1990, sessions: 1 INFO - Found ended 70 [66973] (Shark Tank s14e06 - TBA) Apple TV|6BD43681-2C1B-4919-88F2-7D4F4E398DE3 session that has reached the end of its duration 2584288 with viewOffset 2584234 with skip-next enabled, will skip to next INFO - Found new session 71 [66973] (Shark Tank s14e06 - TBA) Apple TV|6BD43681-2C1B-4919-88F2-7D4F4E398DE3 viewOffset 2584288 joshali1990, sessions: 1 INFO - Found ended 71 [66973] (Shark Tank s14e06 - TBA) Apple TV|6BD43681-2C1B-4919-88F2-7D4F4E398DE3 session that has reached the end of its duration 2584288 with viewOffset 2584288 with skip-next enabled, will skip to next WARNING - Seek target is the end but unable to get PlayQueue 2602 data from server, aborting to prevent extra skips or playback issues WARNING - Seek target is the end but unable to get PlayQueue 2602 data from server, aborting to prevent extra skips or playback issues WARNING - Seek target is the end but unable to get PlayQueue 2602 data from server, aborting to prevent extra skips or playback issues WARNING - Seek target is the end but unable to get PlayQueue 2602 data from server, aborting to prevent extra skips or playback issues

My player is an apple tv on 16.2 beta running plex beta 8.12. Running Plex Media Server and plexautoskip on an M1 mac mini.

mdhiggins commented 1 year ago

Yeah so the plex API isn't able to get the PlayQueue for some reason so it can't check that it's at the end of the queue, it also looks like the skipNext feature is correctly recognizing this and not actually running any commands so you shouldn't be getting any infinite loops of playback, at least not at the fault of PlexAutoSkip (maybe plex is just looping? does the behavior change if its not running cause right now it doesn't look to be sending any commands to player)

Why its unable to get the PlayQueue is another matter, you can turn on debug level logging to see if that provides some more insight but its usually a PlexAPI issue and certain players don't reliable report this info

Sometimes a device reboot on the player or plex server can be helpful; it gets a little tricky since technically the playqueue comes from the server not the player but the ID comes from the player API updates

mdhiggins commented 1 year ago

Actually looking over the logs more closely, the fact that you have a PlayQueue ID being reported from the player (2602) but the server is failing to return the data makes me wonder if this is something weird going on server side. The debug level log data showing what exception the API is returning would probably be helpful here

joshali1990 commented 1 year ago

Just turned on Debug and I'll provide an update when I get a chance to play a test file.

mdhiggins commented 1 year ago

I also pushed out a little update to add an additional element to the logging if you have a chance to do a fresh git pull, might be helpful here

9fad3eea1dc131eb60b4bec4d3b6c325c40c9081