Файл: adultscript-2.0.3-pro/files/admin/modules/grab/grabers/tube8.php
Строк: 86
<?php
defined('_VALID') or die('Restriced Acess!');
define('_RESIZE_THUMB', TRUE);
class VComponent_Admin_grab_tube8 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 id="video_(.*?)">(.*?)<div class="box/', $html, $matches);
            if (isset($matches['2'])) {
                $this->update_progress('0^Processing videos...');
                $total_videos   = count($matches['1']);
                $incr           = round((100/$total_videos), 2);
                $progress       = 0;
                                                             
                foreach ($matches['2'] as $match) {
                    ++$count;
                    if ($count > $this->overflow) {
                        $this->errors[]    = 'Overflow reached (500)! Aborting!';
                        return FALSE;
                    }
                    
                    $video    = array(
                        'site'        => 'tube8',
                        'url'        => '',
                        'title'        => '',
                        'desc'        => '',
                        'tags'      => '',
                        'category'    => '',
                        'thumbs'    => array(),
                        'duration'    => 0,
                        'embed'        => '',
                        'size'        => 0,
                        'file_url'    => ''
                    );
                    
                    preg_match('/<a href="(.*?)" ><img/', $match, $matches_url);
                    if (isset($matches_url['1'])) {
                        preg_match('/<a href="(.*?)"/', $match, $matches_url);
                    }
                    
                    if (isset($matches_url['1'])) {
                        $video['url']    = urldecode(trim($matches_url['1']));
                        $this->update_progress($progress.'^Processing '.$video['url'].' ...');
                        if ($this->already_added('tube8', $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 url...continue!');
                          $progress = sprintf("%01.2f", ($progress+$incr));                        
                          continue;
                      }
                      
                      preg_match('/title="(.*?)"/', $match, $matches_title);
                      if (isset($matches_title['1'])) {
                          $video['title']    = $matches_title['1'];
                      }
                      
                    preg_match('/<div class="video-right-text float-right"><strong>(.*?)</strong></div>/', $match, $matches_duration);
                      if (isset($matches_duration['1'])) {
                          $video['duration'] = $this->duration_to_seconds($matches_duration['1']);
                      }
                    
                    preg_match('/src="(.*?)"/', $match, $matches_thumb);
                    if (isset($matches_thumb['1']) && !empty($matches_thumb['1'])) {
                        $thumb_url            = trim($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',
                            $thumb_url.'/9.jpg',
                            $thumb_url.'/10.jpg',
                            $thumb_url.'/11.jpg',
                            $thumb_url.'/12.jpg',
                            $thumb_url.'/13.jpg',
                            $thumb_url.'/14.jpg',
                            $thumb_url.'/15.jpg',
                            $thumb_url.'/16.jpg',
                        );
                      }
                  
                    $embed            = str_replace('http://www.tube8.com', 'http://www.tube8.com/embed', $video['url']);
                    $video['embed']    = '<iframe src="'.$embed.'" frameborder="0" height="'.$this->vcfg['embed_height'].'" width="'.$this->vcfg['embed_width'].'" scrolling="0" name="t8_embed_video"></iframe>';
                    if ($video['url'] && $video['duration'] && $video['thumbs'] && $video['embed']) {
                        $content = $this->clean_html(VCurl::string($video['url']));
                        
                        preg_match('/<li><strong>Category: </strong><a(.*?)>(.*?)</a></li>/', $content, $match_category);
                        if (isset($match_category['2']) && !empty($match_category['2'])) {
                            $video['category']    = strip_tags(trim($match_category['2']));
                        }
                        
                        preg_match('/<li><strong>Tags:</strong>(.*?)</li>/', $content, $match_tags);
                          if (isset($match_tags['1'])) {
                              preg_match_all('/href="(.*?)"><b>(.*?)</b></a>/', $match_tags['1'], $matches_tags);
                              $tags   = array();
                              if (isset($matches_tags['2'])) {
                                  foreach ($matches_tags['2'] as $tag) {
                                      $tags[] = strtolower(prepare_string($tag));
                                  }
        
                                  $video['tags'] = implode(' ', $tags);
                              }
                          }
                          
                        if ($video['title'] && $video['category'] && $video['tags']) {
                            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 {
                            echo VF::debug($video);
                              $this->update_progress($progress.'^Failed to get video details (title, tags, category) for '.$video['url'].'!');
                              $progress = sprintf("%01.2f", ($progress+$incr));                                           
                            $this->errors[] = 'Failed to get video details (title, tags, category) for '.$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;
    }
}