From 7fd8b999b6e6a04cf369ae7c4ff0c752bbc0ee33 Mon Sep 17 00:00:00 2001 From: Heisenberg74 Date: Wed, 31 Dec 2014 13:40:48 +0100 Subject: [PATCH] Add Free Mobile SMS Notifier Allow SickRage to send SMS notifications through Free Mobile SMS API. Works only for Free Mobile subscribers. --- gui/slick/images/notifiers/freemobile.png | Bin 0 -> 3524 bytes .../default/config_notifications.tmpl | 72 ++++++++++ gui/slick/js/configNotifications.js | 27 ++++ sickbeard/__init__.py | 24 +++- sickbeard/notifiers/__init__.py | 3 + sickbeard/notifiers/freemobile.py | 125 ++++++++++++++++++ sickbeard/webserve.py | 18 ++- 7 files changed, 267 insertions(+), 2 deletions(-) create mode 100644 gui/slick/images/notifiers/freemobile.png create mode 100644 sickbeard/notifiers/freemobile.py diff --git a/gui/slick/images/notifiers/freemobile.png b/gui/slick/images/notifiers/freemobile.png new file mode 100644 index 0000000000000000000000000000000000000000..9aa0b8ceed38bae9ce40fbcc1dbd0896d5fccbe6 GIT binary patch literal 3524 zcmV;#4LkCQP)k zz9m-#NCZd(NCZd(NCZd(NCe3L;Uyz3XZTJ=g6%hn@2jt*N9Dbf2{&jEA;BOaf*AUB zI6|_~YC`xR3ADG5;#*tqahI3piWe$bcE)t8_NPlX%aR9OBLO~q1Vf0^NkpC}j9gAg zj0S51q5Y@~UK78c5RN0nv|L&#H zkidlt*^am0UgzJxzkuq<4ISFW4jIxe7>%id$rK|(Tlw90pCg)>0W14_q5JRGu zPN&*);=~-{a_dz2a}KcaaaMwu;hS4V`!81B8*FOI3OXF|Y)p)e8#(fdYSyg7oI0gb zI-e@fax@-q^IyC;Ie7JImfu{xcN%Nku5{nXPtBstOP2o0}?@J&s`RZ>EnJ9ZG? z`SXN+J-YYpTV!Au(F9TKELw7M8bq&G6*L-&|8HLr(a=G}o*ojo(m1?l@!~%jqN4*w z$aP@YUwdt>=kw1COrx_}4BfQG3JU((p-_m%q(M&0?AfO+xw&WQIx1(H zI<-o)bTMLg5Al?iKG-#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ellular network provider.
It provides to their customer a free SMS API.

+
+
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ + +
+
+ + +
+
Click below to test your settings.
+ + +
+ +
+
diff --git a/gui/slick/js/configNotifications.js b/gui/slick/js/configNotifications.js index 1f1c8f2a..87bf40d3 100644 --- a/gui/slick/js/configNotifications.js +++ b/gui/slick/js/configNotifications.js @@ -268,6 +268,33 @@ $(document).ready(function(){ $('#testNMJv2').prop('disabled', false); }); }); + + $('#testFreeMobile').click(function () { + var freemobile_id = $.trim($('#freemobile_id').val()); + var freemobile_apikey = $.trim($('#freemobile_apikey').val()); + if (!freemobile_id || !freemobile_apikey) { + $('#testFreeMobile-result').html('Please fill out the necessary fields above.'); + if (!freemobile_id) { + $('#freemobile_id').addClass('warning'); + } else { + $('#freemobile_id').removeClass('warning'); + } + if (!freemobile_apikey) { + $('#freemobile_apikey').addClass('warning'); + } else { + $('#freemobile_apikey').removeClass('warning'); + } + return; + } + $('#freemobile_id,#freemobile_apikey').removeClass('warning'); + $(this).prop('disabled', true); + $('#testFreeMobile-result').html(loading); + $.get(sbRoot + '/home/testFreeMobile', {'freemobile_id': freemobile_id, 'freemobile_apikey': freemobile_apikey}) + .done(function (data) { + $('#testFreeMobile-result').html(data); + $('#testFreeMobile').prop('disabled', false); + }); + }); $('#testTrakt').click(function () { var trakt_api = $.trim($('#trakt_api').val()); diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index a97434ca..0f757cde 100755 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -312,6 +312,13 @@ GROWL_NOTIFY_ONSUBTITLEDOWNLOAD = False GROWL_HOST = '' GROWL_PASSWORD = None +USE_FREEMOBILE = False +FREEMOBILE_NOTIFY_ONSNATCH = False +FREEMOBILE_NOTIFY_ONDOWNLOAD = False +FREEMOBILE_NOTIFY_ONSUBTITLEDOWNLOAD = False +FREEMOBILE_ID = '' +FREEMOBILE_APIKEY= '' + USE_PROWL = False PROWL_NOTIFY_ONSNATCH = False PROWL_NOTIFY_ONDOWNLOAD = False @@ -497,7 +504,7 @@ def initialize(consoleLogging=True): showUpdateScheduler, __INITIALIZED__, LAUNCH_BROWSER, UPDATE_SHOWS_ON_START, TRASH_REMOVE_SHOW, TRASH_ROTATE_LOGS, SORT_ARTICLE, showList, loadingShowList, \ NEWZNAB_DATA, NZBS, NZBS_UID, NZBS_HASH, INDEXER_DEFAULT, INDEXER_TIMEOUT, USENET_RETENTION, TORRENT_DIR, \ QUALITY_DEFAULT, FLATTEN_FOLDERS_DEFAULT, SUBTITLES_DEFAULT, STATUS_DEFAULT, DAILYSEARCH_STARTUP, \ - GROWL_NOTIFY_ONSNATCH, GROWL_NOTIFY_ONDOWNLOAD, GROWL_NOTIFY_ONSUBTITLEDOWNLOAD, TWITTER_NOTIFY_ONSNATCH, TWITTER_NOTIFY_ONDOWNLOAD, TWITTER_NOTIFY_ONSUBTITLEDOWNLOAD, \ + GROWL_NOTIFY_ONSNATCH, GROWL_NOTIFY_ONDOWNLOAD, GROWL_NOTIFY_ONSUBTITLEDOWNLOAD, TWITTER_NOTIFY_ONSNATCH, TWITTER_NOTIFY_ONDOWNLOAD, TWITTER_NOTIFY_ONSUBTITLEDOWNLOAD, USE_FREEMOBILE, FREEMOBILE_ID, FREEMOBILE_APIKEY, FREEMOBILE_NOTIFY_ONSNATCH, FREEMOBILE_NOTIFY_ONDOWNLOAD, FREEMOBILE_NOTIFY_ONSUBTITLEDOWNLOAD, \ USE_GROWL, GROWL_HOST, GROWL_PASSWORD, USE_PROWL, PROWL_NOTIFY_ONSNATCH, PROWL_NOTIFY_ONDOWNLOAD, PROWL_NOTIFY_ONSUBTITLEDOWNLOAD, PROWL_API, PROWL_PRIORITY, PROG_DIR, \ USE_PYTIVO, PYTIVO_NOTIFY_ONSNATCH, PYTIVO_NOTIFY_ONDOWNLOAD, PYTIVO_NOTIFY_ONSUBTITLEDOWNLOAD, PYTIVO_UPDATE_LIBRARY, PYTIVO_HOST, PYTIVO_SHARE_NAME, PYTIVO_TIVO_NAME, \ USE_NMA, NMA_NOTIFY_ONSNATCH, NMA_NOTIFY_ONDOWNLOAD, NMA_NOTIFY_ONSUBTITLEDOWNLOAD, NMA_API, NMA_PRIORITY, \ @@ -824,6 +831,13 @@ def initialize(consoleLogging=True): GROWL_HOST = check_setting_str(CFG, 'Growl', 'growl_host', '') GROWL_PASSWORD = check_setting_str(CFG, 'Growl', 'growl_password', '', censor_log=True) + USE_FREEMOBILE = bool(check_setting_int(CFG, 'FreeMobile', 'use_freemobile', 0)) + FREEMOBILE_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'FreeMobile', 'freemobile_notify_onsnatch', 0)) + FREEMOBILE_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'FreeMobile', 'freemobile_notify_ondownload', 0)) + FREEMOBILE_NOTIFY_ONSUBTITLEDOWNLOAD = bool(check_setting_int(CFG, 'FreeMobile', 'freemobile_notify_onsubtitledownload', 0)) + FREEMOBILE_ID = check_setting_str(CFG, 'FreeMobile', 'freemobile_id', '') + FREEMOBILE_APIKEY = check_setting_str(CFG, 'FreeMobile', 'freemobile_apikey', '') + USE_PROWL = bool(check_setting_int(CFG, 'Prowl', 'use_prowl', 0)) PROWL_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Prowl', 'prowl_notify_onsnatch', 0)) PROWL_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Prowl', 'prowl_notify_ondownload', 0)) @@ -1678,6 +1692,14 @@ def save_config(): new_config['Growl']['growl_host'] = GROWL_HOST new_config['Growl']['growl_password'] = helpers.encrypt(GROWL_PASSWORD, ENCRYPTION_VERSION) + new_config['FreeMobile'] = {} + new_config['FreeMobile']['use_freemobile'] = int(USE_FREEMOBILE) + new_config['FreeMobile']['freemobile_notify_onsnatch'] = int(FREEMOBILE_NOTIFY_ONSNATCH) + new_config['FreeMobile']['freemobile_notify_ondownload'] = int(FREEMOBILE_NOTIFY_ONDOWNLOAD) + new_config['FreeMobile']['freemobile_notify_onsubtitledownload'] = int(FREEMOBILE_NOTIFY_ONSUBTITLEDOWNLOAD) + new_config['FreeMobile']['freemobile_id'] = FREEMOBILE_ID + new_config['FreeMobile']['freemobile_apikey'] = FREEMOBILE_APIKEY + new_config['Prowl'] = {} new_config['Prowl']['use_prowl'] = int(USE_PROWL) new_config['Prowl']['prowl_notify_onsnatch'] = int(PROWL_NOTIFY_ONSNATCH) diff --git a/sickbeard/notifiers/__init__.py b/sickbeard/notifiers/__init__.py index ad718dc8..77ae5dae 100644 --- a/sickbeard/notifiers/__init__.py +++ b/sickbeard/notifiers/__init__.py @@ -35,6 +35,7 @@ import boxcar2 import nma import pushalot import pushbullet +import freemobile import tweet import trakt @@ -60,6 +61,7 @@ boxcar2_notifier = boxcar2.Boxcar2Notifier() nma_notifier = nma.NMA_Notifier() pushalot_notifier = pushalot.PushalotNotifier() pushbullet_notifier = pushbullet.PushbulletNotifier() +freemobile_notifier = freemobile.FreeMobileNotifier() # social twitter_notifier = tweet.TwitterNotifier() trakt_notifier = trakt.TraktNotifier() @@ -75,6 +77,7 @@ notifiers = [ synology_notifier, pytivo_notifier, growl_notifier, + freemobile_notifier, prowl_notifier, pushover_notifier, boxcar_notifier, diff --git a/sickbeard/notifiers/freemobile.py b/sickbeard/notifiers/freemobile.py new file mode 100644 index 00000000..bcf10afd --- /dev/null +++ b/sickbeard/notifiers/freemobile.py @@ -0,0 +1,125 @@ +# Author: Marvin Pinto +# Author: Dennis Lutter +# Author: Aaron Bieber +# URL: http://code.google.com/p/sickbeard/ +# +# This file is part of SickRage. +# +# SickRage is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# SickRage is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with SickRage. If not, see . +import httplib +import urllib, urllib2 +import time + +import sickbeard +from sickbeard import logger +from sickbeard.common import notifyStrings, NOTIFY_SNATCH, NOTIFY_DOWNLOAD, NOTIFY_SUBTITLE_DOWNLOAD, NOTIFY_GIT_UPDATE, NOTIFY_GIT_UPDATE_TEXT +from sickbeard.exceptions import ex + +class FreeMobileNotifier: + def test_notify(self, id=None, apiKey=None): + return self._notifyFreeMobile('Test', "This is a test notification from SickRage", id, apiKey, force=True) + + def _sendFreeMobileSMS(self, title, msg, id=None, apiKey=None): + """ + Sends a SMS notification + + msg: The message to send (unicode) + title: The title of the message + userKey: The pushover user id to send the message to (or to subscribe with) + + returns: True if the message succeeded, False otherwise + """ + + if id == None: + id = sickbeard.FREEMOBILE_ID + if apiKey == None: + apiKey = sickbeard.FREEMOBILE_APIKEY + + logger.log("Free Mobile in use with API KEY: " + apiKey, logger.DEBUG) + + # build up the URL and parameters + msg = msg.strip() + msg_quoted = urllib2.quote(title + ": " + msg) + URL = "https://smsapi.free-mobile.fr/sendmsg?user=" + id + "&pass=" + apiKey + "&msg=" + msg_quoted + + req = urllib2.Request(URL) + # send the request to Free Mobile + try: + reponse = urllib2.urlopen(req) + except IOError, e: + if hasattr(e,'code'): + if e.code == 400: + message = "Missing parameter(s)." + logger.log(message, logger.ERROR) + return False, message + if e.code == 402: + message = "Too much SMS sent in a short time." + logger.log(message, logger.ERROR) + return False, message + if e.code == 403: + message = "API service isn't enabled in your account or ID / API key is incorrect." + logger.log(message, logger.ERROR) + return False, message + if e.code == 500: + message = "Server error. Please retry in few moment." + logger.log(message, logger.ERROR) + return False, message + + message = "Free Mobile SMS successful." + logger.log(message, logger.INFO) + return True, message + + + + + def notify_snatch(self, ep_name, title=notifyStrings[NOTIFY_SNATCH]): + if sickbeard.FREEMOBILE_NOTIFY_ONSNATCH: + self._notifyFreeMobile(title, ep_name) + + + def notify_download(self, ep_name, title=notifyStrings[NOTIFY_DOWNLOAD]): + if sickbeard.FREEMOBILE_NOTIFY_ONDOWNLOAD: + self._notifyFreeMobile(title, ep_name) + + def notify_subtitle_download(self, ep_name, lang, title=notifyStrings[NOTIFY_SUBTITLE_DOWNLOAD]): + if sickbeard.FREEMOBILE_NOTIFY_ONSUBTITLEDOWNLOAD: + self._notifyFreeMobile(title, ep_name + ": " + lang) + + def notify_git_update(self, new_version = "??"): + if sickbeard.USE_FREEMOBILE: + update_text=notifyStrings[NOTIFY_GIT_UPDATE_TEXT] + title=notifyStrings[NOTIFY_GIT_UPDATE] + self._notifyFreeMobile(title, update_text + new_version) + + def _notifyFreeMobile(self, title, message, id=None, apiKey=None, force=False): + """ + Sends a SMS notification + + title: The title of the notification to send + message: The message string to send + id: Your Free Mobile customer ID + apikey: Your Free Mobile API key + force: Enforce sending, for instance for testing + """ + + if not sickbeard.USE_FREEMOBILE and not force: + logger.log("Notification for Free Mobile not enabled, skipping this notification", logger.DEBUG) + return False + + logger.log("Sending a SMS for " + message, logger.DEBUG) + + return self._sendFreeMobileSMS(title, message, id, apiKey) + + +notifier = FreeMobileNotifier diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 996e3086..d1fc209c 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -749,6 +749,13 @@ class Home(WebRoot): return accesMsg + def testFreeMobile(self, freemobile_id=None, freemobile_apikey=None): + + result, message = notifiers.freemobile_notifier.test_notify(freemobile_id, freemobile_apikey) + if result: + return "SMS sent successfully" + else: + return "Problem sending SMS: " + message def testGrowl(self, host=None, password=None): # self.set_header('Cache-Control', 'max-age=0,no-cache,no-store') @@ -4332,6 +4339,8 @@ class ConfigNotifications(Config): plex_server_host=None, plex_host=None, plex_username=None, plex_password=None, use_growl=None, growl_notify_onsnatch=None, growl_notify_ondownload=None, growl_notify_onsubtitledownload=None, growl_host=None, growl_password=None, + use_freemobile=None, freemobile_notify_onsnatch=None, freemobile_notify_ondownload=None, + freemobile_notify_onsubtitledownload=None, freemobile_id=None, freemobile_apikey=None, use_prowl=None, prowl_notify_onsnatch=None, prowl_notify_ondownload=None, prowl_notify_onsubtitledownload=None, prowl_api=None, prowl_priority=0, use_twitter=None, twitter_notify_onsnatch=None, twitter_notify_ondownload=None, @@ -4397,6 +4406,13 @@ class ConfigNotifications(Config): sickbeard.GROWL_NOTIFY_ONSUBTITLEDOWNLOAD = config.checkbox_to_value(growl_notify_onsubtitledownload) sickbeard.GROWL_HOST = config.clean_host(growl_host, default_port=23053) sickbeard.GROWL_PASSWORD = growl_password + + sickbeard.USE_FREEMOBILE = config.checkbox_to_value(use_freemobile) + sickbeard.FREEMOBILE_NOTIFY_ONSNATCH = config.checkbox_to_value(freemobile_notify_onsnatch) + sickbeard.FREEMOBILE_NOTIFY_ONDOWNLOAD = config.checkbox_to_value(freemobile_notify_ondownload) + sickbeard.FREEMOBILE_NOTIFY_ONSUBTITLEDOWNLOAD = config.checkbox_to_value(freemobile_notify_onsubtitledownload) + sickbeard.FREEMOBILE_ID = freemobile_id + sickbeard.FREEMOBILE_APIKEY = freemobile_apikey sickbeard.USE_PROWL = config.checkbox_to_value(use_prowl) sickbeard.PROWL_NOTIFY_ONSNATCH = config.checkbox_to_value(prowl_notify_onsnatch) @@ -4716,4 +4732,4 @@ class ErrorLogs(WebRoot): if issue: ui.notifications.message('Your issue ticket #%s was submitted successfully!' % issue.number) - return self.redirect("/errorlogs/") \ No newline at end of file + return self.redirect("/errorlogs/")