mdhiggins / PlexAutoSkip

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

Fails to move to next episode on FireTV #12

Closed cjmanca closed 2 years ago

cjmanca commented 2 years ago

First - I love the script, and it works great for my windows player, but on my FireTV it's able to skip intros, but when it tries to skip at the end of the episode to the next episode, the player reports:

"An error occurred while attempting to play this video. Please check your connection and try again."

When this happens, the script says the following:

INFO - Seek target is the end of 94 [122646] (Peppa Pig s01e07 - Mommy Pig at Work) TV for Plex for Android (TV) player , going to next
ERROR - Connection to remote host was lost.
ERROR - [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
ERROR - [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
ERROR - [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
ERROR - [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
ERROR - [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
ERROR - [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
ERROR - [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
ERROR - [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
ERROR - Connection to remote host was lost.

The episodes in question have been played entirely too many times (seriously, make it stop), so I know they'll play normally without the auto skip.

mdhiggins commented 2 years ago

Hm that's gonna be a tough one to solve, it's a generic web socket error being triggered likely by the "skipNext" API command being called. I have very little control over that and can't find any documentation on that error from the Plex API GitHub. The fact that the intro skipping works on that device means the device is at least communicating with the API and connecting for some commands. I don't have any FireTV devices to test on to see if this is a universal problem or not but it may be that the skipNext command isn't supported.

Does a device restart have any impact?

If you don't use the "next" feature do things still work appropriately?

cjmanca commented 2 years ago

Restarting doesn't fix it. I'll try turning off the "next" feature to see if that helps. Is there any way to specify the "next" feature per device?

mdhiggins commented 2 years ago

Not currently but I can see about making that a feature though I can't imagine any reason why that would be device specific. You don't happen to have more than one Fire TV device do you? Just curious if that's a pattern with all Fire TV devices

mdhiggins commented 2 years ago

I had another thought.

In introSkipper.py line 158

mediaWrapper.media.markWatched()

Try commenting that line out and just leave the skipNext command and see if that makes any difference. Maybe the markWatched() command is what's getting stuck since that's functionally a little different

Edit:

I had a moment of free time and pushed a small update to move the markWatched() to after the skipNext() command and to wrap it in a try/except block, see if updating fixes the issue

I also renamed introSkipper to skipper which I had been meaning to do

This does require the "next" feature to be on to be relevant

c80460da9bdff44407e560ecdcfb4a89321dff29

cjmanca commented 2 years ago

I haven't tried the update, but I tried commenting out that line, and it still does it.

It also doesn't give the error every time. It never skips to the next episode (there's always a 10 second countdown between episodes), but sometimes it gives that error part way through the countdown.

Something new this time though - sometimes the next episode can be heard to start in the background (the audio starts) while the countdown is still playing, so I'm guessing it "sometimes works", but firetv isn't smart enough to stop showing the countdown screen.

Is there any way to add a bit of delay before sending the next episode command? I've noticed the FireTV seems to take a couple of seconds to "think" after the end of an episode before showing the countdown. I'm wondering if the command is coming too soon and it's getting confused.

cjmanca commented 2 years ago

Oh - alternately, maybe an option to send the "next episode" command a set amount of seconds before the end of the episode, therefore bypassing the countdown screen altogether?

EDIT: I added a quick config var for end of episode offset which I'll test later. I don't have access to the TV right now. If it works I'll do a pull request. It works on my windows machine at least, but the test will be whether FireTV likes it =P

mdhiggins commented 2 years ago

Hm seems like maybe the opposite would be a better approach

The whole point of the skip next feature is to avoid that "next episode" interface. I wonder if the FireTV just gets stuck

efd508a9e46726ece6300fadba1be2cb9bcc0467

This update adds a 5 second buffer for the skipNext trigger; once the media gets within the last 5 seconds of the video the skipNext command will fire hopefully before that interface pops up

See if that helps

Edit: Just saw your other reply, clearly we were on the same page

cjmanca commented 2 years ago

Lol, and I edited my reply before seeing yours. Github's ajax update is a bit delayed it seems

mdhiggins commented 2 years ago

All good, probably wouldn't be a bad idea to just have a duration offset in config.ini instead of hard coding it to 5 seconds but figured this would get things working quickly as a test; let me know if it fixes the issue and can probably migrate to that solution

mdhiggins commented 2 years ago

7f80904aa207bde6f5a6b2f112f177287314ffbe

Probably jumping the gun but had a free moment so I migrated the duration offset to a config.ini setting

cjmanca commented 2 years ago

I took a quick look at your commit, and I don't think that commit will fix it. It's testing against an earlier time, but still skipping to the very end (which would trigger the countdown).

I think lines 111, 116 and 156 would need to be changed

Perhaps rather than skipping to the end, it would be better to just call the "nextEpisode" api instead?

EDIT: Oh, I see - the seekTo you're calling is different than the API one, and checks if it should move next instead of doing the real seek. I still think 156 needs to be updated though.

mdhiggins commented 2 years ago

Nah 156 is fine, it's just the seek target which is still set at the duration. Working fine in my tests

cjmanca commented 2 years ago

Ok, if you're confident that mediaWrapper.lastchapter.end will always be exactly equal to mediaWrapper.media.duration, then yeah, it should be fine.

So far the changes seem to be working for my FireStick with an offset setting of 2000 ms.

mdhiggins commented 2 years ago

6dc9154d2c84aed5e8c732e9257847d36013ac54

Adjusted the last chapter behavior skip to the end / duration so that they'll always be equal and the intent of that functionality doesn't skip to the near end for no reason in case the chapters are poorly defined

Closing this out!

mdhiggins commented 2 years ago

Updated wiki