diff --git a/gui/slick/images/notifiers/freemobile.png b/gui/slick/images/notifiers/freemobile.png new file mode 100644 index 00000000..9aa0b8ce Binary files /dev/null and b/gui/slick/images/notifiers/freemobile.png differ diff --git a/gui/slick/interfaces/default/config_notifications.tmpl b/gui/slick/interfaces/default/config_notifications.tmpl index 4d3dd470..36a42b34 100644 --- a/gui/slick/interfaces/default/config_notifications.tmpl +++ b/gui/slick/interfaces/default/config_notifications.tmpl @@ -1192,6 +1192,78 @@ +
+
+ +

Free Mobile

+

Free Mobile is a famous French cellular 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/")