Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/grab/grabers/xhamster.php
Строк: 95
<?php
defined
('_VALID') or die('Restriced Acess!');
class 
VComponent_Admin_grab_xhamster 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) {
//            echo (str_replace('</div>', "</div>n", $html));
            
            
preg_match_all('/<div class='video'>(.*?)</div>/', $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;
                    }
                    
                    
$video    = array(
                        
'site'        => 'xhamster',
                        
'url'        => '',
                        
'title'        => '',
                        
'desc'        => '',
                        
'tags'      => '',
                        
'category'    => '',
                        
'thumbs'    => array(),
                        
'duration'    => 0,
                        
'embed'        => '',
                        
'size'        => 0,
                        
'file_url'    => ''
                    
);
                    
                    
                    
preg_match('/<a href='(.*?)'/', $match, $matches_url);
                    if (isset(
$matches_url['1'])) {
                        
$video['url']    = trim($matches_url['1']);
                        
$this->update_progress($progress.'^Processing '.$video['url'].' ...');
                        if (
$this->already_added('xhamster', $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('/alt='(.*?)'/', $match, $matches_title);
                      if (!isset(
$matches_title['1'])) {
                          
preg_match('/alt="(.*?)"/', $match, $matches_title);
                      }
                      
                      if (isset(
$matches_title['1']) && $matches_title['1']) {
                          
$video['title']    = strip_tags($matches_title['1']);
                      }
                    
                    
preg_match('/<b>(.*?)</b>/', $match, $matches_duration);
                      if (isset(
$matches_duration['1'])) {
                          
$video['duration'] = $this->duration_to_seconds($matches_duration['1']);
                      }
                    
                    
preg_match('/<img src='(.*?)'/', $match, $matches_thumb);
                    if (isset(
$matches_thumb['1']) && isset($matches_thumb['1'])) {
                          
$thumb_url      = str_replace('.jpg', '', $matches_thumb['1']);
                          
$video_id        = substr($thumb_url, strrpos($thumb_url, '_')+1);                          
                          
$thumb_url        = substr($thumb_url, 0, strrpos($thumb_url, '/'));
                          
                        
$video['thumbs']    = array(
                            
$thumb_url.'/1_'.$video_id.'.jpg',
                            
$thumb_url.'/2_'.$video_id.'.jpg',
                            
$thumb_url.'/3_'.$video_id.'.jpg',
                            
$thumb_url.'/4_'.$video_id.'.jpg',
                            
$thumb_url.'/5_'.$video_id.'.jpg',
                            
$thumb_url.'/6_'.$video_id.'.jpg',
                            
$thumb_url.'/7_'.$video_id.'.jpg',
                            
$thumb_url.'/8_'.$video_id.'.jpg',
                            
$thumb_url.'/9_'.$video_id.'.jpg',
                            
$thumb_url.'/10_'.$video_id.'.jpg'
                        
);
                      }
                      
                    if (
$video['title'] && $video['duration'] && $video['thumbs'] && isset($video_id)) {
                        
$content = $this->clean_html(VCurl::string($video['url']));
                        
                        
preg_match('/Categories:</span></td>(.*?)</td>/', $content, $matches_tags);
                          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);
                              }
                          }
                          
                          
$video['category']     = $tags['0'];
                        
$video['embed']     = '<iframe width="'.$this->vcfg['embed_width'].'" height="'.$this->vcfg['embed_height'].'" src="http://xhamster.com/xembed.php?video='.$video_id.'" frameborder="0" scrolling="no"></iframe>';
                        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;
    }

    protected function 
duration_to_seconds($duration)
    {
        
$duration   = str_replace(array('m', 's'), array(':', ''), $duration);
        
$duration   = explode(':', $duration);
        
$minutes    = sprintf('%01d', $duration['0']);
        
$seconds    = sprintf('%01d', $duration['1']);

        return ((
$minutes * 60) + $seconds);
    }    
}
Онлайн: 2
Реклама