File “/Users/flubr/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/bases.py”, line 142, in
getitem = lambda x, y: x.getitem(y),
IndexError: list index out of range
<br />
def EenVideos(sender, pageUrl):<br />
dir = MediaContainer(title2=sender.itemTitle)<br />
content = HTML.ElementFromURL(pageUrl, errors='ignore')<br />
for video in content.xpath('//div[@id="videoArea"]/div/ul/li'):<br />
image = video.xpath("a/img")[0].get('src')<br />
title = video.xpath("h5/a")[0].text<br />
title = title.split(" - ")[1]<br />
link = video.xpath("h5/a")[0].get('href')<br />
link = ROOT_URL + link<br />
Log(link)<br />
<br />
content2 = HTML.ElementFromURL(link)<br />
summary = content2.xpath("//div[@id='videoZoneContainer']/div/p/a")[0].text<br />
rtmpClip = content2.xpath('//div[@class="jw-player"]//param[@name="flashvars"]')[0].get('value')<br />
Log(rtmpClip)<br />
<br />
dir.Append(RTMPVideoItem(url="rtmp://vrt.flash.streampower.be/een", clip="2011/02/ogom_110216_huisdokter_Website_EEN", width=640, height=360, live=False, title=title, summary=summary, thumb=image))<br />
<br />
return dir<br />
with e.g.:
pageUrl = [http://www.een.be/mediatheek/tag/168](http://www.een.be/mediatheek/tag/168)
link = [http://www.een.be/mediatheek/405910](http://www.een.be/mediatheek/405910)
My firefox xpath tools still gives this:
[size=2]So it seems that the xpath in plex doesn't return anything? How can this be?[/size]
try doing a Log(HTTP.Request(pageUrl).content) at the beginning of your function and see if the HTML code that plex sees is the same as what a browser would see. Not entirely sure the javascript snippets are executed in Plex…
I was able to extract the RTMP clip from the java script. In some cases I get redirected to the wrong video, but I think this is an error in the site’s source code since these wrong redirections also occur in my browser. I sent an email to the webmaster and hope it will be resolved
BTW, in the meanwhile I adapted the “deredactie.be” (news) plugin from Sander. I made the “Sporza” (sports news) plugin from it and submitted it for the app store. It’s also on the “unsupported plugins” page.
<br />
<div class="text"><br />
<p><strong>Tomas liet zich vandaag inspireren door de indrukwekkende speech van Khaddafi om al zijn eisen duidelijk te maken aan het volk.</strong></p><br />
<p>Het staat vast dat kolonel Tomas niet zal wijken voor opstandige burgers en dat er erg repressieve maatregelen zullen volgen wanneer zijn wensen niet worden vervuld. </p><br />
</div><br />
However the "strong" part causes some trouble I think. The "strong" parts only make the text bold. This isn't necessary in plex, so I was wondering if anyone knew a way to just extract all the text. Sometimes one word in the middle of the text is made "strong", so the structure isn't fixed.
Thanks in advance!
File “/Users/flubr/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/bases.py”, line 142, in
getitem = lambda x, y: x.getitem(y),
IndexError: list index out of range
Normally I should get a list of videos. The rtmpclips are being fetched from some pages. But sometimes one of these pages doesn’t contain a video (error in the website construction), which results in the error message above. The result is that none of the videos are displayed in the list (e.g. if 14 videos have been fetched correctly but one failed because there’s an error on the site, none of the 15 videos are displayed in the list)
The plugin is quite slow since there is a lot of data to be fetched. I can extract a list with URLs. These URLs redirect me to new pages that contain the rtmpClips. So this means that if I want to list of 15 videos, Plex has to go through 15 pages to fetch all the rtmpclips. Is there a way to do this faster? e.g. by fetching the rtmpClip when you open a video from the list?
For the first problem, check the length of the xpath return before using it
<br />
result = inhoud.xpath('//div[@class="embed"]/script[@type="text/javascript"]')<br />
if len(result) > 0:<br />
rtmpClip = result[0].text <br />
For the second, you need to use a video redirect function. Logically what happens is that instead of extracting the rtmp clip URL in the original page you delegate that to a function that gets called when the video item is selected. The PBS plugin uses this approach
See line 138 for how to use it and 151 on for the function that is called (obviously you'll have to replace the logic in this function by your own to extract the rtmp clip URL).
@pierre: Thanks for your suggestion, but I don’t think this is the problem since it’s also slow when I don’t load any images. The problem is that every time the loop is being executed, another URL is being opened.
@Jonny Wray: Thanks, your solution for the first question seemed to solve the issue. I’ll try to implement your second solution when I’ve got time. I’ll let you know if it worked (but I suppose it will).
Sorry, I just reread my message from earlier and it does not make any sense at all !! I was trying to type it on my iphone with autocorrect on, trying to conceal it from the wife who is starting to hate the fact that I spend so much time on the forum !!!
Well I usually get something along the lines of ‘you talking to your Plex boyfriends again’.
flubr: the solution I posted is exactly to solve that problem of hitting another URL within a loop. It’s a common issue so there’s a general solution. Shouldn’t be too hard, just move your rtmp clip extraction code to another function.
I’ve actually wondered about that but keep forgetting to ask. With thumbnails you do actually need the URL content (the image) in the list, so what does using the Function approach do? Load them in parallel in an asynchronous manner, or does it load when you visit that list item (but then you need multiple images in a list)?
I’ve actually never used this approach for thumbs in my plugins so have never quite understood what it actually does.
In most cases it’s faster and makes sense to find/build the final url to a video in a “PlayVideo” function that gets executed when a user clicks a certain item. Usually this is done for speed, as the opening of additional pages is only done when it’s needed.
However, by looking at this piece of code that was posted above, it doesn’t matter when the final video url is build, because the HTML page that is used for the summary also contains the video info:
for video in content.xpath('//div[@id="content-middle"]//ul/li/div//div[@class="content-inner"]'):<br />
image = video.xpath('div/div/div/div[@class="field-item odd"]/a/img')[0].get('src')<br />
title = video.xpath("div[2]/h2/a")[0].text<br />
subtitle = video.xpath('div[2]/div[@class="info"]/span')[0].text<br />
link = ROOT_URL + video.xpath("div[2]/h2/a")[0].get('href')<br />
# Log(HTTP.Request(link).content) <br />
<br />
inhoud = HTML.ElementFromURL(link) ### <-- Open the webpage containing the info we want,...<br />
summary = inhoud.xpath('//div[@class="text"]/p')[0].text_content() ### <-- ...extract the summary text...<br />
rtmpClip = inhoud.xpath('//div[@class="embed"]/script[@type="text/javascript"]')[0].text ### <-- ...and lets grab the video info too while we are here<br />
rtmpClip = rtmpClip.split('.flv"')[0]<br />
rtmpClip = rtmpClip.split('file: "')[1]<br />
# Log(rtmpClip)<br />