1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-04 15:12:23 -05:00

Add Free Mobile SMS Notifier

Allow SickRage to send SMS notifications through Free Mobile SMS API.

Works only for Free Mobile subscribers.
This commit is contained in:
Heisenberg74 2014-12-31 13:40:48 +01:00
parent 33e95870e0
commit 7fd8b999b6
7 changed files with 267 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -1192,6 +1192,78 @@
</fieldset>
</div><!-- /pushbullet component-group //-->
<div class="component-group">
<div class="component-group-desc">
<img class="notifier-icon" src="$sbRoot/images/notifiers/freemobile.png" alt="" title="Free Mobile" />
<h3><a href="<%= anon_url('http://mobile.free.fr/') %>" rel="noreferrer" onclick="window.open(this.href, '_blank'); return false;">Free Mobile</a></h3>
<p>Free Mobile is a famous French cellular network provider.<br> It provides to their customer a free SMS API.</p>
</div>
<fieldset class="component-group-list">
<div class="field-pair">
<label for="use_freemobile">
<span class="component-title">Enable</span>
<span class="component-desc">
<input type="checkbox" class="enabler" name="use_freemobile" id="use_freemobile" #if $sickbeard.USE_FREEMOBILE then "checked=\"checked\"" else ""# />
<p>should SickRage send SMS notifications ?</p>
</span>
</label>
</div>
<div id="content_use_freemobile">
<div class="field-pair">
<label for="freemobile_notify_onsnatch">
<span class="component-title">Notify on snatch</span>
<span class="component-desc">
<input type="checkbox" name="freemobile_notify_onsnatch" id="freemobile_notify_onsnatch" #if $sickbeard.FREEMOBILE_NOTIFY_ONSNATCH then "checked=\"checked\"" else ""# />
<p>send a SMS when a download starts ?</p>
</span>
</label>
</div>
<div class="field-pair">
<label for="freemobile_notify_ondownload">
<span class="component-title">Notify on download</span>
<span class="component-desc">
<input type="checkbox" name="freemobile_notify_ondownload" id="freemobile_notify_ondownload" #if $sickbeard.FREEMOBILE_NOTIFY_ONDOWNLOAD then "checked=\"checked\"" else ""# />
<p>send a SMS when a download finishes ?</p>
</span>
</label>
</div>
<div class="field-pair">
<label for="freemobile_notify_onsubtitledownload">
<span class="component-title">Notify on subtitle download</span>
<span class="component-desc">
<input type="checkbox" name="freemobile_notify_onsubtitledownload" id="freemobile_notify_onsubtitledownload" #if $sickbeard.FREEMOBILE_NOTIFY_ONSUBTITLEDOWNLOAD then "checked=\"checked\"" else ""# />
<p>send a SMS when subtitles are downloaded ?</p>
</span>
</label>
</div>
<div class="field-pair">
<label for="freemobile_id">
<span class="component-title">Free Mobile customer ID</span>
<input type="text" name="freemobile_id" id="freemobile_id" value="$sickbeard.FREEMOBILE_ID" class="form-control input-sm input250" />
</label>
<label>
<span class="component-title">&nbsp;</span>
<span class="component-desc">It's your Free Mobile customer ID (8 digits)</span>
</label>
</div>
<div class="field-pair">
<label for="freemobile_password">
<span class="component-title">Free Mobile API Key</span>
<input type="text" name="freemobile_apikey" id="freemobile_apikey" value="$sickbeard.FREEMOBILE_APIKEY" class="form-control input-sm input250" />
</label>
<label>
<span class="component-title">&nbsp;</span>
<span class="component-desc">Find your API Key in your customer portal.</span>
</label>
</div>
<div class="testNotification" id="testFreeMobile-result">Click below to test your settings.</div>
<input class="btn" type="button" value="Test SMS" id="testFreeMobile" />
<input type="submit" class="config_submitter btn" value="Save Changes" />
</div><!-- /content_use_freemobile //-->
</fieldset>
</div><!-- /freemobile component-group //-->
</div>

View File

@ -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());

View File

@ -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)

View File

@ -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,

View File

@ -0,0 +1,125 @@
# Author: Marvin Pinto <me@marvinp.ca>
# Author: Dennis Lutter <lad1337@gmail.com>
# Author: Aaron Bieber <deftly@gmail.com>
# 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 <http://www.gnu.org/licenses/>.
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

View File

@ -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/")
return self.redirect("/errorlogs/")