Help regarding redundant menu steps.

Hey all, quick question: 

 

A plugin I am working on requires me to load an individual url for each video to extract a youtube url.  This causes a pretty redundant level of menu hierarchy, as the user is presented with a list of videos (currently DirectoryObjects), chooses one and then is presented with an ObjectContainer containing just one VideoClipObject, which they need to press again to open a third page containing the MetadataObject returned by the built in youtube url service before they can finally play the video clip.

 

Is there anyway to skip the second step?  I have experimented with using VideoClipOjbects on the first page and trying to use a Callback() function for the "url" parameter and that didn't work properly.  I also tried returning the VideoClipObject directly, rather than an OC containing just one object.  This seemed to work ok on Plex/Web but nothing else?  Am I missing something obvious here?  Is there anyway to abstract the second page load from the user?  Ideally I can present the user with a list of VideoClipObjects and selecting one will take them directly to the MetadataObject for the youtube url.

 

Heres some code.  Hope my question makes sense!

@route(PREFIX + "/showcategory")	
def ShowCategory(title, category, page_count):
oc = ObjectContainer(title1 = title)
page_data = HTML.ElementFromURL(BASE_URL + category + "/page/" + str(page_count))

for each in page_data.xpath("//div[@id='region-main']//article[contains(@class,'post')]"):
	url = each.xpath("./a/@href")[0]
	title = each.xpath(".//img/@alt")[0]
	thumb = each.xpath(".//img/@src")[0]
	summary = each.xpath(".//p/text()")[0]
	date = each.xpath(".//span[@class='hidden-mobile meta']/text()")[1].rsplit(" | ")[1]
	
	oc.add(DirectoryObject(
		key = Callback(GetVideoObject, url = url),
		title = title,
		thumb = Resource.ContentsOfURLWithFallback(url = thumb, fallback='icon-cover.png'),
		summary = summary
		)
	)

oc.add(NextPageObject(
	key = Callback(ShowCategory, title = title, category = category, page_count = int(page_count) + 1),
	title = "More...",
	thumb = R(ICON_NEXT)
		)
	)

return oc

@route(PREFIX + “/getvideoobject”)
def GetVideoObject(url):

oc = ObjectContainer()
page_data = HTML.ElementFromURL(url)
iframe = HTML.ElementFromURL(page_data.xpath("//div[@class='article-detail-media']//iframe/@src")[0])
url = iframe.xpath("//link[@rel='canonical']/@href")[0]

oc.add(VideoClipObject(
	url = url
	))

return oc

The problem will be the large number of http requests you'd have to make in order to get all the data you need. There is a way to speed this up a little bit by using @parallelize (and @task).

The Devour channel does this and is a good example of how to make use of this: https://github.com/plexinc-plugins/Devour.bundle/blob/master/Contents/Code/__init__.py

Yeah I thought that would be the case, I've run into this problem before.  Thanks for the help, I'll try implementing @parallelize and see what load times are like.  Is there no way to do something similar to @deferred in this situation, as you would with a "PlayVideo" function in a URL service?  Delay fetching the url for a video clip object until it was asked for?

OFFTOPIC EDIT:  I also noticed when browsing your code that your specifically using a SearchDirectoryObject rather than an InputDirectoryObject (as I do) for search.  Is there any advantages to your way?  I honestly wasn't aware that even existed.

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