Jump to content


Photo

Picture From Url


  • Please log in to reply
4 replies to this topic

#1 cmg

cmg

    X-S Enthusiast

  • Members
  • 20 posts

Posted 26 January 2008 - 05:06 AM

So I am experienced developing for XBMC in Python, but have just recently discovered that XBMC can handle plug-ins in addition to standard scripts. I am writing a Pictures script. I am providing XBMC with a valid URL for the picture using addDirectoryItem, but it just freezes when I try to show the picture.

Can anyone tell me if XMBC can show a picture from a URL like it would with a video or audio file?

Thanks!

#2 nuka1195

nuka1195

    X-S Expert

  • Members
  • PipPipPip
  • 639 posts

Posted 26 January 2008 - 05:17 AM

yes it can, but there are issues with xbmc_pc.exe. is that what you're testing on?

#3 cmg

cmg

    X-S Enthusiast

  • Members
  • 20 posts

Posted 26 January 2008 - 05:55 AM

Yes I am testing in xbmc_pc.exe, but I get the same problem on the real xbox too.

Are there any samples of plugins for pictures from URLs? I can't find ANY plugins for pictures.

#4 nuka1195

nuka1195

    X-S Expert

  • Members
  • PipPipPip
  • 639 posts

Posted 26 January 2008 - 06:58 PM

post the code and i'll have a look.

#5 cmg

cmg

    X-S Enthusiast

  • Members
  • 20 posts

Posted 26 January 2008 - 11:43 PM

Here it is. It is a work in progress, so it is messy:

from __future__ import division
import xbmc, xbmcgui, xbmcplugin
import urllib2, urllib
import sys
import shutil
import os

dlg = xbmcgui.Dialog()
searchTerm = ""
URL = ""
images = []
dp = xbmcgui.DialogProgress()

dlg.ok("",sys.argv[2][1:len(sys.argv[2])])

if (sys.argv[0]=="plugin://pictures/Google Images/"):
keyboard = xbmc.Keyboard("","Enter search term...")
keyboard.doModal()
searchTerm = urllib.quote(keyboard.getText())
URL = "http://images.google...m/images?as_q=" + searchTerm
images = []
req = urllib2.Request(URL)
req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)')
sock = urllib2.urlopen(req)
html = sock.read()
sock.close()
startTag = "dyn.Img("
endTag = ");"
start = html.find(startTag)
while start > -1:
start = start + len(startTag)
end = html.find(");",start)
data = html[start:end]
parsedData = data.split(",")
images.append(parsedData)
currentpos = end
start = html.find(startTag, currentpos)
imgcount=0
for image in images:
imageLabel = ""
for i in range(6,11):
dataElement = image[i].strip('"')
dataElement = dataElement.replace("<b>","")
dataElement = dataElement.replace("</b>","")
dataElement = dataElement.replace("<B>","")
dataElement = dataElement.replace("</B>","")
if len(dataElement) > 0:
if len(imageLabel) > 0:
imageLabel = imageLabel + " - "
imageLabel = imageLabel + dataElement
thumbFile = urllib.urlretrieve("http://tbn0.google.c.../images?q=tbn:" + image[2].strip('"') + image[3].strip('"'))
ok = xbmcplugin.addDirectoryItem(int(sys.argv[1]), "plugin://pictures/Google Images/" + image[3].strip('"'), xbmcgui.ListItem(imageLabel, thumbnailImage=thumbFile[0], iconImage=thumbFile[0]), True, len(images))
imgcount=imgcount+1
xbmcplugin.endOfDirectory(int(sys.argv[1]))





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users