Kicking users who pause for prolonged time

Hey, I have a few users who keep setting their video on pause is there away to have a timeout on plex which stops the video for them after x minutes that a video is paused? I know there are dirty ways of doing this like restarting plex service while having IP of the users blocked in firewall but this can also effect other users whom are streaming.

At the moment there isn’t. There is a lot of talk about that. I don’t know when or if the devs are going to take on that challenge but suspect they’ll look at it again after Plex Cloud & DVR are up and stable. I know, and they know, control of streaming users is really needed

Since the Ninja couldn’t point you to it, here’s a Feature Request that asks for basically what you want: https://forums.plex.tv/discussion/146139/server-tools-kicking-a-user-or-stuck-client/p1

I made that request over well over a year ago, so I knew it existed, where to find it.

You vote for Feature Requests by adding a “Like” to the first post of the thread. Supposedly, these get tallied up and put onto the road map someplace.

Thank you both, I am looking forward to this, I had one user who paused a movie for 2000 minutes. I ended up kicking him in the way described above. (fetch his ip block it in my firewall then restating plex service). I have enough bandwidth to handle most things this just ruins my logs in plexpy, and does do some extent cause tear on my drives.

Since you have ubuntu, if you want to be a real jerk and don’t mind a little keyboard work…

do a ps -ef | grep -i transc and get the pid of the transcoder (presuming it’s running) and just kill -9 that pid. works instantly :slight_smile:

Actually, since you are running Ubuntu and PlexPy, there might be a way to automate this with shell/bash scripting… But this would only work if they are transcoding.

Not sure the code to do this, but you could try something like this:

Person pauses, the PlexPy notification agent executes a script that writes the user ID, PID and time the person paused. It also sets up a cron job to delete the PID after a certain amount of time.

If the person resumes the media, the Playback Resume deletes the cron job and the “paused file” created on a pause script. (Would probably be a good idea to automatically name the file by the User’s ID in Plex or in PlexPy, just to cover yourself.) If not, the cron job kills the offending PID and the person is no longer causing your system grief.

Again, I’m not sure how to write this scripting myself. Just taking a swag that this should be doable, leveraging PlexPy to handle it for you. (Wow! Could this be another reason to integrate this great application into the Web App? Just think of the number of Feature Requests integrating PlexPy could potentially deal with?)

If I have time in the next little while I may try looking into this a bit to see if it’s doable as I think it is. No promises.

@ChuckPa said:
Since you have ubuntu, if you want to be a real jerk and don’t mind a little keyboard work…

do a ps -ef | grep -i transc and get the pid of the transcoder (presuming it’s running) and just kill -9 that pid. works instantly :slight_smile:

I like, I never mind keybord work, just need to find away to automate this, would be nice with some api calls to plex where if pause >= 00:10:00 , then kick only that one transcoder even harder with direct play where tcp session needs to be closed.

well crap. I had a full reply posted and the forum lost it.

attempting to recreate:

Since my last post, I tried to track transcoder activity with the port in use with the cpu time (idle /running). Since the life of a port is short in all cases and the transcoder time possibly very low, tracking via the socket isn’t viable and looking at cpu utilization isn’t either. It would require clever fixed-point math

The other alternative was to read the log files. Not viable with a script.

Next option was writing C (most portable). Whether it does the netstat & process monitoring alone and/or reads the log files (digesting them), it’s a big undertaking. That’s a lot of work and not something I can crank out easily without having a PMS endpoint url.

What I can give you at least for now, which is a cheat but at least it gives you information you need

What I need is in /proc, from netstat and 127.0.0.1:32400/connections all rolled into one.

This will give you the ability to monitor if transcoding is happening. All you can do is see if a pid hangs around. I tried to write script beyond that but can’t validate whether a long standing transcode session is for a 2.5 hour movie or it’s been sitting idle for 2 hours.

As a single ugly command:

watch -n 30  echo Transcoder PIDs active: `pidof "Plex Transcoder"`

Using a shell script: show_transcoder_pids

watch -n 30 show_transcoder_pids

file: show_transcoder_pids

#!/bin/sh
echo "Active transcoder PIDs: `pidof "Plex Transcoder"`

From this, with code to back it up and do process statistics. PID life (duration) can be tracked and killed easily.

This is the best I can do right now.

Doing some digging around and testing with some dirty scripts,

i get to this point
(ss -tp | grep Plex)

ESTAB      0      0        ::ffff:192.168.1.43:32400                 ::ffff:192.168.1.101:52933                 users:(("Plex Media Serv",pid=26652,fd=113))
ESTAB      0      0      ::ffff:84.x.x.x:32400                ::ffff:80.x.x.x:60376                 users:(("Plex Media Serv",pid=26652,fd=84))
ESTAB      0      0        ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.46:57209                 users:(("Plex Media Serv",pid=26652,fd=99))
ESTAB      0      0        ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.84:42299                 users:(("Plex Media Serv",pid=26652,fd=105))
ESTAB      0      0        ::ffff:192.168.1.43:32400                 ::ffff:192.168.1.101:52924                 users:(("Plex Media Serv",pid=26652,fd=91))
ESTAB      0      3231976   ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.84:41738                 users:(("Plex Media Serv",pid=26652,fd=96))
ESTAB      0      0        ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.46:57595                 users:(("Plex Media Serv",pid=26652,fd=104))
ESTAB      0      0        ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.46:51258                 users:(("Plex Media Serv",pid=26652,fd=62))
ESTAB      0      0        ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.46:56166                 users:(("Plex Media Serv",pid=26652,fd=89))
ESTAB      0      0        ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.46:56133                 users:(("Plex Media Serv",pid=26652,fd=83))
ESTAB      0      522286 ::ffff:84.x.x.x:32400                ::ffff:80.x.x.x:59754                 users:(("Plex Media Serv",pid=26652,fd=102))
ESTAB      0      1305256   ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.46:57655                 users:(("Plex Media Serv",pid=26652,fd=63))
ESTAB      0      0      ::ffff:84.xx.x.x:32400                ::ffff:80.x.x.xx:59747                 users:(("Plex Media Serv",pid=26652,fd=93))
ESTAB      0      0      ::ffff:84.x.x.x:32400                ::ffff:84.x.x.x:55892                 users:(("Plex Media Serv",pid=26652,fd=109))
ESTAB      0      0        ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.84:42298                 users:(("Plex Media Serv",pid=26652,fd=92))
ESTAB      0      0        ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.46:57598                 users:(("Plex Media Serv",pid=26652,fd=108))
ESTAB      0      0        ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.46:57644                 users:(("Plex Media Serv",pid=26652,fd=116))
ESTAB      0      0        ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.46:57173                 users:(("Plex Media Serv",pid=26652,fd=95))
ESTAB      0      0        ::ffff:192.168.1.43:32400                  ::ffff:192.168.1.46:51260                 users:(("Plex Media Serv",pid=26652,fd=90))
root@media:~/plex/logs#

That is with 2 active streams and one pause all loook to be running transcoder under one stream.

So would need to catch when someone puts on pause then start a timer to execute a command as such csf -td $ip

I have set up CSF for tempban to be 5000 seconds, running a tail -f on plex media server log fil does not provide info when i pause.


Nov 18, 2016 17:41:34.328 [0x7fb633bff700] DEBUG - Request: [::ffff:192.168.1.84:42523 (Subnet)] OPTIONS /:/timeline?hasMDE=1&ratingKey=147&key=%2Flibrary%2Fmetadata%2F147&state=paused&playQueueItemID=4150&time=3429091&duration=5529504 (23 live) TLS GZIP Signed-in

That seams to be a repeat command looks like plex web keep sending updates every so often to inform on status.

States i can find is paused, playing just would be highly platform dependent as windows has no firewall from cli.

So this is double, sadly by the looks of it plex run all transocoders under same PID so can’t kill that one PID :confused: need to do it in tcp.

Would need to catch all status from pause just add a uniq tag to said command and time them from start until I catch same IP with status playing again. if not playing within 10min drop tcp connection.

tcpkill ip host kill can also be used.

Thank you @ChuckPa you gave good hints how to do this, I think I have a script in mind to do this.

Catch any paused status, if paused from IP is not status playing after 10min. tcpkill ip host

tcpkill host -i enp9s0 192.168.1.84, works also pretty fast. without killing any plexservices.

@Night

So this is double, sadly by the looks of it plex run all transocoders under same PID so can’t kill that one PID need to do it in tcp.

It’s “Plex Transcoder” when the transcoder runs. It’s far too big of a program to have as a thread in PMS proper. If it’s DirectPlay then yes it is a thread. It’s the same mechanism which feeds source input to the transcoder

I found tcpkill. It definitely looks like it’s firewall based and that will be a nightmare because not all linux distros use the same firewall. IPchains vs IPtables vs ipfwadm vs ufw

@ChuckPa said:
@Night

So this is double, sadly by the looks of it plex run all transocoders under same PID so can’t kill that one PID need to do it in tcp.

It’s “Plex Transcoder” when the transcoder runs. It’s far too big of a program to have as a thread in PMS proper. If it’s DirectPlay then yes it is a thread. It’s the same mechanism which feeds source input to the transcoder

I found tcpkill. It definitely looks like it’s firewall based and that will be a nightmare because not all linux distros use the same firewall. IPchains vs IPtables vs ipfwadm vs ufw

True as i said any thing writen would be dependent on many factors and dependents so it is hard to make a universal third party script for every platform as would be ideal.

Lets hope the devs the the use of such a feature

There is a lot going on. It’s not a neglected topic for certain. It IS a prioritization nightmare. This has been a LONG needed feature.

If there were simply a user-facing endpoint (to hit with curl) the problem could be handled externally until the Web team has time & resources to take up the task of making it pretty.

@ChuckPa said:
There is a lot going on. It’s not a neglected topic for certain. It IS a prioritization nightmare. This has been a LONG needed feature.

If there were simply a user-facing endpoint (to hit with curl) the problem could be handled externally until the Web team has time & resources to take up the task of making it pretty.

That is my thought to, I’m looking at API of both Plex and PlexPy now to give me what i want as long as i have IP and state i can do magic