-
Notifications
You must be signed in to change notification settings - Fork 3
/
magicbullet.py
executable file
·66 lines (51 loc) · 2.8 KB
/
magicbullet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
# WARNING: this is a script I threw together and wasn't planning to share with people; so the code quality / documentation is pretty shit.
# forceAutoAdjustQuality - some super secret hidden plex server API setting which will force clients to use auto quality for everything
# unless they have a quality set higher than the quality of the video in question
# (ex: quality set to 4mbps; watching >4mbps will trigger auto quality mode)
# ex2: quality set to original/max; auto quality will never be used & you will always be streaming at the video's original bitrate
# TL;DR: clients won't default to transcoding at 2mbps anymore (srsly plex why would that be the default in the first place?)
# REQUIRES PLEXAPI: pip install plexapi (http://python-plexapi.readthedocs.io/en/latest/introduction.html)
from plexapi.myplex import MyPlexAccount, PlexServer
# Maybe one of these days I'll switch to YAML file for credentials like a good coder ;)
username = 'SERVER_OWNER_USERNAME_HERE'
password = 'REPLACE_ME'
# Friendly name (the name you set in general settings for your server)
servername = 'Friendly_name'
# set to directly connect to plex server without going through plex account auth
baseurl = 'http://plexserver:32400' # use if you have a custom plex URL defined
token = 'PLEX_SERVER_TOKEN'
# server settings to change
# you can probably just manually add these into Preferences.xml instead of using this script but oh well?
settings_dict = {
'forceAutoAdjustQuality': True,
# allowHighOutputBitrates - causes transcode quality to upscale (ex: 8k origianl to 18k kbps...); which is dope but if clients have low bandwidth...not so dope ;=(
'allowHighOutputBitrates': False,
} # Some srsly undocumented blackmagic.
def get_plex_server():
# don't try this at home kids. this is how you become a bad coder.
try:
# try using user/pass/server name first
return MyPlexAccount(username, password).resource(servername).connect()
except:
# fall back to using url/token to connect to server
return PlexServer(baseurl, token)
# Should never get here because that would mean you never changed any of the default credentials...
# And who would be that silly? :)
raise Exception("You had one job. One. Job.")
def main():
plex = get_plex_server()
pset = plex.settings
for x, y in settings_dict.items():
s = plex.settings.get(x)
print(s)
print('current value for {0}: {1}'.format(x, s.value))
s.set(y)
plex.settings.save()
# get fresh server instance because reasons
confirm = get_plex_server() # returns a PlexServer instance
for x, y in settings_dict.items():
s = confirm.settings.get(x)
print('{} -- expected: {} -- actual: {}'.format(x, y, s.value))
if __name__ == "__main__":
main()