Skip to content

Commit

Permalink
plex refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Higgins committed Mar 5, 2015
1 parent 259792d commit 8d802cf
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
5 changes: 5 additions & 0 deletions autoProcess.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ password=
web_root=
ssl=0
api_key=

[Plex]
host=localhost
port=32400
refresh=True
22 changes: 22 additions & 0 deletions autoprocess/plex.py
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions postConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
16 changes: 15 additions & 1 deletion readSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion setup/PostProcess/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 8d802cf

Please sign in to comment.