FAQ  •  Register  •  Login

Pleas help write plugin

<<

Neoromancer

Streaming enthusiast

Posts: 27

Joined: Wed Jun 01, 2011 10:58 am

Location: Lithuania

Post Thu Dec 08, 2011 6:41 pm

Pleas help write plugin

Hi volk!
Firs, I'am not developer but try to understand how work plugin.

I'm trying to write a plugin for this page http://tv.delfi.lt/

Rss http://tv.delfi.lt/feed/rss

I tried to write but do not work. My code:
  Code:
import org.serviio.library.metadata.*
import org.serviio.library.online.*

/** delfitv.info content URL extractor plugin.
 *
 * http://tv.delfi.lt/feed/rss
 *
 * @author Neoromancer
 *
 */
class delfitvUrlExtractor extends FeedItemUrlExtractor {

   final VALID_FEED_URL = '^http://ytv.delfi.lt/v/.*'
   
   String getExtractorName() {
      return getClass().getName();
   }

   boolean extractorMatches(URL feedUrl) {
      return feedUrl ==~ VALID_FEED_URL;
   }

   /* Quality is ignored on delfitv */
   ContentURLContainer extractUrl(Map links, PreferredQuality requestedQuality) {
      def linkUrl = links.alternate != null ? links.alternate : links.default
      // open the HTML page first      
      def webPage = linkUrl.getText()
      // find SWFObject : content file location
      // Example : so.addVariable('file','http://ytv.delfi.lt/v/55rqhjZ8.mp4%3FPHPSESSID%3D863c2f07ab6b1230367086add75ef866%26ft%3Da.mp4');
      def matcher = webPage =~ 'so.addVariable.*file.*'
      def linkParts = matcher[0].toString().split("'")
      def videoUrl = linkParts[3]
      return new ContentURLContainer(fileType: MediaFileType.VIDEO, contentUrl: videoUrl)
   }

   /* Groovy test method */
   static void main(args) {
      delfitvUrlExtractor extractor = new delfitvUrlExtractor()

      assert extractor.extractorMatches( new URL("http://tv.delfi.lt/feed/rss"))
      Map links = ['default': new URL("http://ytv.delfi.lt")]
      ContentURLContainer result = extractor.extractUrl(links, PreferredQuality.MEDIUM)
      println "Result: $result"
   }
}


I do not understand where my mistake. Help write a working plugin. Then try to understand how it works.

Thanks.
Panasonic TX-P42G20E | Ubuntu server 10.04.3 64-bit | Serviio 0.6.2
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Thu Dec 08, 2011 6:51 pm

Re: Pleas help write plugin

you don't need a plugin for this RSS feed, it already includes the stream URL in it's media:content element
<<

Neoromancer

Streaming enthusiast

Posts: 27

Joined: Wed Jun 01, 2011 10:58 am

Location: Lithuania

Post Thu Dec 08, 2011 8:24 pm

Re: Pleas help write plugin

Hmm... I added http://tv.delfi.lt/feed/rss but no show contents.
Panasonic TX-P42G20E | Ubuntu server 10.04.3 64-bit | Serviio 0.6.2
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Thu Dec 08, 2011 9:51 pm

Re: Pleas help write plugin

<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Fri Dec 09, 2011 5:19 am

Re: Pleas help write plugin

As zip says: Did you read "READ BEFORE POSTING" viewtopic.php?f=5&t=1289

The log says:
Cannot parse resource from http://ytv.delfi.lt/v/EsMqIHmA.mp4. Message: Error during feed parsing : Invalid XML: Error on line 1: Content is not allowed in prolog.

The bad line is <media:content>http://ytv.delfi.lt/v/EsMqIHmA.mp4</media:content>
it needs to read:
<media:content url="http://ytv.delfi.lt/v/EsMqIHmA.mp4" />
to be valid so yes you need a groovy.
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Fri Dec 09, 2011 9:21 am

Re: Pleas help write plugin

weird, I'll check it, but it's complaining about line 1, it looks more like the XML is dodgy with some characters at the beginning
<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Fri Dec 09, 2011 5:34 pm

Re: Pleas help write plugin

So you are saying that this form of media:content will be processed correctly by Serviio as well as the <media:content url=".." /> form that is documented?
<media:content>http://ytv.delfi.lt/v/EsMqIHmA.mp4</media:content>
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Fri Dec 09, 2011 6:31 pm

Re: Pleas help write plugin

no, just checked, it needs the url as an attribute
<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Fri Dec 09, 2011 10:06 pm

Re: Pleas help write plugin

So that confirms he needs a groovy? Pretty simple one though.. just read the existing media content urls for each link and return them to serviio.

Just parse the Rss once in "extractorMatches" to get the items as below and then in "extractUrl" find the item for each link and extract and return the url .

That should be enough help.

  Code:
   boolean extractorMatches(URL feedUrl) {
      //get the rss contents
      def rssPage = new URL(feedUrl.toString()).getText()
      //now parse the rss contents into items
      def rssNodes = new XmlParser().parseText(rssPagenew)
      // and create a list of items for use by extractUrl
      itemNode = rssNodes.channel.item
       return feedUrl ==~ VALID_FEED_URL
   }


   ContentURLContainer extractUrl(Map links, PreferredQuality requestedQuality) {
      def linkUrl = links.default  /* The <link> tag */
      def contentUrl    /* The video to be played to be returned */

      // look at each item to find the link url and keep the match
      def matchedItem
      // set matchedItem with contents of Item with matching link
      itemNode.each { it -> if(it.link.text() == linkUrl.toString()) matchedItem = it } 

      //now extract the stream url       
      def mediaLink = matchedItem =~ 'your regex exression goes here'               
      contentUrl = mediaLink[0][1]
   
      return new ContentURLContainer(contentUrl: contentUrl)
   }
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Sat Dec 10, 2011 1:41 am

Re: Pleas help write plugin

you probably don't have to parse the RSS in the plugin, it looks like there is a pattern between the default link URL and the video URL.
<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Sat Dec 10, 2011 2:26 am

Re: Pleas help write plugin

That's probably true for any rss but I had thought it better to do the parse of the whole rss once into items and then match the links to the items and then scan the item for the url rather than scan the rss from the beginning for each link. I don't know how a regex is matched but I assumed it would also take more resource the longer the string that has to be matched.
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Sat Dec 10, 2011 3:42 pm

Re: Pleas help write plugin

No need to scan the whole feed for each item. the extractUrl method will get a map of links for each item, in this case it'll include something like

  Code:
['default':'http://tv.delfi.lt/video/tPA0Sr7h']


and from there the expected content URL is

  Code:
http://ytv.delfi.lt/v/tPA0Sr7h.mp4


so it'd be a few lines of code to go from one to the other
<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Sat Dec 10, 2011 5:07 pm

Re: Pleas help write plugin

OK, now I see..in this case the links can easily be transformed into the filename and the missing .mp4 extension added so we don't even need to look at the malformed media:content tag. But that's kinda special and if they ever change the model or the extension for one of the files you're sol.

So to avoid that I would look at the media:content tag but I either need to scan the rss for each item or just scan the rss once in the extractor for the feed. Maybe that's the same thing but I think the latter is neater and perhaps more effecient as I posted earlier. I'd appreciate your comments because I'm trying to learn about all this. :?
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Sat Dec 10, 2011 5:29 pm

Re: Pleas help write plugin

jhb50 wrote:So to avoid that I would look at the media:content tag but I either need to scan the rss for each item or just scan the rss once in the extractor for the feed. Maybe that's the same thing but I think the latter is neater and perhaps more effecient as I posted earlier. I'd appreciate your comments because I'm trying to learn about all this. :?

The thig is the extractorMatches() method is possibly called for all new feed URLs - when Serviio goes through all plugins to find the first that matches. So if you want to parse the feed there it should be inside an if statement, like (pseudo code):

  Code:
boolean matches = match(url)
if(url matches) {
   parseXml()
}
return matches
<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Sat Dec 10, 2011 6:07 pm

Re: Pleas help write plugin

:roll: Yea, should have thought of that. Thanks. Makings of a good Wiki with all these tips!
<<

Neoromancer

Streaming enthusiast

Posts: 27

Joined: Wed Jun 01, 2011 10:58 am

Location: Lithuania

Post Thu Dec 15, 2011 4:49 pm

Re: Pleas help write plugin

I realized that I really do not understand anything plugin writing.

Have done a little differently, just picked up a rss web and edited so that the program should understand him. It looks like http://podcast.openbox.info/delfi.xml. I update three times a week.

Sorry for bad English.
Panasonic TX-P42G20E | Ubuntu server 10.04.3 64-bit | Serviio 0.6.2

Return to Plugin development

Who is online

Users browsing this forum: No registered users and 14 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.