parent
244428507c
commit
bba933e098
@ -1,5 +1,4 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
Kill Plex video transcoding streams only. All audio streams are left alone.
|
Kill Plex video transcoding streams only. All audio streams are left alone.
|
||||||
|
|
||||||
PlexPy > Settings > Notification Agents > Scripts > Bell icon:
|
PlexPy > Settings > Notification Agents > Scripts > Bell icon:
|
||||||
@ -8,19 +7,15 @@ PlexPy > Settings > Notification Agents > Scripts > Bell icon:
|
|||||||
PlexPy > Settings > Notification Agents > Scripts > Gear icon:
|
PlexPy > Settings > Notification Agents > Scripts > Gear icon:
|
||||||
Playback Start: kill_trans_exp_audio.py
|
Playback Start: kill_trans_exp_audio.py
|
||||||
|
|
||||||
Create custom messages for platforms.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import requests
|
import requests
|
||||||
import platform
|
from plexapi.server import PlexServer
|
||||||
from uuid import getnode
|
|
||||||
|
|
||||||
|
|
||||||
## EDIT THESE SETTINGS ##
|
## EDIT THESE SETTINGS ##
|
||||||
PLEX_HOST = ''
|
PLEX_TOKEN = 'xxxx'
|
||||||
PLEX_PORT = 32400
|
PLEX_URL = 'http://localhost:32400'
|
||||||
PLEX_SSL = '' # s or ''
|
|
||||||
PLEX_TOKEN = 'xxxxx'
|
|
||||||
DEFAULT_REASON = 'This stream has ended due to requiring video transcoding. ' \
|
DEFAULT_REASON = 'This stream has ended due to requiring video transcoding. ' \
|
||||||
'Please raise your Remote Quality to Original to play this content.'
|
'Please raise your Remote Quality to Original to play this content.'
|
||||||
|
|
||||||
@ -31,58 +26,28 @@ DEVICES = {'Android': 'Andriod message',
|
|||||||
'Chromecast': 'Chromecast message'}
|
'Chromecast': 'Chromecast message'}
|
||||||
|
|
||||||
USER_IGNORE = ('') # ('Username','User2')
|
USER_IGNORE = ('') # ('Username','User2')
|
||||||
##
|
##/EDIT THESE SETTINGS ##
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
sess = requests.Session()
|
||||||
url = 'http{}://{}:{}/'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
sess.verify = False
|
||||||
|
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
||||||
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN,
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'X-Plex-Provides': 'controller',
|
|
||||||
'X-Plex-Platform': platform.uname()[0],
|
|
||||||
'X-Plex-Platform-Version': platform.uname()[2],
|
|
||||||
'X-Plex-Product': 'Plexpy script',
|
|
||||||
'X-Plex-Version': '0.9.5',
|
|
||||||
'X-Plex-Device': platform.platform(),
|
|
||||||
'X-Plex-Client-Identifier': str(hex(getnode()))
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
def kill_session():
|
||||||
if t == 'GET':
|
for session in plex.sessions():
|
||||||
r = requests.get(url + path, headers=headers, verify=False)
|
user = session.username[0]
|
||||||
elif t == 'POST':
|
media_type = session.type
|
||||||
r = requests.post(url + path, headers=headers, verify=False)
|
if user in USER_IGNORE or media_type == 'track':
|
||||||
elif t == 'DELETE':
|
print('Ignoring {}\'s {} stream.'.format(user, media_type))
|
||||||
r = requests.delete(url + path, headers=headers, verify=False)
|
exit()
|
||||||
|
trans_dec = session.trancodeSessions[0].videoDecision
|
||||||
|
if trans_dec == 'transcode':
|
||||||
|
platform = session.players[0].platform
|
||||||
|
MESSAGE = DEVICES.get(platform, DEFAULT_REASON)
|
||||||
|
print(MESSAGE)
|
||||||
|
print('Killing {user}\'s stream for transcoding video on {plat}.'.format(user=user, plat=platform))
|
||||||
|
session.stop(reason=MESSAGE)
|
||||||
|
|
||||||
if r and len(r.content): # incase it dont return anything
|
|
||||||
|
|
||||||
return r.json()
|
|
||||||
else:
|
|
||||||
return r.content
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print e
|
|
||||||
|
|
||||||
def kill_stream(sessionId, message):
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN}
|
|
||||||
params = {'sessionId': sessionId,
|
|
||||||
'reason': message}
|
|
||||||
requests.get('http{}://{}:{}/status/sessions/terminate'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT),
|
|
||||||
headers=headers, params=params)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
response = fetch('status/sessions')
|
kill_session()
|
||||||
|
|
||||||
if 'Video' in response['MediaContainer']:
|
|
||||||
for video in response['MediaContainer']['Video']:
|
|
||||||
if video['TranscodeSession']['videoDecision'] == 'transcode' and video['User']['title'] not in USER_IGNORE:
|
|
||||||
MESSAGE = DEVICES.get(video['Player']['platform'], DEFAULT_REASON)
|
|
||||||
print("Killing {}'s stream for transcoding video".format(video['User']['title']))
|
|
||||||
kill_stream(video['Session']['id'], MESSAGE)
|
|
||||||
elif 'Track' in response['MediaContainer']:
|
|
||||||
for track in response['MediaContainer']['Track']:
|
|
||||||
print("{} is streaming audio, let them pass!".format(track['User']['title']))
|
|
||||||
exit()
|
|
||||||
else:
|
|
||||||
exit()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user