spiff Wrote:currently not possible to mix images and other media.
I noticed, and then, I worked around it, with the help from __y
What I ended up doing is using the built-in execute of the Slideshow thanks to __y !
So the addon currently downloads the images to a temporary folder, then does initiate the slideshow.
For those interested, here is a some of the source:
This will Launch it - I used mode 4
Code:
elif mode==4:
screenshots = common.get_screenshots(url)
directory = xbmc.translatePath(os.path.join('special://profile/addon_data/plugin.video.xxx/', 'cache'))
common.Generate_Slideshow(screenshots)
xbmc.executebuiltin("XBMC.SlideShow(" + directory + ")")
from my common.py
Code:
def get_screenshots(url):
UAS = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 ( .NET CLR 3.5.30729; .NET4.0C)'
req = urllib2.Request(url)
req.add_header('User-Agent', UAS)
response = urllib2.urlopen(req)
html=response.read()
response.close()
html = html.replace("\n", "")
html = html.replace("\r", "")
# Cache Folder Preparation - automatically deletes it
folder = xbmc.translatePath(os.path.join('special://profile/addon_data/plugin.video.xxx/', 'cache'))
if os.path.isdir(folder)==False:
os.makedirs(folder)
for the_file in os.listdir(folder):
file_path = xbmc.translatePath(os.path.join(folder, the_file))
if os.path.isfile(file_path):
os.unlink(file_path)
#regex it
regex = '<a href="#" onclick="openimagepopup.+?;return false;"><img src="(.+?)".+?</a>'
images = re.compile(regex).findall(html)
screenshots = []
if len(images) > 0:
total = len(images)
for image in images:
screenshots.append(image)
else:
print "Error"
return "ERROR"
return screenshots
Slideshow Generator Function:
Code:
def Generate_Slideshow(screenshots):
global pDialog
name = "JESUS"
pDialog = xbmcgui.DialogProgress()
dia_title = "Getting Image(s)"
dia_l1 = name
ret = pDialog.create(dia_title, dia_l1)
current_item = 0
total = len(screenshots)
for image in screenshots:
current_item = current_item + 1
name = image.replace('blahblah', '')
thumbnail = image
filename = xbmc.translatePath(os.path.join('special://profile/addon_data/plugin.video.xxx/', 'cache', name))
print "Filename: " + str(filename)
print "URL: " + str(screenshot)
img_download(filename, screenshot, current_item, total)
return
And the image downloader:
Code:
def img_download(fname,url,current_item,total):
from urllib2 import Request, urlopen, URLError, HTTPError
req = Request(url)
try:
global pDialog
percent = (float(current_item) / float(total)) * float(100)
name = url.replace('xxx', '')
pDialog.update(int(percent), name)
f = urlopen(req)
local_file = open(fname, "wb")
local_file.write(f.read())
local_file.close()
except HTTPError, e:
print "HTTP Error:",e.code , url
except URLError, e:
print "URL Error:",e.reason , url
return
Its simple and straight forward imho - I don't do any error checking as of yet, whether I returned error or a list (Array), but that shouldnt be too hard