Help with new plugin

I’m trying to create a plugin for the Notre Dame All Access website (http://www.und.com/allaccess), which shows various sports highlights, interviews, and some games. It is part of the CBS Sports College Network, so I think a plugin could easily be adjusted to work with other college sites.



First, I have no background with Python, so this is pretty new to me. My programming background is pretty much limited to HTML, XML, and VBA. I am starting with the CBS Sports plugin, since I initially assumed that site was similar.



The main page has a player window and then media is sorted by 5 different categories: Most Recent, Sport, Channel, Featured, and Live Events. At some point, I will use those for the main menu in the plugin, but for now I’m just starting with the Channel category. Clicking Channel brings up a list of 6 groups. I was able to find the correct xpath for this, so now the plugin shows up has a first menu. Here is the code for that:



<br />
def MainMenuVideo():<br />
    dir = MediaContainer(mediaType='video')  <br />
    #for item in XML.ElementFromURL(BASE_URL+"/video/player", True, errors='ignore').xpath('//div[@id="channelList"]/ul/li/a'):<br />
    for item in XML.ElementFromURL(BASE_URL, True, errors='ignore').xpath('//div[@id="channel"]/ul/li/a'):<br />
        title = item.text<br />
        if(title != None):<br />
          url = item.get('href')<br />
          dir.Append(Function(DirectoryItem(VideoSection, title=title.strip(), thumb=R(ICON)),  url=url))<br />
          for child in item.xpath('../ul/li/a'):<br />
              if child.text != None:<br />
                Log("Child:"+str(child.text))<br />
                childTitle = title + ": "+child.text<br />
                #childTitle = title<br />
                childUrl = child.get('href')<br />
                Log(childUrl)<br />
                dir.Append(Function(DirectoryItem(VideoSection, title=childTitle.strip(), thumb=R(ICON)),  url=childUrl))<br />
    return dir<br />




My first question is how to get a list of video files now after selecting a group. The CBS Sports plugin uses:


<br />
def VideoSection(sender, url):<br />
    dir = MediaContainer(viewGroup='Details', mediaType='video')  <br />
    content = HTTP.Request(BASE_URL+"/"+url)<br />
    Log(content)<br />
    index = 25 + content.find("CBSi.app.VideoPlayer.Data")<br />
    start = 1 + content.find("[", index)<br />
    end = content.find("]", start)<br />
    items = content[start:end].split("},{")<br />
    for item in items:<br />
        pieces = item.split(",")<br />
        metaData = dict()<br />
        for piece in pieces:<br />
            tokens = piece.split('":"')<br />
            if(len(tokens) > 1):<br />
              metaData[tokens[0].replace('"','')] = tokens[1].replace('"','')<br />
            <br />
        if(metaData.has_key('title')):<br />
          title = metaData['title'].replace('}','')<br />
          thumb = metaData['large_thumbnail']<br />
          summary = metaData['description']<br />
          durationStr = metaData['duration']<br />
          duration = convert(durationStr)<br />
          pid = metaData['pid']<br />
          dir.Append(Function(VideoItem(Video, title, thumb=thumb, summary=summary, duration=duration), pid=pid))<br />
    return dir<br />





My guess is that this searches the HTML file for "CBSi.app.VideoPlayer.Data" and finds individual files after that. The xpath "//div[@id='video_content']/div" will give me a list of files visible on that page, but I'm not sure where to start placing that.

I’m also quite new to writing plug-ins, but I’ll give it a try:



The list of video’s is being generated by a video item function:


dir.Append(Function(VideoItem(Video, title, thumb=thumb, summary=summary, duration=duration), pid=pid))


This video item calls another function (Video, should be somewhere else in the python script). This video function fetches the link to an actual video.
However there's a simpler approach (which takes more time to generate the video menu).
If you use a more specific video item this function generates the video list and fetches the link to a video stream (which is slower, but easier to learn), e.g. RTMPVideoItem:
[http://dev.plexapp.c...cs/Objects.html](http://dev.plexapp.com/docs/Objects.html)

You should always implement this kind of functions in a loop that is being executed for every video in the list.

Here's an example (not a very good piece of code, but it should illustrate the use of the RTMPVideoItem):


<br />
    content = HTML.ElementFromURL(pageUrl, errors='ignore')<br />
    for video in content.xpath('//div[@id="videoArea"]/div/ul/li'):<br />
<br />
        image = video.xpath("a/img")[0].get('src')<br />
        title = video.xpath("h5/a")[0].text<br />
        title = title.split(" - ")[1]<br />
        link = video.xpath("h5/a")[0].get('href')<br />
        link = ROOT_URL + link<br />
        content2 = HTML.ElementFromURL(link)<br />
        rtmpClip = content2.xpath('//div[@class="videoTeaser"]/script[@type="text/javascript"]')[0].text<br />
        summary = content2.xpath("//div[@id='videoZoneContainer']/div/p/a")[0].text<br />
        rtmpClip = rtmpClip.split('.flv"')[0]<br />
        rtmpClip = rtmpClip.split('file: "')[1]<br />
        dir.Append(RTMPVideoItem(url="rtmp://vrt.flash.streampower.be/een", clip=rtmpClip, live=False, title=title, summary=summary, thumb=image))<br />





Btw, something I struggled with in the beginning (I also didn't know any python): whitespace is important and everything is case sensitive! And every plugin has it's log file in the console utility, this is very useful for debug purposes.


Thanks for the tips, I'll play with it again tonight.

Here is my updated code, I commented out a couple of the old sections.



<br />
import re, string, datetime<br />
from PMS import *<br />
from PMS.Objects import *<br />
from PMS.Shortcuts import *<br />
<br />
VIDEO_PREFIX      = "/video/player"<br />
BASE_URL = "http://www.und.com/allaccess"<br />
CACHE_INTERVAL    = 1800<br />
ICON = "icon-default.png"<br />
<br />
####################################################################################################<br />
def Start():<br />
  Plugin.AddPrefixHandler(VIDEO_PREFIX, MainMenuVideo, "Notre Dame All Access", ICON, "art-default.jpg")<br />
  Plugin.AddViewGroup("Details", viewMode="InfoList", mediaType="items")<br />
  MediaContainer.art = R('art-default.jpg')<br />
  MediaContainer.title1 = 'Notre Dame All Access'<br />
  HTTP.SetCacheTime(CACHE_INTERVAL)<br />
  <br />
def MainMenuVideo():<br />
    dir = MediaContainer(mediaType='video')  <br />
    for item in XML.ElementFromURL(BASE_URL, True, errors='ignore').xpath('//div[@id="channel"]/ul/li/a'):<br />
        title = item.text<br />
        if(title != None):<br />
          url = item.get('href')<br />
          dir.Append(Function(DirectoryItem(VideoSection, title=title.strip(), thumb=R(ICON)),  url=url))<br />
          for child in item.xpath('../ul/li/a'):<br />
              if child.text != None:<br />
                Log("Child:"+str(child.text))<br />
                childTitle = title + ": "+child.text<br />
                #childTitle = title<br />
                childUrl = child.get('href')<br />
                Log(childUrl)<br />
                dir.Append(Function(DirectoryItem(VideoSection, title=childTitle.strip(), thumb=R(ICON)),  url=childUrl))<br />
    return dir<br />
    <br />
    <br />
def VideoSection(sender, url):<br />
    dir = MediaContainer(viewGroup='Details', mediaType='video')  <br />
    for item in XML.ElementFromURL(BASE_URL+"/"+url, True, errors='ignore').xpath('//div[@id="video_content"]/div'):<br />
        title = item<br />
        dir.Append(title)<br />
#        if(title != None):<br />
#            url = BASE_URL + "/" + item.get('href')<br />
#            image = item.get('src')<br />
#            rtmpClip = url<br />
#            dir.Append(RTMPVideoItem(url=url, clip=rtmpClip, live=False, title=title, summary=summary, thumb=image))<br />
<br />
    return dir<br />




First, I'd like to just get a list of available videos, not sure if you can do the Append(title) bit. Also, how exactly can you see logs in the console? I've tried entering Log(url), Log(title), etc in various places and don't see anything show up. I'm sure my xpath is off, as I'm still trying to figure that out. Below is a screenshot of the section containing video files.

Thought I would add that the actual link to a video file is http://www.und.com/allaccess/?media=234635. The DIV class "vip-photo-block" contains the link, img link and title/date.

Are you sure you’re looking in the right folder? You should take a look at your plugin log in the folder “PMS Plugin Logs”

Also make sure your plex media server is running and that your plugin is installed. To see the logs, you’ll have to start your plugin in Plex and navigate through the menus.

I don’t think the “Append(title)” will work, but you can try, you should see the result in your log file.



The link you entered is not really the link to the video file, I think you should use something like this (take a look at the source code of your link):





I don’t have enough experience yet (only worked with rtmp streams, but apparently this isn’t one). Maybe you can find a solution if you take a look at this:

http://wiki.plexapp…Flash.29_player

Did you ever have any luck with this? I am trying to do the same with the Ole Miss site which uses CBS also. Thanks in advance for your help.

No luck yet. I was away on vacation until yesterday, so I haven’t had time to play with it much. Before leaving, I did realize that the site uses some JavaScript to generate which files are displayed (very similar to the CBS Sports website), so the code from that plugin might still be useful.



I’ll be swamped with work the next two weeks, so I won’t have much time to work on it unfortunately.

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