corrections
Corrections included are covered in https://github.com/blacktwin/JBOPS/issues/12 Other minor corrections.
This commit is contained in:
parent
d9744f1106
commit
eb9def8c56
@ -69,7 +69,7 @@ def get_get_activity():
|
|||||||
|
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
def fetch(path, t='GET'):
|
||||||
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
url = 'http{}://{}:{}/'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
||||||
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN,
|
headers = {'X-Plex-Token': PLEX_TOKEN,
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -151,36 +151,33 @@ if __name__ == '__main__':
|
|||||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||||
|
|
||||||
response = fetch('status/sessions')
|
response = fetch('status/sessions')
|
||||||
fileDir = fileDir = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if find_sessionID(response):
|
if find_sessionID(response):
|
||||||
stream_info = find_sessionID(response)
|
stream_info = find_sessionID(response)
|
||||||
file_name = "{}.py".format(stream_info[0])
|
file_name = "{}.py".format(stream_info[0])
|
||||||
full_path = os.path.join(fileDir, file_name)
|
file = 'from time import sleep\n' \
|
||||||
file = "from time import sleep\n" \
|
'import sys, os\n' \
|
||||||
"import sys, os\n" \
|
'from {script} import kill_stream \n' \
|
||||||
"from {script} import kill_stream \n" \
|
'message = "{REASON}"\n' \
|
||||||
"message = '{REASON}'\n" \
|
'sessionID = os.path.basename(sys.argv[0])[:-3]\n' \
|
||||||
"sessionID = os.path.basename(sys.argv[0])[:-3]\n" \
|
'x = 0\n' \
|
||||||
"x = 0\n" \
|
'n = {ntime}\n' \
|
||||||
"n = {ntime}\n" \
|
'try:\n' \
|
||||||
"try:\n" \
|
' while x < n and x is not None:\n' \
|
||||||
" while x < n and x is not None:\n" \
|
' sleep({xtime})\n' \
|
||||||
" sleep({xtime})\n" \
|
' x += kill_stream(sessionID, message, {xtime}, n, "{user}", "{title}", "{sess_key}")\n' \
|
||||||
" x += kill_stream(sessionID, message, {xtime}, n, '{user}', '{title}', '{sess_key}')\n" \
|
' kill_stream(sessionID, message, {ntime}, n, "{user}", "{title}", "{sess_key}")\n' \
|
||||||
" kill_stream(sessionID, message, {ntime}, n, '{user}', '{title}', '{sess_key}')\n" \
|
' os.remove(sys.argv[0])\n' \
|
||||||
" os.remove(sys.argv[0])\n" \
|
'except TypeError as e:\n' \
|
||||||
"except TypeError as e:\n" \
|
' os.remove(sys.argv[0])'.format(script=os.path.basename(__file__)[:-3],
|
||||||
" os.remove(sys.argv[0])".format(script=os.path.basename(__file__)[:-3],
|
ntime=TIMEOUT, xtime=INTERVAL, REASON=REASON,
|
||||||
ntime=TIMEOUT, xtime=INTERVAL, REASON=REASON,
|
user=stream_info[1], title=stream_info[2], sess_key=stream_info[3])
|
||||||
user=stream_info[1], title=stream_info[2],
|
|
||||||
sess_key=stream_info[3])
|
|
||||||
|
|
||||||
with open(full_path, "w+") as output:
|
with open(file_name, "w+") as output:
|
||||||
output.write(file)
|
output.write(file)
|
||||||
|
|
||||||
subprocess.Popen([sys.executable, full_path], startupinfo=startupinfo)
|
subprocess.Popen([sys.executable, file_name], startupinfo=startupinfo)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
'''
|
'''
|
||||||
fetch function from https://gist.github.com/Hellowlol/ee47b6534410b1880e19
|
fetch transcode function from https://gist.github.com/Hellowlol/ee47b6534410b1880e19
|
||||||
PlexPy > Settings > Notification Agents > Scripts > Bell icon:
|
PlexPy > Settings > Notification Agents > Scripts > Bell icon:
|
||||||
[X] Notify on pause
|
[X] Notify on pause
|
||||||
|
|
||||||
@ -31,10 +31,10 @@ import requests
|
|||||||
|
|
||||||
## EDIT THESE SETTINGS ##
|
## EDIT THESE SETTINGS ##
|
||||||
|
|
||||||
PLEX_HOST = ''
|
PLEX_HOST = '127.0.0.1'
|
||||||
PLEX_PORT = 32400
|
PLEX_PORT = 32400
|
||||||
PLEX_SSL = '' # s or ''
|
PLEX_SSL = '' # s or ''
|
||||||
PLEX_TOKEN = 'xxx'
|
PLEX_TOKEN = 'rFr9327dn1JepuTA5o4U'
|
||||||
|
|
||||||
TIMEOUT = 30
|
TIMEOUT = 30
|
||||||
INTERVAL = 10
|
INTERVAL = 10
|
||||||
@ -44,7 +44,7 @@ ignore_lst = ('test')
|
|||||||
|
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
def fetch(path, t='GET'):
|
||||||
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
url = 'http{}://{}:{}/'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
||||||
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN,
|
headers = {'X-Plex-Token': PLEX_TOKEN,
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -82,17 +82,16 @@ def kill_stream(sessionId, message, xtime, ntime, user, title, sessionKey):
|
|||||||
response = fetch('status/sessions')
|
response = fetch('status/sessions')
|
||||||
|
|
||||||
if response['MediaContainer']['Video']:
|
if response['MediaContainer']['Video']:
|
||||||
for video in response['MediaContainer']['Video']:
|
for a in response['MediaContainer']['Video']:
|
||||||
part = video['Media'][0]['Part'][0]
|
if a['sessionKey'] == sessionKey:
|
||||||
if video['sessionKey'] == sessionKey:
|
if xtime == ntime and a['Player']['state'] == 'paused' and a['Media']['Part']['decision'] == 'transcode':
|
||||||
if xtime == ntime and video['Player']['state'] == 'paused' and part['decision'] == 'transcode':
|
|
||||||
sys.stdout.write("Killing {user}'s paused stream of {title}".format(user=user, title=title))
|
sys.stdout.write("Killing {user}'s paused stream of {title}".format(user=user, title=title))
|
||||||
requests.get('http://{}:{}/status/sessions/terminate'.format(PLEX_HOST, PLEX_PORT),
|
requests.get('http{}://{}:{}/status/sessions/terminate'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT),
|
||||||
headers=headers, params=params)
|
headers=headers, params=params)
|
||||||
return ntime
|
return ntime
|
||||||
elif video['Player']['state'] in ('playing', 'buffering'):
|
elif a['Player']['state'] in ('playing', 'buffering'):
|
||||||
sys.stdout.write("{user}'s stream of {title} is now {state}".
|
sys.stdout.write("{user}'s stream of {title} is now {state}".
|
||||||
format(user=user, title=title, state=video['Player']['state']))
|
format(user=user, title=title, state=a['Player']['state']))
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return xtime
|
return xtime
|
||||||
@ -104,15 +103,14 @@ def kill_stream(sessionId, message, xtime, ntime, user, title, sessionKey):
|
|||||||
def find_sessionID(response):
|
def find_sessionID(response):
|
||||||
|
|
||||||
sessions = []
|
sessions = []
|
||||||
for video in response['MediaContainer']['Video']:
|
for s in response['MediaContainer']['Video']:
|
||||||
part = video['Media'][0]['Part'][0]
|
if s['sessionKey'] == sys.argv[1] and s['Player']['state'] == 'paused' \
|
||||||
if video['sessionKey'] == sys.argv[1] and video['Player']['state'] == 'paused' \
|
and s['Media']['Part']['decision'] == 'transcode':
|
||||||
and part['decision'] == 'transcode':
|
sess_id = s['Session']['id']
|
||||||
sess_id = video['Session']['id']
|
user = s['User']['title']
|
||||||
user = video['User']['title']
|
sess_key = sys.argv[1]
|
||||||
sess_key = video['sessionKey']
|
title = (s['grandparentTitle'] + ' - ' if s['type'] == 'episode' else '') + s['title']
|
||||||
title = (video['grandparentTitle'] + ' - ' if video['type'] == 'episode' else '') + video['title']
|
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore')
|
||||||
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore').translate(None,"'")
|
|
||||||
sessions.append((sess_id, user, title, sess_key))
|
sessions.append((sess_id, user, title, sess_key))
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
@ -134,7 +132,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
response = fetch('status/sessions')
|
response = fetch('status/sessions')
|
||||||
|
|
||||||
fileDir = fileDir = os.path.dirname(os.path.realpath(__file__))
|
fileDir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if find_sessionID(response):
|
if find_sessionID(response):
|
||||||
|
@ -41,7 +41,7 @@ if USER in ignore_lst:
|
|||||||
|
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
def fetch(path, t='GET'):
|
||||||
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
url = 'http{}://{}:{}/'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
||||||
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN,
|
headers = {'X-Plex-Token': PLEX_TOKEN,
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -75,7 +75,7 @@ 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_HOST, PLEX_PORT),
|
requests.get('http{}://{}:{}/status/sessions/terminate'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT),
|
||||||
headers=headers, params=params)
|
headers=headers, params=params)
|
||||||
|
|
||||||
response = fetch('status/sessions')
|
response = fetch('status/sessions')
|
||||||
@ -83,11 +83,11 @@ response = fetch('status/sessions')
|
|||||||
sessions = []
|
sessions = []
|
||||||
for s in response['MediaContainer']['Video']:
|
for s in response['MediaContainer']['Video']:
|
||||||
if s['User']['title'] == USER:
|
if s['User']['title'] == USER:
|
||||||
id = s['Session']['id']
|
sess_id = s['Session']['id']
|
||||||
user = s['User']['title']
|
user = s['User']['title']
|
||||||
title = (s['grandparentTitle'] + ' - ' if s['type'] == 'episode' else '') + s['title']
|
title = (s['grandparentTitle'] + ' - ' if s['type'] == 'episode' else '') + s['title']
|
||||||
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore')
|
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore')
|
||||||
sessions.append((id, user, title))
|
sessions.append((sess_id, user, title))
|
||||||
|
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
print(u"Killing {}'s second stream of {} for {}".format(session[1], session[2], REASON))
|
print(u"Killing {}'s second stream of {} for {}".format(session[1], session[2], REASON))
|
||||||
|
@ -32,7 +32,7 @@ ADMIN_USER = ('Admin') # additional usernames can be added ('Admin', 'user2')
|
|||||||
##
|
##
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
def fetch(path, t='GET'):
|
||||||
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
url = 'http{}://{}:{}/'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
||||||
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN,
|
headers = {'X-Plex-Token': PLEX_TOKEN,
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -67,7 +67,7 @@ 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_HOST, PLEX_PORT),
|
requests.get('http{}://{}:{}/status/sessions/terminate'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT),
|
||||||
headers=headers, params=params)
|
headers=headers, params=params)
|
||||||
|
|
||||||
def add_to_dictlist(d, key, val):
|
def add_to_dictlist(d, key, val):
|
||||||
@ -87,13 +87,13 @@ if __name__ == '__main__':
|
|||||||
for s in response['MediaContainer']['Video']:
|
for s in response['MediaContainer']['Video']:
|
||||||
try:
|
try:
|
||||||
if s['TranscodeSession']['videoDecision'] == 'transcode' and s['User']['title'] not in ADMIN_USER:
|
if s['TranscodeSession']['videoDecision'] == 'transcode' and s['User']['title'] not in ADMIN_USER:
|
||||||
id = s['Session']['id']
|
sess_id = s['Session']['id']
|
||||||
user = s['User']['title']
|
user = s['User']['title']
|
||||||
percent_comp = int((float(s['viewOffset']) / float(s['duration'])) * 100)
|
percent_comp = int((float(s['viewOffset']) / float(s['duration'])) * 100)
|
||||||
time_to_comp = int(int(s['duration']) - int(s['viewOffset'])) / 1000 / 60
|
time_to_comp = int(int(s['duration']) - int(s['viewOffset'])) / 1000 / 60
|
||||||
title = s['title']
|
title = s['title']
|
||||||
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore')
|
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore')
|
||||||
add_to_dictlist(user_dict, user, [id, percent_comp, title, user, time_to_comp])
|
add_to_dictlist(user_dict, user, [sess_id, percent_comp, title, user, time_to_comp])
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print('{} has a direct stream to ignore.'.format(s['User']['title']))
|
print('{} has a direct stream to ignore.'.format(s['User']['title']))
|
||||||
|
@ -13,7 +13,7 @@ PlexPy > Settings > Notification Agents > Scripts > Gear icon:
|
|||||||
Playback User Concurrent Streams: kill_more_than.py
|
Playback User Concurrent Streams: kill_more_than.py
|
||||||
|
|
||||||
PlexPy > Settings > Notifications > Script > Script Arguments
|
PlexPy > Settings > Notifications > Script > Script Arguments
|
||||||
{user} {ip_address}
|
{username} {ip_address}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ if USER in ignore_lst:
|
|||||||
|
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
def fetch(path, t='GET'):
|
||||||
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
url = 'http{}://{}:{}/'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
||||||
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN,
|
headers = {'X-Plex-Token': PLEX_TOKEN,
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -77,19 +77,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_HOST, PLEX_PORT),
|
requests.get('http{}://{}:{}/status/sessions/terminate'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT),
|
||||||
headers=headers, params=params)
|
headers=headers, params=params)
|
||||||
|
|
||||||
response = fetch('status/sessions')
|
response = fetch('status/sessions')
|
||||||
|
|
||||||
sessions = []
|
sessions = []
|
||||||
for s in response['MediaContainer']['Video']:
|
for s in response['MediaContainer']['Video']:
|
||||||
if s['User']['title'] == USER and s['Player']['address'] == ADDRESS:
|
if s['User']['title'] == USER and s['Player']['address'].lstrip("::ffff:") == ADDRESS::
|
||||||
id = s['Session']['id']
|
sess_id = s['Session']['id']
|
||||||
user = s['User']['title']
|
user = s['User']['title']
|
||||||
title = (s['grandparentTitle'] + ' - ' if s['type'] == 'episode' else '') + s['title']
|
title = (s['grandparentTitle'] + ' - ' if s['type'] == 'episode' else '') + s['title']
|
||||||
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore')
|
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore')
|
||||||
sessions.append((id, user, title))
|
sessions.append((sess_id, user, title))
|
||||||
|
|
||||||
if len(sessions) == 1:
|
if len(sessions) == 1:
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
|
@ -8,7 +8,7 @@ PlexPy > Settings > Notification Agents > Scripts > Gear icon:
|
|||||||
Playback Start: kill_outsider_stream.py
|
Playback Start: kill_outsider_stream.py
|
||||||
|
|
||||||
PlexPy > Settings > Notifications > Script > Script Arguments
|
PlexPy > Settings > Notifications > Script > Script Arguments
|
||||||
{user}
|
{username}
|
||||||
"""
|
"""
|
||||||
import requests
|
import requests
|
||||||
import platform
|
import platform
|
||||||
@ -24,10 +24,10 @@ PLEX_TOKEN = 'xxxxxx'
|
|||||||
REASON = 'Accessing Plex from outside network'
|
REASON = 'Accessing Plex from outside network'
|
||||||
##
|
##
|
||||||
|
|
||||||
USER = sys.argv[1]
|
USERNAME = sys.argv[1]
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
def fetch(path, t='GET'):
|
||||||
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
url = 'http{}://{}:{}/'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
||||||
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN,
|
headers = {'X-Plex-Token': PLEX_TOKEN,
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -61,11 +61,11 @@ 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_HOST, PLEX_PORT),
|
requests.get('http{}://{}:{}/status/sessions/terminate'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT),
|
||||||
headers=headers, params=params)
|
headers=headers, params=params)
|
||||||
|
|
||||||
response = fetch('status/sessions')
|
response = fetch('status/sessions')
|
||||||
for s in response['MediaContainer']['Video']:
|
for s in response['MediaContainer']['Video']:
|
||||||
if s['User']['title'] == USER and s['Session']['location'] == 'wan':
|
if s['User']['title'] == USERNAME and s['Session']['location'] == 'wan':
|
||||||
print("Killing {}'s stream for {}".format(USER, REASON))
|
print("Killing {}'s stream for {}".format(USERNAME, REASON))
|
||||||
kill_stream(s['Session']['id'], REASON)
|
kill_stream(s['Session']['id'], REASON)
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Kill streams
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import platform
|
import platform
|
||||||
from uuid import getnode
|
from uuid import getnode
|
||||||
@ -14,7 +20,7 @@ ignore_lst = ('')
|
|||||||
|
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
def fetch(path, t='GET'):
|
||||||
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
url = 'http{}://{}:{}/'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
||||||
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN,
|
headers = {'X-Plex-Token': PLEX_TOKEN,
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -47,18 +53,18 @@ 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_HOST, PLEX_PORT),
|
requests.get('http{}://{}:{}/status/sessions/terminate'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT),
|
||||||
headers=headers, params=params)
|
headers=headers, params=params)
|
||||||
|
|
||||||
response = fetch('status/sessions')
|
response = fetch('status/sessions')
|
||||||
|
|
||||||
sessions = []
|
sessions = []
|
||||||
for s in response['MediaContainer']['Video']:
|
for s in response['MediaContainer']['Video']:
|
||||||
id = s['Session']['id']
|
sess_id = s['Session']['id']
|
||||||
user = s['User']['title']
|
user = s['User']['title']
|
||||||
title = (s['grandparentTitle'] + ' - ' if s['type'] == 'episode' else '') + s['title']
|
title = (s['grandparentTitle'] + ' - ' if s['type'] == 'episode' else '') + s['title']
|
||||||
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore')
|
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore')
|
||||||
sessions.append((id, user, title))
|
sessions.append((sess_id, user, title))
|
||||||
|
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
if session[1] not in ignore_lst:
|
if session[1] not in ignore_lst:
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
"""
|
"""
|
||||||
PlexPy Playback Start
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
Kill stream if bitrate is > BITRATE_LIMIT
|
||||||
|
|
||||||
|
PlexPy > Settings > Notification Agents > Scripts > Bell icon:
|
||||||
|
[X] Notify on playback start
|
||||||
|
|
||||||
|
PlexPy > Settings > Notification Agents > Scripts > Gear icon:
|
||||||
|
Playback Start: kill_session_bitrate.py
|
||||||
|
|
||||||
|
"""
|
||||||
import requests
|
import requests
|
||||||
import platform
|
import platform
|
||||||
from uuid import getnode
|
from uuid import getnode
|
||||||
@ -13,11 +20,13 @@ PLEX_PORT = 32400
|
|||||||
PLEX_SSL = '' # s or ''
|
PLEX_SSL = '' # s or ''
|
||||||
PLEX_TOKEN = 'xxxxxx'
|
PLEX_TOKEN = 'xxxxxx'
|
||||||
|
|
||||||
|
BITRATE_LIMIT = 4000
|
||||||
|
|
||||||
ignore_lst = ('')
|
ignore_lst = ('')
|
||||||
|
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
def fetch(path, t='GET'):
|
||||||
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
url = 'http{}://{}:{}/'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
||||||
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN,
|
headers = {'X-Plex-Token': PLEX_TOKEN,
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -51,23 +60,22 @@ 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_HOST, PLEX_PORT),
|
requests.get('http{}://{}:{}/status/sessions/terminate'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT),
|
||||||
headers=headers, params=params)
|
headers=headers, params=params)
|
||||||
|
|
||||||
response = fetch('status/sessions')
|
response = fetch('status/sessions')
|
||||||
|
|
||||||
sessions = []
|
sessions = []
|
||||||
for video in response['MediaContainer']['Video']:
|
for s in response['MediaContainer']['Video']:
|
||||||
media = video['Media'][0]
|
sess_id = s['Session']['id']
|
||||||
id = video['Session']['id']
|
user = s['User']['title']
|
||||||
user = video['User']['title']
|
title = (s['grandparentTitle'] + ' - ' if s['type'] == 'episode' else '') + s['title']
|
||||||
title = (video['grandparentTitle'] + ' - ' if video['type'] == 'episode' else '') + video['title']
|
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore')
|
||||||
title = unicodedata.normalize('NFKD', title).encode('ascii','ignore').translate(None,"'")
|
bitrate = s['Media']['bitrate']
|
||||||
bitrate = media['bitrate']
|
sessions.append((sess_id, user, title, bitrate))
|
||||||
sessions.append((id, user, title, bitrate))
|
|
||||||
|
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
if session[1] not in ignore_lst and int(session[3]) > 4000:
|
if session[1] not in ignore_lst and int(session[3]) > BITRATE_LIMIT:
|
||||||
message = "You are not allowed to stream above 4 Mbps."
|
message = "You are not allowed to stream above 4 Mbps."
|
||||||
print("Killing {}'s stream of {} for {}".format(session[1], session[2], message))
|
print("Killing {}'s stream of {} for {}".format(session[1], session[2], message))
|
||||||
kill_stream(session[0], message)
|
kill_stream(session[0], message)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
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:
|
||||||
@ -7,6 +8,8 @@ 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
|
import platform
|
||||||
@ -31,7 +34,7 @@ USER_IGNORE = ('') # ('Username','User2')
|
|||||||
##
|
##
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
def fetch(path, t='GET'):
|
||||||
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
url = 'http{}://{}:{}/'.format(PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
||||||
|
|
||||||
headers = {'X-Plex-Token': PLEX_TOKEN,
|
headers = {'X-Plex-Token': PLEX_TOKEN,
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -65,8 +68,8 @@ 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_HOST, PLEX_PORT),
|
requests.get('http{}://{}:{}/status/sessions/terminate'.format(PLEX_SSL, 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')
|
||||||
|
@ -24,7 +24,7 @@ USER_IGNORE = ('') # ('Username','User2')
|
|||||||
##
|
##
|
||||||
|
|
||||||
def fetch(path, t='GET'):
|
def fetch(path, t='GET'):
|
||||||
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
|
url = 'http{}://{}:{}/'.format(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,8 +58,8 @@ 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_HOST, PLEX_PORT),
|
requests.get('http{}://{}:{}/status/sessions/terminate'.format(PLEX_SSL, 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')
|
||||||
|
Loading…
Reference in New Issue
Block a user