blacktwin / JBOPS

Just a Bunch Of Plex Scripts
1.71k stars 305 forks source link

Plex Pre-Processing Script #239

Closed Phlomos closed 4 years ago

Phlomos commented 4 years ago

Hello,

Because of BTRFS's RAID capabilities, I have built a multimedia system with Plex and BTRFS. Unfortunately, sometimes BTRFS needs to clean up its filesystem ("scrub") and the whole system wears down during that time. Plex's recordings are interrupted, cut and de-synchronized because of it. Fortunately, BTRFS Scrub can be cancelled and resumed. So if I would just get a notice, when Plex starts a recording or broadcasting, then I could start a script, that cancels Scrub during such an event and resume it afterwards. Would you have any idea, how this could be done? Thanks

blacktwin commented 4 years ago

Plex starts a recording or broadcasting,

So only when the LiveTV feature is being used? I'm not sure how those calls are processed so I'm not sure where you'd see them pop up. You can setup this listener and see what happens when you start recording or broadcasting.

Phlomos commented 4 years ago

I desperately tried to make that Python script work. I even changed it a little bit:

if __name__ == '__main__':
    try:
        account = MyPlexAccount('my.email@address.com', 'MyPasswd')
        plex = account.resource('PlexOnHotspot').connect()  # returns a PlexServer instance
#        plex = PlexServer()
        listener = plex.startAlertListener(_print)
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        listener.stop()

I receive an e-mail, saying: "A new device was used to sign in to your Plex account". Though it's IP address is strange. But in the Syslog it says:

myplex:961 INFO Testing 4 resource connections.. myplex:1281 ERROR http://172.104.247.122:8443: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) myplex:1291 INFO Resource connection OK (0s): https://192-168-234-1.997f2f5b2a1a465bb6da87e875c84be3.plex.direct:32400?X-Plex-Token= myplex:1291 INFO Resource connection OK (2s): https://172-104-247-122.997f2f5b2a1a465bb6da87e875c84be3.plex.direct:8443?X-Plex-Token= myplex:1291 INFO Resource connection OK (0s): http://192.168.234.1:32400?X-Plex-Token= myplex:1291 INFO Resource connection ERR (0s): http://172.104.247.122:8443?X-Plex-Token= myplex:1294 INFO Connecting to Resource: https://192-168-234-1.997f2f5b2a1a465bb6da87e875c84be3.plex.direct:32400?X-Plex-Token= alert:46 WARNING Can't use the AlertListener without websocket

I also modified the "config.ini" file in root's home:

[plexapi]
container_size = 50
timeout = 30

[auth]
myplex_username = my.email@address.com
myplex_password = MyPasswd
server_baseurl = http://127.0.0.1:32400
#server_token = XBHSMSJSDJ763JSm
client_baseurl = http://127.0.0.1:32433
#client_token = BDFSLCNSNL789FH7

[header]
#identifier = 0x485b314307f3L
platorm = Linux
platform_version = 4.19.0-10-amd64
product = PlexAPI
version = 4.19.0-10

I can't connect to that URL (http://172.104.247.122:8443) from a Web browser, either.

I am a bit lost now…

Thanks

blacktwin commented 4 years ago

Here is the response I got when starting a recording of Night Court.

{   'ActivityNotification': [   {   'Activity': {   'Context': {   'deviceID': '54',
                                                                   'grabber': 'tv.plex.grabbers.hdhomerun',
                                                                   'itemKey': '/tv.plex.providers.epg.cloud:61/metadata/plex%3A%2F%2Fepisode%2F5cffa191d97525001feae5a9',
                                                                   'itemMediaIndex': '0',
                                                                   'itemRatingKey': 'plex%3A%2F%2Fepisode%2F5cffa191d97525001feae5a9',
                                                                   'source': 'provider://tv.plex.providers.epg.cloud',
                                                                   'subscriptionID': '555'},
                                                    'cancellable': True,
                                                    'progress': 0,
                                                    'subtitle': 'Night Court - '
                                                                'E4 - Ladies '
                                                                'Night',
                                                    'title': 'Recording',
                                                    'type': 'grabber.grab',
                                                    'userID': 1,
                                                    'uuid': 'xxxxx-xxxxx-xxxxx-xxxxx-xxxxx'},
                                    'event': 'started',
                                    'uuid': 'xxxxx-xxxxx-xxxxx-xxxxx-xxxxx'}],
    'size': 1,
    'type': 'activity'}

PlexOnHotspot is your Plex server connected via a Hotspot? You could just use the server's IP and TOKEN to connect.

Phlomos commented 4 years ago

Hello,

Am 18.09.2020 um 15:17 schrieb blacktwin notifications@github.com:

Here is the response I got when starting a recording of Night Court.

{ 'ActivityNotification': [ { 'Activity': { 'Context': { 'deviceID': '54', 'grabber': 'tv.plex.grabbers.hdhomerun', 'itemKey': '/tv.plex.providers.epg.cloud:61/metadata/plex%3A%2F%2Fepisode%2F5cffa191d97525001feae5a9', 'itemMediaIndex': '0', 'itemRatingKey': 'plex%3A%2F%2Fepisode%2F5cffa191d97525001feae5a9', 'source': 'provider://tv.plex.providers.epg.cloud', 'subscriptionID': '555'}, 'cancellable': True, 'progress': 0, 'subtitle': 'Night Court - ' 'E4 - Ladies ' 'Night', 'title': 'Recording', 'type': 'grabber.grab', 'userID': 1, 'uuid': 'xxxxx-xxxxx-xxxxx-xxxxx-xxxxx'}, 'event': 'started', 'uuid': 'xxxxx-xxxxx-xxxxx-xxxxx-xxxxx'}], 'size': 1, 'type': 'activity'}

Would be great to have some kind of daemon with a key-value configuration file, where we have as key the notification and value the script to start. And then as environment variables the more detailled information.

PlexOnHotspot is your Plex server connected via a Hotspot?

“PlexOnHotspot” is my Plex Server, running on the server named "hotspot”. I start your alert listener locally on the same server. It’s a Debian Buster server.

You could just use the server's IP and TOKEN to connect.

I had a problem to find my token. Was not sure, if what I found was the right thing.

Thanks Philip

blacktwin commented 4 years ago

So I'm not sure where to go from here. I don't have any interest in creating a script as you've describe. I've provided a way that may work for what you're trying to do. I'm not sure if you got the alert_listener working.