mdhiggins / PlexAutoSkip

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

Added option to not skip first number of episodes in viewing session #38

Closed ShanaryS closed 1 year ago

ShanaryS commented 1 year ago

Per issue #37.

Added two config options: subsequent-session-episodes = False session-length = 120

If False, it's default behavior. If True, it will never skip the first episode at the start of a viewing session. After session-length (minutes), a session is considered over unless if the same user starts another episode (or the same) of the exact same show. Timer resets each new episode. Movies are ignored.

Logging is all debug. I've tested it and it's working as expected.

Note: The subsequent episodes are always handled elsewhere. Only the first episode of a session has whether or not it will be skipped changed.

mdhiggins commented 1 year ago

You put this together quickly! Busy with work this week but I'll try and review

Also found my chromecast so I'll try and test that out when I get a chance

ShanaryS commented 1 year ago

The project is well written and easy to understand! I also have a lot of experience with PlexAPI as I've made many scripts with it.

ShanaryS commented 1 year ago

I updated the feature to allow user to set how many episodes to play markers for in session before skipping. So instead of a bool, it's an int where 0 is default behavior. If the user sets it to 1, then it's what I described above. Set it any higher say to 3, means the first 3 episodes will have their markers play.

Also, could you confirm if this doesn't affect ads so it's always skipped? I'm not sure if the first episode options do that either as I don't have anything to test with.

mdhiggins commented 1 year ago

So I pulled this into a new branch and did some heavy overhauling, would appreciate your testing

Named this new feature 'binge' and gave it its own class (to not confuse it with the Session and PlexSession classes that already exist) named BingeSessions and BingeSession

Took a slightly different approach than you, I track a session based on user and player with a timeout if the session is inactive, its not specifically limited to an isolated show in case people have a playlist mix or something; limiting it to a specific show might be a nice thing to make optional I'll look into

Rather that block the script activity at the shouldAdd method, I instead wipe the tags and update the markers so that the skip Next feature can still be applied. I also updated the S01E01/S**E01 features to behave similarly

Finally, I added a safe-tags option so that when you're doing these binges you can still let some things be skipped like advertisements or credits while allowing the intros for the first x number of episodes

mdhiggins commented 1 year ago

Added the same show option

ShanaryS commented 1 year ago

The changes are nice! It all seems to work in a continuous session. But if you leave an episode and rejoin, it starts to skip intros even though ignore-skip-for hasn't yet reached 0. It then continues like this indefinitely as the Binge class never reaches the timeout since you're are still playing.

The timeout of 30 seconds seems too short for me. I would like it to be customizable in the config with a default timeout of 15 minutes. Currently, if you pause or exit the player for 30 seconds, it ends the binge. Meaning no bathroom breaks or snacks. I think most people wouldn't want intros again so soon.

A few things small things. I noticed there still is the old "subsequent-session-episodes-after": 0 and "session-length": 120 in the defaults in settings.py, should probably be removed. Also having the log message on line 92 in binge.py different when remaining is already at 0 would make it clearer.

mdhiggins commented 1 year ago

Removed the old settings, good catch

For the sake of communication, going to refer to 'early-binge' episodes as the ones that still play the intro

Leaving an episode and rejoining doesn't increment the early-binge counter if its the same episode, just tested so not sure what you're seeing in that regard, it recognizes that its the same binger session and that the episode is the same and just refreshes the timeout

I also increased the time to 300 but removed the paused state / stopped state check and instead just rely on the "ended" property of the mediaWrapper which the script already tracks which should allow more scenarios that keep the binger alive. I think a long timeout isn't needed (30 was too short though) and would prefer to keep the binge session rolling using server checks like this instead. This new change will allow paused/stopped media to keep the binger from timing out for things like bathroom breaks

I also added some logic so that the counter won't increment if the episode is advanced below a certain watched duration threshold (50% for now), so if you skip and episode early on cause you've seen it or don't want to watch that particular episode it won't eat up your 'early-binge' counter

Let me know how these changes feel

ShanaryS commented 1 year ago

Yep this feels better! Thanks for working on this.

mdhiggins commented 1 year ago

Getting ready to merge this into the master branch, but I had one more thing to try

I added some playqueue integration into the binge logic to try and determine if its truly a binge session. It looks for a couple things, basically

  1. If there is no queue, can assume its a single episode that's being played and binging shouldn't apply
  2. nothing left in the queue, probably not a binge (this only applies on binge start, not when updated), dont apply
  3. same-show only is on but the queue is mixed content, dont apply

Are these helpful?

mdhiggins commented 1 year ago

Also one more feature, a nice side effect of tracking these binges is that you can potentially limit the skip next feature so it doesn't cause indefinite playback, added that new option as well

mdhiggins commented 1 year ago

Went ahead and merged things but let me know if you have any issues

ShanaryS commented 1 year ago

These are nice changes! It gives me an error when I try to play a movie though regardless of my config settings. Only doesn't if I remove 'movie' from the skip section:

2023-02-28 10:39:43 INFO - Found new session 31 [25505] (Creed) iPhone|DB48BC9E-AB7C-405B-99A4-AEFA4212F219 viewOffset 0 StoneColeQ on Plex for iOS, sessions: 0
2023-02-28 10:39:43 ERROR - Unexpected error getting data from session alert
2023-02-28 10:39:43 Traceback (most recent call last):
2023-02-28 10:39:43   File "/usr/local/pas/resources/skipper.py", line 420, in processAlert
2023-02-28 10:39:43     self.addSession(wrapper)
2023-02-28 10:39:43   File "/usr/local/pas/resources/skipper.py", line 535, in addSession
2023-02-28 10:39:43     self.bingeSessions.update(mediaWrapper)
2023-02-28 10:39:43   File "/usr/local/pas/resources/binge.py", line 118, in update
2023-02-28 10:39:43     self.sessions[mediaWrapper.clientIdentifier] = BingeSession(mediaWrapper, self.settings.binge, self.settings.skipnextmax, self.settings.bingesafetags, self.settings.bingesameshowonly)
2023-02-28 10:39:43   File "/usr/local/pas/resources/binge.py", line 19, in __init__
2023-02-28 10:39:43     raise self.BingeSessionWrongTypeException
2023-02-28 10:39:43 AttributeError: 'BingeSession' object has no attribute 'BingeSessionWrongTypeException'

I like using the play queue (didn't even know that was a thing) as it's probably a more robust solution. I had turned off the binge feature for movies as I like to watch the credits after, but now I can keep it an it will only count a movie as binge if I choose to put it in a queue.

The new skip-next-max will disable auto skipping after x amount of skips right? So this means that it won't skip the up next screen once it reaches the limit and requires user input? Basically a "Are you still watching?" feature.

mdhiggins commented 1 year ago

Yeah basically an are you still watching feature, Plex kind of has that built in the but current skip next feature fakes user input so it never triggers, this just lets you set a limit

Fixed that exception error, hadn't completely reverted an earlier change and had that wrong exception type still in place, should be all good now

Movies were always ignored for the binge feature, regardless of queue or not so shouldn't be impacted

ShanaryS commented 1 year ago

Everything works! Huge thanks for this feature, really makes everything seamless.