Файл: adultscript-2.0.3-pro/files/admin/modules/grab/grabers/pornative.php
Строк: 93
<?php
defined('_VALID') or die('Restriced Acess!');
class VComponent_Admin_grab_pornative extends VComponent_Admin_grab_grab
{
    public function __construct($url, $user_id, $category, $status, $unique)
    {
        parent::__construct();
        $this->url        = $url;
        $this->user_id    = $user_id;
        $this->category    = $category;
        $this->status    = $status;
        $this->unique   = $unique;
    }
    
    public function get_videos()
    {
        $count    = 0;
        $this->update_progress('0^Parsing remote html...');
        $html    = $this->clean_html(VCurl::string($this->url));
        if ($html) {
            preg_match_all('/<div class="smallmovie">(.*?)</div>/', $html, $matches);
            if (isset($matches['1']) && $matches['1']) {
                $this->update_progress('0^Processing videos...');
                $total_videos   = count($matches['1']);
                $incr           = round((100/$total_videos), 2);
                $progress       = 0;
            
                foreach ($matches['1'] as $match) {
                    ++$count;
                    if ($count > $this->overflow) {
                        $this->errors[]    = 'Overflow reached (500)! Aborting!';
                        return FALSE;
                    }
                    
                    $video    = array(
                        'site'        => 'pornative',
                        'url'        => '',
                        'title'        => '',
                        'desc'        => '',
                        'tags'      => '',
                        'category'    => '',
                        'thumbs'    => array(),
                        'duration'    => 0,
                        'embed'        => '',
                        'size'        => 0,
                        'file_url'    => ''
                    );
                    
                    preg_match('/<span class="link"><a href="(.*?)"><b>play</b></a></span>/', $match, $matches_url);
                    if (isset($matches_url['1'])) {
                        $video['url']    = 'http://www.pornative.com'.$matches_url['1'];
                        $this->update_progress($progress.'^Processing '.$video['url'].' ...');
                        if ($this->already_added('pornative', $video['url'])) {
                            $this->update_progress($progress.'^Video already added!');
                            $progress = sprintf("%01.2f", ($progress+$incr));
                            ++$this->video_already;                            
                            continue;
                        } 
                    } else {
                        $this->update_progress($progress.'^Failed to find video title...continue!');
                        $progress = sprintf("%01.2f", ($progress+$incr));
                        continue;
                    }
                    
                    preg_match('/<h2>(.*?)</h2>/', $match, $matches_title);
                    if (isset($matches_title['1'])) {
                        $video['title'] = strip_tags(stripslashes($matches_title['1']));
                    }
                    
                    preg_match('/<span class="duration"><b>duration:</b>(.*?)</span>/', $match, $matches_duration);
                    if (isset($matches_duration['1'])) {
                          $video['duration'] = $this->duration_to_seconds(trim($matches_duration['1']));
                    }
                    
                    preg_match('/<img class="thumb" src="(.*?)" alt="" />/', $match, $matches_thumb);
                    if (isset($matches_thumb['1'])) {
                        $thumb_url    = $matches_thumb['1'];
                        $thumb_url    = substr($thumb_url, 0, strrpos($thumb_url, '/'));
                        $video['thumbs'] = array(
                            $thumb_url.'/1.jpg',
                            $thumb_url.'/2.jpg',
                            $thumb_url.'/3.jpg',
                            $thumb_url.'/4.jpg',
                            $thumb_url.'/5.jpg',
                            $thumb_url.'/6.jpg',
                            $thumb_url.'/7.jpg',
                            $thumb_url.'/8.jpg'
                        );
                    }
                    
                    $video_id     = str_replace(array('http://www.pornative.com/', '.html'), '', $video['url']);
                  
                    if ($video['title'] && $video['duration'] && $video['thumbs'] && isset($video_id)) {
                        $tags        = array();
                        $tags_arr    = explode(' ', strtolower(prepare_string($video['title'])));
                        foreach ($tags_arr as $tag) {
                            if (strlen($tag) >= 5) {
                                $tags[] = $tag;
                            }
                        }
                        
                        $video['tags']  = implode(' ', $tags);
                        
                        $content        = $this->clean_html(VCurl::string($video['url']));
                        preg_match('/Channels: <a href="(.*?)">(.*?)</a>/', $content, $matches_category);
                        if (isset($matches_category['2'])) {
                            $category = strip_tags(stripslashes(trim($matches_category['2'])));
                        }
                        
                        $video['embed'] = '<embed src="http://www.pornative.com/embed/player.swf" FlashVars="movie_id='.$video_id.'" quality="high" bgcolor="#000000" width="'.$this->vcfg['embed_width'].'" height="'.$this->vcfg['embed_height'].'" allowScriptAccess="always"  wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
                        
                        if ($this->add_video($video)) {
                            $progress = sprintf("%01.2f", ($progress+$incr));
                            $this->update_progress($progress.'^Video ('.$video['url'].') embedded!');
                            ++$this->video_added;
                        } else {
                            $this->update_progress($progress.'^Failed to add video database entry!');
                            $progress = sprintf("%01.2f", ($progress+$incr));
                            $this->errors[] = 'Failed to add '.$video['url'].'!';
                        }
                    } else {
                        $this->update_progress($progress.'^Failed to get video details for '.$video['url'].'!');
                        $progress = sprintf("%01.2f", ($progress+$incr));                                              
                        $this->errors[] = 'Failed to get video details for '.$video['url'].'!';
                    }
                }
            } else {
                $this->update_progress('100^No videos found while parsing remote html!!!');
                $this->errors[] = 'No videos found while parsing '.$this->url.'!';
            }
        } else {
            $this->update_progress('100^Failed to download remote html page!!!');
            $this->errors[] = 'Failed to download '.$this->url.'!';
        }
        
        if ($this->errors) {
            return FALSE;
        }
        
        return TRUE;
    }
}