From 8d802cf898f2e48d605c45568e9b58cdb15e351a Mon Sep 17 00:00:00 2001 From: Michael Higgins Date: Thu, 5 Mar 2015 09:34:26 -0500 Subject: [PATCH] plex refresh --- autoProcess.ini.sample | 5 +++++ autoprocess/plex.py | 22 ++++++++++++++++++++++ postConversion.py | 3 +++ readSettings.py | 16 +++++++++++++++- setup/PostProcess/main.py | 4 +++- 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 autoprocess/plex.py diff --git a/autoProcess.ini.sample b/autoProcess.ini.sample index cb011e2b..d326a810 100644 --- a/autoProcess.ini.sample +++ b/autoProcess.ini.sample @@ -82,3 +82,8 @@ password= web_root= ssl=0 api_key= + +[Plex] +host=localhost +port=32400 +refresh=True \ No newline at end of file diff --git a/autoprocess/plex.py b/autoprocess/plex.py new file mode 100644 index 00000000..7c5e29bc --- /dev/null +++ b/autoprocess/plex.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import urllib +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 + refresh_url = '%s/%%s/refresh' % 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) + print x + except: + print "Unable to refresh plex, check your settings" \ No newline at end of file diff --git a/postConversion.py b/postConversion.py index ec555fd0..b41698f3 100755 --- a/postConversion.py +++ b/postConversion.py @@ -5,6 +5,7 @@ import urllib import struct from readSettings import ReadSettings +from autoProcess import plex from tvdb_mp4 import Tvdb_mp4 from mkvtomp4 import MkvtoMp4 settings = ReadSettings(os.path.dirname(sys.argv[0]), "autoProcess.ini") @@ -42,6 +43,8 @@ except IOError: print "Couldn't refresh Sickbeard, check your settings" + plex.refreshPlex(settings, 'show') + else: print "Not enough command line arguments present " + str(len(sys.argv)) sys.exit() diff --git a/readSettings.py b/readSettings.py index bc528d26..2e13d7a0 100644 --- a/readSettings.py +++ b/readSettings.py @@ -101,8 +101,12 @@ def __init__(self, directory, filename): 'web_root': '', 'username': '', 'password': '' } + # Default Plex Settings + plex_defaults = {'host': 'localhost', + 'port': '32400', + 'refresh': 'true'} - defaults = {'SickBeard': sb_defaults, 'CouchPotato': cp_defaults, 'Sonarr': sonarr_defaults, 'MP4': mp4_defaults, 'uTorrent': utorrent_defaults, 'SABNZBD': sab_defaults, 'Sickrage': sr_defaults} + defaults = {'SickBeard': sb_defaults, 'CouchPotato': cp_defaults, 'Sonarr': sonarr_defaults, 'MP4': mp4_defaults, 'uTorrent': utorrent_defaults, 'SABNZBD': sab_defaults, 'Sickrage': sr_defaults, 'Plex': plex_defaults} write = False # Will be changed to true if a value is missing from the config file and needs to be written config = ConfigParser.SafeConfigParser() @@ -385,6 +389,16 @@ def __init__(self, directory, filename): self.SAB['sonarr'] = config.get(section, "Sonarr-category").lower() self.SAB['bypass'] = config.get(section, "Bypass-category").lower() + #Read Plex section information + section = "Plex" + self.Plex = {} + self.Plex['host'] = config.get(section, "host") + self.Plex['port'] = config.get(section, "port") + try: + self.Plex['refresh'] = config.getboolean(section, "refresh") + except: + self.Plex['refresh'] = False + #Pass the values on self.config = config self.configFile = configFile diff --git a/setup/PostProcess/main.py b/setup/PostProcess/main.py index 6c6715a9..95e7e1d6 100644 --- a/setup/PostProcess/main.py +++ b/setup/PostProcess/main.py @@ -26,6 +26,7 @@ def callscript(self, message = None, group = None): from readSettings import ReadSettings from mkvtomp4 import MkvtoMp4 from tmdb_mp4 import tmdb_mp4 + from autoprocess import plex except ImportError: log.error('Path to script folder appears to be invalid.') return False @@ -70,5 +71,6 @@ def callscript(self, message = None, group = None): except: log.error('File processing failed: %s', (traceback.format_exc())) + plex.refreshPlex(settings, 'movie') + return success -