All checks were successful
Validate and publish Kaleido / android (push) Successful in 2m27s
23 lines
1.6 KiB
Python
23 lines
1.6 KiB
Python
"""Read-only Plex connectivity inventory; never prints credentials."""
|
|
import json, pathlib, urllib.request, urllib.parse
|
|
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|
env = dict(line.strip().split('=',1) for line in (ROOT/'.env').read_text().splitlines() if '=' in line and not line.startswith('#'))
|
|
base = env['PLEX_SERVER_URL'].strip('\"\'').rstrip('/')
|
|
token = env['PLEX_TOKEN'].strip('\"\'')
|
|
def get(path):
|
|
req = urllib.request.Request(base+path,headers={'X-Plex-Token':token,'Accept':'application/json','X-Plex-Product':'Kaleido','X-Plex-Client-Identifier':'kaleido-development'})
|
|
with urllib.request.urlopen(req,timeout=20) as r: return json.load(r)['MediaContainer']
|
|
if __name__ == '__main__':
|
|
print('Server:', get('/').get('friendlyName'), 'version:', get('/').get('version'))
|
|
sections = get('/library/sections').get('Directory',[])
|
|
for s in sections:
|
|
print('Section', s['key'],s['title'],s['type'])
|
|
d=get('/library/sections/'+s['key']+'/all?X-Plex-Container-Start=0&X-Plex-Container-Size=2&sort=titleSort')
|
|
print('Total:', d.get('totalSize',d.get('size')))
|
|
for m in d.get('Metadata',[]):
|
|
print('Sample:', {k:m.get(k) for k in ['ratingKey','title','type','duration','viewOffset']})
|
|
for media in m.get('Media',[]): print('Media:', {k:media.get(k) for k in ['container','videoCodec','audioCodec','videoResolution']})
|
|
for path in ['/hubs/home','/hubs','/library/onDeck']:
|
|
try:
|
|
d=get(path); print(path,[(h.get('title'),len(h.get('Metadata',[]))) for h in d.get('Hub',[])], 'items:',d.get('size'))
|
|
except Exception as e: print(path,type(e).__name__)
|