How do you change an already cached VideoItem icon?

How can I dynamically change a VideoItem icon image when first arg is
Hi again everyone,

Here's a summary of my current problem:

[list]

[*] If I give a stream URL (this is an hdhomerun stream url) as the first arg to VideoItem, then it plays just fine, but all attempts to change the thumb icon setting fail, due to some form of caching that appears to happen. Not only can I not change the icon dynamically, but the icon setting is fixed even across restarts, so that only removing the userdata/Thumbnails/Video directory can I get a new value.

[*] All my other non-VideoItem items uses callbacks as their first arg, and changing the icons dynamically on them works just fine. Note that all my containers have "noCache=True".

[*] If I change the first arg of VideoItem to be a callback, then I can dynamically change the icons on the VideoItem, but I cannot figure out what to return to make the stream play. Ive tried returning the stream as a string url, as a VideoItem, and a s a VideoItem wrapped in a Redirect(), and all variations seem to give the same behavior: "Error: could not determine input format". I am not sure if I am doing something wrong, or if this is causing the server to take a different code path where the hdhomerun stream urls are not being recognized.

[/list]
So I am looking for a solution to my problem by either one of these methods:

[list]

[*] Figuring out how to change the icon (get around the cache) for a VideoItem when the first arg is a stream url as a string

[*] Figuring out what to return from the VideoItem callback to get this stream to play.

[/list]
For informational purposes, I also would not mind insight into either of the following:

[list]

[*] I have see examples in the forums of the VideoItem callback returning a string, a VideoItem and a Redirect-wrapped VideoItem, so which is supposed to be right?

[*] How does the icon caching strategy work that would explain why most of my icons can dynamically change, but VideoItems cannot?

[/list]
Finally, here's some of the code snippets relevant to my problem:

Code where playing stream works, but the icon does not change:

   dir.Append( VideoItem( streamUrl,<br />
                          "%s %s" % ( L('Watch'), channel.getTitle()),<br />
                          subtitle=channel.getSubtitle(),<br />
                          summary=channel.Resolution,<br />
                          thumb=R(GetChannelImageName(channel)),<br />
                          art=R(ART)<br />
                          ))<br />




Code where changing icon works, but stream does not play (with 3 different return variations):

   dir.Append( Function(<br />
       VideoItem( PlayStreamCallback,<br />
                  "%s %s" % ( L('Watch'), channel.getTitle()),<br />
                  subtitle=channel.getSubtitle(),<br />
                  summary=channel.Resolution,<br />
                  thumb=R(GetChannelImageName(channel)),<br />
                  art=R(ART)<br />
                  ),<br />
       lineupId=lineup.getId(),<br />
       channelId=channel.getId() ))<br />
<br />
def PlayStreamCallback(sender, lineupId, channelId ):<br />
    channel = GetChannelById( lineupId, channelId )<br />
    deviceId = Prefs.Get(DEVICE_ID)<br />
    tunerId = Prefs.Get(TUNER_ID)<br />
    streamUrl = channel.getStreamUrl( deviceId, tunerId )<br />
    # Variant 1<br />
    return streamUrl<br />
    # Variant 2<br />
    return VideoItem( streamUrl, channel.getTitle() )<br />
    # Variant 3<br />
    return Redirect( VideoItem( streamUrl, channel.getTitle() ))<br />




My Plugin is 99.9% completed...and this problem is the 0.1% remaining.

Thanks for any insights.

-tony

return Redirect(streamUrl)

Hello Tony!



[list]

[]noCache=True doesn’t have anything to do with the caching of icons, it only affects the MediaContainer



[
]The correct way to return the url of a video to a VideoItem is:


return Redirect(video_url)


In case of a WebVideoItem, you need to return a WebVideoItem, like so:

return Redirect(WebVideoItem(url))



[*]To get around the icon cache issue, you can have a function that handles and returns the thumb for you. Within this function you can work with a cacheTime and set this to a low value:

<br />
...<br />
...<br />
thumb=GetThumb( GetChannelImageName(channel) ),<br />
...<br />
...<br />
<br />
def GetThumb(url, cacheTime=60):<br />
  data = HTTP.Request(url, cacheTime=cacheTime)<br />
  if data:<br />
    return DataObject(data, 'image/jpeg')<br />
  else:<br />
    return Redirect(R(ICON_DEFAULT))<br />



[/list]

Hope this helps!


Ah, a permutation I missed. Thanks for that suggestion, but unfortunately, doing this yields the same result as the others.

"Error: Could not read from input stream"

This error occurs instantaneously, not after any delay.

My only guess is that maybe I am lacking the right import for Redirect. Here are the imports in that module:


  from PMS import *<br />
  from PMS.Objects import *<br />
  from PMS.Shortcuts import *<br />


Thanks for all that info. A great help. I did not know one could set the thumb to a function. I’ll definitely give that a try.


i think the underlying root of your issue may be the R( ) that you’re wrapping the thumb in. i cant tell for sure from your code snippet, but it looks like those are external images, right? not ones you’re bundling inside the plugin?. R( ) is the shortcut for exposing the items in your plugin bundle’s resources folder.



No, these are actually packaged images in the Resources folder. The image name is just the file name with no path elements. Might I need to more fully qualify the path of the image, or will the R() function always interpret relative to the Resources folder? Is there any notion of these having an absolute path name that I could try?

I definitely do not have a great understanding of how the R() function mechanism work, so I appreciate the help.

-tony

I am seeing this on the dev pages about the Redirect() function:



Note



Redirects can currently only be used to redirect to a URL using the same protocol (i.e. HTTP). This problem will be resolved in a future version of the Plex client application.





I am not sure exactly how to interpret “using the same protocol”, but the stream urls for hdhomerun devices do not begin with http://. Could that be an issue? The redirect url protocol I am returning should be the same as what exactly? The redirect would seem to be the only thing that defines the protocol and everything else is just a callback.

no its just relative to your plugin’s resources folder, like thumb=R(‘icon-default.png’) , if you care what it does under the hood, you can dig into the framework bundle to see, its definded in Shortcuts.py as: def R(itemName): return Resource.ExternalPath(itemName) , which points to some stuff in Resource.py

I’ve tried the thumb function workaround and a few variations, but it did not work. I am also not sure if it should work for my situation.



In my case, the image is a local resource, not an external url. The dynamic control of the image is done within the Plugin code by user selection and changing the VideoItem’s thumb to a different internal thumbs image, Was this solution proposed supposed to work by having the web server that’s hosting the image dynamically change the icon (rather that the user dynamically changing the name of the image)?



I also tried to form an internal URL of the form “http://localhost:32400/video/hdhomerun/:/resources/%s”, but this did not work either.



I originally interpreted this approach as giving ‘thumb’ a callback routine, but now see I was mistaken about that, so the dynamic decision I was hoping for does not seem to be happening.




what version of plex are you on?



Version 0.8.5-f413b5

crap.

the sticky thumbs were supposed to have been fixed in .8.2, but it looks like they're stickier than i thought.

and you're probably not gonna be able to get the redirect to work if the stream urls aren't http. what are they exactly?


Ah, so does that mean my problems are just related to this 'sticky thumbs' bug rather than any specific limitation or misunderstanding of the plugin framework?

Also, my stream URLs are HDHomeRun urls (e.g., hdhomerun://-/...). They work fine if I pass them into a VideoItem directly, but seemingly are not working when they get returned via a callback to the VideoItem.

Thanks for all the help.

-tony

yeah, if im right (and i wish i wasn't) then it isnt your fault, its just plex.




thats because of this :
Redirects can currently only be used to redirect to a URL using the same protocol (i.e. HTTP).

pms communicates with plex via XML over http, so basically your redirect function is called by plex hitting a http url, which can not be redirected to anything not http and expect it to still work.

Thanks much Billy Joe. You diagnoses and explanations have been very helpful. My problem is not quite solved, but I now have a better understanding of how things work (and also how things do not work ;-), At least now I can stop beating my head against the wall and rest comfortably knowing that the solution lies in some future bug fix.



-tony


if i was to load up your plugin later to try to check into the stuck thumbs, would i be able to make the plugin work enough to reproduce the issue without owning one of these devices? and is the 0.2 on the wiki the newest code?



Yes. Everything should work except the actual playing of the streams. So you should be able to change a channel's icon and see if it is reflected. Note that the dynamic channel icon only shows for the VideoItems where playing the stream is selected. You'll still need to enter some settings first. Enter a bogus device id, and some postal code to download some channels, then go to the option to verify and edit channels. Navigate your way the toolbox options for a channel, and the first item in the list to "try" the stream should reflect the channel's icon, with the option to change the icon a few items below it.

You can find my latest code here (tar or zip file):

[http://www.cassandra.org/projects/software/plex-hdhomerun.v0.2.zip](http://www.cassandra.org/projects/software/plex-hdhomerun.v0.2.zip)

or

[http://www.cassandra.org/projects/software/plex-hdhomerun.v0.2.tgz](http://www.cassandra.org/projects/software/plex-hdhomerun.v0.2.tgz)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.