Warning: Function split() is deprecated in ..../global.php(29) : eval()'d code on line 31
Writing Video Server Plugins for Seyret
Results 1 to 1 of 1

Article: Writing Video Server Plugins for Seyret

  1. Writing Video Server Plugins for Seyret

    0 Comments by admin Published on 17th February 2010 07:39
    Seyret video plugins consist of two php files. The first one contains the class that is used for analyzing video link and creating original html embed code. The second file contains the method to get flv source of the video. This modular system increases the performance of Seyret.

    Not to cause any notion complication, we will call the first file type as "standard file" and the second file type as "pro file" on this document.

    Seyret video plugin files have some naming rules. Standard file name should contain the domain name of the video server. You can use dot, ".", in the name of plugin. But you cannot use www, http or some other signs. For example if the domain of the video server is video.com , then you should name the standard file as video.com.php . We strongly advice you to include the domain extension -like .com, .de, .tv etc- in the plugin name. The name of pro file should include a "pro" string only. For example if your standard file name is video.com.php, then pro file name should be video.com.pro.php.

    Now lets explain the contents of these two files in details.

    Standard file :
    Standard file contains the class with the functions for analyzing video details and html embed code. The class basically consists of three functions: __construct, composeDetails, createEmbedVars . These functions will be explained in details below.

    • File information in the header. These information contain necessary information about copyright and author.

    PHP Code:
    //Seyret Component v.0.3// 
    /*
    * @package Seyret
    * @version 0.3
    * @copyright Copyright (C) 2010 Mustafa DINDAR. All rights reserved.
    * @license Dual License - MIT and GPL 
    * @author Joomlaholic Team
    */ 
    • Joomla direct access prevention. A very important line for security.

    PHP Code:
    defined'_JEXEC' ) or die( 'Restricted access' ); 
    • All standard file classes are children classes of our videoserverplugin class. So we should include the parent class file.

    PHP Code:
    require_once (JPATH_SITE.DS.'components'.DS.'com_seyret'.DS."includes".DS."classes".DS."videoserverplugin.php"); 
    • Now, it is time to create the plugin class. As class name cannot contain "." , we are just removing it and just adding "Plugin" string at the end. Make sure that the domain is the same as the standard file name. For example if the standard file name is video.com.php , your class name should be videocomPlugin. We are extending the parent class as the following example.

    PHP Code:
    class videocomPlugin extends videoserverplugin {


    • After creating the main structure of our class, we should create a __construct function. On some video servers, video information expires after some limited time. So we cannot use cached information after that expiration time. In the __construct function we should define that time in minutes. If there is no problem with timeout, you can comment $this->cachetimeout = ***; line. For example, in the following code, we define a 10 minutes cache expiration time.

    PHP Code:
    function __construct() {

        
    // cache timeout in minutes. leave blank for no cache timeout.
        
    $this->cachetimeout 10


    • After creating our class construction function, lets create our second function. composeDetails function. That function is responsible from analyzing video details. There is no input parameters for this method. The name of this function is not relevant to plugin name and it is same on all plugins. Now, lets go ahead and tell details of this function.

    PHP Code:
    function composeDetails(){
            
        return;    

    • We have included a nice tool, PHP Simple HTML DOM Parser, to Seyret for analyzing html pages. If you want to use that class, you can include it within this composeDetails function.

    PHP Code:
    require_once (JPATH_SITE.DS.'components'.DS.'com_seyret'.DS."includes".DS."classes".DS."htmldom.class.php"); 
    • Now, lets start crating needed parameters. First we need to define the video server type. You should use the same naming conventions with the file name. For example if your standard file name is "video.com.php" , then your video server type is "video.com"

    PHP Code:
    $this->videoservertype="video.com"
    • Video link is already defined by Seyret core. It is time to get video page using that video link. Parent class has a built in getvideoinfo function to read video url. It returns the content of the page.

    PHP Code:
    $str=$this->getvideoinfo($this->videolink); 
    • After reading video page and getting it to a string, you should analyze that string and define following variables. To achieve this, you can use your own php knowledge and the class that we have included above. That is the last step for this function and you can return the function after filling these variables.

    PHP Code:
    $this->videoservercode
    $this
    ->videotitle
    $this
    ->videodescription
    $this
    ->videoduration
    $this
    ->videotags
    $this
    ->videothumb 
    • Our last function in this class is createEmbedVars . This function is responsible for creating standard embed code of the video server. Be careful, this is not the embed code of Seyret player. The content of the function is so simple. It is very important that $this->htmlembedcode variable should contain some html tags like following.

    PHP Code:
    function createEmbedVars(){
       
            
    $this->htmlembedcode '<div style="display:block;width:' $this->playerwidth 'px;height:' $this->playerheight 'px;" id="player"> *********** Video server embed code goes here ************ </div>';
            
            
    $this->embedcode=$this->htmlembedcode;


    • Also you should change the width and height parameters of video server embed code with $this->playerwidth and $this->playerheight. Of course the video server code is stored in $this->videoservercode variable. You should use it in embed code.


    Now, you can test your plugin standard file by adding a video to Seyret from that video server site.



    Pro File:
    This file includes the pro class that has only one function with getflv name. In this function flv source of the video is detected and returned to Seyret core. Now lets see how that plugin is created.


    • File information in the header. These information contain necessary information about copyright and author.

    PHP Code:
    //Seyret Component v.0.3// 
    /*
    * @package Seyret
    * @version 0.3
    * @copyright Copyright (C) 2010 Mustafa DINDAR. All rights reserved.
    * @license Dual License - MIT and GPL 
    * @author Joomlaholic Team
    */ 
    • Joomla direct access prevention. A very important line for security.

    PHP Code:
    defined'_JEXEC' ) or die( 'Restricted access'  ); 
    • All standard file classes are children classes of our videoserverproplugin class. So we should include the parent class file. Be careful parent class contains a pro string in it and it is different from videoserverplugin.

    PHP Code:
    require_once   (JPATH_SITE.DS.'components'.DS.'com_seyret'.DS."includes".DS."classes".DS."videoserverproplugin.php"); 
    • Now we should create the class. Naming is almost the same with standard file class. Name of the class just has an extra Pro string in it. See the example:

    PHP Code:
    final class videocomProPlugin extends videoserverproplugin {


    • Our class is ready. Lets add the needed function. The name of the function is getflv and should not be changed. It has no relation with plugin name. If you want to use Simple HTML DOM Parser, you can include it here.

    PHP Code:
    final public function getflv(){
           require_once (
    JPATH_SITE.DS.'components'.DS.'com_seyret'.DS."includes".DS."classes".DS."htmldom.class.php");


    • After creating getflv function, now lets tell how to fill that function. As the first step, we should check the cache for this video. The checkcachefile method of parent class needs two parameters. the first one is plugin name without any dots, the second one is video server code. If the cache file is ok, the flv url will be read from the cache file. So no need to continue. If the cache file is outdated or not created, $this->proflvlink will not contain any information and we will need to define it.

    PHP Code:
    $this->checkcachefile("videocom"$this->videoservercode);    
    if (
    $this->proflvlink != "") return; 
    • If the cache is not ok, we should find the flv url here. You can use HTML DOM Parser functions and your own php knowledge to detect it. Also our parent class has two methods to read url pages. fetchURL method includes the header information of the video link. This is useful if the link is redirected. getvideoinfo method returns the final page content and uses CURL or file_get_contents functions. If CURL function is available, it is used as default connection method.

    PHP Code:
    $str=$this->fetchURL($videoinfourltrue);
    $str=$this->getvideoinfo($videoinfourl); 
    • After detecting flv url, we have some common and strongly advised lines. Returned video flv url should not contain http:// and &amp; strings. Also it will be very useful to trim the link, sometimes we get useless blanks or line chars.

    PHP Code:
    $videodownloadlink=trim($videodownloadlink);
    $videodownloadlink str_replace("&amp;""&"$videodownloadlink);
    $videodownloadlink str_replace("http://"""$videodownloadlink); 
    • As a last important step, we should create the cache file. Otherwise it will cause server load and unnecessary bandwidth usage. Of course we will not forget to assign the urlencoded flv link to the proflvlink variable.


    PHP Code:
    $this->createcachefile("videocom"$this->videoservercode$videodownloadlink);    
    $this->proflvlink urlencode($videodownloadlink); 
    If you want to develop your own video server plugins, please download the attached file. It contains necessary structure for plugin files.
    Attached Files
    Last edited by admin; 3rd March 2010 at 01:06.

  2. Total Comments 0

    Comments

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •