mdhiggins/PlexAutoSkip

Custom definition option to mute instead of skip?

mmguero opened this issue · 17 comments

I am not that familiar with the Plex API, so my apologies if this is not doable.

Would it be possible for you to implement an option for custom defined sections of media to mute, rather than skip?

There is a setVolume option

https://github.com/pkkid/python-plexapi/blob/2b960cf868f12364717e89caf23343c471fd74cb/plexapi/client.py#L445

But I don't believe many players support it

I'd be open to a pull request if you can get it to work but it would require a decent amount of extra work to implement compared to just calling the skip command

You'd have to mute, track current state, unmute, and then flag the operation in some way so it doesn't try to continuously adjust the volume after that point

I can try and look into it but probably won't have time for a while

d0dcfaf

Haven't updated the wiki yet but I was able to put this together

Lots of limitations due to the plexAPI and setVolume command only working on a small number of players

  • Works perfectly on iOS
  • Partially works on Plex for Windows (can't get current volume but can change, so restoring the previous volume doesn't work, have to use a predefined value)
  • Doesn't work on web player or roku at all

And that's all I have available for testing

I'll update the readme after you test this out but here are the relavent settings, the sample files are updated

[Skip]
mode = volume

...

[Volume]
low = 0
high = 100

Additionally, you can set the mode using custom.json on a case-by-case basis instead of applying it globally

Let me know how this works

Any luck?

I'm sorry I have been out of town but I will be back this week and try it.

All good keep me posted

Interesting that it didn't work on Web Player for you, I tried it on there first actually, and it worked perfectly, setting the volume to 0 at the beginning of my custom marker and setting it back at the end:

    "markers": {
        "32452": [
            {
                "start": 559000,
                "end": 651000
            }
        ]
    },
INFO - Found a custom marker for media 137 [32452] (The Orville s03e01 - Electric Sheep) Firefox with range 559000-651000 and viewOffset 559532 (32452), lowering volume
INFO - Setting Plex Web player volume playing 137 [32452] (The Orville s03e01 - Electric Sheep) Firefox from 90 to 0
INFO - Passed a custom marker for media 137 [32452] (The Orville s03e01 - Electric Sheep) Firefox with range 559000-651000 and viewOffset 651022, restoring volume (32452)
INFO - Setting Plex Web player volume playing 137 [32452] (The Orville s03e01 - Electric Sheep) Firefox from 0 to 90

The only thing I wasn't quite sure about was:

Additionally, you can set the mode using custom.json on a case-by-case basis instead of applying it globally.

What does that look like? I tried this:

    "markers": {
        "32452": [
            {
                "mode": "volume",
                "start": 559000,
                "end": 651000
            }
        ]
    },

but it just skipped. Setting it globaly in my config.ini did work, however.

I will try it on a chromecast tomorrow. All in all I think it's very cool, thank you!

Oh, wait, looking at the sample custom.json I think I specified it wrong, I'll play around with it.

Yeah I was just doing it wrong, this worked perfectly:

{
    "markers": {
        "32452": [
            {
                "start": 559000,
                "end": 651000
            }
        ]
    },
    "allowed": {
        "users": [],
        "clients": [],
        "keys": []
    },
    "blocked": {
        "users": [],
        "clients": [],
        "keys": []
    },
    "clients": {},
    "offsets": {},
    "tags": {},
    "mode": {
        "32452": "volume"
    }
}

Hm so there was some flawed logic in my first implementation if there were situations where there were multiple markers and some issues that would report false data if the low volume wasn't zero, needed to look at the big picture instead of firing setVolume on individual marker levels otherwise two mute markers would compete to adjust the volume

17b75ab

That fixes things

I additionally liked the idea of letting individual custom markers have different modes (one skip, one volume etc) so I supported your attempt to include mode in the marker definition

Grab the latest update and test it out and make sure I didn't break anything

Also what browser are you using? The volume adjustment still isn't working for me but skipping works fine. Using edge chromium

Firefox 101.0.1 on Linux x86_64. I'll grab your latest commit and try it out.

Hmmm with the latest commit, I'm getting stuff like this whenever the episode is playing:

user@host PlexAutoSkip [mas:org/mas] › python3 main.py 
INFO - /home/user/.asdf/installs/python/3.10.4/bin/python3
INFO - Loading config file /home/user/devel/github/media/PlexAutoSkip/config/config.ini.
INFO - Loading custom JSON file /home/user/devel/github/media/PlexAutoSkip/config/custom.json
INFO - Loading custom JSON file /home/user/devel/github/media/PlexAutoSkip/config/orville.json
INFO - Connected to Plex server plexserver using plex.tv account
INFO - Skipper initiated and ready
INFO - Found new session 2 [32452] (The Orville s03e01 - Electric Sheep) Firefox viewOffset 0 ['user'], sessions: 0
ERROR - Unexpected error getting data from session alert
Traceback (most recent call last):
  File "/home/user/devel/github/media/PlexAutoSkip/resources/skipper.py", line 299, in processAlert
    self.addSession(sessionKey, wrapper)
  File "/home/user/devel/github/media/PlexAutoSkip/resources/skipper.py", line 398, in addSession
    self.checkMedia(mediaWrapper)
  File "/home/user/devel/github/media/PlexAutoSkip/resources/skipper.py", line 107, in checkMedia
    self.checkMediaSkip(mediaWrapper, leftOffset, rightOffset)
  File "/home/user/devel/github/media/PlexAutoSkip/resources/skipper.py", line 142, in checkMediaSkip
    if (marker.start + leftOffset) <= mediaWrapper.viewOffset <= marker.end:
  File "/home/user/devel/github/media/PlexAutoSkip/resources/mediaWrapper.py", line 240, in viewOffset
    return vo if vo <= (self.duration or vo) else self.duration
AttributeError: 'MediaWrapper' object has no attribute 'duration'
INFO - Found new session 2 [32452] (The Orville s03e01 - Electric Sheep) Firefox viewOffset 0 ['user'], sessions: 0
ERROR - Unexpected error getting data from session alert
Traceback (most recent call last):
  File "/home/user/devel/github/media/PlexAutoSkip/resources/skipper.py", line 299, in processAlert
    self.addSession(sessionKey, wrapper)
  File "/home/user/devel/github/media/PlexAutoSkip/resources/skipper.py", line 398, in addSession
    self.checkMedia(mediaWrapper)
  File "/home/user/devel/github/media/PlexAutoSkip/resources/skipper.py", line 107, in checkMedia
    self.checkMediaSkip(mediaWrapper, leftOffset, rightOffset)
  File "/home/user/devel/github/media/PlexAutoSkip/resources/skipper.py", line 142, in checkMediaSkip
    if (marker.start + leftOffset) <= mediaWrapper.viewOffset <= marker.end:
  File "/home/user/devel/github/media/PlexAutoSkip/resources/mediaWrapper.py", line 240, in viewOffset
    return vo if vo <= (self.duration or vo) else self.duration
AttributeError: 'MediaWrapper' object has no attribute 'duration'
INFO - Found new session 2 [32452] (The Orville s03e01 - Electric Sheep) Firefox viewOffset 0 ['user'], sessions: 0

Using a custom JSON that looks like this:

{
    "markers": {
        "32452": [
            {
                "mode": "volume",
                "start": 559000,
                "end": 651000
            },
            {
                "mode": "volume",
                "start": 1750000,
                "end": 1812000
            }
        ]
    },
    "allowed": {
        "users": [],
        "clients": [],
        "keys": []
    },
    "blocked": {
        "users": [],
        "clients": [],
        "keys": []
    },
    "clients": {},
    "offsets": {},
    "tags": {},
    "mode": {}
}

Whoops unrelated to your issues

c97130c

Made a type when trying to fix #20

Thanks, with that commit I tried it out with a custom JSON that has 4 volume regions and 2 skip regions and they all worked as expected! (web player on firefox 101.0.1 on linux x86_64)

Awesome, just pushed the update to the wiki, going to close this out then but feel free to let me know if there's any issues

Out of curiosity, what version of the web player are you running?

https://forums.plex.tv/t/plex-web/20528/389

It looks like they removed the "advertise as player" option and I'm wondering if that's what's breaking some of the web player commands as now my ability to skip intro isn't working on the web player either

Version 4.76.1