Plex notification
This commit is contained in:
@@ -17,11 +17,8 @@ config = [{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'host',
|
'name': 'host',
|
||||||
'default': 'localhost',
|
'default': 'localhost:32400',
|
||||||
},
|
'description': 'Default should be on localhost:32400',
|
||||||
{
|
|
||||||
'name': 'password',
|
|
||||||
'type': 'password',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
from couchpotato.core.helpers.variable import cleanHost
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.notifications.base import Notification
|
from couchpotato.core.notifications.base import Notification
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
|
import traceback
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
@@ -11,22 +13,26 @@ class Plex(Notification):
|
|||||||
if self.isDisabled(): return
|
if self.isDisabled(): return
|
||||||
|
|
||||||
log.info('Sending notification to Plex')
|
log.info('Sending notification to Plex')
|
||||||
hosts = [x.strip() for x in self.conf('host').split(",")]
|
hosts = [cleanHost(x.strip()) for x in self.conf('host').split(",")]
|
||||||
|
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
|
|
||||||
source_type = ['movie']
|
source_type = ['movie']
|
||||||
base_url = 'http://%s/library/sections' % host
|
base_url = '%slibrary/sections' % host
|
||||||
refresh_url = '%s/%%s/refresh' % base_url
|
refresh_url = '%s/%%s/refresh' % base_url
|
||||||
|
|
||||||
try:
|
try:
|
||||||
xml_sections = minidom.parse(self.urlopen(base_url))
|
sections_xml = self.urlopen(base_url)
|
||||||
|
xml_sections = minidom.parseString(sections_xml)
|
||||||
sections = xml_sections.getElementsByTagName('Directory')
|
sections = xml_sections.getElementsByTagName('Directory')
|
||||||
|
|
||||||
for s in sections:
|
for s in sections:
|
||||||
if s.getAttribute('type') in source_type:
|
if s.getAttribute('type') in source_type:
|
||||||
url = refresh_url % s.getAttribute('key')
|
url = refresh_url % s.getAttribute('key')
|
||||||
x = self.urlopen(url)
|
x = self.urlopen(url)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
log.error('Plex library update failed for %s.' % host)
|
log.error('Plex library update failed for %s: %s' % (host, traceback.format_exc()))
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user