From 2d19accdd1c147bddcfa35b1ffdbde8bc8b75a0f Mon Sep 17 00:00:00 2001 From: drzoidberg33 Date: Sun, 23 Aug 2015 00:08:55 +0200 Subject: [PATCH 1/5] Revert "Info pages" --- data/interfaces/default/css/plexpy.css | 20 ++------- data/interfaces/default/info.html | 56 +++++++++++--------------- plexpy/pmsconnect.py | 5 +-- 3 files changed, 27 insertions(+), 54 deletions(-) diff --git a/data/interfaces/default/css/plexpy.css b/data/interfaces/default/css/plexpy.css index 7bbf8d46..7d715a3c 100644 --- a/data/interfaces/default/css/plexpy.css +++ b/data/interfaces/default/css/plexpy.css @@ -23,7 +23,7 @@ select { outline: none; } select.input-sm { - margin: 5px 0 5px 0; + margin: 5px 0 5px 0; border: 2px solid #444; background: #333; -webkit-border-radius: 2px; @@ -34,8 +34,8 @@ select.input-sm { } img { -webkit-box-sizing: content-box; - -moz-box-sizing: content-box; - box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; } .navbar { background: #000; @@ -792,11 +792,6 @@ input[type="color"], width: 174px; height: 260px; } -.summary-content-poster a:hover .poster-face { - webkit-box-shadow: inset 0 0 0 2px #e9a049; - -moz-box-shadow: inset 0 0 0 2px #e9a049; - box-shadow: inset 0 0 0 2px #e9a049; -} .summary-content-poster img { bottom: 0; overflow: hidden; @@ -848,13 +843,6 @@ input[type="color"], line-height: 32px; float: left; } -.summary-content-title h1 a{ - color: #F9AA03; -} -.summary-content-title h1 a:hover{ - color: #F9AA03; - text-decoration: underline; -} .summary-content-details-wrapper { width: 100%; padding-bottom: 15px; @@ -921,8 +909,6 @@ input[type="color"], } .summary-content-people-wrapper { margin-top: 25px; - margin-right: 25px; - float: left; } .summary-content-people-wrapper hidden-phone hidden-tablet { overflow: hidden; diff --git a/data/interfaces/default/info.html b/data/interfaces/default/info.html index 8eba3f9b..b2ba2b98 100644 --- a/data/interfaces/default/info.html +++ b/data/interfaces/default/info.html @@ -54,18 +54,10 @@ DOCUMENTATION :: END
-
@@ -342,8 +332,8 @@ DOCUMENTATION :: END % endif % endif diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 7fb15618..54d2093f 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -1,4 +1,4 @@ -# This file is part of PlexPy. +# This file is part of PlexPy. # # PlexPy is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -334,8 +334,6 @@ class PmsConnect(object): elif metadata_type == 'episode': metadata = {'type': metadata_type, 'rating_key': helpers.get_xml_attr(metadata_main, 'ratingKey'), - 'parent_rating_key': helpers.get_xml_attr(metadata_main, 'parentRatingKey'), - 'grandparent_rating_key': helpers.get_xml_attr(metadata_main, 'grandparentRatingKey'), 'grandparent_title': helpers.get_xml_attr(metadata_main, 'grandparentTitle'), 'parent_index': helpers.get_xml_attr(metadata_main, 'parentIndex'), 'parent_title': helpers.get_xml_attr(metadata_main, 'parentTitle'), @@ -396,7 +394,6 @@ class PmsConnect(object): show_details = self.get_metadata_details(parent_rating_key) metadata = {'type': metadata_type, 'rating_key': helpers.get_xml_attr(metadata_main, 'ratingKey'), - 'parent_rating_key': helpers.get_xml_attr(metadata_main, 'parentRatingKey'), 'grandparent_title': helpers.get_xml_attr(metadata_main, 'grandparentTitle'), 'parent_index': helpers.get_xml_attr(metadata_main, 'parentIndex'), 'parent_title': helpers.get_xml_attr(metadata_main, 'parentTitle'), From 29204cb6ba5bc6cf89ab41a09b90e373f4e1988a Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 6 Sep 2015 15:33:17 +0200 Subject: [PATCH 2/5] Fix weird issue with bad merge. --- plexpy/pmsconnect.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 8bb317b0..d25e783e 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -1,4 +1,4 @@ -# This file is part of PlexPy. +# This file is part of PlexPy. # # PlexPy is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -383,6 +383,8 @@ class PmsConnect(object): elif metadata_type == 'episode': metadata = {'type': metadata_type, 'rating_key': helpers.get_xml_attr(metadata_main, 'ratingKey'), + 'parent_rating_key': helpers.get_xml_attr(metadata_main, 'parentRatingKey'), + 'grandparent_rating_key': helpers.get_xml_attr(metadata_main, 'grandparentRatingKey'), 'grandparent_title': helpers.get_xml_attr(metadata_main, 'grandparentTitle'), 'parent_index': helpers.get_xml_attr(metadata_main, 'parentIndex'), 'parent_title': helpers.get_xml_attr(metadata_main, 'parentTitle'), @@ -443,6 +445,7 @@ class PmsConnect(object): show_details = self.get_metadata_details(parent_rating_key) metadata = {'type': metadata_type, 'rating_key': helpers.get_xml_attr(metadata_main, 'ratingKey'), + 'parent_rating_key': helpers.get_xml_attr(metadata_main, 'parentRatingKey'), 'grandparent_title': helpers.get_xml_attr(metadata_main, 'grandparentTitle'), 'parent_index': helpers.get_xml_attr(metadata_main, 'parentIndex'), 'parent_title': helpers.get_xml_attr(metadata_main, 'parentTitle'), From fad0fdb4b8bfbb68161c9a38cd63889b924802ff Mon Sep 17 00:00:00 2001 From: rossdargan Date: Sun, 11 Oct 2015 21:50:58 +0100 Subject: [PATCH 3/5] Add in IFTTT notifier --- plexpy/config.py | 12 +++++-- plexpy/notifiers.py | 86 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/plexpy/config.py b/plexpy/config.py index 6810a693..29ba205d 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -1,4 +1,4 @@ -import plexpy.logger +import plexpy.logger import itertools import os import re @@ -181,6 +181,14 @@ _CONFIG_DEFINITIONS = { 'PUSHBULLET_ON_RESUME': (int, 'PushBullet', 0), 'PUSHBULLET_ON_BUFFER': (int, 'PushBullet', 0), 'PUSHBULLET_ON_WATCHED': (int, 'PushBullet', 0), + 'IFTTT_KEY': (str, 'Ifttt', ''), + 'IFTTT_ENABLED': (int, 'IFTTT', 0), + 'IFTTT_ON_PLAY': (int, 'IFTTT', 0), + 'IFTTT_ON_STOP': (int, 'IFTTT', 0), + 'IFTTT_ON_PAUSE': (int, 'IFTTT', 0), + 'IFTTT_ON_RESUME': (int, 'IFTTT', 0), + 'IFTTT_ON_BUFFER': (int, 'IFTTT', 0), + 'IFTTT_ON_WATCHED': (int, 'IFTTT', 0), 'PUSHOVER_APITOKEN': (str, 'Pushover', ''), 'PUSHOVER_ENABLED': (int, 'Pushover', 0), 'PUSHOVER_KEYS': (str, 'Pushover', ''), @@ -320,4 +328,4 @@ class Config(object): """ for name, value in kwargs.items(): key, definition_type, section, ini_key, default = self._define(name) - self._config[section][ini_key] = definition_type(value) \ No newline at end of file + self._config[section][ini_key] = definition_type(value) diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 2a6555e2..0b77e84a 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -1,4 +1,4 @@ -# This file is part of PlexPy. +# This file is part of PlexPy. # # PlexPy is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ import os.path import subprocess import gntp.notifier import json +import ssl import oauth2 as oauth import pythontwitter as twitter @@ -50,7 +51,8 @@ AGENT_IDS = {"Growl": 0, "OSX Notify": 8, "Boxcar2": 9, "Email": 10, - "Twitter": 11} + "Twitter": 11, + "IFTTT": 12} def available_notification_agents(): agents = [{'name': 'Growl', @@ -184,6 +186,18 @@ def available_notification_agents(): 'on_resume': plexpy.CONFIG.TWITTER_ON_RESUME, 'on_buffer': plexpy.CONFIG.TWITTER_ON_BUFFER, 'on_watched': plexpy.CONFIG.TWITTER_ON_WATCHED + }, + {'name': 'IFTTT', + 'id': AGENT_IDS['IFTTT'], + 'config_prefix': 'ifttt', + 'has_config': True, + 'state': checked(plexpy.CONFIG.IFTTT_ENABLED), + 'on_play': plexpy.CONFIG.IFTTT_ON_PLAY, + 'on_stop': plexpy.CONFIG.IFTTT_ON_STOP, + 'on_pause': plexpy.CONFIG.IFTTT_ON_PAUSE, + 'on_resume': plexpy.CONFIG.IFTTT_ON_RESUME, + 'on_buffer': plexpy.CONFIG.IFTTT_ON_BUFFER, + 'on_watched': plexpy.CONFIG.IFTTT_ON_WATCHED } ] @@ -245,6 +259,9 @@ def get_notification_agent_config(config_id): elif config_id == 11: tweet = TwitterNotifier() return tweet.return_config_options() + elif config_id == 12: + iftttClient = IFTTT() + return iftttClient.return_config_options() else: return [] else: @@ -290,6 +307,9 @@ def send_notification(config_id, subject, body): elif config_id == 11: tweet = TwitterNotifier() tweet.notify(subject=subject, message=body) + elif config_id == 12: + iftttClient = IFTTT() + iftttClient.notify(subject=subject, message=body) else: logger.debug(u"PlexPy Notifier :: Unknown agent id received.") else: @@ -1251,4 +1271,64 @@ class Email(object): } ] - return config_option \ No newline at end of file + return config_option + +class IFTTT(object): + + def __init__(self): + self.apikey = plexpy.CONFIG.IFTTT_KEY + self.on_play = plexpy.CONFIG.IFTTT_ON_PLAY + self.on_stop = plexpy.CONFIG.IFTTT_ON_STOP + self.on_watched = plexpy.CONFIG.IFTTT_ON_WATCHED + + + def notify(self, message, subject): + if not message or not subject: + return + + context = ssl.create_default_context() + #context = ssl._create_unverified_context() + http_handler = HTTPSConnection("maker.ifttt.com", context=context) + + data = {'value1': subject.encode("utf-8"), + 'value2': message.encode("utf-8")} + + logger.debug("Ifttt SENDING: %s" % json.dumps(data)) + + http_handler.request("POST", + "/trigger/plextv/with/key/%s" % plexpy.CONFIG.IFTTT_KEY, + headers={'Content-type': "application/json"}, + body=json.dumps(data)) + response = http_handler.getresponse() + request_status = response.status + logger.debug(u"Ifttt response status: %r" % request_status) + logger.debug(u"Ifttt response headers: %r" % response.getheaders()) + logger.debug(u"Ifttt response body: %r" % response.read()) + + if request_status == 200: + logger.info(u"Ifttt notifications sent.") + return True + elif request_status >= 400 and request_status < 500: + logger.info(u"Ifttt request failed: %s" % response.reason) + return False + else: + logger.info(u"Ifttt notification failed serverside.") + return False + + def test(self, apikey): + + self.enabled = True + self.apikey = apikey + + self.notify('Main Screen Activate', 'Test Message') + + def return_config_options(self): + config_option = [{'label': 'Ifttt Maker Channel Key', + 'value': self.apikey, + 'name': 'ifttt_key', + 'description': 'Your Pushbullet key.', + 'input_type': 'text' + } + ] + + return config_option From 937d11412523e61d361f07b8d0af3067cc53c8ac Mon Sep 17 00:00:00 2001 From: rossdargan Date: Sun, 11 Oct 2015 22:07:35 +0100 Subject: [PATCH 4/5] Hide debug stuff, and make the event customizable --- plexpy/config.py | 3 ++- plexpy/notifiers.py | 28 ++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/plexpy/config.py b/plexpy/config.py index 29ba205d..3c08a463 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -181,7 +181,8 @@ _CONFIG_DEFINITIONS = { 'PUSHBULLET_ON_RESUME': (int, 'PushBullet', 0), 'PUSHBULLET_ON_BUFFER': (int, 'PushBullet', 0), 'PUSHBULLET_ON_WATCHED': (int, 'PushBullet', 0), - 'IFTTT_KEY': (str, 'Ifttt', ''), + 'IFTTT_KEY': (str, 'Ifttt', ''), + 'IFTTT_EVENT': (str, 'Ifttt', 'plextv'), 'IFTTT_ENABLED': (int, 'IFTTT', 0), 'IFTTT_ON_PLAY': (int, 'IFTTT', 0), 'IFTTT_ON_STOP': (int, 'IFTTT', 0), diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 0b77e84a..5ba62633 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -1276,7 +1276,8 @@ class Email(object): class IFTTT(object): def __init__(self): - self.apikey = plexpy.CONFIG.IFTTT_KEY + self.apikey = plexpy.CONFIG.IFTTT_KEY + self.event = plexpy.CONFIG.IFTTT_EVENT self.on_play = plexpy.CONFIG.IFTTT_ON_PLAY self.on_stop = plexpy.CONFIG.IFTTT_ON_STOP self.on_watched = plexpy.CONFIG.IFTTT_ON_WATCHED @@ -1285,25 +1286,26 @@ class IFTTT(object): def notify(self, message, subject): if not message or not subject: return - - context = ssl.create_default_context() - #context = ssl._create_unverified_context() + # This should be the contex we use, but it isn't working as it casues an SSL validation error + # Unfortunately this is beyond my phython ability! + #context = ssl.create_default_context() + context = ssl._create_unverified_context() http_handler = HTTPSConnection("maker.ifttt.com", context=context) data = {'value1': subject.encode("utf-8"), 'value2': message.encode("utf-8")} - logger.debug("Ifttt SENDING: %s" % json.dumps(data)) + #logger.debug("Ifttt SENDING: %s" % json.dumps(data)) http_handler.request("POST", - "/trigger/plextv/with/key/%s" % plexpy.CONFIG.IFTTT_KEY, + "/trigger/%s/with/key/%s" % (plexpy.CONFIG.IFTTT_EVENT, plexpy.CONFIG.IFTTT_KEY), headers={'Content-type': "application/json"}, body=json.dumps(data)) response = http_handler.getresponse() request_status = response.status - logger.debug(u"Ifttt response status: %r" % request_status) - logger.debug(u"Ifttt response headers: %r" % response.getheaders()) - logger.debug(u"Ifttt response body: %r" % response.read()) + #logger.debug(u"Ifttt response status: %r" % request_status) + #logger.debug(u"Ifttt response headers: %r" % response.getheaders()) + #logger.debug(u"Ifttt response body: %r" % response.read()) if request_status == 200: logger.info(u"Ifttt notifications sent.") @@ -1326,7 +1328,13 @@ class IFTTT(object): config_option = [{'label': 'Ifttt Maker Channel Key', 'value': self.apikey, 'name': 'ifttt_key', - 'description': 'Your Pushbullet key.', + 'description': 'Your Ifttt key. You can get a key from here https://ifttt.com/maker', + 'input_type': 'text' + }, + {'label': 'Ifttt event', + 'value': self.apikey, + 'name': 'ifttt_event', + 'description': 'The Ifttt maker event to fire.', 'input_type': 'text' } ] From 8c72dfc641db129407e3f3f3bad3d3162d20e7d7 Mon Sep 17 00:00:00 2001 From: rossdargan Date: Sun, 11 Oct 2015 22:27:13 +0100 Subject: [PATCH 5/5] Fixed an issue with the even setting --- plexpy/notifiers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 5ba62633..7fa506f1 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -1317,11 +1317,11 @@ class IFTTT(object): logger.info(u"Ifttt notification failed serverside.") return False - def test(self, apikey): + def test(self, apikey, event): self.enabled = True self.apikey = apikey - + self.event = event self.notify('Main Screen Activate', 'Test Message') def return_config_options(self): @@ -1332,7 +1332,7 @@ class IFTTT(object): 'input_type': 'text' }, {'label': 'Ifttt event', - 'value': self.apikey, + 'value': self.event, 'name': 'ifttt_event', 'description': 'The Ifttt maker event to fire.', 'input_type': 'text'