Ok ik heb de code aangepast (beetje afgekeken van SickRage).
Je moet onderstaande code in een bestandje genaamd boxcar.py opslaan.
Vervolgens vervang je de orginele boxcar.py door deze versie.
Het lijkt me verstandig de oude te bewaren tot je deze hebt uitgetest.
In autosub zelf moet je boxcar aanzetten en in plaats van het mailadres moet je nu het token dat je van boxcar gekregen hebt daar neer zetten.
Zoals ik al zei kan ik niet testen.
De locatie voor boxcar.py is:
/volume1/@appstore/AutoSub-BootstrapBill/autosub/notify
import logging
import autosub
import urllib, urllib2
import time
log = logging.getLogger('thelogger')
API_URL = "https://new.boxcar.io/api/notifications"
def test_notify(boxcaruser):
if not boxcaruser:
boxcaruser = autosub.BOXCARUSER
log.debug("Boxcar: Trying to send a notification.")
title = 'Auto-Sub Bootstrap Bill'
message = 'Testing Boxcar settings from Auto-Sub.'
return _send_notify(message, title, boxcaruser)
def send_notify(lang, subtitlefile, videofile, website):
log.debug("Boxcar 2: Trying to send a notification.")
title = 'Auto-Sub'
message = "Auto-Sub just downloaded the following subtitle: \n%s from %s" %(subtitlefile, website)
boxcaruser = autosub.BOXCARUSER
return _send_notify(message, title, boxcaruser)
def _send_notify(message, title, boxcaruser, subscribe=False):
# build up the URL and parameters
message = message.strip()
curUrl = API_URL
# if this is a subscription notification then act accordingly
if subscribe:
data = urllib.urlencode({'email': boxcaruser})
curUrl = curUrl + "/subscribe"
# for normal requests we need all these parameters
else:
data = urllib.urlencode({
'user_credentials': boxcaruser,
'notification[title]': title + ' : subtitle downloaded',
'notification[long_message]': message,
'notification[sound]': "notifier-2"
})
# 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'):
log.error("Boxcar: Notification failed.")
return False
else:
log.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:
log.info("Boxcar: 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 your service.
elif e.code == 401:
# If the user has already added your service, we'll return an HTTP status code of 401.
if subscribe:
log.info("Boxcar: Already subscribed to service")
return False
#HTTP status 401 if the user doesn't have the service added
else:
subscribeNote = _send_notify(message, title, boxcaruser, True)
if subscribeNote:
log.debug("Boxcar: Subscription sent")
return True
else:
log.error("Boxcar: 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:
log.error("Boxcar: Wrong data send to boxcar")
return False
log.info("Boxcar: Notification successful.")
return True
Edit: Even een te veel geplaatst forum tag uit het code deel verwijdert.