Python's driving me bonkers !!!!!
#31
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.

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.
Reply
#32
Been mulling this over and I can't come up with a good reason for this to happen. Do you have your code somewhere like github? If you can get me a copy of the addon as-is I'll test it on my end and see what I can come up with
Reply
#33
Hi Bstrdsmkr,

OK, you're going to think I'm making this up. I was using the code that N3MIS15 posted above. I swear that I tested it and repeat tested before I posted the log and it wasn't working. I was just about to reply to you and before doing so thought I'd better test one more time, and of course it's working perfectly now. So the images are being shown pretty much instantaneously to hitting the spincontrol.

Code:
21:17:08 T:4412   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
21:17:09 T:3528   DEBUG: CCurlFile::GetMimeType - http://www.peachnote.com/rest/api/v0/image?sid=IMSLP26221&w=300&page=3 -> image/png
21:17:09 T:3528   DEBUG: CFileCache::Open - opening <rest/api/v0/image> using cache
21:17:09 T:3528   DEBUG: CurlFile::Open(0BA193B0) http://www.peachnote.com/rest/api/v0/image?sid=IMSLP26221&w=300&page=3
21:17:09 T:3856  NOTICE: Thread CFileCache start, auto delete: false
21:17:10 T:3856    INFO: CFileCache::Process - Hit eof.
21:17:10 T:3856   DEBUG: Thread CFileCache 3856 terminating
21:17:10 T:3528   DEBUG: Caching image 'http://www.peachnote.com/rest/api/v0/image?sid=IMSLP26221&w=300&page=3' to '5/5261f735.jpg':
21:17:10 T:3528   DEBUG: cached image 'special://masterprofile/Thumbnails/5/5261f735.jpg' size 300x400
21:17:11 T:4412   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
21:17:12 T:3528   DEBUG: CCurlFile::GetMimeType - http://www.peachnote.com/rest/api/v0/image?sid=IMSLP26221&w=300&page=4 -> image/png
21:17:12 T:3528   DEBUG: CFileCache::Open - opening <rest/api/v0/image> using cache

So, I wonder if it was internet problems at one or other end that was causing all the inabilities to stat errors. Though I don't understand why I was able to get the images in a webpage if that was the case.

Guaranteed as soon as I post this it will stop again.
Reply
#34
lol gotta love those

Test it again with a different song and see what you get. I get the feeling it was something about the caching that wasn't working right
Reply
#35
Sorry, had to take a few days break.

So, I amended Nemisis' code so that rather than a fixed score lookup it would read the now playing track from the player :

Code:
import xbmcgui
import xbmcaddon
import re
import json
import urllib

__addon__ = xbmcaddon.Addon("script.notes")
__addonpath__    = __addon__.getAddonInfo('path')


  # get the track information  from tag
def search_term():
    full_name = xbmc.Player().getMusicInfoTag().getArtist()
    title = xbmc.Player().getMusicInfoTag().getTitle()
    search_term = full_name + " " + title
    return search_term

  # set the search url to get the image ID from Peachnote
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']
number_pages = unpacked_info['items'][0]['pageCount']
Score_URL = 'http://www.peachnote.com/rest/api/v0/image?sid=' + scoreId + '&w=300&page='

images = [Score_URL+str(x) for x in range(1, number_pages+1)]

class notesDialog(xbmcgui.WindowXMLDialog):
    def __init__(self, xmlFile, resourcePath, forceFallback=False, images=[]):
        self.images = images

    def onInit(self):
        image_panel_items = [xbmcgui.ListItem(thumbnailImage=x) for x in self.images]
        self.getControl(12000).addItems(image_panel_items)

if __name__ == '__main__':
    gui = notesDialog(
        "notes.xml",
        __addonpath__,
        images=images
    )
    gui.doModal()
    del gui

When I select a random track (not previously cached) it still struggles to immediately find and load the url page. The log below shows my paging up and down a number of times until the picture display takes. It eventually found and displayed pages 2, 3 and 4 but I gave up on page 1.

Code:
12:07:24 T:4716    INFO: XCURL::DllLibCurlGlobal::easy_aquire - Created session to http://www.peachnote.com
12:07:54 T:4716   DEBUG: CTextureCacheJob::GetImageHash - unable to stat url http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=1
12:08:08 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:08:31 T:4716   DEBUG: CTextureCacheJob::GetImageHash - unable to stat url http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=2
12:08:35 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:08:46 T:4716   DEBUG: CTextureCacheJob::GetImageHash - unable to stat url http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=3
12:08:49 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:08:58 T:744    INFO: XCURL::DllLibCurlGlobal::easy_aquire - Created session to http://www.peachnote.com
12:09:03 T:744   DEBUG: CTextureCacheJob::GetImageHash - unable to stat url http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=4
12:09:07 T:4716   DEBUG: CTextureCacheJob::GetImageHash - unable to stat url http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=3
12:09:12 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:09:17 T:744   DEBUG: CCurlFile::GetMimeType - http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=3 -> image/png
12:09:17 T:744   DEBUG: SECTION:LoadDLL(special://xbmcbin/system/ImageLib.dll)
12:09:17 T:744   DEBUG: CFileCache::Open - opening <rest/api/v0/image> using cache
12:09:17 T:744   DEBUG: CurlFile::Open(0C9C9410) http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=3
12:09:23 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:09:23 T:4528  NOTICE: Thread CFileCache start, auto delete: false
12:09:23 T:4528    INFO: CFileCache::Process - Hit eof.
12:09:24 T:744   DEBUG: Caching image 'http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=3' to '1/13191994.jpg':
12:09:24 T:744   DEBUG: cached image 'special://masterprofile/Thumbnails/1/13191994.jpg' size 300x355
12:09:24 T:4528   DEBUG: Thread CFileCache 4528 terminating
12:09:31 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:09:40 T:4716   DEBUG: CTextureCacheJob::GetImageHash - unable to stat url http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=4
12:09:45 T:4716   DEBUG: CTextureCacheJob::GetImageHash - unable to stat url http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=1
12:09:47 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:09:54 T:5056   DEBUG: SECTION:UnloadDelayed(DLL: special://xbmcbin/system/ImageLib.dll)
12:09:56 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:10:05 T:744   DEBUG: CCurlFile::GetMimeType - http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=2 -> image/png
12:10:05 T:744   DEBUG: SECTION:LoadDLL(special://xbmcbin/system/ImageLib.dll)
12:10:05 T:744   DEBUG: CFileCache::Open - opening <rest/api/v0/image> using cache
12:10:05 T:744   DEBUG: CurlFile::Open(0C9C9088) http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=2
12:10:21 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:10:28 T:3888   DEBUG: CCurlFile::GetMimeType - http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=4 -> image/png
12:10:28 T:3888   DEBUG: CFileCache::Open - opening <rest/api/v0/image> using cache
12:10:28 T:3888   DEBUG: CurlFile::Open(0C9C9410) http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=4
12:10:28 T:4524  NOTICE: Thread CFileCache start, auto delete: false
12:10:28 T:4524    INFO: CFileCache::Process - Hit eof.
12:10:28 T:3888   DEBUG: Caching image 'http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=4' to '0/0d5e4991.jpg':
12:10:28 T:3888   DEBUG: cached image 'special://masterprofile/Thumbnails/0/0d5e4991.jpg' size 300x355
12:10:28 T:4524   DEBUG: Thread CFileCache 4524 terminating
12:10:35 T:4788  NOTICE: Thread CFileCache start, auto delete: false
12:10:36 T:4788    INFO: CFileCache::Process - Hit eof.
12:10:36 T:744   DEBUG: Caching image 'http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=2' to '1/17d80423.jpg':
12:10:36 T:744   DEBUG: cached image 'special://masterprofile/Thumbnails/1/17d80423.jpg' size 300x355
12:10:36 T:4788   DEBUG: Thread CFileCache 4788 terminating
12:10:45 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:10:52 T:744   DEBUG: CImageLoader::DoWork - took 5830 ms to load special://masterprofile/Thumbnails/1/13191994.jpg
12:10:54 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:10:58 T:5056    INFO: XCURL::DllLibCurlGlobal::CheckIdle - Closing session to http://www.peachnote.com (easy=0109FDD0, multi=0012F1B0)
12:10:59 T:744   DEBUG: CImageLoader::DoWork - took 191 ms to load special://masterprofile/Thumbnails/1/17d80423.jpg
12:11:06 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
12:11:08 T:5056   DEBUG: SECTION:UnloadDelayed(DLL: special://xbmcbin/system/ImageLib.dll)
12:11:08 T:5056    INFO: XCURL::DllLibCurlGlobal::CheckIdle - Closing session to http://www.peachnote.com (easy=0991E6D8, multi=0012ED70)
12:11:11 T:744    INFO: XCURL::DllLibCurlGlobal::easy_aquire - Created session to http://www.peachnote.com
12:11:46 T:744   DEBUG: CTextureCacheJob::GetImageHash - unable to stat url http://www.peachnote.com/rest/api/v0/image?sid=IMSLP67097&w=300&page=1
12:11:48 T:5056   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick

The other odd thing I found was that one of the JSON info fields I'm calling tells me the total number of pages there should be, For some reason the number of pages shown in the spin control is always 1 fewer. So, if the total pages was 4 the spin control shows page 1 of 3. That's why I wrote the list line to add 1 to the number of pages:

Code:
images = [Score_URL+str(x) for x in range(1, number_pages+1)]
Reply
#36
the +1 thing is normal. To get a list from 1 to 10 you do range(1, 11).

no idea whats happening when the images fail to load..
Image
Reply
#37
Thanks N3MIS15, how odd! I'm sure that range leaving off one number is the same thing they do to me every pay day.
Reply

Logout Mark Read Team Forum Stats Members Help
Python's driving me bonkers !!!!!0