Skip to content

Commit

Permalink
Merge pull request #20 from l3uddz/develop
Browse files Browse the repository at this point in the history
Added Kick 4K Transcodes logic  (#19)
  • Loading branch information
desimaniac authored Jan 23, 2019
2 parents 73a69e4 + 649cc01 commit 29bfa83
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion patrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def should_kick_stream(stream):
return True, 0, config.KICK_TRANSCODE_MESSAGE
if stream.state == 'paused' and config.KICK_PAUSED_TRANSCODES:
return True, config.KICK_PAUSED_GRACE_MINS, config.KICK_PAUSED_MESSAGE
if stream.quality == '4K' and config.KICK_4K_TRANSCODE:
return True, 0, config.KICK_4K_TRANSCODE_MESSAGE

else:
# stream is directplay - check specifics
Expand Down Expand Up @@ -176,4 +178,4 @@ def check_streams():
while True:
log.debug("Checking streams in %d seconds", config.CHECK_INTERVAL)
time.sleep(config.CHECK_INTERVAL)
check_streams()
check_streams()
5 changes: 4 additions & 1 deletion settings.ini.default
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ SERVER_TOKEN = your_server_token
SERVER_NAME = Your_Server_Name
# how often to check the active streams in seconds
CHECK_INTERVAL = 90
# instantly kick 4K transcodes?
KICK_4K_TRANSCODE = true
# instantly kick video transcodes?
KICK_VIDEO_TRANSCODES = false
# instantly kick audio transcodes
Expand All @@ -26,9 +28,10 @@ KICK_PAUSED_DIRECTPLAY = false
# when the KICK_PAUSED* options above are true, the user has this many minutes to resume, otherwise kick
KICK_PAUSED_GRACE_MINS = 5
# messages to be displayed for different kick types
KICK_4K_TRANSCODE_MESSAGE = You are not allowed to transcode 4K content, use a better client!
KICK_PAUSED_MESSAGE = You are not allowed to pause a stream for that long... cya!
KICK_TRANSCODE_MESSAGE = You are not allowed to transcode streams, use a better client!
KICK_PLAYER_MESSAGE = You are not allowed to use this trash player. Use the official software from www.plex.tv/downloads -> Get An App!!!
KICK_MULTI_IP_MESSAGE = You are not allowed to stream from more than 1 IP address!
# user list seperated by a , who are immune from all kicks
WHITELISTED_USERS = User1, User2, User3
WHITELISTED_USERS = User1, User2, User3
4 changes: 3 additions & 1 deletion utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
SERVER_NAME = config('SERVER_NAME')
CHECK_INTERVAL = config('CHECK_INTERVAL', 60, cast=int)

KICK_4K_TRANSCODE = config('KICK_4K_TRANSCODE',False,cast=bool)
KICK_4K_TRANSCODE_MESSAGE = config('KICK_4K_TRANSCODE_MESSAGE','You are not allowed to transcode 4K content, use a better client!')
KICK_VIDEO_TRANSCODES = config('KICK_VIDEO_TRANSCODES', False, cast=bool)
KICK_AUDIO_TRANSCODES = config('KICK_AUDIO_TRANSCODES', False, cast=bool)
KICK_CLIENT_PLAYERS = config('KICK_CLIENT_PLAYERS', [], cast=Csv())
Expand All @@ -31,4 +33,4 @@
'Use the official software from www.plex.tv/downloads -> Get An App!!!')
KICK_MULTI_IP_MESSAGE = config('KICK_MULTI_IP_MESSAGE', 'You are not allowed to stream from more than 1 IP address!')

WHITELISTED_USERS = config('WHITELISTED_USERS', [], cast=Csv())
WHITELISTED_USERS = config('WHITELISTED_USERS', [], cast=Csv())
10 changes: 9 additions & 1 deletion utils/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ def __init__(self, stream):
self.player = 'Unknown'
self.ip = 'Unknown'

self.quality = "Unknown"
if 'Media' in stream:
for media in stream['Media']:
if 'Part' in media:
for part in media['Part']:
if 'Stream' in part and 'displayTitle' in part['Stream'][0]:
self.quality = part['Stream'][0]['displayTitle'].split(' ')[0].upper()

if 'Session' in stream:
self.session_id = stream['Session']['id']
else:
Expand Down Expand Up @@ -202,4 +210,4 @@ def __getattr__(self, item):
pass

# Default behaviour
return 'Unknown'
return 'Unknown'

0 comments on commit 29bfa83

Please sign in to comment.