Hints for first plugin





Using a function to load thumbnails makes your plugin more responsive/faster (users can start browsing more quickly) because the thumb data is being loaded after the list has been built:

Without a function call for thumbs:
Build list -> load thumb 1 -> load thumb 2 -> load thumb 3 -> **display list**

Loading thumbs by using a function call:
Build list -> **display list** -> load thumb 1 -> load thumb 2 -> load thumb 3

Well spotted Sander, I never noticed that.



flubr: In cases like this you have two options: slow, with more meta-data (summary) or fast, with less meta-data (no summary here). I usually decide depending on how slow things feel for the particular site.


Thanks man, I sort of assumed that was the case but good to get a confirmation.


Thank you all for your help. I was already expecting some difficulties with the summary.



However, Jonny, I’m thinking of a third option!

Isn’t it possible to use a function that loads the summaries after the list is displayed, like the thumbnails function pierre proposed? The rtmpclip could also be fetched with a function so that it’s being fetched when you click on the video in the list (like you proposed). This way, I could both increase the speed AND display the summary?

I’m not 100% sure but I think the load later trick only works with thumbnails not any other meta-data. No harm in trying though I guess.


I tried this code, but unfortunately it doesn’t work. The log is never being called, and in plex all the summaries are "/video/stubru/:/function/getSummary?function_’.

Is my function call correct? I’m also not sure about the return type, but since the log isn’t called, I suppose this can’t be the problem (yet).



        	dir.Append(RTMPVideoItem(url="rtmp://vrt.flash.streampower.be:80/stubru/", clip=rtmpClip, live=False, title=title, subtitle=subtitle, summary=Function(getSummary,url=link), thumb=image))<br />
<br />
    <br />
#####################################<br />
def getSummary(url):<br />
	try:<br />
		page = HTML.ElementFromURL(url)<br />
		summar = page.xpath('//div[@class="text"]/p')[0].text_content()<br />
		Log(summar)<br />
		return str(summar)<br />
	except:		return "Failed"<br />





Btw: oops, I just see that this topic is called "tips for first plugin", I meant "hints for first plugin" (tip is the Dutch translation) is there a way to change the topic title?


Unfortunately, using a function to load summaries is not supported. I ran into the same problem with the NFB|ONF plugin so it only displays a brief summary excerpt.

Ok, thanks, it was worth trying :slight_smile:

Just changed it for you.



Jonny


Ok, thanks.



I’ve got two random questions:

  1. Is it possible to see how much a plugin gets downloaded from Plex online?
  2. I made some plugins and edited the art-default.jpg afterwards. However, the old artwork is still being showed. Do I have to remove some kind of cache? I tried deleting some caches, restarting plex, etc… but after more than a week, I still see the old artwork.


1. the Devs do have access to this info. Not sure how willing they are to share, though.

2. move everything from ~Library/App support/Plex/userdata/thumbnails/plexmediaserver to the trash

I’m writing a new plugin and I encountered a problem.



The videos are located at http://vtm.be/videozone



Since these videos are .mp4 files, I figured they should be implemented with the “VideoItem” function. (In my previous plugins, I used the RTMPVideoItem)

So this is the code I wrote:


			dir.Append(VideoItem("http://flvpd.vtm.be/vtm_od/opgekniptnieuws/2011/07/28/PTL_20110728T140811_Trailer_Night@_D.mp4", "test")) 



The URL plays fine if I open it in my browser, but if I open the link in Plex, it starts buffering and the next thing I hear sounds like a glitch, as if the sound of the whole video is played in one second. After this second, plex returns to the menu.
In the log file, I only see this, the rest seems normal: 2011-07-28 15:47:28,814 (-4f967000) : DEBUG (runtime:621) - Response: 200

Does anyone know what I'm doing wrong?

I would try to add a function with callback, something like :



dir.Append(Function(VideoItem(PlayVideo, title='Belgian Video', subtitle='With Fries, yes, please', summary='Fries and beer what else can you dream of ?', thumb=R('Mankenpiss.jpg')), url=<HTMLPAGE>)) <br />
<br />
def PlayVideo(sender, url):<br />
    #put here a function to extract the video url<br />
    #videoUrl= HTML.ElementFromURL("url" ).xpath( blah blah)<br />
    #or for testing purposes:<br />
    videoUrl = 'http://flvpd.vtm.be/vtm_od/opgekniptnieuws/2011/07/28/PTL_20110728T140811_Trailer_Night@_D.mp4'<br />
<br />
    return Redirect(videoUrl)<br />


Thanks for your help, I have implemented your suggestion but it’s still not running the way it should.

When I start a video in Plex, it starts buffering and then suddenly it stops buffering and returns to the menu.



This is my complete code:



import math, re<br />
<br />
PLUGIN_PREFIX = "/video/vtm"<br />
MEDIA = "http://vtm.be/videozone"<br />
ROOT_URL      = "http://vtm.be"<br />
<br />
TITLE = "VTM"<br />
ICON  = "icon-default.png"<br />
ART   = "art-default.jpg"<br />
<br />
####################################################################################################<br />
def Start():<br />
	Plugin.AddPrefixHandler(PLUGIN_PREFIX, MainMenu, TITLE, ICON, ART)<br />
	Plugin.AddViewGroup("InfoList", viewMode="InfoList", mediaType="items")<br />
<br />
	MediaContainer.title1 = TITLE<br />
	MediaContainer.art = R(ART)<br />
	MediaContainer.viewGroup = "InfoList"<br />
<br />
	DirectoryItem.thumb = R(ICON)<br />
	VideoItem.thumb = R(ICON)<br />
<br />
	HTTP.CacheTime = CACHE_1HOUR<br />
	HTTP.Headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'<br />
<br />
<br />
#####################################  <br />
def MainMenu():<br />
	dir = MediaContainer()<br />
	for item in HTML.ElementFromURL(MEDIA).xpath('//div[@class="subnavigation clearfix"]//a'):<br />
		title = item.text_content()<br />
		link = ROOT_URL + item.get('href')<br />
		dir.Append(Function(DirectoryItem(Videos, title=title), pageUrl=link))<br />
	return dir<br />
<br />
<br />
#####################################<br />
def Videos(sender, pageUrl):<br />
	dir = MediaContainer(title2=sender.itemTitle)<br />
	content = HTML.ElementFromURL(pageUrl, errors='ignore')<br />
	for video in content.xpath('//div[@id="videozone_items"]/div'):<br />
		try:<br />
			image = video.xpath('div[@class="video-thumb"]/img')[0].get('src')<br />
			title = video.xpath('h3[@class="videozone_title"]/a')[0].text<br />
			link = video.xpath('h3[@class="videozone_title"]/a')[0].get('href')<br />
			dir.Append(Function(VideoItem(PlayVideo, title=title, subtitle='With Fries, yes, please', summary='Fries and beer what else can you dream of ?', thumb=Function(Thumb, url=image)), link=MEDIA)) <br />
		except:<br />
			pass<br />
	return dir<br />
<br />
#####################################<br />
def PlayVideo(sender, link):<br />
#	content = HTML.ElementFromURL(link, errors='ignore')<br />
#	clips = content.xpath('//div[@id="videoplayer"]/object/param[@name="flashvars"]')[0].get('value')<br />
#	clips = clips.split('&streamer')[0]<br />
#	clips = clips.split('file=')[1]<br />
#	Log(clips)<br />
	videoUrl='http://flvpd.vtm.be/vtm_od/opgekniptnieuws/2011/07/28/PTL_20110728T140811_Trailer_Night@_D.mp4'<br />
	return Redirect(videoUrl)<br />
<br />
#####################################<br />
def Thumb(url):<br />
	try:<br />
		data = HTTP.Request(url, cacheTime=CACHE_1WEEK).content<br />
		return DataObject(data, 'image/jpeg')<br />
	except:<br />
		pass<br />
<br />
	return Redirect(R(ICON))<br />





The log file shows this:

2011-07-29 13:41:05,437 (-4faed000) : DEBUG (runtime:621) - Response: 200
2011-07-29 13:41:07,026 (-4faed000) : DEBUG (runtime:478) - Handling request GET /video/vtm/:/function/PlayVideo?function_args=Y2VyZWFsMQozCmRpY3QKZGljdApGcmFtZXdvcmsub2JqZWN0cy5JdGVtSW5mb1JlY29yZAoyCnMyMwpodHRwOi8vdnRtLmJlL3ZpZGVvem9uZXM0CmxpbmtyMgpzNgpzZW5kZXI1CnMzNApNb3NzZWxlbiBpbiBwYXBpbG90dGUgbWV0IHdpdCBiaWVyczkKaXRlbVRpdGxlczMKVlRNczYKdGl0bGUxczEyCk1lZXN0IFJlY2VudHM2CnRpdGxlMnMzOAovdmlkZW8vdnRtLzovcmVzb3VyY2VzL2FydC1kZWZhdWx0LmpwZ3MzCmFydHMyMDYKL3ZpZGVvL3Z0bS86L2Z1bmN0aW9uL1RodW1iP2Z1bmN0aW9uX2FyZ3M9WTJWeVpXRnNNUW94Q21ScFkzUUtNUXB6T1RJS2FIUjBjRG92TDNOMFlYUnBZeTUyZEcwdVltVXZjMmwwWlhNdmRuUnRMbUpsTDJacGJHVnpMMmx0WVdkbFkyRmphR1V2Wm5KdmJuUndZV2RsWDJGeWRHbHJaV3hmYlM5aGMzTmxkSE12TURBMEx6QXhNeTh3TXk1cWNHZHpNd3AxY214eU1Bb19zNQp0aHVtYnIxCnIwCg__
2011-07-29 13:41:07,026 (-4faed000) : DEBUG (runtime:703) - Calling function 'PlayVideo'
2011-07-29 13:41:07,029 (-4faed000) : DEBUG (runtime:621) - Response: 301

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