2020-04-10, 14:24
Thanks for making this add-on!!! It's exactly what I had in mind and needed. I wanted to post here though because I had to tweak the code a little bit. I have Dahua cameras, which require Digest and not basic authentication. I made a little change to the code so I can get digest authentication to work. I also changed the addon id to drivewaycam so I can have multiple cameras pop up, and added a 4 second timeout to the jpg grab. Sometimes the cameras give an HTTP 500 error, which I found out, happens if you set your quality too high.
There's a little gotcha with it too. You need to change the realm and FQDN in the add_password line to whatever your camera answers with. To get the realm, run the python script below...
Hopefully this helps some people out. I know the code isn't the greatest, but it seems to work for digest auth. Good Luck!
And here is that program you can run to grab the realm.
There's a little gotcha with it too. You need to change the realm and FQDN in the add_password line to whatever your camera answers with. To get the realm, run the python script below...
Hopefully this helps some people out. I know the code isn't the greatest, but it seems to work for digest auth. Good Luck!
Code:
--- default-orig.py 2020-04-10 07:05:01.018475968 -0500
+++ default.py 2020-04-10 07:06:22.163698273 -0500
@@ -5,7 +5,7 @@
ACTION_PREVIOUS_MENU = 10
ACTION_BACKSPACE = 110
ACTION_NAV_BACK = 92
-ADD_ON_ID = 'script.securitycam'
+ADD_ON_ID = 'script.drivewaycam'
# Set plugin variables
__addon__ = xbmcaddon.Addon()
@@ -64,7 +64,7 @@
def downloadSnapshot(self, url, destination):
log('Retreiving Image \n', xbmc.LOGDEBUG)
try:
- imgData = urllib2.urlopen(url).read()
+ imgData = urllib2.urlopen(url,timeout=4).read()
filename = snapshot = xbmc.translatePath( os.path.join( destination, 'snapshot' + str(time.time()) + '.jpg' ).encode("utf-8") ).decode("utf-8")
output = open(filename,'wb')
log('Saving Image To: [' + filename + ']\n', xbmc.LOGDEBUG)
@@ -95,11 +95,9 @@
# Add Basic Authentication Headers
if (username is not None and username != ''):
- passwordManager = urllib2.HTTPPasswordMgrWithDefaultRealm()
- passwordManager.add_password(None, url, username, password)
- authhandler = urllib2.HTTPBasicAuthHandler(passwordManager)
- opener = urllib2.build_opener(authhandler)
- urllib2.install_opener(opener)
+ ah = urllib2.HTTPDigestAuthHandler()
+ ah.add_password('Login to <some random code>', 'http://driveway.foo.bar/', username, password)
+ urllib2.install_opener(urllib2.build_opener(ah))
# Replace URL agruments
argCount = len(sys.argv)
And here is that program you can run to grab the realm.
Code:
#!/usr/bin/python
import os,urllib2
theurl = "http://driveway.foo.bar/cgi-bin/snapshot.cgi?0"
req = urllib2.Request(theurl)
try:
handle = urllib2.urlopen(req)
except IOError, e:
if hasattr(e, 'code'):
if e.code != 401:
print 'We got another error'
print e.code
else:
print e.headers
print e.headers['www-authenticate']