forked from mdhiggins/sickbeard_mp4_automator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the `token` option for plex home token refreshing
- Loading branch information
michael
committed
Jul 1, 2015
1 parent
1bc7148
commit 85e2a18
Showing
6 changed files
with
45 additions
and
20 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,3 +99,4 @@ api_key= | |
host=localhost | ||
port=32400 | ||
refresh=True | ||
token= |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,41 @@ | ||
#!/usr/bin/env python | ||
import urllib | ||
import logging | ||
from xml.dom import minidom | ||
|
||
def refreshPlex(settings, source_type): | ||
host = settings.Plex['host'] | ||
port = settings.Plex['port'] | ||
approved_sources = ['movie', 'show'] | ||
if settings.Plex['refresh'] and source_type in approved_sources: | ||
base_url = 'http://%s:%s/library/sections' % (host, port) | ||
refresh_url = '%s/%%s/refresh' % base_url | ||
def refreshPlex(settings, source_type, logger=None): | ||
if logger: | ||
log = logger | ||
else: | ||
log = logging.getLogger(__name__) | ||
|
||
try: | ||
xml_sections = minidom.parse(urllib.urlopen(base_url)) | ||
sections = xml_sections.getElementsByTagName('Directory') | ||
for s in sections: | ||
if s.getAttribute('type') == source_type: | ||
url = refresh_url % s.getAttribute('key') | ||
x = urllib.urlopen(url) | ||
except Exception as e: | ||
print "Unable to refresh plex, check your settings" | ||
print e | ||
host = settings.Plex['host'] | ||
port = settings.Plex['port'] | ||
token = settings.Plex['token'] | ||
|
||
log.debug("Host: %s." % host) | ||
log.debug("Port: %s." % port) | ||
log.debug("Token: %s." % token) | ||
|
||
approved_sources = ['movie', 'show'] | ||
if settings.Plex['refresh'] and source_type in approved_sources: | ||
base_url = 'http://%s:%s/library/sections' % (host, port) | ||
refresh_url = '%s/%%s/refresh' % base_url | ||
|
||
if token: | ||
refresh_url = refresh_url + "?X-Plex-Token=" + token | ||
base_url = base_url + "?X-Plex-Token=" + token | ||
log.debug("Plex home token detected.") | ||
|
||
log.debug("Refresh URL: %s." % refresh_url) | ||
log.debug("Base URL: %s." % base_url) | ||
|
||
try: | ||
xml_sections = minidom.parse(urllib.urlopen(base_url)) | ||
sections = xml_sections.getElementsByTagName('Directory') | ||
for s in sections: | ||
if s.getAttribute('type') == source_type: | ||
url = refresh_url % s.getAttribute('key') | ||
x = urllib.urlopen(url) | ||
except Exception: | ||
log.exception("Unable to refresh plex, check your settings.") |
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
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
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