2013-12-15, 15:58
Link to the full log. What version of xbmc are you using?
00:38:55 T:5928 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <class 'socket.timeout'>
Error Contents: timed out
Traceback (most recent call last):
File "C:\Users\User\AppData\Roaming\XBMC\addons\script.securitycam\default.py", line 61, in <module>
urllib.urlretrieve(url, __snapshot__)
File "C:\Program Files\XBMC\system\python\Lib\urllib.py", line 93, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "C:\Program Files\XBMC\system\python\Lib\urllib.py", line 267, in retrieve
block = fp.read(bs)
File "C:\Program Files\XBMC\system\python\Lib\socket.py", line 377, in read
data = self._sock.recv(left)
timeout: timed out
-->End of Python script error report<--
(2013-11-21, 05:21)edrikk Wrote: I've made a bunch of modifications to the script, which I'm posting below. Python isn't my first (or second, or third, or fourth) language, so please excuse if things aren't as tight as they could/should be. Some changes:
- Accept parameter for cameraID and cameraName. Use case: I call this from BlueIris, which results in XBMC pulling a stream from BlueIris based on the camID.
- The existing image refresh didn't work for me (Window 8, on Gotham). So I made each image pulled have a unique name
- Cleanup the contents of the temp directory after it's done
- urlretrieve didn't work on my pc for some reason. So I switched out to urlopen
- Corrected some paths for images etc.
Code:# Import the XBMC/XBMCGUI modules.
import xbmc, xbmcgui, time, urllib2, xbmcvfs, xbmcaddon, os, glob
__addon__ = xbmcaddon.Addon()
__addonid__ = __addon__.getAddonInfo('id')
#############
#Grab (/ set default) parameters
#############
args = ['CamID','CamName']
dbvar = {'CamID': 'cam1',
'CamName': 'Camera 1'}
for item in sys.argv:
arg = item.split('=')
i = arg[0]
if arg[0] in args:
j = arg[1]
dbvar.update({arg[0]:arg[1]})
#############
# Global Vars
#############
url='http://IPADDRESS/image/'+str(dbvar['CamID'])
path = xbmc.translatePath('special://profile/addon_data/%s' % __addonid__)
imagefile_template = os.path.join(path, 'camera_'+str(dbvar['CamID'])+'_image')
imagefile_ext = '.jpg'
imagefile = imagefile_template+imagefile_ext
video_length = 14
notification_length = 13800
#############
#If path to temp files doesn't exist, create it
#############
if not xbmcvfs.exists(path):
xbmcvfs.mkdir(path)
####################################################################################
#Retrieves a file from a given URL
####################################################################################
def getFile(file_name,file_mode,base_url):
#create the url and the request
req = urllib2.Request(base_url)
# Open the url
try:
f = urllib2.urlopen(req)
# Open our local file for writing
local_file = open(file_name, "wb" + file_mode)
#Write to our local file
local_file.write(f.read())
local_file.close()
f.close()
del local_file
del f
#handle errors
except urllib2.HTTPError, e:
print "HTTP Error:",e.code , url
f.close()
del local_file
del f
except urllib2.URLError, e:
print "URL Error:",e.reason , url
f.close()
del local_file
del f
####################################################################################
#Deletes all files matching the mask that we have created in this call of the script
####################################################################################
def delFiles():
del_mask = imagefile_template+'*'+imagefile_ext
for del_filename in glob.glob(del_mask) :
os.remove( del_filename )
####################################################################################
#Main class and function
####################################################################################
class CamView(xbmcgui.WindowDialog):
def __init__(self):
#set the initial image before the window is shown
imagefile = imagefile_template+imagefile_ext
getFile(imagefile,"",url)
self.image = xbmcgui.ControlImage(870, 383, 380, 253, "")
self.addControl(self.image)
viewer = CamView()
viewer.show()
start_time = time.time()
firstimage = True
while(time.time() - start_time <= video_length):
curr_time = round(time.time() - start_time, 0)
imagefile = imagefile_template+'_'+str(curr_time)+imagefile_ext
getFile(imagefile,"",url)
viewer.image.setImage("")
viewer.image.setImage(imagefile)
if firstimage:
nowtime=time.strftime("%I:%M %p")
xoptions="Notification(\"IP Camera "+str(dbvar['CamName'])+" alert\",%s, notification_length, special://home/addons/script.doorbell/bell_icon.png)" % (nowtime)
xbmc.executebuiltin(xoptions)
viewer.image.setAnimations([('conditional', 'effect=fade start=0 end=90 time=250 delay=125 condition=true',), ('conditional', 'effect=slide start=0,400 end=0,0 time=250 condition=true',)])
firstimage = False
elif curr_time == video_length:
viewer.image.setAnimations([('conditional', 'effect=fade start=90 end=90 time=0 condition=true',), ('conditional', 'effect=slide start=0,0 end=0,400 time=250 condition=true',)])
#print "catch"
else:
viewer.image.setAnimations([('conditional', 'effect=fade start=90 end=90 time=0 condition=true',)])
#print curr_time
xbmc.sleep(500)
viewer.close()
delFiles()
del viewer
while((time.time() - startTime) * 1000 <= duration):
urllib.urlretrieve(url, __snapshot__)
camPreview.update(__snapshot__)
xbmc.sleep(interval)
camPreview.update(__snapshot__)
xbmc.sleep(15000)
# Import the modules
import xbmc, xbmcgui, time, urllib2, xbmcvfs, xbmcaddon, os, urlparse
# Set plugin variables
__addon__ = xbmcaddon.Addon()
__cwd__ = __addon__.getAddonInfo('path').decode("utf-8")
__resource__ = xbmc.translatePath( os.path.join( __cwd__, 'resources' ).encode("utf-8") ).decode("utf-8")
__icon__ = xbmc.translatePath( os.path.join( __cwd__, 'resources', 'media', 'icon.png' ).encode("utf-8") ).decode("utf-8")
__snapshot__ = xbmc.translatePath( os.path.join( __cwd__, 'resources', 'media', 'temp.jpg' ).encode("utf-8") ).decode("utf-8")
# Get settings
url = __addon__.getSetting('url')
username = __addon__.getSetting('username')
password = __addon__.getSetting('password')
width = int(float(__addon__.getSetting('width')))
height = int(float(__addon__.getSetting('height')))
interval = int(float(__addon__.getSetting('interval')))
duration = int(float(__addon__.getSetting('duration')) * 1000)
# Inject username / password into url
if (username is None):
urlObject = urlparse(url)
urlObject.username = username
urlObject.password = password
url = urlunparse(urlObject)
# Methods
def notify():
xbmc.executebuiltin('Notification(%s, %s, %d, %s)'%('SecurityCam', time.strftime("%I:%M %p"), duration, __icon__))
# Classes
class CamPreviewDialog(xbmcgui.WindowDialog):
def __init__(self):
COORD_GRID_WIDTH = 1280
COORD_GRID_HEIGHT = 720
scaledWidth = int(float(COORD_GRID_WIDTH) / self.getWidth() * width)
scaledHeight = int(float(COORD_GRID_HEIGHT) / self.getHeight() * height)
self.image = xbmcgui.ControlImage(COORD_GRID_WIDTH - scaledWidth, COORD_GRID_HEIGHT - scaledHeight, scaledWidth, scaledHeight, "")
self.addControl(self.image)
self.image.setAnimations([('WindowOpen', 'effect=slide start=%d time=1000 tween=cubic easing=in'%(scaledWidth),), ('WindowClose', 'effect=slide end=%d time=1000 tween=cubic easing=in'%(scaledWidth),)])
def update(self, image):
self.image.setImage("")
self.image.setImage(image)
def getFile(file_name,file_mode,base_url):
#create the url and the request
req = urllib2.Request(base_url)
# Open the url
try:
f = urllib2.urlopen(req)
# Open our local file for writing
local_file = open(file_name, "wb" + file_mode)
#Write to our local file
local_file.write(f.read())
local_file.close()
f.close()
del local_file
del f
#handle errors
except urllib2.HTTPError, e:
print "HTTP Error:",e.code , url
f.close()
del local_file
del f
except urllib2.URLError, e:
print "URL Error:",e.reason , url
f.close()
del local_file
del f
# Main execution
camPreview = CamPreviewDialog()
notify()
camPreview.show()
startTime = time.time()
while((time.time() - startTime) * 1000 <= duration):
getFile(__snapshot__,"",url)
camPreview.image.setImage("")
camPreview.image.setImage(__snapshot__)
camPreview.update(__snapshot__)
xbmc.sleep(interval)
camPreview.close()
del camPreview
os.remove(__snapshot__)
(2013-11-21, 05:21)edrikk Wrote: I've made a bunch of modifications to the script, which I'm posting below. Python isn't my first (or second, or third, or fourth) language, so please excuse if things aren't as tight as they could/should be. Some changes:
- Accept parameter for cameraID and cameraName. Use case: I call this from BlueIris, which results in XBMC pulling a stream from BlueIris based on the camID.
- The existing image refresh didn't work for me (Window 8, on Gotham). So I made each image pulled have a unique name
- Cleanup the contents of the temp directory after it's done
- urlretrieve didn't work on my pc for some reason. So I switched out to urlopen
- Corrected some paths for images etc.
Code:# Import the XBMC/XBMCGUI modules.
import xbmc, xbmcgui, time, urllib2, xbmcvfs, xbmcaddon, os, glob
__addon__ = xbmcaddon.Addon()
__addonid__ = __addon__.getAddonInfo('id')
#############
#Grab (/ set default) parameters
#############
args = ['CamID','CamName']
dbvar = {'CamID': 'cam1',
'CamName': 'Camera 1'}
for item in sys.argv:
arg = item.split('=')
i = arg[0]
if arg[0] in args:
j = arg[1]
dbvar.update({arg[0]:arg[1]})
#############
# Global Vars
#############
url='http://IPADDRESS/image/'+str(dbvar['CamID'])
path = xbmc.translatePath('special://profile/addon_data/%s' % __addonid__)
imagefile_template = os.path.join(path, 'camera_'+str(dbvar['CamID'])+'_image')
imagefile_ext = '.jpg'
imagefile = imagefile_template+imagefile_ext
video_length = 14
notification_length = 13800
#############
#If path to temp files doesn't exist, create it
#############
if not xbmcvfs.exists(path):
xbmcvfs.mkdir(path)
####################################################################################
#Retrieves a file from a given URL
####################################################################################
def getFile(file_name,file_mode,base_url):
#create the url and the request
req = urllib2.Request(base_url)
# Open the url
try:
f = urllib2.urlopen(req)
# Open our local file for writing
local_file = open(file_name, "wb" + file_mode)
#Write to our local file
local_file.write(f.read())
local_file.close()
f.close()
del local_file
del f
#handle errors
except urllib2.HTTPError, e:
print "HTTP Error:",e.code , url
f.close()
del local_file
del f
except urllib2.URLError, e:
print "URL Error:",e.reason , url
f.close()
del local_file
del f
####################################################################################
#Deletes all files matching the mask that we have created in this call of the script
####################################################################################
def delFiles():
del_mask = imagefile_template+'*'+imagefile_ext
for del_filename in glob.glob(del_mask) :
os.remove( del_filename )
####################################################################################
#Main class and function
####################################################################################
class CamView(xbmcgui.WindowDialog):
def __init__(self):
#set the initial image before the window is shown
imagefile = imagefile_template+imagefile_ext
getFile(imagefile,"",url)
self.image = xbmcgui.ControlImage(870, 383, 380, 253, "")
self.addControl(self.image)
viewer = CamView()
viewer.show()
start_time = time.time()
firstimage = True
while(time.time() - start_time <= video_length):
curr_time = round(time.time() - start_time, 0)
imagefile = imagefile_template+'_'+str(curr_time)+imagefile_ext
getFile(imagefile,"",url)
viewer.image.setImage("")
viewer.image.setImage(imagefile)
if firstimage:
nowtime=time.strftime("%I:%M %p")
xoptions="Notification(\"IP Camera "+str(dbvar['CamName'])+" alert\",%s, notification_length, special://home/addons/script.doorbell/bell_icon.png)" % (nowtime)
xbmc.executebuiltin(xoptions)
viewer.image.setAnimations([('conditional', 'effect=fade start=0 end=90 time=250 delay=125 condition=true',), ('conditional', 'effect=slide start=0,400 end=0,0 time=250 condition=true',)])
firstimage = False
elif curr_time == video_length:
viewer.image.setAnimations([('conditional', 'effect=fade start=90 end=90 time=0 condition=true',), ('conditional', 'effect=slide start=0,0 end=0,400 time=250 condition=true',)])
#print "catch"
else:
viewer.image.setAnimations([('conditional', 'effect=fade start=90 end=90 time=0 condition=true',)])
#print curr_time
xbmc.sleep(500)
viewer.close()
delFiles()
del viewer
# Import the modules
import xbmc, xbmcgui, time, urllib2, xbmcvfs, xbmcaddon, os, urlparse
# Grab (and set default) parameters
args = ['CamID','CamName']
dbvar = {'CamID': 'FrontDoor',
'CamName': 'Front Door'}
for item in sys.argv:
arg = item.split('=')
i = arg[0]
if arg[0] in args:
j = arg[1]
dbvar.update({arg[0]:arg[1]})
# Set plugin variables
__addon__ = xbmcaddon.Addon()
__cwd__ = __addon__.getAddonInfo('path').decode("utf-8")
__resource__ = xbmc.translatePath( os.path.join( __cwd__, 'resources' ).encode("utf-8") ).decode("utf-8")
__icon__ = xbmc.translatePath( os.path.join( __cwd__, 'resources', 'media', 'icon.png' ).encode("utf-8") ).decode("utf-8")
__snapshot__ = xbmc.translatePath( os.path.join( __cwd__, 'resources', 'media', 'temp.jpg' ).encode("utf-8") ).decode("utf-8")
# Get settings
base_url = __addon__.getSetting('url')
url = base_url+str(dbvar['CamID'])
username = __addon__.getSetting('username')
password = __addon__.getSetting('password')
width = int(float(__addon__.getSetting('width')))
height = int(float(__addon__.getSetting('height')))
interval = int(float(__addon__.getSetting('interval')))
duration = int(float(__addon__.getSetting('duration')) * 1000)
# Inject username / password into url
if (username is None):
urlObject = urlparse(url)
urlObject.username = username
urlObject.password = password
url = urlunparse(urlObject)
# Methods
def notify():
xbmc.executebuiltin('Notification(%s, %s, %s, %d, %s)'%('SecurityCam', str(dbvar['CamName']), time.strftime("%I:%M %p"), duration, __icon__))
def getFile(file_name,file_mode,base_url):
#create the url and the request
req = urllib2.Request(base_url)
# Open the url
try:
f = urllib2.urlopen(req)
# Open our local file for writing
local_file = open(file_name, "wb" + file_mode)
#Write to our local file
local_file.write(f.read())
local_file.close()
f.close()
del local_file
del f
#handle errors
except urllib2.HTTPError, e:
print "HTTP Error:",e.code , url
f.close()
del local_file
del f
except urllib2.URLError, e:
print "URL Error:",e.reason , url
f.close()
del local_file
del f
# Classes
class CamPreviewDialog(xbmcgui.WindowDialog):
def __init__(self):
COORD_GRID_WIDTH = 1280
COORD_GRID_HEIGHT = 720
scaledWidth = int(float(COORD_GRID_WIDTH) / self.getWidth() * width)
scaledHeight = int(float(COORD_GRID_HEIGHT) / self.getHeight() * height)
self.image = xbmcgui.ControlImage(COORD_GRID_WIDTH - scaledWidth, COORD_GRID_HEIGHT - scaledHeight, scaledWidth, scaledHeight, "")
self.addControl(self.image)
#self.image.setAnimations([('WindowOpen', 'effect=slide start=%d time=1000 tween=cubic easing=in'%(scaledWidth),), ('WindowClose', 'effect=slide end=%d time=1000 tween=cubic easing=in'%(scaledWidth),)])
def update(self, image):
self.image.setImage("")
self.image.setImage(image)
# Main execution
camPreview = CamPreviewDialog()
notify()
camPreview.show()
firstimage = True
startTime = time.time()
while((time.time() - startTime) * 1000 <= duration):
curr_time = round(time.time() - startTime, 0)
getFile(__snapshot__,"",url)
camPreview.image.setImage("")
camPreview.image.setImage(__snapshot__)
if firstimage:
nowtime=time.strftime("%I:%M %p")
camPreview.image.setAnimations([('conditional', 'effect=fade start=0 end=90 time=250 delay=125 condition=true',), ('conditional', 'effect=slide start=0,400 end=0,0 time=250 condition=true',)])
firstimage = False
elif curr_time == duration:
camPreview.image.setAnimations([('conditional', 'effect=fade start=90 end=90 time=0 condition=true',), ('conditional', 'effect=slide start=0,0 end=0,400 time=250 condition=true',)])
else:
camPreview.image.setAnimations([('conditional', 'effect=fade start=90 end=90 time=0 condition=true',)])
camPreview.update(__snapshot__)
xbmc.sleep(interval)
camPreview.close()
del camPreview
os.remove(__snapshot__)
http://XBMCIPAddress:Port/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Addons.ExecuteAddon","params":{"addonid":"script.securitycam","params":{"CamID":"BlueIris_Cam_Short-Name","CamName":"Camera_Name"}}}
(2013-12-15, 10:06)lokipoki Wrote:(2013-12-04, 23:18)iolaus Wrote:(2013-12-04, 10:30)lokipoki Wrote: Hi.
Thanks for your reply. My bad. Of course you have to use a forward slash. What was I thinking
I changed it and got this:
Code:19:28:01 T:4924 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.EOFError'>
Error Contents: EOF when reading a line
Traceback (most recent call last):
File "C:\Users\Loki\AppData\Roaming\XBMC\addons\script.securitycam\default.py", line 61, in <module>
urllib.urlretrieve(url, __snapshot__)
File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib.py", line 93, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib.py", line 239, in retrieve
fp = self.open(url, data)
File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib.py", line 207, in open
return getattr(self, name)(url)
File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib.py", line 457, in open_https
return self.http_error(url, fp, errcode, errmsg, headers)
File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib.py", line 375, in http_error
result = method(url, fp, errcode, errmsg, headers)
File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib.py", line 690, in http_error_401
return getattr(self,name)(url, realm)
File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib.py", line 767, in retry_https_basic_auth
user, passwd = self.get_user_passwd(host, realm, i)
File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib.py", line 783, in get_user_passwd
user, passwd = self.prompt_user_passwd(host, realm)
File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib.py", line 792, in prompt_user_passwd
host))
EOFError: EOF when reading a line
-->End of Python script error report<--
19:28:01 T:200 DEBUG: ------ Window Deinit () ------
19:28:01 T:200 DEBUG: ------ Window Init (DialogKaiToast.xml) ------
19:28:01 T:4924 INFO: Python script stopped
19:28:01 T:4924 DEBUG: Thread XBPyThread 4924 terminating
19:28:01 T:200 DEBUG: waiting for python thread 13 (C:\Users\Loki\AppData\Roaming\XBMC\addons\script.securitycam\default.py) to stop
19:28:01 T:200 DEBUG: python thread 13 (C:\Users\Loki\AppData\Roaming\XBMC\addons\script.securitycam\default.py) destructed
Cheers mate.
The Error Type: <type 'exceptions.EOFError'> makes me think that the code was unable to retrieve the image from the provided URL for some reason.
I just noticed the line that I haven`t posted. It goes just in front of the log I posted:
Code:19:00:41 T:5992 ERROR: Control has invalid animation type (no condition or no type)
I tried every combination:
https://10.1.1.50:90/image.jpg
https://10.1.1.50:90/image.jpg
http://10.1.1.50/image.jpg
http://10.1.1.50:90/image.jpg
I do get an image if I just type in a browser but dont get the script to run
Anyone any ideas?!
Cheers.
Quote:Ok, I found the mistake.
DCS 5020L:
Under Maintenance>Admin>DISABLE Snapshot URL Authentication.
What about audio stream?!
(2013-12-18, 16:25)CodeSmoke Wrote:Quote:Ok, I found the mistake.
DCS 5020L:
Under Maintenance>Admin>DISABLE Snapshot URL Authentication.
What about audio stream?!
No audio, this just takes snapshot images from your camera and makes it look like a video by updating about 2 images a second.
(2013-12-19, 10:30)lokipoki Wrote:(2013-12-18, 16:25)CodeSmoke Wrote:Quote:Ok, I found the mistake.
DCS 5020L:
Under Maintenance>Admin>DISABLE Snapshot URL Authentication.
What about audio stream?!
No audio, this just takes snapshot images from your camera and makes it look like a video by updating about 2 images a second.
I know. I thought there would be a way to stream the audio as well.
Also is there a way to start that script from Eventghost?
Cheers.
http://XBMCIPAddress:Port/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Addons.ExecuteAddon","params":{"addonid":"script.securitycam","params":{"CamID":"BlueIris_Cam_Short-Name","CamName":"Camera_Name"}}}
(2013-12-19, 15:05)CodeSmoke Wrote:(2013-12-19, 10:30)lokipoki Wrote: [quote='CodeSmoke' pid='1576758' dateline='1387376724']
No audio, this just takes snapshot images from your camera and makes it look like a video by updating about 2 images a second.
I know. I thought there would be a way to stream the audio as well.
Also is there a way to start that script from Eventghost?
Cheers.
http://XBMCIPAddress:Port/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Addons.ExecuteAddon","params":{"addonid":"script.securitycam","params":{"CamID":"BlueIris_Cam_Short-Name","CamName":"Camera_Name"}}}
(2013-12-24, 20:40)iolaus Wrote: Here is the latest version of my script.
I added an option for whether you want the image to auto-close after a specified duration or just stay open.