2013-05-08, 16:15
So this is a really bad combination of wild fumbling in the dark and a refusal to give in, but I did some random testing last night, which may help people far cleverer than me understand what may be going on.
The fact that I couldn't get N3MIS15's script to work and the error message in my log lead me to believe it's a caching problem as suggested by Bstrdsmkr. So to test I searched my textures.db for any reference to the URL I'm calling from and deleted them, along with the associated jpgs in my thumbnail folder.
I then reduced my script to a simple format that calls the URL with a page number defined in the doInit call.
I then ran the script calling page 1 as above. First time around nothing happens, so I run again. Again nothing, Run a third time. Each time I get the message back:
Finally, on the 8th attempt there's still no picture, but the log says:
A new textures.db item now pops up and a new jpg is created in my thumbnails folder called 001acdaa.jpg.
I now go back and run the script again and sure enough the image appears and the log says:
So I change the page call number to 2 and go through the same process, but even after a bazillion attempts nothing.
So, I delete the entry in textures.db and the saved jpg, and try again. However many times I try I can't get page 2 to load.
I exited XBMC restarted and tried all over again. Finally, on about the 12th attempt I get:
A new entry in textures.db pops up with a new thumbnail d1e37599.jpg.
Sure enough next time I run the script page 2 pops up on screen.
The full logs are first run, where success happens on line 2062 and second run where the page is finally stored on line 1415.
I can't see a pattern as to when or why a call will finally succeed. Just to confirm that when I paste any page number into a browser it pops up with no delay at all. Maybe someone else can understand what's happening and ultimately explain.
Thanks
Errr, mainly it's because that's how all the examples and tutorials I've been following do it (sheep not wolf). But I also thought if the code started getting complicated as you start adding if statements, loops, etc, you were supposed to break it up into smaller pieces.
The fact that I couldn't get N3MIS15's script to work and the error message in my log lead me to believe it's a caching problem as suggested by Bstrdsmkr. So to test I searched my textures.db for any reference to the URL I'm calling from and deleted them, along with the associated jpgs in my thumbnail folder.
I then reduced my script to a simple format that calls the URL with a page number defined in the doInit call.
Code:
# Import Libraries
import urllib
import xbmcaddon
import xbmcgui
import json
import xbmc
import re
# Used to identify the path from Addon.xml to save temp items in userdata\addondata folder
__addon__ = xbmcaddon.Addon()
__addonid__ = __addon__.getAddonInfo('id') #should be script.scores
__cwd__ = xbmc.translatePath(__addon__.getAddonInfo('path')).decode("utf-8")
__profile__ = xbmc.translatePath(__addon__.getAddonInfo('profile')).decode("utf-8")
__language__ = __addon__.getLocalizedString
# get the track information from tag
def search_term():
full_name = xbmc.Player().getMusicInfoTag().getArtist()
list_name = re.sub("[^\w]", " ", full_name).split()
last_name = list_name[-1]
composition = xbmc.Player().getMusicInfoTag().getAlbum()
title = xbmc.Player().getMusicInfoTag().getTitle()
search_term = full_name + " " + title + " " + composition
return search_term
def locate_image(*args):
Metadata_URL = 'http://www.peachnote.com/rest/api/v0/scoreSearchMeta?app_id=49a5ba91&app_key=d31dde72176c31c2fe25bafca534cd01&limit=1&q=' + search_term()
response = urllib.urlopen(Metadata_URL)
Metadata = response.read()
response.close()
unpacked_info = json.loads(Metadata)
scoreId = unpacked_info['items'][0]['scoreId']
total_pages = unpacked_info['items'][0]['pageCount']
for i in args:
page = i
Image_URL = 'http://www.peachnote.com/rest/api/v0/image?sid=' + scoreId + '&page=' + str(page) + '&w=300'
print ('Image URL is ', Image_URL)
return Image_URL, total_pages, page
class MyClass(xbmcgui.Window):
def __init__( self ):
self.addControl (xbmcgui.ControlImage(5, 10, 500, 650, locate_image(2)[0]))
my_win = MyClass()
my_win.doModal()
my_win.show()
I then ran the script calling page 1 as above. First time around nothing happens, so I run again. Again nothing, Run a third time. Each time I get the message back:
Code:
CTextureCacheJob::GetImageHash - unable to stat url http://www.peachnote.com/rest/api/v0/image?sid=IMSLP49966&page=1&w=300
Finally, on the 8th attempt there's still no picture, but the log says:
Code:
CCurlFile::GetMimeType - http://www.peachnote.com/rest/api/v0/image?sid=IMSLP49966&page=1&w=300 -> image/png
SECTION:LoadDLL(special://xbmcbin/system/ImageLib.dll)
CFileCache::Open - opening <rest/api/v0/image> using cache
DEBUG: CurlFile::Open(0A9FF678) http://www.peachnote.com/rest/api/v0/image?sid=IMSLP49966&page=1&w=300
A new textures.db item now pops up and a new jpg is created in my thumbnails folder called 001acdaa.jpg.
I now go back and run the script again and sure enough the image appears and the log says:
Code:
CImageLoader::DoWork - took 190 ms to load special://masterprofile/Thumbnails/0/001acdaa.jpg
So I change the page call number to 2 and go through the same process, but even after a bazillion attempts nothing.
Code:
INFO: XCURL::DllLibCurlGlobal::easy_aquire - Created session to http://www.peachnote.com
.......
DEBUG: CTextureCacheJob::GetImageHash - unable to stat url http://www.peachnote.com/rest/api/v0/image?sid=IMSLP49966&page=2&w=300
So, I delete the entry in textures.db and the saved jpg, and try again. However many times I try I can't get page 2 to load.
I exited XBMC restarted and tried all over again. Finally, on about the 12th attempt I get:
Code:
CCurlFile::GetMimeType - http://www.peachnote.com/rest/api/v0/image?sid=IMSLP49966&page=2&w=300 -> image/png
SECTION:LoadDLL(special://xbmcbin/system/ImageLib.dll)
CFileCache::Open - opening <rest/api/v0/image> using cache
CurlFile::Open(0B0175B0) http://www.peachnote.com/rest/api/v0/image?sid=IMSLP49966&page=2&w=300
A new entry in textures.db pops up with a new thumbnail d1e37599.jpg.
Sure enough next time I run the script page 2 pops up on screen.
The full logs are first run, where success happens on line 2062 and second run where the page is finally stored on line 1415.
I can't see a pattern as to when or why a call will finally succeed. Just to confirm that when I paste any page number into a browser it pops up with no delay at all. Maybe someone else can understand what's happening and ultimately explain.
Thanks
(2013-05-08, 14:35)Bstrdsmkr Wrote: Is there any particular reason you want to use a custom class? You could just add the rest of the controls you need to my working code snippet
Errr, mainly it's because that's how all the examples and tutorials I've been following do it (sheep not wolf). But I also thought if the code started getting complicated as you start adding if statements, loops, etc, you were supposed to break it up into smaller pieces.