question about scraping and playing vid from page that uses flowplayer
Ok, I could use a little more help. I'd like to know how to scrape and play the video from [this page](http://tekpub.com/view/concepts/1). Also, I'd like to know how to figure it out. I may build other plugins so I want to know how to go about figuring it out for other sources.
Here is the existing code which just results in the "error while opening file" error.
The above code is scraping a page [like this](http://tekpub.com/production/concepts), which then point to the corresponding vid pages such as the example above.
I could still use help getting the seekbar right, and probably some other tweaks. but its working. I posted a sample video page link and link to the plugin at the top of this thread. Let me know if you can either help or explain how to figure out seekbar position and config.
Instead of writing your own Site Config, in this case you could also use the “default” Plex Flash player. All the info you need is in the source of the video pages (netConnectionUrl in ‘plugin’ and the url in ‘clip’):
The Site Config for this default player is already availble in Plex (so you don't have to write one yourself). Use the above url with a WebVideoItem, or use the netConnectionUrl as **url** and url as **clip** parameters in combination with [RTMPVideoItem](http://dev.plexapp.com/docs/Objects.html?highlight=rtmpvideoitem#RTMPVideoItem).
That sounds like a good idea, but how to I get those pieces of information? I’ve been comfortable using xpath for finding html info; I don’t know where to start for this though.
It’s not very common to use an xpath query to find the stuff we need in this page since it’s not really an HTML tag, but a piece of text inside a script tag. You would end up with something like this:
//script/text()[contains(., ".swf")]
but that's not very useful and it's still too much information.
These are the changes you can make to your .py file to make the videos work with the Plex Flashplayer at plexapp.com. I also added some extra tips for changes you can make.
We need to be able to use regular expressions on pieces of text. For this we import the **re** Python module:
from PMS import *<br />
from PMS.Objects import * # <-- You can delete this line<br />
from PMS.Shortcuts import * # <-- You can delete this line<br />
import re # <-- re is imported so we can use regular expressions
Since we are going to look for the video information ourself we need some extra steps.
def VideoPage(sender, titleUrl):<br />
dir = MediaContainer(title2=sender.itemTitle)<br />
dir.viewGroup = 'InfoList'<br />
content = XML.ElementFromURL(titleUrl, True)<br />
slide = content.xpath('//div[@class="column span-17"]/img')[0].get('src')<br />
idx = 0<br />
for item in content.xpath('//div[@class="item"]/h2/a'):<br />
title = item.text<br />
titleUrl = item.get('href')<br />
description = item.xpath('../../p')[idx].text<br />
<br />
# Opening the videopage at this point to find the info is going to take too much time, as we need to open pages for all the<br />
# videos in the list we're buidling here.<br />
# Instead we postpone those steps until the moment a user selects a video. For this we add an extra function that's going to<br />
# be called at the moment a user selects a video. In this example it's called "PlayVideo" (you can name it whatever you<br />
# want) and we send it the url of the video page.<br />
<br />
dir.Append(Function(WebVideoItem(PlayVideo, title=title, summary=description, thumb=R(ICON)), url=BASE_URL+titleUrl))<br />
<br />
idx = idx + 1<br />
return dir
def PlayVideo(sender, url):<br />
# Open the webpage containing the video<br />
videopage = HTTP.Request(url)<br />
<br />
# Find the two pieces of information we need in the webpage by using regular expressions<br />
# These regex things may look a bit scary at first ;)<br />
url = re.search("netConnectionUrl: '(.+?)'", videopage).group(1)<br />
clip = re.search("clip.+?url: '(.+?)'", videopage, re.DOTALL).group(1)<br />
<br />
return Redirect(RTMPVideoItem(url, clip))
That worked perfectly! I took your example exactly and pasted it just to see. Thank you very much! That completes my first ever Plex plugin. I’ll have it checked into github shortly.