Created
July 18, 2017 13:32
-
-
Save blacktwin/1cd5e03082a9570c879cee5902d1f75c to your computer and use it in GitHub Desktop.
Collect Plex sessions and metadata xmls.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@elit3ge Did you set the PlexPy argument {rating_key}?