I'm writing a channel that returns a list of TV shows which I would like to display the appropriate thumbnails. I can scrape the page to get the images, but I think this would probably timeout making too many HTTP requests.
Some of the shows returned may already be in my library, so the metadata will already be downloaded, however I believe the API does not allow channels to query/access the library/metadata. Ideally I would like to pass the API a string of the show name and have it return an object if it exists or go look it up with an available agent (theTVdb) if not.
Assuming I will have to grab the metadata myself what is the best way to proceed as I shouldn't be issuing HTTP requests when building a container? Some kind of async callback? Really long cache times?
Asynchronous callbacks are allowed for thumbs but not other metadata. If you require an extra (or a couple extra) http requests to grab images, that's no big deal. The common usage provides a fallback to the channel icon if the request for the thumb image fails for some reason.
thumb = Resource.ContentsOfURLWithFallback(url=image_url, fallback="icon-default.jpg")
If you need to make one or more http requests to get the "image_url", you can create your own thumb callback instead.
thumb = Callback(GetThumb, url=showlist_url, title=show)
...
def GetThumb(url, title):
...
''' find the actual image_url '''
return Redirect(image_url)
Those sorts of callbacks won't work for other metadata but, as long as you have the title (and perhaps a summary), you should be ok for a list of a bunch of different shows or episodes. Ideally, you'll have more metadata available for follow-up requests but that's another topic.