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

48 lines
1.4 KiB
PHP
Executable File

<?php
$list = scandir("../../../Filme");
$path = "../rsc/thumbnails/"; //TODO
$data = new class{};
for($i=2;$i<=count($list)-1;$i++){
if (strpos($list[$i], '.mp4') !== false) {
$list[$i]=str_replace(' ', '%20', substr($list[$i], 0, -4));
//TODO
if (file_exists($path.str_replace('%20', ' ', $list[$i]).".jpg")) { //TODO
echo "exists!\n";
}else {
echo("exists not: ".str_replace('%20', ' ', $list[$i]).".jpg\n");
$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=de-DE&include_adult=true&query=".$moviename;
//$query = "https://api.themoviedb.org/3/search/movie?api_key=9fd90530b11447f5646f8e6fb4733fb4&language=de-DE&include_adult=true&query=eeeeeee";
$result = json_decode(file_get_contents($query));
if ($result->total_results == 0) {
echo("\n\nno result found for".$moviename);
}else {
$moviedata = $result->results[0];
echo json_encode($moviedata);
file_put_contents ('./'.str_replace('%20', ' ', $list[$i]).'.json', json_encode($moviedata));
// $data->{$moviedata->title} = $moviedata;
}
}
}
}
?>