예제 #1
0
 function get()
 {
     // Check first in these server using *only* the URL
     $video_servers = array('youtube.com' => 'check_youtube', 'yfrog.com' => 'check_yfrog');
     $base_host = preg_replace('/^www\\./', '', $this->parsed_url['host']);
     if ($video_servers[$base_host]) {
         if ($this->debug) {
             echo "<!-- Check thumb by URL: {$video_servers[$base_host]} -->\n";
         }
         if ($this->{$video_servers}[$base_host]()) {
             if ($this->debug) {
                 echo "<!-- Selected thumb by URL: {$video_servers[$base_host]} -->\n";
             }
             $this->selected->video = true;
             return $this->selected;
         }
     }
     $res = get_url($this->url, $this->referer, null, false);
     if (!$res) {
         if ($this->debug) {
             echo "<!-- Error getting " . htmlentities($this->url) . "-->\n";
         }
         return;
     }
     if ($this->debug) {
         echo "<!-- Got {$this->url} (" . strlen($res['content']) . ") -->\n";
     }
     if ($res['location'] != $this->url) {
         $this->redirected = clean_input_url($res['location']);
         $this->parsed_redirected = parse_url($this->redirected);
         if ($this->debug) {
             echo "<!-- Redirected to URL: {$this->redirected} -->\n";
         }
     }
     if (preg_match('/^image/i', $res['content_type'])) {
         $img = new BasicThumb($this->url);
         if ($img->fromstring($res['content'])) {
             $img->type = 'local';
             $img->candidate = true;
             $this->selected = $img;
         }
     } elseif (preg_match('/text\\/html/i', $res['content_type'])) {
         $this->html = $res['content'];
         $this->title = get_html_title($this->html);
         if ($this->debug) {
             echo "<!-- HTML {$this->title} -->\n";
         }
         // First check for thumbnail head metas
         if ((preg_match('/<meta\\s+?property=[\'"]og:image[\'"]\\s+?content=[\'"](.+?)[\'"].*?>/is', $this->html, $match) || preg_match('/<meta\\s+?name=[\'"]product-image[\'"]\\s+?content=[\'"](.+?)[\'"].*?>/is', $this->html, $match) || preg_match('/<meta\\s+?name=[\'"]thumbnail_url[\'"]\\s+?content=[\'"](.+?)[\'"].*?>/is', $this->html, $match) || preg_match('/<link\\s+?rel=[\'"]image_src[\'"]\\s+?href=[\'"](.+?)[\'"].*?>/is', $this->html, $match)) && !preg_match('/favicon/i', $match[1])) {
             $url = $match[1];
             $url = build_full_url($url, $this->url);
             if ($this->debug) {
                 echo "<!-- Try to select from {$url} -->\n";
             }
             $img = new BasicThumb($url);
             if ($img->get() && $img->is_not_black()) {
                 $img->type = 'local';
                 $img->candidate = true;
                 if ($img->x > 150 && $img->y > 150) {
                     if ($this->debug) {
                         echo "<!-- Selected from {$img->url} -->\n";
                     }
                     $this->selected = $img;
                     return $this->selected;
                 } else {
                     if ($this->debug) {
                         echo "<!-- Failback {$img->url} -->\n";
                     }
                     $this->fallback = $img;
                 }
             }
         }
         // Analyze HTML <img's
         if (preg_match('/<base *href=["\'](.+?)["\']/i', $this->html, $match)) {
             $this->base = $match[1];
         }
         $html_short = $this->shorten_html($this->html);
         //	echo "<!-- $this->html -->\n";
         $this->parse_img($html_short);
         // If there is no image or image is slow
         // Check if there are players
         if ((!$this->selected || $this->selected->surface() < 120000) && preg_match('/(< *(?:embed|iframe|object|param))[^>]*>|\\.flv/i', $this->html)) {
             if ($this->debug) {
                 echo "<!-- Searching for video -->\n";
             }
             if ($this->check_youtube() || $this->check_yfrog() || $this->check_google_video() || $this->check_metacafe() || $this->check_vimeo() || $this->check_zapp_internet() || $this->check_daily_motion() || $this->check_elmundo_video()) {
                 $this->selected->video = true;
                 return $this->selected;
             }
         }
     }
     if (!$this->selected && $this->fallback != false) {
         $this->selected = $this->fallback;
     }
     if ($this->debug) {
         echo "<!-- FINAL selection: {$this->selected} -->\n";
     }
     return $this->selected;
 }
예제 #2
0
파일: webimages.php 프로젝트: rasomu/chuza
	function get() {

		// Check first in these server using *only* the URL
		$video_servers = array(
						// 'video.google.com' => 'check_google_video',
						'youtube.com' => 'check_youtube',
						// 'metacafe.com' => 'check_metacafe',
						// 'vimeo.com' => 'check_vimeo', 
						// 'zappinternet.com' => 'check_zapp_internet',
						// 'dailymotion.com' => 'check_daily_motion',
				);
		$base_host = preg_replace('/^www\./', '', $this->parsed_url['host']);
		if ($video_servers[$base_host]) {
			if ($this->debug) echo "<!-- Check video by URL: $video_servers[$base_host] -->\n";
			if($this->$video_servers[$base_host]()) {
				if ($this->debug) echo "<!-- Selected video by URL: $video_servers[$base_host] -->\n";
				$this->selected->video = true;
			}
			return $this->selected;
		}

		$res = get_url($this->url, $this->referer);
		if (!$res) {
			echo "<!-- Error getting " . htmlentities($this->url) . "-->\n";
			return;
		}
		if ($this->debug) echo "<!-- Got $this->url (". strlen($res['content']) .") -->\n";
		if ($res['location'] != $this->url) {
			$this->redirected = clean_input_url($res['location']);
			$this->parsed_redirected = parse_url($this->redirected);
			if ($this->debug)
				echo "<!-- Redirected to URL: $this->redirected -->\n";
		}

		if (preg_match('/^image/i', $res['content_type'])) {
			$img = new BasicThumb($this->url);
			if ($img->fromstring($res['content'])) {
				$img->type = 'local';
				$img->candidate = true;
				$this->selected = $img;
			}
		} elseif (preg_match('/text\/html/i', $res['content_type'])) {
			$this->html = $res['content'];
			$this->title = get_html_title($this->html);
			if ($this->debug) echo "<!-- HTML $this->title -->\n";

			// First check for thumbnail head metas
			if ((preg_match('/<link\s+?rel=[\'"]image_src[\'"]\s+?href=[\'"](.+?)[\'"].*?>/is', $this->html, $match) ||
				preg_match('/<meta\s+?name=[\'"]thumbnail_url[\'"]\s+?content=[\'"](.+?)[\'"].*?>/is', $this->html, $match))
				&& ! preg_match('/meneame/i', $match[1])) { // a bad thumbnail meta in aldea-irreductible
				$url = $match[1];
				if ($this->debug)
					echo "<!-- Try to select from $url -->\n";
				$img = new BasicThumb($url);
				if ($img->get()) {
					$img->type = 'local';
					$img->candidate = true;
					$this->selected = $img;
					if ($this->debug)
						echo "<!-- Selected from $img->url -->\n";
					return $this->selected;
				}
			}


			// Analyze HTML <img's
			if (preg_match('/<base *href=["\'](.+?)["\']/i', $this->html, $match)) {
				$this->base = $match[1];
			}
			$html_short = $this->shorten_html($this->html);
			//  echo "<!-- $this->html -->\n";
			$this->parse_img($html_short);

			// If there is no image or image is slow
			// Check if there are players
			if ((!$this->selected || $this->selected->surface() < 120000)
					&& $this->other_html 
					&& preg_match('/(< *(?:embed|iframe|object|param))|\.flv/i', $this->html)) {
				if ($this->debug)
					echo "<!-- Searching for video -->\n";
				if ($this->check_youtube() || 
						$this->check_google_video() ||
						$this->check_metacafe() ||
						$this->check_vimeo() ||
						$this->check_zapp_internet() ||
						$this->check_daily_motion() ||
						$this->check_elmundo_video() ) {
					$this->selected->video = true;
					return $this->selected;
				}
			}

		}
		return $this->selected;
	}