HomeMediacenter/php/mergescripts/getthumbnailsmovies.php
2020-05-16 20:41:32 +02:00

47 lines
1.6 KiB
PHP
Executable File

<?php
$list = scandir("../../../Filme");
$path = "../../rsc/thumbnails/";
for($i=2;$i<=count($list)-1;$i++){
if (strpos($list[$i], '.mp4') !== false) {
$list[$i]=str_replace(' ', '%20', substr($list[$i], 0, -4));
if (file_exists($path.str_replace('%20', ' ', $list[$i]).".jpg")) {
echo "exists!\n";
}else {
echo("exists not: ".str_replace('%20', ' ', $list[$i]).".jpg");
$moviename = $list[$i];
$year = 0;
if( preg_match( '!\(([^\)]+)\)!', $list[$i], $match ) ){
$text = $match[0];
$year = $match[1];
$moviename = str_replace($text,"",$list[$i]);
echo $text."\n\n";
}
$query = "https://api.themoviedb.org/3/search/movie?api_key=9fd90530b11447f5646f8e6fb4733fb4&language=en-US&include_adult=true&query=".$moviename;
$result = json_decode(file_get_contents($query));
if ($result->total_results == 0) {
echo("\n\nno result found for".$moviename);
}else {
if ($year != 0) {
for ($n=0; $n < count($result->results); $n++) {
if(strpos($result->results[$n]->release_date, $year) !== false)
{
copy("http://image.tmdb.org/t/p/w342/".$result->results[$n]->poster_path, $path.str_replace('%20', ' ', $list[$i]).".jpg");
}
}
}else {
echo("http://image.tmdb.org/t/p/original/".$result->results[0]->poster_path."\n\n");
copy("http://image.tmdb.org/t/p/w342/".$result->results[0]->poster_path, $path.str_replace('%20', ' ', $list[$i]).".jpg");
}
}
}
}
}
?>