Play FLV file after clicking an item

plugin-dev

#1

Hello people,



I just discovered Plex and started creating a plugin. I've used some other scripts to create what I have now.



from PMS import Plugin, Log, XML, HTTP, JSON, Prefs, RSS, Utils<br />
from PMS.MediaXML import MediaContainer, DirectoryItem, WebVideoItem, VideoItem, SearchDirectoryItem<br />
from PMS.Shorthand import _L, _R, _E, _D<br />
from PMS.FileTypes import PLS<br />
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer<br />
import base64<br />
import re<br />
<br />
DUMPERT_PLUGIN_PREFIX   = "/video/Dumpert"<br />
DUMPERT_ROOT            = "http://www.dumpert.nl/"<br />
DUMPERT_HIGH_RATED    = DUMPERT_ROOT + "toppers/"<br />
DUMPERT_FLV_URL      = DUMPERT_ROOT + "mediabase/flv/%s/.mov.flv"<br />
<br />
DUMPERT_BY_RANK      = "dumpert-toppers"<br />
DUMPERT_GET_MOVIE      = "dumpert-fetch"<br />
<br />
# this is a patch for feedparser.py to handle the yahoo/media namespace.<br />
def _start_media_thumbnail(self, attrsD):<br />
    context = self._getContext()<br />
    context.setdefault('media_thumbnail', [])<br />
    context['media_thumbnail'].append(attrsD)<br />
RSS.feedparser._FeedParserMixin._start_media_thumbnail = _start_media_thumbnail<br />
<br />
################################################################################<br />
####################<br />
<br />
def Start():<br />
  Plugin.AddRequestHandler(DUMPERT_PLUGIN_PREFIX, HandleRequest, "Dumpert", "icon-default.png", "art-default.jpg")<br />
  Plugin.AddViewGroup("InfoList", viewMode="InfoList", contentType="items")<br />
  <br />
################################################################################<br />
####################<br />
<br />
def HandleRequest(pathNouns, count):<br />
  dir = MediaContainer('art-default.jpg', title1="Dumpert")<br />
<br />
  if count == 0:<br />
      dir.AppendItem(DirectoryItem(DUMPERT_PLUGIN_PREFIX + "/" + DUMPERT_BY_RANK, "Toppers"))<br />
<br />
  else:<br />
    if (pathNouns[0] == DUMPERT_BY_RANK):<br />
      return getMoviesByRank()<br />
    if (pathNouns[0] == DUMPERT_GET_MOVIE):<br />
      return dumpertVideo(count, pathNouns)<br />
      <br />
  return dir.ToXML()<br />
<br />
################################################################################<br />
####################<br />
<br />
  <br />
################################################################################<br />
####################<br />
<br />
def dumpertVideo(count, pathNouns):<br />
<br />
  playlist = PLS()<br />
<br />
  playlist.AppendTrack("http://www.dumpert.nl/mediabase/flv/a60913e3_hanneke.mov.flv")<br />
  playlist.ContentType = "video/x-flv"<br />
<br />
  return playlist.Content()<br />
<br />
def getMoviesByRank():<br />
  dir = MediaContainer('art-default.jpg', title1="Toppers")<br />
<br />
  site = XML.ElementFromString(HTTP.Get(DUMPERT_HIGH_RATED, 36000), True)   <br />
<br />
    #http://www.dumpert.nl/mediabase/flv/a60913e3_hanneke.mov.flv<br />
    # Now grab the other episodes<br />
<br />
  episodeObjs = site.xpath('//div[@id="filmcontainer"]/a')<br />
  numEpisodes = len(episodeObjs)<br />
  for episode in range(0,numEpisodes):<br />
    episodeObj = episodeObjs[episode-1]<br />
    url = episodeObjs[episode-1].xpath('@href')[0]<br />
    name = episodeObjs[episode-1].xpath('//h3')[episode].text<br />
    desc = episodeObjs[episode-1].xpath('//p')[episode].text<br />
    date = episodeObjs[episode-1].xpath('//div[@class="date"]')[episode].text<br />
    thumbUrls = episodeObjs[episode-1].xpath('//img[contains(@width, 100)]')[episode]<br />
    thumbUrl = thumbUrls.get("src")<br />
<br />
    #video = VideoItem(str("http://www.dumpert.nl/mediabase/flv/a60913e3_hanneke.mov.flv"), name, desc, "", thumbUrl)<br />
    #video = WebVideoItem(str(url), name,  name, "",  _R("icon-default.png"))<br />
    #itempath = DUMPERT_PLUGIN_PREFIX + "/" + DUMPERT_GET_MOVIE +"/" + base64.b64encode(url, "_;")<br />
    #item = VideoItem(itempath, name, desc, "", thumbUrl)<br />
<br />
    item = DirectoryItem(DUMPERT_PLUGIN_PREFIX + "/" + DUMPERT_GET_MOVIE + "/" + base64.b64encode(url, "_;"), name, thumbUrl, desc)<br />
    item.SetAttr("subtitle", date)<br />
    <br />
    dir.AppendItem(item)   <br />
<br />
  return dir.ToXML()





My problem is: I want that when you click a DirectoryItem from the getMoviesByRank section it starts playing an FLV. I can figure out by myself how to find the FLV url I think, but now I need help how to start playing an FLV movie.



I hope someone can help me because I could not find any documentation.



I know the code here is not working, the dumpertVideo function is not working. This is just to show you what I had.



Greetings,

Matthijs


#2

I have fixed it already and will release my plugin soon.


#3

Nice! I've expanded on the plugins section of the wiki to include submission to the App Store:



http://wiki.plexapp.com/index.php?title=App_Store_Submission


#4

Why does it nothing when I try to use this code:


#mms://wm-ondemand10.omroep.nl/ug-ondemand-wm3/wm3c1/ceres/bnn/rest/2009/POW_00222653/bb.20090320.asf<br />
return Plugin.Redirect(stream_url)



When I do this with an FLV it just works, I have tested this stream in QuickTime, it works.