How to play web hosted mp4 file from Plex Plugin

Hey All,



I’m brand spanking new to Plugin Development and Im trying my hand on some sample code. I am trying to get a web hosted mp4 file to play via Plex Media Center and I’m at a point where I have no idea whats going on.



Here is my code:



import re, datetime<br />
<br />
###################################################################################################<br />
<br />
###################################################################################################<br />
def Start():<br />
  Plugin.AddPrefixHandler("/video/test-plugin", MainMenu, "Test")<br />
  Plugin.AddViewGroup("InfoList", viewMode="InfoList", mediaType="items")<br />
  Plugin.AddViewGroup("List", viewMode="List", mediaType="items")<br />
<br />
  ObjectContainer.title1     = "Test"<br />
  ObjectContainer.view_group = "InfoList"<br />
<br />
<br />
####################################################################################################<br />
def MainMenu():<br />
  oc = ObjectContainer(view_group="List")<br />
<br />
  oc.add(DirectoryObject(key=Callback(MoviesList), title="Movies Level 1"))<br />
<br />
  return oc<br />
<br />
####################################################################################################<br />
def MoviesList():<br />
  oc = ObjectContainer()<br />
<br />
  oc.add(MovieObject(<br />
    url="http://cdnapac.videodetective.net/svideo-mp4-750/mp4/750/7583/318505.mp4?c=300120&r=750&s=318505&d=152&sub=MOBILE-IPAD&ref=na&fmt=4&e=20121012032210&h=060daef9262fdc6039535", <br />
    title="Sinister", <br />
    originally_available_at=Datetime.ParseDate("01/01/2012").date(), <br />
    duration=(152*1000), <br />
    summary="summary")<br />
    )<br />




Here's what my Info.plist file looks like:

[xml]<?xml version="1.0" encoding="UTF-8"?>



CFBundleIdentifier
com.plexapp.plugins.test
PlexAudioCodec

AAC

PlexClientPlatformExclusions
Roku
PlexClientPlatforms
*
PlexFrameworkVersion
2
PlexMediaContainer

MP4

PlexVideoCodec

H.264


[/xml]

When I try to run the plugin, I can see the first item "Movies Level 1". But as soon as I click on that in the Plex Client, nothing happens.

Here's the plex plugin log:


2012-10-11 23:48:25,395 (-4faed000) :  DEBUG (runtime:654) - Handling request GET /video/test-plugin/:/function/MoviesList?function_args=Y2VyZWFsMQoxCmRpY3QKMApyMAo_<br />
2012-10-11 23:48:25,396 (-4faed000) :  DEBUG (runtime:750) - Found route matching /video/test-plugin/:/function/MoviesList<br />
2012-10-11 23:48:25,397 (-4faed000) :  DEBUG (runtime:143) - Calling function 'MoviesList'<br />
2012-10-11 23:48:25,399 (-4faed000) :  DEBUG (services:598) - No service found for URL 'http://cdnapac.videodetective.net/svideo-mp4-750/mp4/750/7583/318505.mp4?c=300120&r=750&s=318505&d=152&sub=MOBILE-IPAD&ref=na&fmt=4&e=20121012032210&h=060daef9262fdc6039535'<br />
2012-10-11 23:48:25,400 (-4faed000) :  DEBUG (services:613) - No matching services found for 'http://cdnapac.videodetective.net/svideo-mp4-750/mp4/750/7583/318505.mp4?c=300120&r=750&s=318505&d=152&sub=MOBILE-IPAD&ref=na&fmt=4&e=20121012032210&h=060daef9262fdc6039535'<br />
2012-10-11 23:48:25,401 (-4faed000) :  INFO (services:691) - No normalization function found for URL 'http://cdnapac.videodetective.net/svideo-mp4-750/mp4/750/7583/318505.mp4?c=300120&r=750&s=318505&d=152&sub=MOBILE-IPAD&ref=na&fmt=4&e=20121012032210&h=060daef9262fdc6039535'<br />
2012-10-11 23:48:25,402 (-4faed000) :  DEBUG (services:598) - No service found for URL 'http://cdnapac.videodetective.net/svideo-mp4-750/mp4/750/7583/318505.mp4?c=300120&r=750&s=318505&d=152&sub=MOBILE-IPAD&ref=na&fmt=4&e=20121012032210&h=060daef9262fdc6039535'<br />
2012-10-11 23:48:25,402 (-4faed000) :  CRITICAL (runtime:889) - Exception when constructing response (most recent call last):<br />
  File "/Users/johne/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/runtime.py", line 870, in construct_response<br />
    el = result._to_xml()<br />
  File "/Users/johne/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/objectkit.py", line 497, in _to_xml<br />
    el = Framework.modelling.objects.ModelInterfaceObjectContainer._to_xml(self)<br />
  File "/Users/johne/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/modelling/objects.py", line 375, in _to_xml<br />
    root = Container._to_xml(self)<br />
  File "/Users/johne/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/modelling/objects.py", line 139, in _to_xml<br />
    self._append_children(root, self._objects)<br />
  File "/Users/johne/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/modelling/objects.py", line 145, in _append_children<br />
    el = obj._to_xml()<br />
  File "/Users/johne/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/objectkit.py", line 434, in _to_xml<br />
    if self._core.services.function_in_service_is_deferred(Framework.components.services.MEDIA_OBJECTS_FUNCTION_NAME, service):<br />
  File "/Users/johne/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/services.py", line 552, in function_in_service_is_deferred<br />
    service.sandbox.context.import_values(values)<br />
AttributeError: 'NoneType' object has no attribute 'sandbox'<br />
<br />
2012-10-11 23:48:25,403 (-4faed000) :  DEBUG (runtime:946) - Unable to handle response type: <class 'Framework.modelling.objects.MediaContainer'><br />
2012-10-11 23:48:25,404 (-4faed000) :  DEBUG (runtime:843) - Response: [500] MediaContainer, 0 bytes<br />
<br />




After some googling I'm at a point where I have no idea what Im doing anymore. I'd appreciate any help!

Oh! I should mention that the Plex Client I am using is the Plex Media Center for Mac OSX

Thanks!!

The “url” parameter, when defining a Video Object is used to call an URL Service that will then return playable media objects for the given url. The error you see in the logs is just saying that PMS cannot find an URL Service to handle that specific URL. Before we get into how to fix the issue (as there are a couple different ways), do you intend for your plugin to handle more than one video from the same hosting site, or is it just this video that you want to have in the plugin? Or more complex, do you want videos from multiple hosting sites in the same plugin?

The scenario is multiple videos all hosted at the same site

Ok. Then the ideal solution is to create an URL Service for the host site. Here’s a good primer on using URL Services http://devblog.plexapp.com/2012/05/11/the-power-of-the-url-service/

I have a quick question about this. I am a bit confused by why the URL service is necessary. I have been looking at some simple video bundles (Ask A Ninja and Wimp.com) trying to get a basic understanding of how video plugins work. Though the Ask A Ninja plugin uses a search service, neither of these plugins I have looked at use a URL service. Why does this person need to set up a URL service for his plugin to work? Does the use of HTML.ElementFromURL and xpath code for the value of url within the video object somehow bypass the need to use the URL Service to determine the value of the URL attribute?



Does the fact that he is trying to play an mp4 file or the website that host the files he is accessing play into the need to use a URL Service?



Or am I completely off and lost when it comes to the concept of video objects?

When you set the URL parameter of a VideoObject, you are implicitly calling the URL Service. More often than not, the URL Service is located in the global Services.bundle rather than in the plugin bundle. That’s because it allows for other uses of the URL Service, such as supporting the associated website with the PlexIt bookmarklet and the myPlex Queue. Using the 2.1 version of the framework without an URL Servce actually makes the plugin code look more complicated, as it necessitates setting a rating_key and key with a callback function for each VideoObject. I would suggest browsing the Services.bundle to examine some of the existing services. There is quite a wide variety with some being fairly simple and straightforward and others being quite complex.

Thanks. That helps alot. I will do some research into the Services.bundle so I understand it better.


Regardless the URL service issue, there's a small error in your code. Nothing is returned from the *MoviesList* function. (Add return oc at the end of the function to fix this).

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