Only one xpath result

Hi,



The code below works fine in plex, the only problem is that only one result is shown in plex after I parse the content from break.com into plex.



How is it possible that only one items shows up instead of all the twelve items that are available on the website?



# -*- coding: utf-8 -*-<br />
from PMS import *<br />
from PMS.Objects import *<br />
from PMS.Shortcuts import *<br />
<br />
VIDEO_TITLE = 'Break.com'<br />
VIDEO_PREFIX = '/video/break'<br />
BREAK_ROOT = 'http://www.break.com'<br />
BREAK_NEWEST = 'http://www.break.com/videos/newest/'<br />
BREAK_MVDAILY = 'http://www.break.com/videos/most-viewed-daily/'<br />
BREAK_MVWEEKLY = 'http://www.break.com/videos/most-viewed-weekly/'<br />
BREAK_MVMONTHLY = 'http://www.break.com/videos/most-viewed-monthly/'<br />
BREAK_MVALLTIME = 'http://www.break.com/videos/most-viewed/'<br />
BREAK_TRDAILY = 'http://www.break.com/videos/top-rated-daily/'<br />
BREAK_TRWEEKLY = 'http://www.break.com/videos/top-rated-weekly/'<br />
BREAK_TRMONTHLY = 'http://www.break.com/videos/top-rated-monthly/'<br />
BREAK_TRALLTIME = 'http://www.break.com/videos/top-rated/'<br />
BREAK_MDDAILY = 'http://www.break.com/videos/most-discussed-daily/'<br />
BREAK_MDWEEKLY = 'http://www.break.com/videos/most-discussed-weekly/'<br />
BREAK_MDMONTHLY = 'http://www.break.com/videos/most-discussed-monthly/'<br />
BREAK_MDALLTIME = 'http://www.break.com/videos/most-discussed/'<br />
BREAK_MSDAILY = 'http://www.break.com/videos/most-shared-daily/'<br />
BREAK_MSWEEKLY = 'http://www.break.com/videos/most-shared-weekly/'<br />
BREAK_MSMONTHLY = 'http://www.break.com/videos/most-shared-monthly/'<br />
BREAK_MSALLTIME = 'http://www.break.com/videos/most-shared/'<br />
<br />
XPATH_VIDEOS = "//div[@class='cat-cnt-item-th']"<br />
<br />
ART           = 'art-back.png'<br />
ICON          = 'icon-main.png'<br />
<br />
<br />
####################################################################################################<br />
<br />
def Start():<br />
<br />
    Plugin.AddPrefixHandler(VIDEO_PREFIX, MainMenu, "Break.com", ICON, ART)<br />
<br />
    Plugin.AddViewGroup("InfoList", viewMode="InfoList", mediaType="items")<br />
    Plugin.AddViewGroup("List", viewMode="List", mediaType="items")<br />
<br />
    MediaContainer.art = R('art-default.png')<br />
    MediaContainer.title1 = "BREAK Videos"<br />
    DirectoryItem.thumb = R('icon-default.png')<br />
<br />
####################################################################################################<br />
<br />
def MainMenu():<br />
    <br />
    dir = MediaContainer(viewGroup="InfoList")<br />
<br />
    dir.Append(Function(DirectoryItem(Video, "Newest",thumb=R(ICON),art=R(ART)), url=BREAK_NEWEST))<br />
 <br />
    dir.Append(Function(DirectoryItem(Video, "Most Viewed - Daily",thumb=R(ICON),art=R(ART)), url=BREAK_MVDAILY))<br />
    dir.Append(Function(DirectoryItem(Video, "Most Viewed - Weekly",thumb=R(ICON),art=R(ART)), url=BREAK_MVWEEKLY))<br />
    dir.Append(Function(DirectoryItem(Video, "Most Viewed - Monthly",thumb=R(ICON),art=R(ART)), url=BREAK_MVMONTHLY))<br />
    dir.Append(Function(DirectoryItem(Video, "Most Viewed - All Time",thumb=R(ICON),art=R(ART)), url=BREAK_MVALLTIME))<br />
<br />
    dir.Append(Function(DirectoryItem(Video, "Top Rated - Daily",thumb=R(ICON),art=R(ART)), url=BREAK_TRDAILY))<br />
    dir.Append(Function(DirectoryItem(Video, "Top Rated - Weekly",thumb=R(ICON),art=R(ART)), url=BREAK_TRWEEKLY))<br />
    dir.Append(Function(DirectoryItem(Video, "Top Rated - Monthly",thumb=R(ICON),art=R(ART)), url=BREAK_TRMONTHLY))<br />
    dir.Append(Function(DirectoryItem(Video, "Top Rated - All Time",thumb=R(ICON),art=R(ART)), url=BREAK_TRALLTIME))<br />
<br />
    dir.Append(Function(DirectoryItem(Video, "Most Discussed - Daily",thumb=R(ICON),art=R(ART)), url=BREAK_MDDAILY))<br />
    dir.Append(Function(DirectoryItem(Video, "Most Discussed - Weekly",thumb=R(ICON),art=R(ART)), url=BREAK_MDWEEKLY))<br />
    dir.Append(Function(DirectoryItem(Video, "Most Discussed - Monthly",thumb=R(ICON),art=R(ART)), url=BREAK_MDMONTHLY))<br />
    dir.Append(Function(DirectoryItem(Video, "Most Discussed - All Time",thumb=R(ICON),art=R(ART)), url=BREAK_MDALLTIME))<br />
<br />
    dir.Append(Function(DirectoryItem(Video, "Most Shared - Daily",thumb=R(ICON),art=R(ART)), url=BREAK_MSDAILY))<br />
    dir.Append(Function(DirectoryItem(Video, "Most Shared - Weekly",thumb=R(ICON),art=R(ART)), url=BREAK_MSWEEKLY))<br />
    dir.Append(Function(DirectoryItem(Video, "Most Shared - Monthly",thumb=R(ICON),art=R(ART)), url=BREAK_MSMONTHLY))<br />
    dir.Append(Function(DirectoryItem(Video, "Most Shared - All Time",thumb=R(ICON),art=R(ART)), url=BREAK_MSALLTIME))<br />
<br />
    return dir<br />
<br />
####################################################################################################<br />
<br />
def Video(sender, url):<br />
<br />
  dir = MediaContainer(title3=sender.itemTitle, art=R(ART), viewGroup="InfoList")<br />
<br />
  videos = XML.ElementFromURL(url, isHTML=True, errors='ignore').xpath(XPATH_VIDEOS)<br />
  for content in videos:<br />
    title = content.xpath("./a/span")[0].text<br />
    thumb = content.xpath("./a/img")[0].get('src')<br />
    summary = content.xpath("./a")[0].get('title')<br />
  for content2 in videos:<br />
    url = content.xpath("./a")[0].get('href')<br />
  dir.Append(Function(VideoItem(PlayVideo, title=title, summary=summary, thumb=thumb), url=url))<br />
<br />
  return dir<br />
<br />
####################################################################################################<br />
<br />
def PlayVideo(sender, url):<br />
<br />
......<br />


Hi,



This is your issue:


<br />
 for content in videos:<br />
    title = content.xpath("./a/span")[0].text<br />
    thumb = content.xpath("./a/img")[0].get('src')<br />
    summary = content.xpath("./a")[0].get('title')<br />
  for content2 in videos:<br />
    url = content.xpath("./a")[0].get('href')<br />
  dir.Append(Function(VideoItem(PlayVideo, title=title, summary=summary, thumb=thumb), url=url))<br />




Not exactly sure what you are trying to do but the last line, which adds video items to the directory, is not inside the loop. It will only be executed once with last values populated. Indent it to the correct position to get it inside the loop block.

As a second point, what is the point of the second loop? Don't you want:


<br />
for content in videos:<br />
    title = content.xpath("./a/span")[0].text<br />
    thumb = content.xpath("./a/img")[0].get('src')<br />
    summary = content.xpath("./a")[0].get('title')<br />
    url = content.xpath("./a")[0].get('href')<br />
    dir.Append(Function(VideoItem(PlayVideo, title=title, summary=summary, thumb=thumb), url=url))<br />


Thanks for the tip, it worked and I also removed the second loop (I did the second loop because first it would not pick up the fourth xpath in one loop, but now it does). It is all pretty new to me but I am starting to understand it.



Thanks again.

As a last thing. I tried as a test to play a video item but plex keeps saying that it cannot read from the url, what is it?



def Video(sender, url):<br />
<br />
  dir = MediaContainer(title3=sender.itemTitle, art=R(ART), viewGroup="InfoList")<br />
<br />
  videos = XML.ElementFromURL(url, isHTML=True, errors='ignore').xpath(XPATH_VIDEOS)<br />
  for content in videos:<br />
    title = content.xpath("./a/span")[0].text<br />
    thumb = content.xpath("./a/img")[0].get('src')<br />
    summary = content.xpath("./a")[0].get('title')<br />
    url = content.xpath("./a")[0].get('href')<br />
    dir.Append(Function(VideoItem(PlayVideo, title=title, summary=summary, thumb=thumb), url=url))<br />
<br />
  return dir<br />
<br />
####################################################################################################<br />
<br />
def PlayVideo(sender):<br />
  <br />
  dir.Append(Function(VideoItem("http://video1.break.com/dnet/media/2009/12/christmas-carol-of-the-bells-with-dominoes_3.mp4", title="Test")))

If you know the path the URL of the video, you don’t need a Function, you can just add it directly like this:



<br />
dir.Append(VideoItem(url, title=title, summary=summary, thumb=thumb))<br />


Yes i tried that also but it did not work either.

Can you be specific about how it failed? For example, can you paste the resulting XML from the directory in here?



I recommend running the Media Server from the Terminal to watch output, and turning on debug logging in Plex.

In plex it say: “Could not read input stream”



and below is the log output:



00:14:18.699190: com.plexapp.plugins.break : (Framework) Bundle verification complete

00:14:18.737557: com.plexapp.plugins.break : (Framework) Debugging is enabled

00:14:18.737611: com.plexapp.plugins.break : (Framework) Default encoding is utf-8

00:14:18.738608: com.plexapp.plugins.break : (Framework) Loaded en strings

00:14:18.739386: com.plexapp.plugins.break : (Framework) Loaded en-us strings

00:14:18.739419: com.plexapp.plugins.break : (Framework) Configured framework modules

00:14:18.746745: com.plexapp.plugins.break : (Framework) Imported plug-in module

00:14:18.752352: com.plexapp.plugins.break : (Framework) Loaded shared resource named ‘trust.json’

00:14:18.753347: com.plexapp.plugins.break : (Framework) WARNING: Non-code file named ‘.DS_Store’ found inside the Code directory. Future framework versions will abort at this point.

00:14:18.762219: com.plexapp.plugins.break : (Framework) Checked module imports

00:14:18.769740: com.plexapp.plugins.break : (Framework) Loaded the dictionary file

00:14:18.796597: com.plexapp.plugins.break : (Framework) Loaded HTTP cookies

00:14:19.012401: com.plexapp.plugins.break : (Framework) Loaded HTTP cache

00:14:19.012453: com.plexapp.plugins.break : (Framework) Initialized framework modules

00:14:19.012480: com.plexapp.plugins.break : (Framework) Attempting to start the plug-in…

00:14:19.012518: com.plexapp.plugins.break : (Framework) Added a handler for prefix ‘/video/break’

00:14:19.236273: com.plexapp.plugins.break : (Framework) Added a view group named ‘InfoList’

00:14:19.237629: com.plexapp.plugins.break : (Framework) Added a view group named ‘List’

00:14:19.238401: com.plexapp.plugins.break : (Framework) Plug-in started

00:14:19.251124: com.plexapp.plugins.break : (Framework) Entering run loop

00:14:19.251664: com.plexapp.plugins.break : (Framework) Handling request : /:/prefixes

00:14:19.252072: com.plexapp.plugins.break : (Framework) Resource named ‘icon-main.png’ of type ‘image/png’ was made public.

00:14:19.252345: com.plexapp.plugins.break : (Framework) Resource named ‘art-back.png’ of type ‘image/png’ was made public.

00:14:19.252443: com.plexapp.plugins.break : (Framework) Response OK

00:14:23.110365: com.plexapp.plugins.break : (Framework) Couldn’t find nl strings

00:14:23.110502: com.plexapp.plugins.break : (Framework) Handling request : /video/break

00:14:23.113078: com.plexapp.plugins.break : (Framework) Response OK



00:14:23.990195: com.plexapp.plugins.break : (Framework) Handling request : /video/break/:/function/Video/KGRwMApTJ3VybCcKcDEKUydodHRwOi8vd3d3LmJyZWFrLmNvbS92aWRlb3MvbmV3ZXN0LycKcDIKc1Mnc2VuZGVyJwpwMwpjY29weV9yZWcKX3JlY29uc3RydWN0b3IKcDQKKGNQTVMuT2JqZWN0cwpJdGVtSW5mb1JlY29yZApwNQpjX19idWlsdGluX18Kb2JqZWN0CnA2Ck50cDcKUnA4CihkcDkKUydpdGVtVGl0bGUnCnAxMApTJ05ld2VzdCcKcDExCnNTJ3RpdGxlMScKcDEyClMnQlJFQUsgVmlkZW9zJwpwMTMKc1MndGl0bGUyJwpwMTQKTnNTJ2FydCcKcDE1Ck5zYnMu

00:14:23.991351: com.plexapp.plugins.break : (Framework) Calling named function ‘Video’

00:14:24.481798: com.plexapp.plugins.break : (Framework) Received response from http://www.break.com/videos/newest/

00:14:24.493911: com.plexapp.plugins.break : (Framework) Response OK

00:14:25.005512: com.plexapp.plugins.break : (Framework) Handling request : /video/break/:/function/PlayVideo/KGRwMApTJ3VybCcKcDEKUydodHRwOi8vd3d3LmJyZWFrLmNvbS9icmVhay1jbGFzc2ljcy9icmVhay1tb3N0LWF3ZXNvbWUvMTAtbW9zdC1wb3B1bGFyLWJyZWFrLXZpZGVvcy1vZi0yMDA5Lmh0bWwnCnAyCnNTJ3NlbmRlcicKcDMKY2NvcHlfcmVnCl9yZWNvbnN0cnVjdG9yCnA0CihjUE1TLk9iamVjdHMKSXRlbUluZm9SZWNvcmQKcDUKY19fYnVpbHRpbl9fCm9iamVjdApwNgpOdHA3ClJwOAooZHA5ClMnaXRlbVRpdGxlJwpwMTAKUycxMCBNb3N0IFBvcHVsYXIgQnJlYWsgVmlkZW9zIG9mIDIwMDknCnAxMQpzUyd0aXRsZTEnCnAxMgpTJ0JSRUFLIFZpZGVvcycKcDEzCnNTJ3RpdGxlMicKcDE0Ck5zUydhcnQnCnAxNQpTJy92aWRlby9icmVhay86L3Jlc291cmNlcy9hcnQtYmFjay5wbmcnCnAxNgpzYnMu

00:14:25.005868: com.plexapp.plugins.break : (Framework) Calling named function ‘PlayVideo’

00:14:25.006014: com.plexapp.plugins.break : (Framework) An exception happened:

Traceback (most recent call last):

File “/Users/davidvanineveld/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Plugin.py”, line 640, in __call

return function(*args, **kwargs)

TypeError: PlayVideo() got an unexpected keyword argument ‘url’



00:14:25.006083: com.plexapp.plugins.break : (Framework) Request not handled by plug-in

00:14:27.724902: com.plexapp.plugins.break : (Framework) Handling request : /video/break/:/function/PlayVideo/KGRwMApTJ3VybCcKcDEKUydodHRwOi8vd3d3LmJyZWFrLmNvbS9jdXRlLWdpcmxzL3R3by1ob3R0aWVzLXdpc2gteW91LWEtbmV3LXllYXIuaHRtbCcKcDIKc1Mnc2VuZGVyJwpwMwpjY29weV9yZWcKX3JlY29uc3RydWN0b3IKcDQKKGNQTVMuT2JqZWN0cwpJdGVtSW5mb1JlY29yZApwNQpjX19idWlsdGluX18Kb2JqZWN0CnA2Ck50cDcKUnA4CihkcDkKUydpdGVtVGl0bGUnCnAxMApTJ1R3byBIb3R0aWVzIFdpc2ggWW91IEEgTmV3IFllYXInCnAxMQpzUyd0aXRsZTEnCnAxMgpTJ0JSRUFLIFZpZGVvcycKcDEzCnNTJ3RpdGxlMicKcDE0Ck5zUydhcnQnCnAxNQpTJy92aWRlby9icmVhay86L3Jlc291cmNlcy9hcnQtYmFjay5wbmcnCnAxNgpzYnMu

00:14:27.725292: com.plexapp.plugins.break : (Framework) Calling named function ‘PlayVideo’

00:14:27.725476: com.plexapp.plugins.break : (Framework) An exception happened:

Traceback (most recent call last):

File “/Users/davidvanineveld/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Plugin.py”, line 640, in __call

return function(*args, **kwargs)

TypeError: PlayVideo() got an unexpected keyword argument ‘url’



00:14:27.725552: com.plexapp.plugins.break : (Framework) Request not handled by plug-in



00:14:29.483283: com.plexapp.plugins.break : (Framework) Saved shared HTTP data

You’re still using the Function, which isn’t working b/c you’re trying to pass a url argument to it. The function would need to look like this:



<br />
def PlayVideo(sender, url):<br />
  return Redirect(url)<br />




But this is really just evidence that you don't need the function in the first place :-)

Ok, I understand what you say I think, but as a matter of taking small steps I would like to play a predefined video in plex after i scrolled through the generated video list in plex. Later I will create a function that will read the url from the website and then play the video. So I thought that I could define the url of the video and then play it, but that does not work. So how can I play the predefined url in plex within that function, so that, that url plays after each item i click in the generated list in plex.



In this way i can understand the working of it better.

Fine approach.



<br />
def PlayVideo(sender):<br />
  dir.Append(Function(VideoItem("http://video1.break.com/dnet/media/2009/12/christmas-carol-of-the-bells-with-dominoes_3.mp4", title="Test")))<br />




needs to be

<br />
def PlayVideo(sender, url):<br />
  <br />
  return Redirect("http://video1.break.com/dnet/media/2009/12/christmas-carol-of-the-bells-with-dominoes_3.mp4")<br />




and then PlayVideo needs to be changed to parse the page at the end of url and extract the video link.

Thanks for your help!

No problem. The days of trying to figure out python (I still dislike indents for block demarcation), Plex, video formats, xpath, etc. at the same time are still fresh in my mind. Once you have the basic concepts down, which your example already has, the rest is pretty straightforward.




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