From adbd2c83190862ed26c70c5deb22270f42dff859 Mon Sep 17 00:00:00 2001 From: Pyntel Date: Mon, 1 Apr 2013 15:21:56 +0200 Subject: [PATCH 1/2] Pushover notification added New notification option added to Advanced Settings dialog. For details about setting up, options and the required API key and user key see http://pushover.net --- .gitignore | 23 ++++++++++++++--- mylar/PostProcessor.py | 6 +++++ mylar/__init__.py | 20 ++++++++++++++- mylar/notifiers.py | 58 ++++++++++++++++++++++++++++++++++++++++++ mylar/search.py | 5 +++- mylar/webserve.py | 12 ++++++++- 6 files changed, 117 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 18c999bc..da979ff2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,20 @@ -mylar.db -config.ini + +.gitignore + *.pyc -.idea -logs \ No newline at end of file + +*.db + +*.jpg + +*.txt + +*.ini + +*.csv + +*.log + +*.1 + +*.2 diff --git a/mylar/PostProcessor.py b/mylar/PostProcessor.py index fbe3f81f..290e7d08 100755 --- a/mylar/PostProcessor.py +++ b/mylar/PostProcessor.py @@ -404,6 +404,12 @@ class PostProcessor(object): nma = notifiers.NMA() nma.notify(series, str(issueyear), str(issuenum)) + if mylar.PUSHOVER_ENABLED: + pushmessage = series + '(' + issueyear + ') - issue #' + issuenum + logger.info(u"Pushover request") + pushover = notifiers.PUSHOVER() + pushover.notify(pushmessage,"Download and Postprocessing completed") + # retrieve/create the corresponding comic objects if mylar.ENABLE_EXTRA_SCRIPTS: diff --git a/mylar/__init__.py b/mylar/__init__.py index b10ee5fa..13579e44 100755 --- a/mylar/__init__.py +++ b/mylar/__init__.py @@ -131,6 +131,11 @@ NMA_ENABLED = False NMA_APIKEY = None NMA_PRIORITY = None NMA_ONSNATCH = None +PUSHOVER_ENABLED = True +PUSHOVER_PRIORITY = 1 +PUSHOVER_APIKEY = None +PUSHOVER_USERKEY = None +PUSHOVER_ONSNATCH = True SKIPPED2WANTED = False CVINFO = False LOG_LEVEL = None @@ -252,7 +257,7 @@ def initialize(): USE_NZBGET, NZBGET_HOST, NZBGET_PORT, NZBGET_USERNAME, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_PRIORITY, NZBSU, NZBSU_APIKEY, DOGNZB, DOGNZB_APIKEY, NZBX,\ NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS,\ RAW, RAW_PROVIDER, RAW_USERNAME, RAW_PASSWORD, RAW_GROUPS, EXPERIMENTAL, \ - PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, \ + PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, PUSHOVER_ENABLED, PUSHOVER_PRIORITY, PUSHOVER_APIKEY, PUSHOVER_USERKEY, PUSHOVER_ONSNATCH, \ PREFERRED_QUALITY, MOVE_FILES, RENAME_FILES, LOWERCASE_FILENAMES, USE_MINSIZE, MINSIZE, USE_MAXSIZE, MAXSIZE, CORRECT_METADATA, FOLDER_FORMAT, FILE_FORMAT, REPLACE_CHAR, REPLACE_SPACES, ADD_TO_CSV, CVINFO, LOG_LEVEL, POST_PROCESSING, \ COMIC_LOCATION, QUAL_ALTVERS, QUAL_SCANNER, QUAL_TYPE, QUAL_QUALITY, ENABLE_EXTRA_SCRIPTS, EXTRA_SCRIPTS, ENABLE_PRE_SCRIPTS, PRE_SCRIPTS, PULLNEW, COUNT_ISSUES, COUNT_HAVES, COUNT_COMICS, SYNO_FIX, ANNUALS_ON @@ -335,6 +340,12 @@ def initialize(): NMA_PRIORITY = check_setting_int(CFG, 'NMA', 'nma_priority', 0) NMA_ONSNATCH = bool(check_setting_int(CFG, 'NMA', 'nma_onsnatch', 0)) + PUSHOVER_ENABLED = bool(check_setting_int(CFG, 'PUSHOVER', 'pushover_enabled', 0)) + PUSHOVER_APIKEY = check_setting_str(CFG, 'PUSHOVER', 'pushover_apikey', '') + PUSHOVER_USERKEY = check_setting_str(CFG, 'PUSHOVER', 'pushover_userkey', '') + PUSHOVER_PRIORITY = check_setting_int(CFG, 'PUSHOVER', 'pushover_priority', 0) + PUSHOVER_ONSNATCH = bool(check_setting_int(CFG, 'PUSHOVER', 'pushover_onsnatch', 0)) + USE_MINSIZE = bool(check_setting_int(CFG, 'General', 'use_minsize', 0)) MINSIZE = check_setting_str(CFG, 'General', 'minsize', '') USE_MAXSIZE = bool(check_setting_int(CFG, 'General', 'use_maxsize', 0)) @@ -717,6 +728,13 @@ def config_write(): new_config['NMA']['nma_priority'] = NMA_PRIORITY new_config['NMA']['nma_onsnatch'] = int(NMA_ONSNATCH) + new_config['PUSHOVER'] = {} + new_config['PUSHOVER']['pushover_enabled'] = int(PUSHOVER_ENABLED) + new_config['PUSHOVER']['pushover_apikey'] = PUSHOVER_APIKEY + new_config['PUSHOVER']['pushover_userkey'] = PUSHOVER_USERKEY + new_config['PUSHOVER']['pushover_priority'] = PUSHOVER_PRIORITY + new_config['PUSHOVER']['pushover_onsnatch'] = int(PUSHOVER_ONSNATCH) + new_config['Raw'] = {} new_config['Raw']['raw'] = int(RAW) new_config['Raw']['raw_provider'] = RAW_PROVIDER diff --git a/mylar/notifiers.py b/mylar/notifiers.py index 64a0af52..986b9ec8 100644 --- a/mylar/notifiers.py +++ b/mylar/notifiers.py @@ -126,3 +126,61 @@ class NMA: if not request: logger.warn('Error sending notification request to NotifyMyAndroid') +# 2013-04-01 Added Pushover.net notifications, based on copy of Prowl class above. +# No extra care has been put into API friendliness at the moment (read: https://pushover.net/api#friendly) +class PUSHOVER: + + def __init__(self): + self.enabled = mylar.PUSHOVER_ENABLED + self.apikey = mylar.PUSHOVER_APIKEY + self.userkey = mylar.PUSHOVER_USERKEY + self.priority = mylar.PUSHOVER_PRIORITY + # other API options: + # self.device_id = mylar.PUSHOVER_DEVICE_ID + # device - option for specifying which of your registered devices Mylar should send to. No option given, it sends to all devices on Pushover (default) + # URL / URL_TITLE (both for use with the COPS/OPDS server I'm building maybe?) + # Sound - name of soundfile to override default sound choice + + # not sure if this is needed for Pushover + + #def conf(self, options): + # return cherrypy.config['config'].get('Pushover', options) + + def notify(self, message, event): + if not mylar.PUSHOVER_ENABLED: + return + + http_handler = HTTPSConnection("api.pushover.net:443") + + data = {'token': mylar.PUSHOVER_APIKEY, + 'user': mylar.PUSHOVER_USERKEY, + 'message': message.encode("utf-8"), + 'title': event, + 'priority': mylar.PUSHOVER_PRIORITY } + + http_handler.request("POST", + "/1/messages.json", + body = urlencode(data), + headers = {'Content-type': "application/x-www-form-urlencoded"} + ) + response = http_handler.getresponse() + request_status = response.status + + if request_status == 200: + logger.info(u"Pushover notifications sent.") + return True + elif request_status == 401: + logger.info(u"Pushover auth failed: %s" % response.reason) + return False + else: + logger.info(u"Pushover notification failed.") + return False + + def test(self, apikey, userkey, priority): + + self.enabled = True + self.apikey = apikey + self.userkey = userkey + self.priority = priority + + self.notify('ZOMG Lazors Pewpewpew!', 'Test Message') \ No newline at end of file diff --git a/mylar/search.py b/mylar/search.py index bcd0cd04..a90a0dc2 100755 --- a/mylar/search.py +++ b/mylar/search.py @@ -823,7 +823,10 @@ def NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr, Is logger.info(u"Sending NMA notification") nma = notifiers.NMA() nma.notify(snatched_nzb=nzbname) - + if mylar.PUSHOVER_ENABLED and mylar.PUSHOVER_ONSNATCH: + logger.info(u"Sending Pushover notification") + pushover = notifiers.PUSHOVER() + pushover.notify(nzbname,"Download started") foundc = "yes" done = True diff --git a/mylar/webserve.py b/mylar/webserve.py index 3bca713f..1699c2fa 100755 --- a/mylar/webserve.py +++ b/mylar/webserve.py @@ -1255,6 +1255,11 @@ class WebInterface(object): "nma_apikey": mylar.NMA_APIKEY, "nma_priority": int(mylar.NMA_PRIORITY), "nma_onsnatch": helpers.checked(mylar.NMA_ONSNATCH), + "pushover_enabled": helpers.checked(mylar.PUSHOVER_ENABLED), + "pushover_onsnatch": helpers.checked(mylar.PUSHOVER_ONSNATCH), + "pushover_apikey": mylar.PUSHOVER_APIKEY, + "pushover_userkey": mylar.PUSHOVER_USERKEY, + "pushover_priority": mylar.PUSHOVER_PRIORITY, "enable_extra_scripts" : helpers.checked(mylar.ENABLE_EXTRA_SCRIPTS), "extra_scripts" : mylar.EXTRA_SCRIPTS, "post_processing" : helpers.checked(mylar.POST_PROCESSING), @@ -1378,7 +1383,7 @@ class WebInterface(object): use_nzbget=0, nzbget_host=None, nzbget_port=None, nzbget_username=None, nzbget_password=None, nzbget_category=None, nzbget_priority=None, usenet_retention=None, nzbsu=0, nzbsu_apikey=None, dognzb=0, dognzb_apikey=None, nzbx=0, newznab=0, newznab_host=None, newznab_apikey=None, newznab_enabled=0, raw=0, raw_provider=None, raw_username=None, raw_password=None, raw_groups=None, experimental=0, - prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=None, nma_enabled=0, nma_apikey=None, nma_priority=0, nma_onsnatch=0, + prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=None, nma_enabled=0, nma_apikey=None, nma_priority=0, nma_onsnatch=0, pushover_enabled=0, pushover_onsnatch=0, pushover_apikey=None, pushover_userkey=None, pushover_priority=None, preferred_quality=0, move_files=0, rename_files=0, add_to_csv=1, cvinfo=0, lowercase_filenames=0, folder_format=None, file_format=None, enable_extra_scripts=0, extra_scripts=None, enable_pre_scripts=0, pre_scripts=None, post_processing=0, syno_fix=0, destination_dir=None, replace_spaces=0, replace_char=None, use_minsize=0, minsize=None, use_maxsize=0, maxsize=None, autowant_all=0, autowant_upcoming=0, comic_cover_local=0, zero_level=0, zero_level_n=None, interface=None, **kwargs): mylar.HTTP_HOST = http_host @@ -1443,6 +1448,11 @@ class WebInterface(object): mylar.NMA_APIKEY = nma_apikey mylar.NMA_PRIORITY = nma_priority mylar.NMA_ONSNATCH = nma_onsnatch + mylar.PUSHOVER_ENABLED = pushover_enabled + mylar.PUSHOVER_APIKEY = pushover_apikey + mylar.PUSHOVER_USERKEY = pushover_userkey + mylar.PUSHOVER_PRIORITY = pushover_priority + mylar.PUSHOVER_ONSNATCH = pushover_onsnatch mylar.USE_MINSIZE = use_minsize mylar.MINSIZE = minsize mylar.USE_MAXSIZE = use_maxsize From 3157028fcb9574a7c1a26140a4b805b252327d88 Mon Sep 17 00:00:00 2001 From: Pyntel Date: Mon, 1 Apr 2013 15:30:28 +0200 Subject: [PATCH 2/2] Necessary HTML for Pushover in Advanced Settings Necessary HTML for Pushover in Advanced Settings --- data/interfaces/default/config.html | 123 ++++++++++++++++++---------- 1 file changed, 81 insertions(+), 42 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index cf2bd439..f4bcf40a 100755 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -591,48 +591,68 @@ -
-

NotifyMyAndroid

-
- -
-
-
-
- -
- - - Separate multiple api keys with commas -
-
- - -
-
-
- +
+

NotifyMyAndroid

+
+ +
+
+
+
+ +
+ + + Separate multiple api keys with commas +
+
+ + +
+
+
+
+

Pushover

+
+ +
+
+
+ +
+
+ +
+
+ +
+
+ + +
+
+
@@ -713,6 +733,25 @@ } }); + if ($("#pushover").is(":checked")) + { + $("#pushoveroptions").show(); + } + else + { + $("#pushoveroptions").hide(); + } + + $("#pushover").click(function(){ + if ($("#pushover").is(":checked")) + { + $("#pushoveroptions").slideDown(); + } + else + { + $("#pushoveroptions").slideUp(); + } + }); var deletedNewznabs = 0;