<?php
class VGrab_boysfood
{
    var $url;
    var $page;
    var $curl;
    function __construct()
    {
        $this->curl = new VCurl();
    }
    
    function VGrab_boysfood()
    {
        $this->__construct();
    }

    function getPage( $url ) {
        $this->url  = $url;
        if ( $this->page = $this->curl->saveToString($url) ) {
            $this->page = trim($this->page);
            $this->page = str_replace("\n", '', $this->page);
            $this->page = str_replace("\r", '', $this->page);
            $this->page = preg_replace('/\s\s+/', ' ', $this->page);
            return true;
        }
        
        return false;
    }
    
    function getVideoTitle()
    {
        preg_match('/<title>(.*?)<\/title>/', $this->page, $matches);
        if ( isset($matches['0']) ) {
            $title  = str_replace('<title>', '', $matches['0']);
            $title  = str_replace('</title>', '', $title);
            
            return $title;
        }
    }
    
    function getVideoTags()
    {
		return '';
    }
    
    function getVideoCategory()
    {
		return '';
    }
    
	function getPlayerURL()
	{
		preg_match('/so1.addVariable\(\"config\", \"\/cgi-bin\/config.cgi\?(.*?)\"\);/ms', $this->page, $matches);
		if (isset($matches['1'])) {
			return 'http://www.boysfood.com/cgi-bin/config.cgi?'.$matches['1'];
		}
	}
	
    function getVideoId()
    {
		
		preg_match('/so1.addVariable\(\"config\", \"\/cgi-bin\/config.cgi\?(.*?)\"\);/ms', $this->page, $matches);
		if (isset($matches['1'])) {
			$parts = explode('=', $matches['1']);
			if (isset($parts['0'])) {
				return $parts['0'];
			}
		}
    }
    
    function getVideoUrl()
    {
        $this->getPage($this->getPlayerURL());

        preg_match('/FLVPath(.*?)\/>/', $this->page, $matches);
        if ( isset($matches['0']) ) {
            $flv_url    = str_replace('FLVPath" Value="', '', $matches['0']);
            $flv_url    = str_replace('/>', '', $flv_url);
			
			return $flv_url;
        }
    }
}
