BG Development


  Reply to this topicStart new topicStart Poll

> Извиличане на thumb
ArenaPlay
Публикувано на: 15-08-2023, 16:21
Quote Post



Име:
Група: Потребител
Ранг: Новопостъпил

Мнения: 1
Регистриран на: 15.08.23



Някой може ли да ми помогне малко със този код.
Кода си работи перфектно но искам да променя изображението която извлича.
Сега изважда: [tt]https://srv07.dropload.io/i/01/00052/2psk2u69zhbs_xt.jpg[/tt]
Искам да изважда: [tt]https://srv07.dropload.io/i/01/00052/2psk2u69zhbs_t.jpg[/tt]
Промяната трябва да е от "_xt.jpg" на "_t.jpg"

CODE

function get_info($url)
{
      $video_data = array();
      
      $target_url  = $url;

      $error = 0;

      if(function_exists('curl_init'))
      {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $target_url);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
            curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
            $video_data = curl_exec($ch);
            $errormsg = curl_error($ch);
            curl_close($ch);
            
            if($errormsg != '')
            {
                  echo $errormsg;
                  return false;
            }
      }
      else if(ini_get('allow_url_fopen') == 1)
      {
            $stream_options = array('http' => array(
                  'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0',
            ));
            $ctx = stream_context_create($stream_options);
            $video_data = @file_get_contents($target_url, 0, $ctx);
            if($video_data === false)
                  $error = 1;
      }
      
      if(!is_array($video_data))
      {
            $video_data = explode("\n", $video_data);
      }

      return $video_data;
}

function get_flv($video_data)
{
      return '';
}

function get_thumb_link($video_id)
{

      $thumb_link = '';

      $target_url = 'https://dropload.io/'. $video_id;
      $video_data = get_info($target_url);
      $arr_length = pm_count($video_data);

      for($i = 0; $i < $arr_length; $i++)
      {
            if(preg_match('/src=\"(.*?)\" style=\"width:100%;height:100%;\"(.*?)/i', $video_data[$i], $matches) != 0)
            {
                  $thumb_link = $matches[1];
                  break;
            }
      }

      return $thumb_link;
}

function video_details($video_data, $url, &$info)
{
      $title = $thumb = $id = $tags = $duration = false;
      
      $arr_length = pm_count($video_data);
      
      for ($i = 0; $i < $arr_length; $i++)
      {
            if (strlen($video_data[$i]) < 10)
            {
                  continue;
            }

            if ( ! $title)
            {
                  if (preg_match('/<h1>(.*?)<\/h1>/i', $video_data[$i], $matches) != 0)
                  {
                        $info['video_title'] = $matches[1];
                        $title = true;
                        $title = true;
                  }
            }


            if ( ! $id)
            {
                  $temp_url = '';
                  if (preg_match('/((io\/))(\S+)/', $video_data[$i], $matches) != 0)
                  {
                        $pieces = explode('/', $matches[1]);
                        $info['yt_id'] = $pieces[1];
                        $yt_id = true;
                  }
            }            

            if ( ! $thumb)
            {

                  if(preg_match('/src=\"(.*?)\" style=\"width:100%;height:100%;\"(.*?)/i', $video_data[$i], $matches) != 0)
                  {
                        $info['yt_thumb'] = $matches[1];
                        $thumb = true;
                  }


            }

            if ( ! $tags)
            {
                  if (strpos($video_data[$i], 'name="keywords"'))
                  {
                        if (preg_match('/content="(.*?)"/', $video_data[$i], $matches) != 0)
                        {
                              $info['tags'] = $matches[1];
                              $tags = true;
                        }
                  }
            }

            if ( ! $duration)
            {
                  if (strpos($video_data[$i], '"video:duration"'))
                  {
                        if (preg_match('/content="(.*?)"/', $video_data[$i], $matches) != 0)
                        {
                              $info['duration'] = $matches[1];
                              $duration = true;
                        }
                  }
            }

            if ( ! $direct)
            {
                  if (strpos($video_data[$i], '"og:url"'))
                  {
                        if (preg_match('/content="(.*?)"/', $video_data[$i], $matches) != 0)
                        {
                              $info['direct'] = $matches[1];
                              $thumb = true;
                        }
                  }
            }

            if ($title && $id && $tags && $duration)
            {
                  break;
            }

      }
      
      if ($info['yt_id'] == '')
      {
            preg_match("/((io\/))(\S+)/", $url, $matches);
            $info['yt_id'] = $matches[3];
            // print_r($matches);
      }

      if ($info['direct'] == '')
      {
            $info['direct'] = 'https://dropload.io/'. $info['yt_id'];
      }

      $info['url_flv'] = $info['direct'];

      return;
}


function fetch_headers($url)
{
      $headers = array();
      $url = trim($url);
      
      $error = 0;
      if(function_exists('get_headers'))
      {
            $url = str_replace(' ', '%20', $url);
            if( ! strstr($url, "http://"))
            {
                  $url = "http://" . $url;
            }
            $headers = @get_headers($url, 0);
            if(!$headers)
            {
                  $error = 1;
            }
      }
      
      if($error == 1 || function_exists('get_headers') === FALSE)
      {
            $error = 0;

            if(function_exists('curl_init'))
            {
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL, $url);
                  curl_setopt($ch, CURLOPT_HEADER, 0);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
                  curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
                  $data = curl_exec($ch);
                  $errormsg = curl_error($ch);
                  curl_close($ch);
                  
                  if($errormsg != '')
                  {
                        echo $errormsg;
                        return false;
                  }                        
                  $headers = explode("\n", $data);
            }
            else if(ini_get('allow_url_fopen') == 1)
            {
                  $fp = @fopen($url, "r");
                  if(!$fp)
                        $error = 1;
                  else
                  {
                        if(function_exists('stream_get_meta_data'))
                        {
                              $data = @stream_get_meta_data($fp);
                              $headers = $data['wrapper_data'];
                        }
                        else
                        {
                              $headers = $http_response_header;
                        }
                  }
                  @fclose($fp);
            }
      }
      return $headers;
}

function download_thumb($thumbnail_link, $upload_path, $video_uniq_id, $overwrite_existing_file = false) {
      
      if (strpos($thumbnail_link, '//') === 0)
      {
            $thumbnail_link = 'http:'. $thumbnail_link;
      }
      
      if (strpos($thumbnail_link, 'http') !== 0)
      {
            $thumbnail_link = 'http://'. $thumbnail_link;
      }
      
      $last_ch = substr($upload_path, strlen($upload_path)-1, strlen($upload_path));
      if($last_ch != "/")
            $upload_path .= "/";

      $ext = ".jpg";
      
      $thumb_name = $video_uniq_id . "-1" . $ext;
      
      if(is_file( $upload_path . $thumb_name ) && ! $overwrite_existing_file) {
            return FALSE;
      }
      
      $error = 0;

      if ( function_exists('curl_init') )
      {

            $ch = curl_init();
            $timeout = 0;
            curl_setopt ($ch, CURLOPT_URL, $thumbnail_link);
            curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            // Getting binary data
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            
            $image = curl_exec($ch);
            curl_close($ch);
            
            //      create & save image;
            $img_res = @imagecreatefromstring($image);
            if($img_res === false)
                  return FALSE;
            
            $img_width = imagesx($img_res);
            $img_height = imagesy($img_res);
            
            $resource = @imagecreatetruecolor($img_width, $img_height);
            
            if( function_exists('imageantialias'))
            {
                  @imageantialias($resource, true);
            }
            
            @imagecopyresampled($resource, $img_res, 0, 0, 0, 0, $img_width, $img_height, $img_width, $img_height);
            @imagedestroy($img_res);
      
            switch($ext)
            {
                  case ".gif":
                        //GIF
                        @imagegif($resource, $upload_path . $thumb_name);
                  break;
                  case ".jpg":
                        //JPG
                        @imagejpeg($resource, $upload_path . $thumb_name);
                  break;  
                  case ".png":
                        //PNG
                        @imagepng($resource, $upload_path . $thumb_name);
                  break;
            }
      }
      else if( ini_get('allow_url_fopen') == 1 )
      {
            // try copying it... if it fails, go to backup method.
            if(!copy($thumbnail_link, $upload_path . $thumb_name ))
            {
                  //      create a new image
                  list($img_width, $img_height, $img_type, $img_attr) = @getimagesize($thumbnail_link);

                  $image = '';

                  switch($img_type)
                  {
                        case 1:
                              //GIF
                              $image = imagecreatefromgif($thumbnail_link);
                              $ext = ".gif";
                        break;
                        case 2:
                              //JPG
                              $image = imagecreatefromjpeg($thumbnail_link);
                              $ext = ".jpg";
                        break;  
                        case 3:
                              //PNG
                              $image = imagecreatefrompng($thumbnail_link);
                              $ext = ".png";
                        break;
                  }
                  
                  $resource = @imagecreatetruecolor($img_width, $img_height);
                  if( function_exists('imageantialias'))
                  {
                        @imageantialias($resource, true);
                  }
                  
                  @imagecopyresampled($resource, $image, 0, 0, 0, 0, $img_width, $img_height, $img_width, $img_height);
                  @imagedestroy($image);
            }
            
            $thumb_name = $video_uniq_id . "-1" . $ext;
            
            $img_type = 2;
            switch($img_type)
            {
                  default:
                  case 1:
                        //GIF
                        @imagegif($resource, $upload_path . $thumb_name);
                  break;
                  case 2:
                        //JPG
                        @imagejpeg($resource, $upload_path . $thumb_name);
                  break;  
                  case 3:
                        //PNG
                        @imagepng($resource, $upload_path . $thumb_name);
                  break;
            }
            
            if($resource === '')
                  $error = 1;
      }

      return $upload_path . $thumb_name;
}
function do_main(&$video_details, $url)
{

      $video_data = get_info($url);

      foreach ($video_data as $k=>$v){

            if(stripos($v, 'Unavailable in your region') !== false){
                  echo pm_alert_error('Your server cannot access <strong>Vevo.com</strong> videos due to regional restrictions imposed by <strong>Vevo.com</strong>.');
            }
      }

      if($video_data != false)
      {
            video_details($video_data, $url, $video_details);
      }
      else
      {
            $video_details = array();
      }
}
PMEmail Poster
Top
1 потребители преглеждат тази тема в момента (1 гости, 0 анонимни потребители)
Потребители, преглеждащи темата в момента:

Topic Options Reply to this topicStart new topicStart Poll

 


Copyright © 2003-2019 | BG Development | All Rights Reserved
RSS 2.0