plugin tutorial?

I know it’s frustrating if something doesn’t work, but please mind your language, pstarS!



Anyway, as I said before, a DirectoryItem accepts only a couple of predefined arguments, so pageUrl is in the wrong place. It shouldn’t be inside DirectoryItem(), instead it should be inside Function(), like so:



<br />
def MainMenu():<br />
    dir = MediaContainer(mediaType='video')<br />
    dir.Append(<br />
              Function(<br />
                       DirectoryItem(<br />
                         all_shows,<br />
                         title="Shows",<br />
                         summary="Browse Show List"<br />
                       ),<br />
                   pageUrl = VBS_FULL_EPISODES_SHOW_LIST<br />
                   )<br />
              )<br />
    return dir<br />




Now pageUrl is passed on from **MainMenu** to **all_shows**.


ahhhh, ok now thats an explanation.

and sorry about the "bad words" but im not even sure what i had written.... but i will watch my tongue

ok let me try to clear this up.

directoryItems are basically the items on the list, whats shown on the menu.

the Function is the description of an action, or data that is important to a function.

so like said, you can only use the code for each, in each. not overall in both.

im used to html, where sometimes you can blanket some code with a basic code to encompass everything as a base. but now that i remember back to programming a database in php that, well it doest work that way.

ok ill try that and see what happens

Sent command: GET /video/vbs2<br />
User-Agent: Plex Firefox/2.0.0.11<br />
Host: localhost:32400<br />
Accept: */*<br />
Connection: keep-alive<br />
X-Plex-Language: en<br />
X-Plex-Version: 0.8.5-f4b13b5<br />
<br />
17:20:33.308990: com.plexapp.plugins.vbs                 :   (Framework) Loaded en strings<br />
17:20:33.309304: com.plexapp.plugins.vbs                 :   (Framework) Handling request :  /video/vbs2<br />
17:20:33.309565: com.plexapp.plugins.vbs                 :   (Framework) Response OK<br />
Reading 563 bytes in the body, code is 200<br />
Request: GET /video/vbs2/:/function/all_shows/KGRwMApTJ3BhZ2VVcmwnCnAxClMnaHR0cDovL3d3dy52YnMudHYvc2hvd3MvbGFiZWwvQWxsLycKcDIKc1Mnc2VuZGVyJwpwMwpjY29weV9yZWcKX3JlY29uc3RydWN0b3IKcDQKKGNQTVMuT2JqZWN0cwpJdGVtSW5mb1JlY29yZApwNQpjX19idWlsdGluX18Kb2JqZWN0CnA2Ck50cDcKUnA4CihkcDkKUydpdGVtVGl0bGUnCnAxMApTJ1Nob3dzJwpwMTEKc1MndGl0bGUxJwpwMTIKTnNTJ3RpdGxlMicKcDEzCk5zUydhcnQnCnAxNApOc2JzLg__<br />
<br />
Sent command: GET /video/vbs2/:/function/all_shows/KGRwMApTJ3BhZ2VVcmwnCnAxClMnaHR0cDovL3d3dy52YnMudHYvc2hvd3MvbGFiZWwvQWxsLycKcDIKc1Mnc2VuZGVyJwpwMwpjY29weV9yZWcKX3JlY29uc3RydWN0b3IKcDQKKGNQTVMuT2JqZWN0cwpJdGVtSW5mb1JlY29yZApwNQpjX19idWlsdGluX18Kb2JqZWN0CnA2Ck50cDcKUnA4CihkcDkKUydpdGVtVGl0bGUnCnAxMApTJ1Nob3dzJwpwMTEKc1MndGl0bGUxJwpwMTIKTnNTJ3RpdGxlMicKcDEzCk5zUydhcnQnCnAxNApOc2JzLg__<br />
User-Agent: Plex Firefox/2.0.0.11<br />
Host: localhost:32400<br />
Accept: */*<br />
Connection: keep-alive<br />
X-Plex-Language: en<br />
X-Plex-Version: 0.8.5-f4b13b5<br />
<br />
17:20:43.858126: com.plexapp.plugins.vbs                 :   (Framework) Handling request :  /video/vbs2/:/function/all_shows/KGRwMApTJ3BhZ2VVcmwnCnAxClMnaHR0cDovL3d3dy52YnMudHYvc2hvd3MvbGFiZWwvQWxsLycKcDIKc1Mnc2VuZGVyJwpwMwpjY29weV9yZWcKX3JlY29uc3RydWN0b3IKcDQKKGNQTVMuT2JqZWN0cwpJdGVtSW5mb1JlY29yZApwNQpjX19idWlsdGluX18Kb2JqZWN0CnA2Ck50cDcKUnA4CihkcDkKUydpdGVtVGl0bGUnCnAxMApTJ1Nob3dzJwpwMTEKc1MndGl0bGUxJwpwMTIKTnNTJ3RpdGxlMicKcDEzCk5zUydhcnQnCnAxNApOc2JzLg__<br />
17:20:43.859319: com.plexapp.plugins.vbs                 :   (Framework) Calling named function 'all_shows'<br />
17:20:44.828548: com.plexapp.plugins.vbs                 :   (Framework) Received gzipped response from http://www.vbs.tv/shows/label/All/<br />
17:20:44.839127: com.plexapp.plugins.vbs                 :   (Framework) Response OK<br />
Reading 112 bytes in the body, code is 200<br />
17:20:49.830538: com.plexapp.plugins.vbs                 :   (Framework) Saved shared HTTP data<br />




that fixed the argument issue thanks. but still nothing showing on the screen but its getting into that menu screen now.

now its up to me to point it to the right place.

does everything look ok so far? as far as the log is concerned? nothing is jumping out at me as an issue.

also it would be great is someone could review my last few posts and tell me if my explanation of how the video titles are parsed is correct. i want to make sure im on the right track


I think I noticed somewhere that you didn't understand the Log() Function... Log(titleUrl), will print the value of titleUrl to the log. That way you can see for yourself if your xpath is working.
This is also a very handy tool for finding the correct xpath: [https://addons.mozil...fox/addon/1095/](https://addons.mozilla.org/en-US/firefox/addon/1095/)

This is also a great resource for understanding xpath: [http://www.w3schools...ath/default.asp](http://www.w3schools.com/xpath/default.asp)

If this is the url that you are trying to parse. [http://www.vbs.tv/shows/label/All/](http://www.vbs.tv/shows/label/All/)
It looks like you might need something more like this:

def all_shows(sender, pageUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(pageUrl, True)<br />
    for item in content.xpath('//ul[@class="covers covers-wide"]/li'):<br />
      titleUrl = item.xpath("./h4/a")[0].get('href')<br />
      Log(titleUrl)<br />
      image = item.xpath(".//img")[0].get('src')<br />
      Log(image)<br />
      title = item.xpath("./h4/a")[0].text<br />
      Log(title)<br />
      dir.Append(Function(DirectoryItem(VideoPage, title, thumb=image), pageUrl = titleUrl))<br />
    return dir 



Notice how the Log() Function can be used...

well i got it showing titles, kind of. ( im fudging the title text with the url text because i dont know the xpath call out to grab just the text from the href )



but i get this error now, and Im not sure how to rearrange the url.



im not sure i understand they “unknown url” response.



is it because the dir.append is “webvideoitem” is it starting to look for the player info? i didnt think it was on that page yet.



Sent command: GET /video/vbs2/:/function/VideoPage/KGRwMApTJ3dhdGNoVXJsJwpwMQpTJy93YXRjaC9iYWxscy1kZWVwJwpwMgpzUydzZW5kZXInCnAzCmNjb3B5X3JlZwpfcmVjb25zdHJ1Y3RvcgpwNAooY1BNUy5PYmplY3RzCkl0ZW1JbmZvUmVjb3JkCnA1CmNfX2J1aWx0aW5fXwpvYmplY3QKcDYKTnRwNwpScDgKKGRwOQpTJ2l0ZW1UaXRsZScKcDEwClMnL3dhdGNoL2JhbGxzLWRlZXAnCnAxMQpzUyd0aXRsZTEnCnAxMgpOc1MndGl0bGUyJwpwMTMKUydTaG93cycKcDE0CnNTJ2FydCcKcDE1Ck5zYnMu<br />
User-Agent: Plex Firefox/2.0.0.11<br />
Host: localhost:32400<br />
Accept: */*<br />
Connection: keep-alive<br />
X-Plex-Language: en<br />
X-Plex-Version: 0.8.5-f4b13b5<br />
<br />
21:05:46.878938: com.plexapp.plugins.vbs                 :   (Framework) Handling request :  /video/vbs2/:/function/VideoPage/KGRwMApTJ3dhdGNoVXJsJwpwMQpTJy93YXRjaC9iYWxscy1kZWVwJwpwMgpzUydzZW5kZXInCnAzCmNjb3B5X3JlZwpfcmVjb25zdHJ1Y3RvcgpwNAooY1BNUy5PYmplY3RzCkl0ZW1JbmZvUmVjb3JkCnA1CmNfX2J1aWx0aW5fXwpvYmplY3QKcDYKTnRwNwpScDgKKGRwOQpTJ2l0ZW1UaXRsZScKcDEwClMnL3dhdGNoL2JhbGxzLWRlZXAnCnAxMQpzUyd0aXRsZTEnCnAxMgpOc1MndGl0bGUyJwpwMTMKUydTaG93cycKcDE0CnNTJ2FydCcKcDE1Ck5zYnMu<br />
21:05:46.879359: com.plexapp.plugins.vbs                 :   (Framework) Calling named function 'VideoPage'<br />
21:05:46.880828: com.plexapp.plugins.vbs                 :   (Framework) An exception happened:<br />
Traceback (most recent call last):<br />
  File "/Users/sethreid70/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Plugin.py", line 640, in __call<br />
    return function(*args, **kwargs)<br />
  File "/Users/sethreid70/Library/Application Support/Plex Media Server/Plug-ins/VBS.bundle/Contents/Code/__init__.py", line 60, in VideoPage<br />
    content = XML.ElementFromURL(watchUrl, True)<br />
  File "/Users/sethreid70/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/XML.py", line 23, in ElementFromURL<br />
    return ElementFromString(HTTP.Request(url, values, headers, cacheTime, autoUpdate, encoding, errors), isHTML)<br />
  File "/Users/sethreid70/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/HTTP.py", line 133, in Request<br />
    f = urllib2.urlopen(request)<br />
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 124, in urlopen<br />
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 373, in open<br />
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 244, in get_type<br />
ValueError: unknown url type: /watch/balls-deep<br />
<br />
21:05:46.880942: com.plexapp.plugins.vbs                 :   (Framework) Request not handled by plug-in<br />
Reading 0 bytes in the body, code is 404<br />
21:05:49.401337: com.plexapp.plugins.vbs                 :   (Framework) Saved shared HTTP data<br />






this is the current code, I changed the episode list tag because the "all show list" was on a different directory than the pages the videos were actually on.

/shows/all vs /watch/XXXX

but i noticed the show list is also on the /watch page so that populates still. im trying to like add the base url to the titleUrl to make the full url. as retarded as that sounds. but i cant seem to get the code working.


# PMS plugin framework<br />
from PMS import *<br />
from PMS.Objects import *<br />
from PMS.Shortcuts import *<br />
<br />
####################################################################################################<br />
<br />
VBS_PREFIX = "/video/vbs2"<br />
<br />
VBS_URL                     = "http://www.vbs.tv"<br />
VBS_WATCH_URL               = "http://www.vbs.tv/shows/label/All/"<br />
VBS_IMAGE_THUMB_URL         = "http://assets.vbs.tv/%s_small.jpg"<br />
CACHE_INTERVAL              = 3600<br />
DEBUG                       = True<br />
ART           = 'art-default.png'<br />
ICON          = 'icon-default.png'<br />
<br />
####################################################################################################<br />
<br />
def Start():<br />
  Plugin.AddPrefixHandler(VBS_PREFIX, MainMenu, L("VBS"), VBS_IMAGE_THUMB_URL)<br />
  Plugin.AddViewGroup("InfoList", viewMode="InfoList", mediaType="items")<br />
<br />
####################################################################################################<br />
def MainMenu():<br />
    dir = MediaContainer(mediaType='video')<br />
    dir.Append(<br />
              Function(<br />
                       DirectoryItem(<br />
                         all_shows,<br />
                         title="Shows",<br />
                         summary="Browse Show List"<br />
                       ),<br />
                   watchUrl = VBS_WATCH_URL<br />
                   )<br />
              )<br />
    return dir<br />
    <br />
####################################################################################################<br />
def all_shows(sender, watchUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(watchUrl, True)<br />
    for item in content.xpath('//ul[@class="covers covers-wide"]/li'):<br />
      titleUrl = item.xpath("./h4/a")[0].get('href')<br />
      Log(titleUrl)<br />
      image = item.xpath(".//img")[0].get('src')<br />
      Log(image)<br />
      title = item.xpath("./h4/a")[0].text<br />
      Log(title)<br />
      dir.Append(Function(DirectoryItem(VideoPage, title, thumb=image), watchUrl = titleUrl))<br />
    return dir <br />
<br />
####################################################################################################<br />
def VideoPage(sender, watchUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(watchUrl, True)<br />
    for item2 in content.xpath('//div[@id="shows-dd"]//a/@href'):<br />
        vidUrl = item2.xpath("a")[0].get('href')<br />
        if vidUrl.count("http://") == 0:<br />
          vidUrl=VBS_WATCH_URL+vidUrl       <br />
        Log(vidUrl)<br />
        thumb2 = item2.xpath("a/img")[0].get('src')<br />
        title2 = item2.xpath("a")[0].get('href')<br />
        Log(title2)<br />
        dir.Append(WebVideoItem(vidUrl, title=title2, thumb=thumb2))<br />
    return dir




**** edit ****

added Dbl_a's code for all_shows

works great, i had some code working also, but yours is cleaner. thanks.

still producing that error, so it has to be in the videoPage()

the watchUrl is not quite what i said it was anymore, since i had to change it back to use dbl_a's code. and i am really burnt on this right now. so im going to take a break right now.

but thats some progress, to see it populate the list 2 hours ago, was great. and now with images etc. awesomer.

It looks like this line is the problem:


content = XML.ElementFromURL(watchUrl, True)



It seems that watchUrl is a relative path, and just contains "/watch/...". The plug-in has no idea what the path is relative to. You always need to pass a full URL in, starting with "http://...".


EDIT: Also, learning to read the exceptions and use the Log() function are probably the best things you can do with regard to debugging. In the traceback, look for a reference to your own __init__.py file. See here:


  File "/Users/sethreid70/Library/Application Support/Plex Media Server/Plug-ins/VBS.bundle/Contents/Code/__init__.py", line 60, in VideoPage<br />
    content = XML.ElementFromURL(watchUrl, True)<br />




It tells you the exact line causing the problem :)

ok real quick this log you guys keep saying, this is different than the terminal log?



I read the terminal log and notice where the error is ( exceptions ), i just have issues seeing the problem in the code sometimes.



but the url given for watchUrl is - http://www.vbs.tv/shows/label/All/



it seems to be the videoPage is stripping some of the url out. but im not sure why.



this is the drawback of using an already made plugin as a template, but its part of the process. i tried the “kickstart” app thing, but it didnt give me enough to go on.

Look at the source of the page. The links you are extracting in the all_shows function look like this:


<a href="/watch/far-out--2">Play</a>


See? No http://www.vbs.tv at the beginning. You're then passing that to the VideoPage function and trying to use it as a URL in XML.ElementFromURL. As I said above, the plug-in has no idea what should go before the /watch/... which is why it's throwing the exception. The traceback & exception message say exactly what is wrong, and exactly where the problem line is :)

Log() is a function that simply writes whatever you pass into it to the log. This appears both in the plug-in's log file, and in the console output if you're running the media server in Terminal.



ok i get that part. yeah i noticed the passed link is not full, but im having issues figuring out how to make it full.

can i just add the VBS_URL to the link grabbed?

is it as simple as changing the vidUrl=VBS_WATCH_URL+vidUrl to vidUrl=VBS_URL+vidUrl?

vidUrl = item2.xpath("a")[0].get('href')
if vidUrl.count("http://") == 0:
vidUrl=VBS_WATCH_URL+vidUrl
Log(vidUrl)

im not on my mac, im at work. so i cant test it. but im pretty sure i had it that was last night. but im not sure if I did during the new code.

I will check it out though. but am I on the right track? can you add arguments together like that?

Look at this function:


<br />
def VideoPage(sender, watchUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(watchUrl, True)<br />
    for item2 in content.xpath('//div[@id="shows-dd"]//a/@href'):<br />
        vidUrl = item2.xpath("a")[0].get('href')<br />
        if vidUrl.count("http://") == 0:<br />
          vidUrl=VBS_WATCH_URL+vidUrl       <br />
        Log(vidUrl)<br />
        thumb2 = item2.xpath("a/img")[0].get('src')<br />
        title2 = item2.xpath("a")[0].get('href')<br />
        Log(title2)<br />
        dir.Append(WebVideoItem(vidUrl, title=title2, thumb=thumb2))<br />
    return dir<br />




You're trying to fetch the content of watchUrl directly, on the third line. At this point, watchUrl only contains the relative path. You just need to add "http://www.vbs.tv" to the beginning of the string.

To figure out what the full path is when only a relative path is given in the html, go to your browser, click the link, and look at the address bar. Whatever is before the"/watch" is what you have to add. I did this in the nbc_harley (not harvey) plugin by adding a string called NBC_URL, which is a global string variable, to the relative url. This string was equal to “http://www.NBC.com” and was added to things like “/watch/” so that I could send PMS the full www address.

alright guys, thanks for all the help.



I hate to keep posting this stuff as i feel im just bothering everyone.



but im almost there, i can taste it.



i fixed the error, only to produce another. and fix those and produce another.



so here we are.



User-Agent: Plex Firefox/2.0.0.11<br />
Host: localhost:32400<br />
Accept: */*<br />
Connection: keep-alive<br />
X-Plex-Language: en<br />
X-Plex-Version: 0.8.5-f4b13b5<br />
<br />
22:26:34.497468: com.plexapp.plugins.vbs                 :   (Framework) Handling request :  /video/vbs2/:/function/VideoPage/KGRwMApTJ3RpdGxlVXJsJwpwMQpTJ2h0dHA6Ly93d3cudmJzLnR2L3dhdGNoL2Zhci1vdXQtLTInCnAyCnNTJ3NlbmRlcicKcDMKY2NvcHlfcmVnCl9yZWNvbnN0cnVjdG9yCnA0CihjUE1TLk9iamVjdHMKSXRlbUluZm9SZWNvcmQKcDUKY19fYnVpbHRpbl9fCm9iamVjdApwNgpOdHA3ClJwOAooZHA5ClMnaXRlbVRpdGxlJwpwMTAKUydGYXIgT3V0JwpwMTEKc1MndGl0bGUxJwpwMTIKTnNTJ3RpdGxlMicKcDEzClMnU2hvd3MnCnAxNApzUydhcnQnCnAxNQpOc2JzLg__<br />
22:26:34.497785: com.plexapp.plugins.vbs                 :   (Framework) Calling named function 'VideoPage'<br />
22:26:36.256569: com.plexapp.plugins.vbs                 :   (Framework) Received gzipped response from http://www.vbs.tv/watch/far-out--2<br />
22:26:36.264490: com.plexapp.plugins.vbs                 :   http://www.vbs.tv/watch/far-out--2/heimo-s-arctic-refuge-full-length<br />
22:26:36.264637: com.plexapp.plugins.vbs                 :   http://cdn.c.ooyala.com/na/vice/1jZ2U4MTqduF8Ec7ju9RrwRNK99I_bL3/gppeeu0qy3MPW9zH5kMDoxOjA0OwfPun<br />
22:26:36.264962: com.plexapp.plugins.vbs                 :   (Framework) An exception happened:<br />
Traceback (most recent call last):<br />
  File "/Users/sethreid70/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Plugin.py", line 640, in __call<br />
    return function(*args, **kwargs)<br />
  File "/Users/sethreid70/Library/Application Support/Plex Media Server/Plug-ins/VBS.bundle/Contents/Code/__init__.py", line 63, in VideoPage<br />
    title = item2.xpath("./a")[0].text<br />
IndexError: list index out of range<br />
<br />
22:26:36.266252: com.plexapp.plugins.vbs                 :   (Framework) Request not handled by plug-in<br />
Reading 0 bytes in the body, code is 404<br />
22:26:38.529791: com.plexapp.plugins.vbs                 :   (Framework) Saved shared HTTP data<br />
<br />




here is the current code that prduced said error


####################################################################################################<br />
<br />
VBS_PREFIX = "/video/vbs2"<br />
<br />
VBS_URL                     = "http://www.vbs.tv"<br />
VBS_WATCH_URL               = "http://www.vbs.tv/shows/label/All/"<br />
VBS_IMAGE_THUMB_URL         = "http://assets.vbs.tv/%s_small.jpg"<br />
CACHE_INTERVAL              = 3600<br />
DEBUG                       = True<br />
ART           = 'art-default.png'<br />
ICON          = 'icon-default.png'<br />
<br />
####################################################################################################<br />
<br />
def Start():<br />
  Plugin.AddPrefixHandler(VBS_PREFIX, MainMenu, L("VBS"), VBS_IMAGE_THUMB_URL)<br />
  Plugin.AddViewGroup("InfoList", viewMode="InfoList", mediaType="items")<br />
<br />
####################################################################################################<br />
def MainMenu():<br />
    dir = MediaContainer(mediaType='video')<br />
    dir.Append(<br />
              Function(<br />
                       DirectoryItem(<br />
                         all_shows,<br />
                         title="Shows",<br />
                         summary="Browse Show List"<br />
                       ),<br />
                   pageUrl = VBS_WATCH_URL<br />
                   )<br />
              )<br />
    return dir<br />
    <br />
####################################################################################################<br />
def all_shows(sender, pageUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(pageUrl, True)<br />
    for item in content.xpath('//ul[@class="covers covers-wide"]/li'):<br />
      titleUrl = item.xpath("./h4/a")[0].get('href')<br />
      Log(titleUrl)<br />
      image = item.xpath(".//img")[0].get('src')<br />
      Log(image)<br />
      title = item.xpath("./h4/a")[0].text<br />
      Log(title)<br />
      dir.Append(Function(DirectoryItem(VideoPage, title, thumb=image), titleUrl = VBS_URL+titleUrl))<br />
    return dir <br />
<br />
####################################################################################################<br />
def VideoPage(sender, titleUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(titleUrl, True)<br />
    for item2 in content.xpath('//div[@class="img"]//a'):<br />
        vidUrl = item2.xpath(".")[0].get('href')<br />
        vidUrl = VBS_URL+vidUrl       <br />
        Log(vidUrl)<br />
        image2 = item2.xpath(".//img")[0].get('src')<br />
        Log(image2)<br />
        title = item2.xpath("./a")[0].text<br />
        Log(title2)<br />
        dir.Append(WebVideoItem(vidUrl, thumb=image2, title=title2))<br />
    return dir



so, before i get bashed for the basics. i understand what the issue is, im calling out TOO much text. the xpath is too general. the div class is used too many times for it to limit the results.

so this is where im stuck as of tonight. trying to figure out how to access all the info i want.

video url seems to be in one div
image seems to be in another ( sometimes halfway down the page )
title/ description thats in another spot sometimes with the url sometimes not. but never with the image in the same parent div.

can i grab data from all over the page? from what it looks like, its specific to the <"...."> class you are calling to look for. but not all my data is in one <"......">

so, im going to continue to work on it tomorrow, if anyone has suggestions that would be great, but im not asking you to do the coding for me, examples would be great.

im almost there!

i just noticed that some how my image is being called after the url in the log. not sure what thats all about. but will check into that also.



You might be using an Xpath that is too specific in your VideoPage() Function. I didn't notice any "text" to parse in your selection. (probably causing the error.) You'll need to "back-up" (choose an html tag that is a "parent" of all the data you want to parse.)

I think you will want to use this in your "for loop":
xpath("//ul[@class='videos videos-wide']/li"

Then you'll need to identify the individual items you are trying to parse.


-Dbl_A

yeah help me out on the xpath and how its written. i read a bit about it but its still kind of eluding me








if i write

xpath("//ul[@class='a']/b3" = means its grabbing the info from the "" tag?

xpath("//ul[@class='a']/b3/c4" = means its grabbing the info from the "" tag? and skipping the b3 tag?

the first set of tags after the [ ] in the xpath are the tags its going to see next? or the tags its supposed to skip? till it sees what I want?

similar to this


for item in content.xpath('//ul[@class="covers covers-wide"]/li'):<br />
      titleUrl = item.xpath("./h4/a")[0].get('href')<br />
      Log(titleUrl)<br />
      image = item.xpath(".//img")[0].get('src')<br />
      Log(image)<br />
      title = item.<br />
<br />




so the first xpath is starting it out, saying look for covers cover-wide then /li. but is it saying that because it wants to start at li, or skip li?

then the other parts

xpath("./h4/a")[0].get('href') thats using the same xpath, but saying grab past li, to h4, then a and grab me the href after that tag? is that right?

.xpath(".//img")[0].get('src') this ones saying, using the same xpath start over and find the img tag and grab the src? thats what it looks like to me.

im just trying to get clarification on how it grabs the info, searching xpath defenitions and codes dont come up with much as far as a detailed " this is what this means and that means in this situation" type explanations.


for item in content.xpath('//ul[@class="covers covers-wide"]/li'):
-This is creating a for loop. Assigning an element in ('//ul[@class="covers covers-wide"]/li') to the variable "item" with each pass of the loop.
(this means it is assigning all the HTML tags of "/li" AND all of the children of "/li")

titleUrl = item.xpath("./h4/a")[0].get('href')
-This is assigning the value of "href" located at ('//ul[@class="covers covers-wide"]/li/h4/a') to the variable "titleUrl."

image = item.xpath(".//img")[0].get('src')
-This is assigning the value of "src" located at ('//ul[@class="covers covers-wide"]/li//img') to the variable "image."


Does this make sense? I would strongly recommend playing around with the XPath Checker add-on in Firefox if you haven't already.

-Dbl_A

yeah, thats starting to make sense.



and yea i have the xpath checker, and am using it quite a bit to check my xpath scripts. sometimes the code doesnt translate from xpath to the plex app though.



but your explination helps, now i understand the first xpath call out is telling reading ALL of the /li HTML tag for “covers covers-wide”, along with the /li after that.



then each additional reference below it is just specifying specific html tags WITHIN “covers cover-wide” or children.



thanks again, ill plug away at this later tonight.

Sounds like you’re almost there. To add to what Dbl_A said:



<br />
content.xpath('//ul[@class="covers covers-wide"]/li')<br />




This performs the xpath expression on content (which is the whole html file I guess). The leading '//' means look anywhere in the XML tree, and then it looks for li elements as direct children of the ul elements with the given class attribute. You can also start with '/' but then the whole explicit tree path from html element to the li element would need to be specified.


<br />
item.xpath("./h4/a")[0].get('href')<br />



This operates on the item previously extracted. The leading '.' means start at the item, rather than the root of the document, then extract a elements that are direct children of h4 elements. This could in theory produce multiple, so you get a list. The [0] takes the first entry in that list (presumably since you are only expecting one) and the get('href') looks for the href attribute.

Jonny

success! thanks for the help guys



well getting into the second video page, success



its not fine tuned yet, im still having issues finding some xml that has ALL the data i want inside its tags. and no one has said if i can redo the xpath search for different items in the same container.



so yeah, the href is being used for the title too…so sue me. i wanted to see it work



but heres the code


####################################################################################################<br />
<br />
VBS_PREFIX = "/video/vbs2"<br />
<br />
VBS_URL                     = "http://www.vbs.tv"<br />
VBS_WATCH_URL               = "http://www.vbs.tv/shows/label/All/"<br />
VBS_IMAGE_THUMB_URL         = "http://assets.vbs.tv/%s_small.jpg"<br />
CACHE_INTERVAL              = 3600<br />
DEBUG                       = True<br />
ART           = 'art-default.png'<br />
ICON          = 'icon-default.png'<br />
<br />
####################################################################################################<br />
<br />
def Start():<br />
  Plugin.AddPrefixHandler(VBS_PREFIX, MainMenu, L("VBS"), VBS_IMAGE_THUMB_URL)<br />
  Plugin.AddViewGroup("InfoList", viewMode="InfoList", mediaType="items")<br />
<br />
####################################################################################################<br />
def MainMenu():<br />
    dir = MediaContainer(mediaType='video')<br />
    dir.Append(<br />
              Function(<br />
                       DirectoryItem(<br />
                         all_shows,<br />
                         title="Shows",<br />
                         summary="Browse Show List"<br />
                       ),<br />
                   pageUrl = VBS_WATCH_URL<br />
                   )<br />
              )<br />
    return dir<br />
    <br />
####################################################################################################<br />
def all_shows(sender, pageUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(pageUrl, True)<br />
    for item in content.xpath('//ul[@class="covers covers-wide"]/li'):<br />
      titleUrl = item.xpath("./h4/a")[0].get('href')<br />
      Log(titleUrl)<br />
      image = item.xpath(".//img")[0].get('src')<br />
      Log(image)<br />
      title = item.xpath("./h4/a")[0].text<br />
      Log(title)<br />
      dir.Append(Function(DirectoryItem(VideoPage, title, thumb=image), titleUrl = VBS_URL+titleUrl))<br />
    return dir <br />
<br />
####################################################################################################<br />
def VideoPage(sender, titleUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(titleUrl, True)<br />
    for item2 in content.xpath('//div[@class="img"]//a'):<br />
        vidUrl = item2.xpath(".")[0].get('href')<br />
        vidUrl = VBS_URL+vidUrl       <br />
        Log(vidUrl)<br />
        image2 = item2.xpath(".//img")[0].get('src')<br />
        Log(image2)<br />
        title2 = item2.xpath(".")[0].get('href')<br />
        Log(title2)<br />
        dir.Append(WebVideoItem(vidUrl, thumb=image2, title=title2))<br />
    return dir



now to work on the site config file, so that a video might play

its playing, but not pausing haha



but its working. kind of



yeah it works, i need to fine tune the site config for the player. i was trying to fudge the coordinates as i dont have a photo manipulator on my Htpc mini. so i was using preview, guess it didnt work.



but thanks guys, i will make a bundle soon and attach it here.



still work in progress



but i have started on another already…

okie, need a bit more direction guys.



the site config, i followed the online docs. but i still cant get the video to pause, fastforward, etc.



here is the code for VBS



<?xml version="1.0" encoding="UTF-8"?><br />
<site site="http://www.vbs.tv"<br />
	    plugin="http://www.vbs.tv/vbs_tv.swf"<br />
			initialState="playing"<br />
			version="1.0"><br />
	<br />
	<br />
	<crop x="0" y="0" width="640" height="361" /><br />
	<br />
	<seekbar type="simple"><br />
		<start x="90" y="240" /><br />
		<end   x="435" y="240" /><br />
		<played><br />
				<color rgb="FFFFFF" /><br />
		</played><br />
	</seekbar><br />
	<br />
	<!-- PLAYING --><br />
	<state name="playing"><br />
		<event><br />
			<condition><br />
				<command name="pause" /><br />
			</condition><br />
			<action><br />
				<click x="80" y="260" /><br />
				<goto state="paused" /><br />
			</action><br />
		</event><br />
		<br />
		<!-- Video ends --><br />
		<event><br />
			<condition><br />
				<url matches="http://www.vbs.tv/watch/" /><br />
			</condition><br />
			<action><br />
				<goto state="end" /><br />
			</action><br />
		</event><br />
	</state><br />
	<br />
	<!-- PAUSED --><br />
	<state name="paused"><br />
		<event><br />
			<condition><br />
				<command name="play" /><br />
			</condition><br />
			<action><br />
				<click x="80" y="260" /><br />
				<goto state="playing" /><br />
			</action><br />
		</event><br />
	</state><br />
</site>



i opened the image on my iMac and used photoshop to measure the pixels.... im not sure where i went wrong