Файл: adultscript-2.0.3-pro/files/admin/modules/grab/grabers/tnaflix.php
Строк: 113
<?php
defined('_VALID') or die('Restriced Acess!');
class VComponent_Admin_grab_tnaflix 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, 'video_type_preview=image'));
        if ($html) {
            preg_match_all('/<div class="video(.*?)height=/', $html, $matches);
            if (isset($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;
                    }
                    
                    if (substr($match, 'empflix.com') !== false) {
//                        continue;
                    }
                    
                    $video    = array(
                        'site'        => 'tnaflix',
                        'url'        => '',
                        'title'        => '',
                        'desc'        => '',
                        'tags'      => '',
                        'category'    => '',
                        'thumbs'    => array(),
                        'duration'    => 0,
                        'embed'        => '',
                        'size'        => 0,
                        'file_url'    => ''
                    );
                    
                    preg_match('/<a href="(.*?)" class="videoThumb"/', $match, $matches_url);
                    if (isset($matches_url['1']) && !empty($matches_url['1'])) {
                        $video['url']    = trim(urldecode(substr($matches_url['1'], 0, strrpos($matches_url['1'], '?'))));
                        if (substr($video['url'], 0, 1) == '/') {
                            $video['url'] = 'http://www.tnaflix.com'.$video['url'];
                        }
                        
                        $this->update_progress($progress.'^Processing '.$video['url'].' ...');
                        if (strpos($video['url'], 'premium') === FALSE) {
                            if ($this->already_added('tnaflix', $video['url'])) {
                                $this->update_progress($progress.'^Video already added!');
                                $progress = sprintf("%01.2f", ($progress+$incr));
                                ++$this->video_already;
                                continue;
                            }
                        } else {
                            $this->update_progress($progress.'^Video is premium...skipping!');
                            $progress = sprintf("%01.2f", ($progress+$incr));
                              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']) && !empty($matches_title['1'])) {
                        $video['title']    = strip_tags(stripslashes($matches_title['1']));
                    }
                    
                    preg_match('/<span class="widescreen">(.*?)</span>/', $match, $matches_duration);
                    if (!isset($matches_duration['1']) OR !$matches_duration['1']) {
                        preg_match('/<span class="standard_screen">(.*?)<//', $match, $matches_duration);
                        if (!isset($matches_duration['1']) OR !$matches_duration['1']) {
                            preg_match('/<span class="duringTime">(.*?)</span>/', $match, $matches_duration);
                        }
                    }
                    
                      if (isset($matches_duration['1'])) {
                          $video['duration'] = $this->duration_to_seconds($matches_duration['1']);
                      }
                    
                    preg_match('/data-src="(.*?)" alt/', $match, $matches_thumb);
                    if (!isset($matches_thumb['1']) OR empty($matches_thumb['1'])) {
                        preg_match('/src="(.*?)" /', $match, $matches_thumb);
                    }
                    
                    if (isset($matches_thumb['1']) && $matches_thumb['1']) {
                        $thumb_url  = explode('_', $matches_thumb['1']);
                        $url_left   = substr($thumb_url['0'], 0, strrpos($thumb_url['0'], '/'));
                        $video['thumbs']    = array(
                            $url_left.'/1_'.$thumb_url['1'],
                            $url_left.'/2_'.$thumb_url['1'],
                            $url_left.'/3_'.$thumb_url['1'],
                            $url_left.'/4_'.$thumb_url['1'],
                            $url_left.'/5_'.$thumb_url['1'],
                            $url_left.'/6_'.$thumb_url['1'],
                            $url_left.'/7_'.$thumb_url['1'],
                            $url_left.'/8_'.$thumb_url['1'],
                            $url_left.'/9_'.$thumb_url['1'],
                            $url_left.'/10_'.$thumb_url['1'],
                            $url_left.'/11_'.$thumb_url['1'],
                            $url_left.'/12_'.$thumb_url['1'],
                            $url_left.'/13_'.$thumb_url['1'],
                            $url_left.'/14_'.$thumb_url['1'],
                            $url_left.'/15_'.$thumb_url['1'],
                            $url_left.'/16_'.$thumb_url['1'],
                            $url_left.'/17_'.$thumb_url['1'],
                            $url_left.'/18_'.$thumb_url['1'],
                            $url_left.'/19_'.$thumb_url['1'],
                            $url_left.'/20_'.$thumb_url['1'],
                            $url_left.'/21_'.$thumb_url['1'],
                            $url_left.'/22_'.$thumb_url['1'],
                            $url_left.'/23_'.$thumb_url['1'],
                            $url_left.'/24_'.$thumb_url['1'],
                            $url_left.'/25_'.$thumb_url['1'],
                            $url_left.'/26_'.$thumb_url['1'],
                            $url_left.'/27_'.$thumb_url['1'],
                            $url_left.'/28_'.$thumb_url['1'],
                            $url_left.'/29_'.$thumb_url['1'],
                            $url_left.'/30_'.$thumb_url['1']
                        );
                    }
                    
                    $video_id  = str_replace('video', '', substr($video['url'], strrpos($video['url'], '/')+1));
                    $video['video_id']    = $video_id;
                    
                    if ($video['title'] && $video['duration'] && $video['thumbs'] && isset($video_id)) {
                        $content    = $this->clean_html(VCurl::string($video['url'], 'video_type_preview=image'));
                        preg_match('/<span class="infoTitle">Categories:</span>(.*?)</span>/', $content, $matches_category);
                        if (isset($matches_category['1']) && !empty($matches_category['1'])) {
                            preg_match_all('/<a href="(.*?)">(.*?)</a>/', $matches_category['1'], $matches_categs);
                            if (isset($matches_categs['2']) && !empty($matches_categs['2'])) {
                                $video['category'] = $matches_categs['2']['0'];
                            }
                        }
                        
                        preg_match('/<span class="infoTitle">Tags:</span> <span class="listView">(.*?)</span>/', $content, $matches_tags);
                        if (isset($matches_tags['1'])) {
                            preg_match_all('/href="(.*?)">(.*?)</a>/', $matches_tags['1'], $matches_urls);
                            if (isset($matches_urls['2'])) {
                                $tags = array();
                                foreach ($matches_urls['2'] as $tag) {
                                    $tags[] = prepare_string(strip_tags(stripslashes($tag)));
                                }
                                
                                  $video['tags']  = strtolower(implode(' ', $tags));
                            }
                        }
                        
                        $video['embed']    = '<iframe src="http://player.tnaflix.com/video/'.$video_id.'" width="'.$this->vcfg['embed_width'].'" height="'.$this->vcfg['embed_height'].'" frameborder="0"></iframe>';                        
                        
                        if ($video['category'] && $video['tags'] && $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 (2) '.$video['url'].'(category/tags/embed)!');
                            $progress = sprintf("%01.2f", ($progress+$incr));
                            $this->errors[] = 'Failed to get video details for (2) '.$video['url'].'!';
                        }
                    } else {
                        $this->update_progress($progress.'^Failed to get video details for (1) '.$video['url'].'!');
                        $progress = sprintf("%01.2f", ($progress+$incr));
                        $this->errors[] = 'Failed to get video details for (1) '.$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;
    }
}