Skip to content

Instantly share code, notes, and snippets.

@blacktwin
Created July 18, 2017 13:32
Show Gist options
  • Save blacktwin/1cd5e03082a9570c879cee5902d1f75c to your computer and use it in GitHub Desktop.
Save blacktwin/1cd5e03082a9570c879cee5902d1f75c to your computer and use it in GitHub Desktop.
Collect Plex sessions and metadata xmls.
import requests
import platform
from uuid import getnode
import sys
# PlexPy argument {rating_key}
## EDIT THESE SETTINGS ##
PLEX_HOST = '127.0.0.1'
PLEX_PORT = 32400
PLEX_SSL = '' # s or ''
PLEX_TOKEN = ''
rating_key = sys.argv[1]
def fetch(path):
url = 'http%s://%s:%s/' % (PLEX_SSL, PLEX_HOST, PLEX_PORT)
headers = {'X-Plex-Token': PLEX_TOKEN,
'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()))
}
r = requests.get(url + path, headers=headers, verify=False)
return r.content
session = fetch('status/sessions')
meta = fetch('library/metadata/{}'.format(rating_key))
with open('sessions.xml', 'w') as f:
f.write(session)
with open('{}.xml'.format(rating_key), 'w') as f:
f.write(meta)
@elit3ge
Copy link

elit3ge commented Jul 26, 2017

Traceback (most recent call last):
  File "xml_collect.py", line 16, in <module>
    rating_key = sys.argv[1]
IndexError: list index out of range

@blacktwin
Copy link
Author

@elit3ge how did you run it?

@elit3ge
Copy link

elit3ge commented Aug 8, 2017

@blacktwin in PlexPy

@blacktwin
Copy link
Author

@elit3ge Did you set the PlexPy argument {rating_key}?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment