Файл: adultscript-2.0.3-pro/files/admin/modules/grab/grabers/pron.php
Строк: 111
<?php
defined('_VALID') or die('Restriced Acess!');
define('_RESIZE_THUMB', TRUE);
class VComponent_Admin_grab_pron 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('/<li> <script(.*?)</li>/', $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'        => 'pron',
                        'url'        => '',
                        'title'        => '',
                        'desc'        => '',
                        'tags'      => '',
                        'category'    => '',
                        'thumbs'    => array(),
                        'duration'    => 0,
                        'embed'        => '',
                        'size'        => 0,
                        'file_url'    => ''
                    );
                                        
                    preg_match('/href="(.*?)" target="_self"/', $match, $matches_url);
                    if (isset($matches_url['1'])) {
                        if (strpos($matches_url['1'], 'www.pron.com') !== FALSE) {
                            $video['url']    = $matches_url['1'];
                        } else {
                            $video['url']    = 'http://www.pron.com'.$matches_url['1'];
                        }
                        $this->update_progress($progress.'^Processing '.$video['url'].' ...');
                        if ($this->already_added('pron', $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('/<span class="duration">(.*?)</span>/', $match, $matches_duration);
                    if (isset($matches_duration['1'])) {
                          $video['duration'] = $this->duration_to_seconds(trim($matches_duration['1']));
                    }
                    
                    preg_match('/<img src="(.*?)" alt="(.*?)" name/', $match, $matches_thumb);
                    if (isset($matches_thumb['1']) && isset($matches_thumb['2'])) {
                        $video['title']     = strip_tags(stripslashes($matches_thumb['2']));
                        $thumb_url         = $matches_thumb['1'];
                        $thumb_url         = explode('-', $thumb_url);
                        $thumb_url         = $thumb_url['0'];
                        $thumb_url         = explode('/', $thumb_url);
                        $thumbs             = array();
                        foreach ($thumb_url as $string) {
                            $thumbs[] = (strpos($string, ' ') !== FALSE) ? rawurlencode($string) : $string;
                        }
                        
                        $thumb_url         = implode('/', $thumbs);
                        $video['thumbs'] = array(
                            $thumb_url.'-1.jpg',
                            $thumb_url.'-2.jpg',
                            $thumb_url.'-3.jpg',
                            $thumb_url.'-4.jpg',
                            $thumb_url.'-5.jpg'
                        );
                    }
                    
                    echo VF::debug($video);
                    
                    if ($video['title'] && $video['duration'] && $video['thumbs']) {
                        $content = $this->clean_html(VCurl::string($video['url']));
                        preg_match('/<strong>Tags:</strong>(.*?)</div></td>/', $content, $matches_tags);
                        
                        if (trim($matches_tags['1']) != 'n/a') {
                              if (isset($matches_tags['1'])) {
                                preg_match_all('/<a href='(.*?)'>(.*?)</a>/', $matches_tags['1'], $matches_tag);
                                  $tags   = array();
                                  if (isset($matches_tag['2'])) {
                                      foreach ($matches_tag['2'] as $tag) {
                                          $tags[] = strtolower(prepare_string($tag));
                                      }
                                      $video['tags'] = implode(' ', $tags);
                                  }
                              }
                          } else {
                              $video['tags'] = $this->get_pron_tags($video['title']);
                          }
                        
                        preg_match('/<strong>Description:</strong><br />(.*?)</label>/', $content, $matches_desc);
                        if (isset($matches_desc['1'])) {
                            $video['desc'] = strip_tags(stripslashes(trim($matches_desc['1'])));
                        }
                        
                        preg_match('/readonly="readonly" value='<script(.*?)</script>/', $content, $matches_embed);
                        if (isset($matches_embed['1'])) {
                            $video['embed'] = '<script '.str_replace('width=425&height=344', 'width='.$this->vcfg['embed_width'].'&height='.$this->vcfg['embed_height'], $matches_embed['1']).'</script>';
                        }
                        
                        if ($video['tags'] && $video['desc'] && $video['embed']) {
                            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'].'(tags/desc/embed)!';
                        }
                    } 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;
    }
    
    public function get_pron_tags($title)
    {
        $title     = prepare_tags($title);
        $title    = str_replace(',', '', $title);
        $title    = explode(' ', $title);
        $tags    = array();
        foreach ($title as $string) {
            if (strlen($string) >= 4) {
                $tags[] = $string;
            }
        }
        
        return implode(' ', $tags);
    }
}