YouTube VideoClipObject

Hi,

 

I'm writing a plugin for DocumentaryAddicts.com.

 

The plugin works fine, however at present I have to use a seperate page to parse the youtube url for a video item, which means you have to click inside an object and then click again to play. This is not ideal, I would prefer for the video to launch as it is. I presume this is possible, but I don't know how to do it.

def VideoList(page):
	oc = ObjectContainer()
	html = HTML.ElementFromURL(ROOT_PATH % page)
	Log(html)
	nextPage = ""
	prevPage = ""
	for row in html.xpath("//div[@class=\'pagination\']/a"):
		if (row.text.strip()=="Next Page"):
			nextPage = row.get("href")
		if (row.text.strip()=="Previous Page"):
			prevPage = row.get("href")
	if (len(prevPage)!=0):
		oc.add(DirectoryObject(key = Callback(VideoList, page = prevPage), title = "[Previous Page]"))
	for row in html.xpath('//div[@class=\'large-3 small-12 columns vidbrowse\']'):
		url = row.xpath("./div/a[1]")[0].get("href")
		title = row.xpath("./div/a[1]")[0].get("title")
		thumb = row.xpath("./div/a[1]/img")[0].get("src")
		description = row.xpath("./p[2]")[0].text
		views = row.xpath("./p[3]")[0].text
		category = row.xpath("./p[1]")[0].text
		oc.add(DirectoryObject(key = Callback(VideoPage, url=url), title=title, summary=description, thumb=Resource.ContentsOfURLWithFallback(thumb)))
	if (len(nextPage)!=0):
		oc.add(DirectoryObject(key = Callback(VideoList, page = nextPage), title = "[Next Page]"))
return oc

def VideoPage(url):
oc = ObjectContainer()
html = HTML.ElementFromURL(ROOT_PATH%url)
data = html.xpath("//div[@id=‘video’]/iframe")[0].get(“src”)
video_id = re.match(“http://www.youtube.com/embed/([^?]+)?", data).group(1)
url = “http://www.youtube.com/watch?v=%s”%video_id
title = html.xpath(”//div[@class=‘large-12 small-12 columns’]/h2/span")[0].text
description = html.xpath("//div[@class=‘text-justify’]")[0].text
rating = html.xpath("//div/strong/span/span")[0].text
oc.add(VideoClipObject(url=url, summary=description, title=title, rating=float(rating)))
return oc

I've tried a few things, such as using VideoClipObject instead of DirectoryObject using the VideoPage function as a callback, but I couldn't get this to work.

When you put a value for "url=" in a VideoClipObject, it assumes there is a Plex URL service for that url. The Plex URL service then will open that url, find the metadata, build a media object and find the location of the actual video file that plays on that page.

But there is not a URL service for Documentary Addict, so you are having to find the video on Youtube and use the YouTube URL since there is a URL service for YouTube. And trying to call on each page to find the youtube url from within the one function would just be too many http requests.

You could set up a URL service for Documentary Addict and then you would be able to put the url for the Documentary Addict page that plays the video in the url value of the VideoClipObject. It would also allow users to pull up a page the on Documentary Addict website that plays a video and use the Plexit button there to save them to their queue.

Since it does use the YouTube URL service, you would just need to call that service within your URL service for Documentary Addict. There are a few URL services that check for YouTube URLs and call that service. I did a search of the Plex Services.bundle for the word "youtube" and found these results - https://github.com/plexinc-plugins/Services.bundle/search?q=youtube&ref=cmdform. The ones for Tested and Howcast look pretty straight forward.

Aye, that is what I figured. Thanks a lot :)

Hey, just wondering if you'd share your plugin. I love DA and would love to have a plugin for it. Thx!

Hey, just wondering if you'd share your plugin. I love DA and would love to have a plugin for it. Thx!

+1 !

Check this out:

https://github.com/meriko/DocumentaryAddict.bundle

Cheers!

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