Live webcam viewer?
#1
hey i've been trying to make a script that views live webcam images from the internet with no luck. i'm a complete newbie to python.

i found this code on this forum and have been trying to get it to work, but when i try to run it nothing happens at all:

Quote:import urllib
import xbmc
import xbmcgui

action_menu = 10
root_dir = "q:\\scripts\\cache\\"
url_webcam = 'http://www.tcomeng.com/webcams/emeraldhills.jpg'

class webcam(xbmcgui.window):
def (self):
imgpath = root_dir + 'webcam.jpg'
loc = urllib.urlopener()
loc.retrieve(url_webcam, imgpath)
self.addcontrol(xbmcgui.controlimage(100, 100, 0, 0, imgpath))

def onaction(self, action):
if action == action_menu:
self.close()

win = webcam()
win.domodal()
del win

can anyone help me fix this? all i want is for the image to download and display every x seconds!
- mike
Reply
#2
self.addcontrol(xbmcgui.controlimage(100, 100, 0, 0, imgpath))
i never try this !
controlimage parameters are (x, y, w, h, picfile)
where
x=horizontal position
y= vertical position
w=width of the pic
h=height of the pic
picfile= the path+name of the pic

w and h are set to 0... it may be the problem !
Reply
#3
first of all do what solexalex said, it's an "obvious" problem Smile

if that didn't solve your problem, try to transfer the saved webcam.jpg to your computer and open it - or just try to open it in xbmc's picture viewer. if it doesn't view correctly, or there is no such file, there is something wrong in the image-fetching code.
xbmcscripts.com administrator
Reply
#4
changed the image code, still didn't do anything. it's like the script "crashes", i try to run it, and it says "running" for a split second and then stops.

it doesn't even get to the point of downloading the image, so there must be something really wrong in the code to stop it like that! what could be wrong?

all the other scripts i have run perfectly fine :\

ps i'm also using the newest version of xbmc!
Reply
#5
may be a stupid question but have you created the "cache" folder

and it may be smart to use "try"
i'm using this in my phyton script
if self.downloadurl(webfile[0],localfile) == 'ok':
self.pic1 = xbmcgui.controlimage(int(60*self.scalex),int(260*self.scaley),133,200, 'q:\\scripts\\filmweb\\cover_temp1.jpg')
else:
self.pic1 = xbmcgui.controlimage(int(60*self.scalex),int(260*self.scaley),133,200, 'q:\\scripts\\filmweb\\cover_temp2.jpg')



def downloadurl(self,source, destination):
try:
loc = urllib.urlopener()
loc.retrieve(source, destination)
return 'ok'
except:
return 'feil'
Reply
#6
yep, the cache folder exists!

tried using your code in my script, still doesn't even execute. i dunno why, it's driving me crazy.

Quote:import urllib
import xbmc
import xbmcgui

action_menu = 10
root_dir = "q:\\scripts\\cache\\"
url_webcam = 'http://www.tcomeng.com/webcams/emeraldhills.jpg'

class webcam(xbmcgui.window):
def (self):
imgpath = root_dir + 'webcam.jpg'

if self.downloadurl(url_webcam, imgpath) == 'ok':

self.addcontrol(xbmcgui.controlimage(100, 100, 100, 100, imgpath))

def downloadurl(self,source, destination):
try:
loc = urllib.urlopener()
loc.retrieve(source, destination)
return 'ok'
except:
return 'feil'


def onaction(self, action):
if action == action_menu:
self.close()

win = webcam()
win.domodal()
del win

is there a way to log what goes wrong when i try to run it? i don't see anything wrong with the code i'm using...

btw, does using tabs or spaces matter?
thanks!!!
Reply
#7
edit your xboxmediacenter.xml to find the things about log...
set log on 0 to log as many things as possible
then restart xbmc, launch the script (crash !Wink
then open you log file (xbmc.log in the install dir of xbmc)

of course you wrote underscoreunderscoreinitunderscoreunderscore(self)  as your first def ?
---
arf... fucking forum ! some chars are forbidden or what !!grrrr
Reply
#8
are you sure you have internet connection?

did you install the python libraries?
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#9
holy shiot, it works!!!
thanks guys! this is pretty awesome!

now all i have to do is make the image fullscreen and stuff, but i already know how to do that!!

now... does anyone know how to add a timer so that the image is refreshed every 30 seconds?
Reply
#10
i was playing around with this script trying to modify it for my own uses when i came across a problem.
the script works fine for jpg's but not to well for gif's.
when substituting the url for a .gif the script downloads the picture fine but hangs on displaying it with this error in the logs

07-03-2005 22:07:38 error exception in capplication::render()

i have successfully view the file using myfiles and mypictures within xbmc but the script itself cannot display it.

does the librarys with this python only support jpg's?
is there any work arounds eg download the files then change their format to jpg's?

this problem has been hounding me on and off for months.
Reply
#11
i have rendered a gif file fine. so perhaps something is missing in your xbmc install?
but i took a gif that was localy saved.
perhaps that gif you wanted to display didn't download correctly (don't see why, but atleast you now know that gifs works in phyton gui)
Reply
#12
after some searching it seems that it may have trouble with some type of gif's. this one has a transparent background which is also a pain. this is one of the images im having trouble with

http://seabreeze.com.au/images/forecast/2/sydn.gif

thanks for your feedback. i will do some more testing/converting to see what can be done.
Reply
#13
Quote:now... does anyone know how to add a timer so that the image is refreshed every 30 seconds?
yes ! i know
in fact it is pretty simple :
you make a loop
while 1:
#do your stuff to dl and show the pic
time.sleep(30) #wait 30secs

but big problem... you can't quit !
so you have to find a way to do what you want while something else is doing the job to refresh...
so you'll have to use threading.
it will be difficult to explain how to make it work... try by yourself , watch for examples on internet : threading module
if you can't make it, ask me and i'll do my best to help you...

---

gif troubles :
yes, not all gif types work with python... you can see your pic inside xbmc but can't make it displaying on you python scripts... maybe pil library is the clue (python imaging library)


---

no interest ... :
i visited sydney a couple of years ago ! i loved this city and i love australia :d
Reply
#14
for a thread example you can look at this script which contains a clock:

http://www.radioparanoia.com/tvguide_nor.zip

i think the basic thread example there should fit your needs pretty good. remember the end loop thing in onaction or else the script will lock up as the thread wasn't idle when tried ended. if there is a problem just ask away...
xbmcscripts.com administrator
Reply
#15
before i can even get the timer started, it looks like i can't even refresh the webcam image by pushing the a button!

Quote:import urllib
import xbmc
import xbmcgui

action_menu = 10
action_refresh = 7
root_dir = "q:\\scripts\\cache\\"
url_webcam = 'http://www.katkam.ca/pix/pic.jpg'

class webcam(xbmcgui.window):
def (self):

self.scalex = ( float(self.getwidth()) / float(720) )
self.scaley = ( float(self.getheight()) / float(480) )
self.fullwidth = int(720)
self.fullheight = int(480)

imgpath = root_dir + 'webcam.jpg'
self.displaypic(url_webcam, imgpath)



def downloadurl(self, source, destination):
try:
loc = urllib.urlopener()
loc.retrieve(source, destination)
return 'ok'
except:
return 'feil'

def displaypic(self, source, destination):
if self.downloadurl(source, destination) == 'ok':
self.addcontrol(xbmcgui.controlimage(int((self.getwidth()-self.fullwidth)/2),int((self.getheight()-self.fullheight)/2), self.fullwidth, self.fullheight, destination, '0xffff3300'))



def onaction(self, action):
if action == action_menu:
self.close()
elif action == action_refresh:
self.displaypic(url_webcam, imgpath)

win = webcam()
win.domodal()
del win


i guess i can't call self.displaypic(url_webcam, imgpath) more than once. i press the a button while the script is running, and nothing happens. i exit the script, and run it again, the webcam image has changed!

i'm guessing that the same image object is being called so that the image on the screen isn't updated with the new downloaded copy or something!

how do i fix this, anyone know?

btw, thanks everyone for all your help with this!! it'll be one badass script whenever it gets working :p
Reply

Logout Mark Read Team Forum Stats Members Help
Live webcam viewer?0