mirror of
https://github.com/rembo10/headphones.git
synced 2026-08-17 05:31:08 +01:00
Merge remote-tracking branch 'daktak/master' into develop
This commit is contained in:
@@ -737,6 +737,22 @@
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<h3>Boxcar.IO</h3>
|
||||
<div class="row checkbox">
|
||||
<input type="checkbox" name="boxcar_enabled" id="boxcar" value="1" ${config['boxcar_enabled']} /><label>Enable Boxcar.IO</label>
|
||||
</div>
|
||||
<div id="boxcaroptions">
|
||||
<div class="row">
|
||||
<div class="row checkbox">
|
||||
<input type="checkbox" name="boxcar_onsnatch" value="1" ${config['boxcar_onsnatch']} /><label>Notify on snatch?</label>
|
||||
</div>
|
||||
<label>Boxcar Username (email)</label>
|
||||
<input type="text" name="boxcar_username" value="${config['boxcar_username']}" size="30">
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<h3>Pushbullet</h3>
|
||||
<div class="row checkbox">
|
||||
@@ -1427,6 +1443,26 @@
|
||||
$("#pushbulletoptions").hide();
|
||||
}
|
||||
|
||||
if ($("#boxcar").is(":checked"))
|
||||
{
|
||||
$("#boxcaroptions").show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#boxcaroptions").hide();
|
||||
}
|
||||
|
||||
$("#boxcar").click(function(){
|
||||
if ($("#boxcar").is(":checked"))
|
||||
{
|
||||
$("#boxcaroptions").slideDown();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#boxcaroptions").slideUp();
|
||||
}
|
||||
});
|
||||
|
||||
$("#pushbullet").click(function(){
|
||||
if ($("#pushbullet").is(":checked"))
|
||||
{
|
||||
|
||||
@@ -258,6 +258,10 @@ PUSHOVER_PRIORITY = 1
|
||||
PUSHOVER_KEYS = None
|
||||
PUSHOVER_ONSNATCH = True
|
||||
PUSHOVER_APITOKEN = None
|
||||
BOXCAR_ENABLED = False
|
||||
BOXCAR_USERNAME = None
|
||||
BOXCAR_ONSNATCH = False
|
||||
|
||||
PUSHBULLET_ENABLED = True
|
||||
PUSHBULLET_APIKEY = None
|
||||
PUSHBULLET_DEVICEID = None
|
||||
@@ -347,6 +351,7 @@ def initialize():
|
||||
MUSIC_ENCODER, ADVANCEDENCODER, ENCODEROUTPUTFORMAT, ENCODERQUALITY, ENCODERVBRCBR, ENCODERLOSSLESS, ENCODER_MULTICORE, ENCODER_MULTICORE_COUNT, DELETE_LOSSLESS_FILES, \
|
||||
GROWL_ENABLED, GROWL_HOST, GROWL_PASSWORD, GROWL_ONSNATCH, PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, PUSHOVER_ENABLED, PUSHOVER_PRIORITY, PUSHOVER_KEYS, PUSHOVER_ONSNATCH, PUSHOVER_APITOKEN, MIRRORLIST, \
|
||||
TWITTER_ENABLED, TWITTER_ONSNATCH, TWITTER_USERNAME, TWITTER_PASSWORD, TWITTER_PREFIX, \
|
||||
BOXCAR_ENABLED, BOXCAR_USERNAME, BOXCAR_ONSNATCH, \
|
||||
PUSHBULLET_ENABLED, PUSHBULLET_APIKEY, PUSHBULLET_DEVICEID, PUSHBULLET_ONSNATCH, \
|
||||
MIRROR, CUSTOMHOST, CUSTOMPORT, CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, \
|
||||
XBMC_NOTIFY, LMS_ENABLED, LMS_HOST, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, SYNOINDEX_ENABLED, ALBUM_COMPLETION_PCT, PREFERRED_BITRATE_HIGH_BUFFER, \
|
||||
@@ -596,6 +601,10 @@ def initialize():
|
||||
PUSHOVER_PRIORITY = check_setting_int(CFG, 'Pushover', 'pushover_priority', 0)
|
||||
PUSHOVER_APITOKEN = check_setting_str(CFG, 'Pushover', 'pushover_apitoken', '')
|
||||
|
||||
BOXCAR_ENABLED = bool(check_setting_int(CFG, 'BOXCAR', 'boxcar_enabled', 0))
|
||||
BOXCAR_USERNAME = check_setting_str(CFG, 'BOXCAR', 'boxcar_username', '')
|
||||
BOXCAR_ONSNATCH = bool(check_setting_int(CFG, 'BOXCAR', 'boxcar_onsnatch', 0))
|
||||
|
||||
PUSHBULLET_ENABLED = bool(check_setting_int(CFG, 'PushBullet', 'pushbullet_enabled', 0))
|
||||
PUSHBULLET_APIKEY = check_setting_str(CFG, 'PushBullet', 'pushbullet_apikey', '')
|
||||
PUSHBULLET_DEVICEID = check_setting_str(CFG, 'PushBullet', 'pushbullet_deviceid', '')
|
||||
@@ -1009,6 +1018,11 @@ def config_write():
|
||||
new_config['Pushover']['pushover_priority'] = int(PUSHOVER_PRIORITY)
|
||||
new_config['Pushover']['pushover_apitoken'] = PUSHOVER_APITOKEN
|
||||
|
||||
new_config['BOXCAR'] = {}
|
||||
new_config['BOXCAR']['boxcar_enabled'] = int(BOXCAR_ENABLED)
|
||||
new_config['BOXCAR']['boxcar_username'] = BOXCAR_USERNAME
|
||||
new_config['BOXCAR']['boxcar_onsnatch'] = int(BOXCAR_ONSNATCH)
|
||||
|
||||
new_config['PushBullet'] = {}
|
||||
new_config['PushBullet']['pushbullet_enabled'] = int(PUSHBULLET_ENABLED)
|
||||
new_config['PushBullet']['pushbullet_apikey'] = PUSHBULLET_APIKEY
|
||||
|
||||
@@ -22,6 +22,7 @@ import simplejson
|
||||
import os.path
|
||||
import subprocess
|
||||
import gntp.notifier
|
||||
import time
|
||||
|
||||
from xml.dom import minidom
|
||||
from httplib import HTTPSConnection
|
||||
@@ -694,3 +695,117 @@ class TwitterNotifier:
|
||||
return self._send_tweet(prefix+": "+message)
|
||||
|
||||
notifier = TwitterNotifier
|
||||
|
||||
API_URL = "https://boxcar.io/devices/providers/WqbewHpV8ZATnawpCsr4/notifications"
|
||||
|
||||
class BOXCAR:
|
||||
|
||||
def test_notify(self, email, title="Test"):
|
||||
return self._sendBoxcar("This is a test notification from Headphones", title, email)
|
||||
|
||||
def _sendBoxcar(self, msg, title, email, subscribe=False):
|
||||
"""
|
||||
Sends a boxcar notification to the address provided
|
||||
|
||||
msg: The message to send (unicode)
|
||||
title: The title of the message
|
||||
email: The email address to send the message to (or to subscribe with)
|
||||
subscribe: If true then instead of sending a message this function will send a subscription notificat$
|
||||
|
||||
returns: True if the message succeeded, False otherwise
|
||||
"""
|
||||
|
||||
# build up the URL and parameters
|
||||
msg = msg.strip()
|
||||
curUrl = API_URL
|
||||
# if this is a subscription notification then act accordingly
|
||||
if subscribe:
|
||||
data = urllib.urlencode({'email': email})
|
||||
curUrl = curUrl + "/subscribe"
|
||||
# for normal requests we need all these parameters
|
||||
else:
|
||||
data = urllib.urlencode({
|
||||
'email': email,
|
||||
'notification[from_screen_name]': title,
|
||||
'notification[message]': msg.encode('utf-8'),
|
||||
'notification[from_remote_service_id]': int(time.time())
|
||||
})
|
||||
|
||||
logger.info(data)
|
||||
# send the request to boxcar
|
||||
try:
|
||||
req = urllib2.Request(curUrl)
|
||||
handle = urllib2.urlopen(req, data)
|
||||
handle.close()
|
||||
|
||||
except urllib2.URLError, e:
|
||||
# if we get an error back that doesn't have an error code then who knows what's really happening
|
||||
if not hasattr(e, 'code'):
|
||||
logger.error("Boxcar notification failed." + ex(e))
|
||||
return False
|
||||
else:
|
||||
logger.error("Boxcar notification failed. Error code: " + str(e.code))
|
||||
|
||||
# HTTP status 404 if the provided email address isn't a Boxcar user.
|
||||
if e.code == 404:
|
||||
logger.error("Username is wrong/not a boxcar email. Boxcar will send an email to it")
|
||||
return False
|
||||
|
||||
# For HTTP status code 401's, it is because you are passing in either an invalid token, or the user has not added$
|
||||
elif e.code == 401:
|
||||
|
||||
# If the user has already added your service, we'll return an HTTP status code of 401.
|
||||
if subscribe:
|
||||
logger.error("Already subscribed to service")
|
||||
# i dont know if this is true or false ... its neither but i also dont know how we got here in the first $
|
||||
return False
|
||||
|
||||
#HTTP status 401 if the user doesn't have the service added
|
||||
else:
|
||||
subscribeNote = self._sendBoxcar(msg, title, email, True)
|
||||
if subscribeNote:
|
||||
logger.info("Subscription send")
|
||||
return True
|
||||
else:
|
||||
logger.info("Subscription could not be send")
|
||||
return False
|
||||
|
||||
# If you receive an HTTP status code of 400, it is because you failed to send the proper parameters
|
||||
elif e.code == 400:
|
||||
logger.info("Wrong data sent to boxcar")
|
||||
logger.info('data:' + data)
|
||||
return False
|
||||
|
||||
logger.fdebug("Boxcar notification successful.")
|
||||
return True
|
||||
|
||||
def notify(self, artist=None, album=None, snatched_nzb=None, username=None, force=False):
|
||||
"""
|
||||
Sends a boxcar notification based on the provided info or SB config
|
||||
|
||||
title: The title of the notification to send
|
||||
message: The message string to send
|
||||
username: The username to send the notification to (optional, defaults to the username in the config)
|
||||
force: If True then the notification will be sent even if Boxcar is disabled in the config
|
||||
"""
|
||||
if not headphones.BOXCAR_ENABLED and not force:
|
||||
logger.fdebug("Notification for Boxcar not enabled, skipping this notification")
|
||||
return False
|
||||
|
||||
# if no username was given then use the one from the config
|
||||
if not username:
|
||||
username = headphones.BOXCAR_USERNAME
|
||||
|
||||
if snatched_nzb:
|
||||
title = "Headphones. Sucessfully Snatched!"
|
||||
message = u"Headphones has snatched: " + snatched_nzb + " and has sent it to SABnzbd+"
|
||||
else:
|
||||
title = "Headphones. Successfully Downloaded & Post-Processed!"
|
||||
message = u"Headphones has downloaded and postprocessed: " + artist + ' [' + album + ']'
|
||||
|
||||
logger.info("Sending notification to Boxcar")
|
||||
|
||||
self._sendBoxcar(message, title, username)
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -458,6 +458,12 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list,
|
||||
pushover = notifiers.PUSHOVER()
|
||||
pushover.notify(pushmessage,"Headphones")
|
||||
|
||||
if headphones.BOXCAR_ENABLED:
|
||||
pushmessage = release['ArtistName'] + ' - ' + release['AlbumTitle']
|
||||
logger.info(u"Boxcar request")
|
||||
boxcar = notifiers.BOXCAR()
|
||||
boxcar.notify(artist=release['ArtistName'], album=release['AlbumTitle'])
|
||||
|
||||
if headphones.PUSHBULLET_ENABLED:
|
||||
pushmessage = release['ArtistName'] + ' - ' + release['AlbumTitle']
|
||||
logger.info(u"PushBullet request")
|
||||
@@ -1122,4 +1128,4 @@ def forcePostProcess(dir=None, expand_subfolders=True, album_dir=None):
|
||||
else:
|
||||
logger.info('No match found on MusicBrainz for: %s - %s', name, album)
|
||||
|
||||
| ||||