Fix part
fix for `part` and added session_key to check against.
This commit is contained in:
parent
4c78110765
commit
bff9d2b5a6
@ -2,14 +2,18 @@
|
|||||||
Kill Plex paused video transcoding streams.
|
Kill Plex paused video transcoding streams.
|
||||||
|
|
||||||
PlexPy > Settings > Notification Agents > Scripts > Bell icon:
|
PlexPy > Settings > Notification Agents > Scripts > Bell icon:
|
||||||
[X] Notify on playback pause
|
[X] Notify on playback start
|
||||||
|
|
||||||
PlexPy > Settings > Notification Agents > Scripts > Gear icon:
|
PlexPy > Settings > Notification Agents > Scripts > Gear icon:
|
||||||
Playback Pause: kill_trans_pause.py
|
Playback Start: new_kill_trans_pause.py
|
||||||
|
|
||||||
|
PlexPy > Settings > Notifications > Script > Script Arguments:
|
||||||
|
{session_key}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import requests
|
import requests
|
||||||
import platform
|
import platform
|
||||||
|
import sys
|
||||||
from uuid import getnode
|
from uuid import getnode
|
||||||
|
|
||||||
|
|
||||||
@ -17,14 +21,14 @@ from uuid import getnode
|
|||||||
PLEX_HOST = ''
|
PLEX_HOST = ''
|
||||||
PLEX_PORT = 32400
|
PLEX_PORT = 32400
|
||||||
PLEX_SSL = '' # s or ''
|
PLEX_SSL = '' # s or ''
|
||||||
PLEX_TOKEN = 'xxxxx'
|
PLEX_TOKEN = ''
|
||||||
MESSAGE = 'This stream has ended due to being paused and transcoding.'
|
MESSAGE = 'This stream has ended due to being paused and transcoding.'
|
||||||
|
|
||||||
USER_IGNORE = ('') # ('Username','User2')
|
USER_IGNORE = ('') # ('Username','User2')
|
||||||
##
|
##
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
def fetch(path, t='GET'):
|
||||||
url = 'http{}://{}:{}/'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
||||||
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN,
|
headers = {'X-Plex-Token': PLEX_TOKEN,
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -58,18 +62,19 @@ def kill_stream(sessionId, message):
|
|||||||
headers = {'X-Plex-Token': PLEX_TOKEN}
|
headers = {'X-Plex-Token': PLEX_TOKEN}
|
||||||
params = {'sessionId': sessionId,
|
params = {'sessionId': sessionId,
|
||||||
'reason': message}
|
'reason': message}
|
||||||
requests.get('http{}://{}:{}/status/sessions/terminate'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT),
|
requests.get('http://{}:{}/status/sessions/terminate'.format(PLEX_HOST, PLEX_PORT),
|
||||||
headers=headers, params=params)
|
headers=headers, params=params)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
response = fetch('status/sessions')
|
response = fetch('status/sessions')
|
||||||
|
|
||||||
|
for s in response['MediaContainer']['Video']:
|
||||||
|
part = s['Media'][0]['Part'][0]
|
||||||
try:
|
try:
|
||||||
for video in response['MediaContainer']['Video']:
|
if s['sessionKey'] == sys.argv[1] and part['decision'] == 'transcode' \
|
||||||
if video['TranscodeSession']['videoDecision'] == 'transcode' and video['User']['title'] not in USER_IGNORE \
|
and s['User']['title'] not in USER_IGNORE and s['Player']['state'] == 'paused':
|
||||||
and video['Player']['state'] == 'paused':
|
print("Killing {}'s stream for pausing a transcode stream of {}".format(s['User']['title'], s['title']))
|
||||||
print("Killing {}'s stream for pausing a transcode stream of {}".format(video['User']['title'], s['title']))
|
kill_stream(s['Session']['id'], MESSAGE)
|
||||||
kill_stream(video['Session']['id'], MESSAGE)
|
except Exception:
|
||||||
except Exception as e:
|
|
||||||
print('Session error: {}'.format(e))
|
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user