'; // getCriterionPosters(); $html = file_get_contents('html/0xdb.html'); $string = explode('id="iconPoster', $html); for ($i = 1; $i < count($string); $i++) { $substring = explode('"', $string[$i]); $id = $substring[0]; if (strlen($id) == 7 || strlen($id) == 34) { $file_exists = false; foreach ($imagetype as $value) { if (file_exists('posters/wikipedia.org/' . substr($id, 0, 4) . '/' . $id . '.' . $value)) { $file_exists = true; break; } if (file_exists('posters/wikipedia.org/' . substr($id, 0, 4) . '/_' . $id . '.' . $value)) { $file_exists = true; break; } } if (!$file_exists) { $file = getWikipedia($id); if ($file) echo 'writing ' . $id . '
'; } else echo 'reading ' . $id . '
' . str_repeat(' ', 10000); $file_exists = false; foreach ($imagetype as $value) { if (file_exists('posters/imdb.com/' . substr($id, 0, 4) . '/' . $id . '.' . $value)) { $file_exists = true; break; } } if (!$file_exists) getImdb($id); if (!file_exists('posters/0xdb.org/' . substr($id, 0, 4) . '/' . $id . '.jpg')) get0xdb($id); flush(); ob_flush(); } } // getImpawardsIndex(); } function returnPoster($id, $size) { if ($size == 'small') $source = array('piratecinema', 'karagarga', 'criterion', 'wikipedia', 'impawards', 'imdb', '0xdb'); else $source = array('piratecinema', 'karagarga', 'criterion', 'wikipedia', 'impawards'); foreach ($source as $value) { $function = get . ucfirst($value); $file[$value] = $function($id); // echo $value . time() . ' '; } foreach ($source as $value) { if ($file[$value]) returnImage($id, $size, $file[$value]); } // returnImage($id, $size, 'png/poster' . ucfirst($size) . '.png'); if ($size == 'small') returnImage($id, 'small', 'posters/0xdb.org/' . substr($id, 0, 4) . '/' . $id . '.png'); else returnImage($id, 'large', 'png/posterLarge.png'); } function getTitle($id) { $html = getUrl('http://www.imdb.com/title/tt' . $id . '/'); $string = explode('', $html); $string = explode('', $string[1]); $string = explode(' (', $string[0]); $title = html_entity_decode($string[0]); return $title; } function getImdb($id) { global $imagetype; foreach ($imagetype as $value) { $file = 'posters/imdb.com/' . substr($id, 0, 4) . '/' . $id . '.' . $value; if (file_exists($file)) return $file; } $html = getUrl('http://www.imdb.com/title/tt' . $id . '/'); $string = explode('', $html); for ($i = 0; $i < count($string) - 1; $i++) { $substring = explode('"; if (strstr($html, '"/wiki/Image:')) { // echo "image ok
"; $string = explode('"/wiki/Image:', $html); $string = explode('"', $string[1]); $url = 'http://en.wikipedia.org/wiki/Image:' . $string[0]; $html = getUrl($url); $string = explode('src="http://upload.wikimedia.org/', $html); $string = explode('"', $string[1]); $url = 'http://upload.wikimedia.org/' . $string[0]; $pathinfo = pathinfo($url); $extension = strtolower($pathinfo['extension']); $imagesize = getimagesize($url); if ($imagesize[0] > 128 || $imagesize[1] > 128) { $file = 'posters/wikipedia.org/' . substr($id, 0, 4) . '/' . $id . '.' . $extension; $data = getUrl($url); writeFile($file, $data); // echo "$file $title\n"; return $file; } } break; } } return false; } function getImpawards($id) { global $imagetype; foreach ($imagetype as $value) { $file = 'posters/impawards.com/' . substr($id, 0, 4) . '/' . $id . '.' . $value; if (file_exists($file)) return $file; } } function getCriterion($id) { global $imagetype; foreach ($imagetype as $value) { $file = 'posters/criterion.com/' . substr($id, 0, 4) . '/' . $id . '.' . $value; if (file_exists($file)) return $file; } } function getKaragarga($id) { global $imagetype; foreach ($imagetype as $value) { $file = 'posters/karagarga.net/' . substr($id, 0, 4) . '/' . $id . '.' . $value; if (file_exists($file)) return $file; } } function getPiratecinema($id) { global $imagetype; foreach ($imagetype as $value) { $file = 'posters/piratecinema.org/' . substr($id, 0, 4) . '/' . $id . '.' . $value; if (file_exists($file)) return $file; } } function returnImage($id, $size, $file) { $pathinfo = pathinfo($file); $extension = $pathinfo['extension']; if ($extension == 'gif') $source = imagecreatefromgif($file); else if ($extension == 'png') $source = imagecreatefrompng($file); else $source = imagecreatefromjpeg($file); if ($size == 'small') $size = 128; else $size = 512; $imagesize = getimagesize($file); if ($imagesize[0] > $imagesize[1]) { $width = $size; $height = round($width * $imagesize[1] / $imagesize[0]); } else { $height = $size; $width = round($height * $imagesize[0] / $imagesize[1]); } $target = imagecreatetruecolor($width, $height); imagecopyresampled($target, $source, 0, 0, 0, 0, $width, $height, $imagesize[0], $imagesize[1]); if (strstr($file, 'png/poster')) { header('Content-Type: image/png'); header('Content-Disposition: inline; filename="' . $id . '.png"'); imagepng($target); } else { header('Content-Type: image/jpeg'); header('Content-Disposition: inline; filename="' . $id . '.jpg"'); imagejpeg($target, NULL, 100); } exit; } function getUrl($url) { $url = parse_url($url); $host = $url['host']; $file = $url['path'] . str_repeat('?', $url['query'] != '') . $url['query']; // echo $host . ' ' . $file . '
'; $headers = "GET $file HTTP/1.1\r\n"; $headers .= "Accept: */*\r\n"; $headers .= "Accept-Language: en\r\n"; // $headers .= "Accept-Encoding: gzip, deflate\r\n"; $headers .= "User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3\r\n"; $headers .= "Connection: close\r\n"; $headers .= "Host: $host\r\n\r\n"; $f = @fsockopen($host, 80, $errorNumber, $errorString, 60); if ($f) { fwrite($f, $headers); while (!feof($f)) $data .= fread($f, 1024); fclose($f); $data = substr($data, strpos($data, "\r\n\r\n") + 4); } return $data; } function writeFile($file, $data) { $pathinfo = pathinfo($file); $dirname = $pathinfo['dirname']; $filename = $dirname . '/' . $pathinfo['basename']; $string = explode('/', $dirname); for ($i = 0; $i < count($string); $i++) { if ($i > 0) $subdirname .= '/'; $subdirname .= $string[$i]; if (!file_exists($subdirname)) mkdir($subdirname, 0777); } @file_put_contents($filename, $data); @chmod($filename, 0666); } function getCriterionPosters() { $html = getUrl('http://www.criterion.com/asp/browse.asp?sort=spine'); $string = explode('height="20" valign="top" class="regtext">
', $string[$i]); $substring = explode('<', $substring[1]); $title = $substring[0]; $substring = explode('class="regtext">', $string[$i]); $substring = explode('<', $substring[1]); $director = $substring[0]; $substring = explode('class="regtext">', $string[$i]); $substring = explode('<', $substring[4]); $spine = $substring[0]; $url = 'http://www.google.com/search?q=' . urlencode('site:imdb.com "' . $title . '" ' . $director); $html = getUrl($url); $id = 0; $string_ = explode('" class=l>', $html); for ($i_ = 0; $i_ < count($string_) - 1; $i_++) { $substring = explode('\n"; } } function crawlPath($path) { global $list; if (substr($path, -1) == '/') $path = substr($path, 0, -1); $dir = dir($path); while ($file = $dir->read()) { if (substr($file, 0, 1) != '.') { $file = $path . '/' . $file; if (is_dir($file)) crawlPath($file); else $list[count($list)] = $file; } } return $list; } ?>