add posters

This commit is contained in:
j 2007-07-25 14:12:17 +00:00
commit 6198a0732c
15 changed files with 21085 additions and 0 deletions

128
0xdbPoster.php Normal file
View File

@ -0,0 +1,128 @@
<?php
$id = $_GET['id'];
$data = json_decode(file_get_contents("http://rlx:luxor@0xdb.org/$id/posterData.json"), true);
$director = utf8_decode($data['director']);
$title = utf8_decode($data['title']);
$url = "http://rlx:luxor@0xdb.org/$id/posterStill.png";
$md5 = md5("$director/$title");
$rPoster = round(hexdec(substr($md5, 0, 2)) / 2);
$gPoster = round(hexdec(substr($md5, 2, 2)) / 2);
$bPoster = round(hexdec(substr($md5, 4, 2)) / 2);
$imagePoster = imagecreatetruecolor(80, 128);
$color = imagecolorallocate($imagePoster, $rPoster, $gPoster, $bPoster);
imagefilledrectangle($imagePoster, 0, 0, 79, 127, $color);
$color = imagecolorallocate($imagePoster, 0, 0, 0);
imagefilledrectangle($imagePoster, 0, 45, 79, 63, $color);
$imageStill = imagecreatefrompng($url);
$imagesize = getimagesize($url);
$wStill = $imagesize[0];
$hStill = $imagesize[1];
if ($wStill / $hStill >= 8 / 5) {
$xStill = round($wStill / 2 - $hStill * 4 / 5);
$yStill = 0;
$wStill = round($hStill * 8 / 5);
}
else {
$xStill = 0;
$yStill = round($hStill / 2 - $wStill * 5 / 16);
$hStill = round($wStill * 5 / 8);
}
imagecopyresampled($imagePoster, $imageStill, 0, 0, $xStill, $yStill, 80, 50, $wStill, $hStill);
/*
$color = imagecolorallocate($imagePoster, $rPoster + 128, $gPoster + 128, $bPoster + 128);
imagettftext($imagePoster, 10, 0, 4, 60, $color, 'ttf/DINMit', 'Bla bla bla');
*/
$imageForeground = imagecreatetruecolor(80, 128);
$colorBlack = imageColorAllocate($imageForeground, 0, 0, 0);
imagefilledrectangle($imageForeground, 0, 0, 79, 127, $colorBlack);
$imageFont = imagecreatefrompng('png/font.png');
$imageForeground = writeString($imageForeground, $imageFont, $director, 'director');
$imageForeground = writeString($imageForeground, $imageFont, $title, 'title');
$imageForeground = writeString($imageForeground, $imageFont, substr($id, 0, 2) . strtoupper(substr($id, 2, 6)), 'id');
for ($y = 0; $y < 128; $y++) {
for ($x = 0; $x < 80; $x++) {
$rgb = imagecolorat($imagePoster, $x, $y);
$rB = ($rgb >> 16) & 255;
$gB = ($rgb >> 8) & 255;
$bB = $rgb & 255;
$rgb = imagecolorat($imageForeground, $x, $y);
$rF = ($rgb >> 16) & 255;
$gF = ($rgb >> 8) & 255;
$bF = $rgb & 255;
if ($rF + $gF + $bF) {
$r = $rB + $rF / 2;
$g = $gB + $gF / 2;
$b = $bB + $bF / 2;
$color = imagecolorallocate($imagePoster, $r, $g, $b);
imagesetpixel($imagePoster, $x, $y, $color);
}
}
}
header('Content-Type: image/png');
imagepng($imagePoster);
function writeString($imageForeground, $imageFont, $text, $type) {
$wPoster = 80;
$hPoster = 128;
$xMargin = 4;
$wFont = 64;
$hFont = 128;
if ($type == 'director')
$width = 36;
else if ($type == 'title')
$width = 24;
else
$width = 12;
$line = formatString($text, $width);
if ($type == 'director') {
while (count($line) > 3) {
$string = explode(', ', $text);
array_pop($string);
$text = implode(', ', $string);
$line = formatString($text, $width);
}
}
$wLine = $wPoster - 2 * $xMargin;
$hLine = round($wLine / $width * 2);
foreach ($line as $key => $value) {
$len = strlen($value);
// die(($maxlen * $wFont) . '!');
$imageLine = imagecreatetruecolor($width * $wFont, $hFont);
for ($i = 0; $i < $len; $i++) {
$ord = ord(substr($value, $i, 1));
$x = ($ord % 16) * $wFont;
$y = floor($ord / 16) * $hFont;
imagecopy($imageLine, $imageFont, $i * $wFont, 0, $x, $y, $wFont, $hFont);
}
if ($type == 'director')
$y = 63 - (count($line) - $key) * $hLine;
else if ($type == 'title')
$y = 66 + $key * $hLine;
else
$y = 113;
imagecopyresampled($imageForeground, $imageLine, $xMargin, $y, 0, 0, $wLine, $hLine, $width * $wFont, $hFont);
}
return $imageForeground;
}
function formatString($string, $width) {
$lines = count(explode("\n", wordwrap($string, $width)));
while ($width > 0) {
$width--;
if (count(explode("\n", wordwrap($string, $width))) > $lines) {
$width++;
break;
}
}
return explode("\n", wordwrap($string, $width));
}
?>

50
admin.php Executable file
View File

@ -0,0 +1,50 @@
<?
include('php/library.php');
echo '<tt>';
$poster = $_GET['poster'];
$kill = $_GET['kill'];
if ($poster) {
echo '<img src="' . $poster . '" /><br />' . $poster . ' <a href="admin.php?kill=' . $poster . '">kill</a>';
exit;
}
if ($kill) {
rename($kill, substr($kill, 0, 27) . '_' . substr($kill, 27));
echo $kill . ' killed.';
exit;
}
$path = 'posters/wikipedia.org';
$list = crawlPath($path);
foreach ($list as $value) {
if (strstr($value, '/_'))
$signature[$value] = md5(file_get_contents($value));
else if (strstr($value, '_'))
unlink($value);
}
echo (count($list) - count($signature)) . ' posters<br /><br />';
sort($list);
foreach ($list as $value) {
if (!$signature[$value]) {
if (in_array(md5(file_get_contents($value)), $signature)) {
rename($value, substr($value, 0, 27) . '_' . substr($value, 27));
// echo '<img src="' . substr($value, 0, 27) . '_' . substr($value, 27) . '" /><br />';
}
else {
$pathinfo = pathinfo($value);
$extension = $pathinfo['extension'];
$imagesize = getimagesize($value);
if ($extension == 'png' || $imagesize[0] >= $imagesize[1])
echo '<img src="' . $value . '" /><br />' . $value . ' <a href="admin.php?poster=' . $value . '">kill</a><br /><br />';
}
}
}
?>

1
data/posters.data Normal file

File diff suppressed because one or more lines are too long

7
download.php Executable file
View File

@ -0,0 +1,7 @@
<?
include('php/library.php');
downloadPosters();
?>

20252
html/0xdb.html Normal file

File diff suppressed because it is too large Load Diff

525
php/library.php Executable file
View File

@ -0,0 +1,525 @@
<?php
$id = str_pad($_GET['id'], 7, '0', STR_PAD_LEFT);
$size = $_GET['size'];
if ($size != 'large')
$size = 'small';
$imagetype = array('gif', 'jpeg', 'jpg', 'png');
function downloadPosters() {
global $imagetype;
set_time_limit(0);
echo '<tt>';
// 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 . '<br />';
}
else
echo 'reading ' . $id . '<br />' . 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('<title>', $html);
$string = explode('</title>', $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('<a name="poster"', $html);
$string = explode('src="', $string[1]);
$string = explode('"', $string[1]);
$url = $string[0];
if ($url && $url != 'http://ia.imdb.com/media/imdb/01/I/44/47/29.gif') {
$data = getUrl($url);
$pathinfo = pathinfo($url);
$extension = strtolower($pathinfo['extension']);
$file = 'posters/imdb.com/' . substr($id, 0, 4) . '/' . $id . '.' . $extension;
// die($url . ' ' . $file);
writeFile($file, $data);
return $file;
}
}
function get0xdb($id) {
$file = 'posters/0xdb.org/' . substr($id, 0, 4) . '/' . $id . '.png';
/*
if (file_exists($file))
return $file;
*/
// the following is used to remove broken images from the db
if (file_exists($file)) {
$image = @imagecreatefrompng($file);
if ($image)
return $file;
else
unlink($file);
}
$data = file_get_contents('http://rlx:luxor@services.0xdb.org/posters/0xdbPoster.php?id=' . $id);
writeFile($file, $data);
$image = @imagecreatefrompng($file);
if ($image)
return $file;
else {
unlink($file);
return 'png/posterSmall.png';
}
}
function getWikipedia($id) {
global $imagetype;
foreach ($imagetype as $value) {
$file = 'posters/wikipedia.org/' . substr($id, 0, 4) . '/' . $id . '.' . $value;
if (file_exists($file))
return $file;
$file = 'posters/wikipedia.org/' . substr($id, 0, 4) . '/_' . $id . '.' . $value;
if (file_exists($file))
return false;
}
$title = getTitle($id);
$url = 'http://www.google.com/search?q=' . urlencode('site:en.wikipedia.org "' . $title . '"');
$html = getUrl($url);
$string = explode('" class=l>', $html);
for ($i = 0; $i < count($string) - 1; $i++) {
$substring = explode('<a href="', $string[$i]);
$url = $substring[count($substring) - 1];
$html = getUrl($url);
if (strstr($html, 'imdb.com/title/tt' . $id)) {
// echo "tt ok<br>";
if (strstr($html, '"/wiki/Image:')) {
// echo "image ok<br>";
$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 . '<br />';
$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"><a href="release.asp?id=', $html);
for ($i = 1; $i , count($string); $i++) {
$substring = explode('class="browse">', $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('<a href="', $string_[$i_]);
$url = $substring[count($substring) - 1];
if (strstr($url, 'title/tt')) {
$substring = explode('title/tt', $url);
$id = substr($substring[1], 0, 7);
break;
}
}
if ($id) {
echo $title . ' (' . $director . ') = ' . getTitle($id) . '<br />' . str_repeat(' ', 10000);
$file = 'posters/criterion.com/' . substr($id, 0, 4) . '/' . $id . '.jpg';
if (!file_exists($file)) {
$data = getUrl('http://www.criterion.com/content/images/full_boxshot/' . $spine . '_box_348x490.jpg');
writeFile($file, $data);
}
}
}
}
function getImpawardsIndex($p = 1) {
global $url;
$html = getUrl('http://www.impawards.com/alpha' . $p . '.html');
// echo $html;
for ($y = 19; $y <= 20; $y++) {
$string = explode('href = ' . $y, $html);
for ($i = 1; $i < count($string); $i++) {
$substring = explode('>', $string[$i]);
if (strstr($substring[0], '_ver1') || !strstr($substring[0], '_ver')) {
$key = count($url);
$url[$key] = '/' . $y . $substring[0];
getImpawardsPage($url[$key]);
}
}
}
if (strstr($html, 'href = alpha' . ($p + 1)))
getImpawardsIndex($p + 1);
}
function getImpawardsPage($url) {
$html = getUrl('http://www.impawards.com' . $url);
$string = explode('imdb.com/title/tt', $html);
$string = explode(' ', $string[1]);
$id = str_pad($string[0], 7, '0', STR_PAD_LEFT);
if ($id > 0) {
$dirname = 'posters/impawards.com/' . substr($id, 0, 4);
$filename = $dirname . '/' . $id . '.jpg';
if (strstr($html, '_xlg.html'))
$poster = 'http://www.impawards.com' . substr($url, 0, 5) . '/posters' . substr($url, 5, -5) . '_xlg.jpg';
else
$poster = 'http://www.impawards.com' . substr($url, 0, 5) . '/posters' . substr($url, 5, -5) . '.jpg';
if (!file_exists($filename)) {
if (!file_exists($dirname))
mkdir($dirname, 0777);
$jpg = file_get_contents($poster);
$f = fopen($filename, 'w');
fwrite($f, $jpg);
fclose($f);
chmod($filename, 0666);
}
echo "$id $poster<br />\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;
}
?>

13
piratecinema.php Executable file
View File

@ -0,0 +1,13 @@
<?
include('php/library.php');
$list = crawlPath('/mnt/storage/gas/Archive/Movies/');
foreach ($list as $value) {
$pathinfo = pathinfo($value);
if (in_array($pathinfo['extension'], $imagetype))
echo "$value\n";
}
?>

BIN
png/font.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

BIN
png/posterLarge.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

BIN
png/posterSmall.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

10
poster.php Executable file
View File

@ -0,0 +1,10 @@
<?
include('php/library.php');
if (!$id)
die('poster.php returns a poster for a given IMDb id<br />usage: poster.php?id=ID[&size=SIZE]<br />ID: IMDb id<br />POSTER: small [128px] or large [512px]');
returnPoster($id, $size);
?>

94
posters.php Normal file
View File

@ -0,0 +1,94 @@
<?php
set_time_limit(300);
$time = $_GET['time'];
if (!$time)
die('posters.php returns all IMDb ids for which new posters have been found since a given time<br />usage: posters.php?time=TIME<br />TIME: timestamp of last update');
$filename = 'data/posters.data';
if (file_exists($filename))
$oldData = unserialize(file_get_contents($filename));
$source = array('piratecinema.org', 'karagarga.net', 'criterion.com', 'wikipedia.org', 'impawards.com', 'imdb.com');
foreach ($source as $value) {
$path = 'posters/' . $value;
$dir = dir($path);
while ($file = $dir->read()) {
if (substr($file, 0, 1) != '.') {
$subpath = $path . '/' . $file;
$subdir = dir($subpath);
while ($subfile = $subdir->read()) {
if (substr($subfile, 0, 1) != '.') {
$string = explode('.', $subfile);
if (strlen($string[0]) == 7 || strlen($string[0]) == 34) {
$id = $string[0];
if (!$newData[$id]) {
$newData[$id]['source'] = $value;
$newData[$id]['time'] = filemtime($subpath . '/' . $subfile);
if ($newData[$id]['source'] != $oldData[$id]['source'] || $newData[$id]['time'] >= $time)
$result[count($result)] = $id;
}
}
}
}
}
}
}
foreach ($oldData as $id => $value) {
if (!in_array($id, $result)) {
if ($newData[$id]['source'] != $oldData[$id]['source'])
$result[count($result)] = $id;
}
}
ksort($newData);
file_put_contents($filename, serialize($newData));
if ($result) {
sort($result);
foreach ($result as $value)
echo "$value\n";
}
/*
$path = 'posters';
$dir = dir($path);
while ($file = $dir->read()) {
if (substr($file, 0, 1) != '.') {
$subpath = $path . '/' . $file;
$subdir = dir($subpath);
while ($subfile = $subdir->read()) {
if (substr($subfile, 0, 1) != '.') {
$subsubpath = $subpath . '/' . $subfile;
$subsubdir = dir($subsubpath);
while ($subsubfile = $subsubdir->read()) {
if (substr($subsubfile, 0, 1) != '.') {
$filename = $subsubpath . '/' . $subsubfile;
if (filemtime($filename) >= $time) {
$string = explode('.', $subsubfile);
$id = str_replace('_', '', $string[0]);
if (strlen($id) > 7)
unlink($filename);
else
$result[$id] = true;
}
}
}
}
}
}
}
if ($result) {
ksort($result);
foreach ($result as $key => $value)
echo "$key\n";
}
*/
?>

5
svn-commit.tmp Normal file
View File

@ -0,0 +1,5 @@
add posters
--This line, and those below, will be ignored--
A .

BIN
ttf/Corsiva.ttf Normal file

Binary file not shown.

0
ttf/DINMit Executable file
View File