<?php
class VGrab_snizzshare
{
    var $url;
    var $page;
    var $curl;
    function __construct()
    {
        $this->curl = new VCurl();
    }
    
    function VGrab_pornhub()
    {
        $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()
    {        
        preg_match('/Tags:<\/strong>(.*?)<\DIV>/', $this->page, $matches);
        if ( isset($matches['0']) ) {
            preg_match_all('/>[a-zA-Z0-9]+<\/A>/', $matches['0'], $matches_tag);
            if ( isset($matches_tag['0']) ) {
                $tag_links  = $matches_tag['0'];
                $tags       = array();
                foreach ( $tag_links as $link ) {
                    $tag    = str_replace('>', '', $link);
                    $tag    = str_replace('</A', '', $tag);
                    $tags[] = $tag;
                }
                
                return implode(' ', $tags);
            }
        }
    }
    
    function getVideoCategory()
    {
        preg_match('/Channels:<\/strong>&nbsp;(.*?)<\/DIV>/', $this->page, $matches);
        if ( isset($matches['0']) ) {
            preg_match('/>[a-zA-Z0-9]+<\/A>/', $matches['0'], $matches_channel);
            if ( isset($matches_channel['0']) ) {
                $category   = str_replace('>', '', $matches_channel['0']);                
                return str_replace('</A', '', $category);
            }
        }
    }
    
    function getVideoId()
    {
        preg_match('/\/uploads\/(.*?)\/(.*?)\/(.*?)+\/(.*?).flv&autostart/', $this->page, $matches);
        if ( isset($matches['0']) ) {
            $video_id       = str_replace('flvplayer.swf?file=http://www.snizzshare.com/uploads/', '', $matches['0']);
            $video_id       = str_replace('.flv&autostart', '', $video_id);
            $video_id       = substr($video_id, strrpos($video_id, '/')+1);    
            return $video_id;
        }         
    }
    
    function getVideoUrl()
    {
        preg_match('/\/uploads\/(.*?)\/(.*?)\/(.*?)+\/(.*?).flv&autostart/', $this->page, $matches);
        if ( isset($matches['0']) ) {
            $url    = str_replace('&autostart', '', $matches['0']);
            return 'http://www.snizzshare.com' .$url;
        }
    }
}