services-posters/posters.php
2007-07-25 14:12:17 +00:00

94 lines
No EOL
2.3 KiB
PHP

<?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";
}
*/
?>