Commit 87dd1bf9 authored by Nico Schallehn's avatar Nico Schallehn

test nfo export

parent 3c8f6280
...@@ -85,7 +85,7 @@ class Media { ...@@ -85,7 +85,7 @@ class Media {
} }
public function filme($action = "einlesen"){ public function filme($action = "einlesen"){
$start = time(); $start = time();
if(in_array($action, array( "einlesen","check", "checkmd5"))){ if(in_array($action, array( "einlesen","check", "checkmd5", "nfo"))){
//var_dump($this->config); //var_dump($this->config);
echo $this->Console->getColoredString("Filme > ".$action, "black", "light_gray") .PHP_EOL; echo $this->Console->getColoredString("Filme > ".$action, "black", "light_gray") .PHP_EOL;
...@@ -121,16 +121,16 @@ class Media { ...@@ -121,16 +121,16 @@ class Media {
$Counter=0; $Counter=0;
//var_dump($FilmeArr); //var_dump($FilmeArr);
foreach ($FilmeArr as $value) { foreach ($FilmeArr as $value) {
$array = $this->parseMovie((($action == "einlesen")?$this->PfadzumEinlesen."/":$this->PfadzumAusgeben."Filme/").(strlen($value[0])>0?$value[0].'/':''), $value[1]); $array = $this->parseMovie((($action == "einlesen")?$this->PfadzumEinlesen."/":$this->PfadzumAusgeben."Filme/").(strlen($value[0])>0?$value[0].'/':''), $value[1],(($action == "nfo")?true:false));
if(($array == false)){ if(($array == false)){
echo $this->Console->getColoredString(" ","black", "red").PHP_EOL; echo $this->Console->getColoredString(" ","black", "red").PHP_EOL;
$fehler = $this->Console->getColoredString("Fehler!","black", "red")." ".$this->PfadzumEinlesen.'/'.(strlen($value[0])>0?$value[0].'/':'').$value[1].PHP_EOL; $fehler = $this->Console->getColoredString("Fehler!","black", "red")." ".$this->PfadzumEinlesen.'/'.(strlen($value[0])>0?$value[0].'/':'').$value[1].PHP_EOL;
echo $fehler; echo $fehler;
$fehlerArr[] = $fehler; $fehlerArr[] = $fehler;
echo $this->Console->getColoredString(" ","black", "red").PHP_EOL; echo $this->Console->getColoredString(" ","black", "red").PHP_EOL;
}else if((file_exists("./phpTestout/".$array['imdbID'].".txt"))){ }/*else if((file_exists("./phpTestout/".$array['imdbID'].".txt"))){
echo $this->Console->getColoredString("Info!","black", "red")."Film wurde bereits verarbeitet!! Bitte Outputfile in 'phpTestout' löschen!".PHP_EOL; echo $this->Console->getColoredString("Info!","black", "red")."Film wurde bereits verarbeitet!! Bitte Outputfile in 'phpTestout' löschen!".PHP_EOL;
}else{ }*/else{
$Pfad = (($action == "einlesen")?$this->PfadzumEinlesen."/":$this->PfadzumAusgeben."Filme/").(strlen($value[0])>0?$value[0].'/':''); $Pfad = (($action == "einlesen")?$this->PfadzumEinlesen."/":$this->PfadzumAusgeben."Filme/").(strlen($value[0])>0?$value[0].'/':'');
$PfadOrg = (strlen($value[0])>0?$value[0].'/':''); $PfadOrg = (strlen($value[0])>0?$value[0].'/':'');
...@@ -167,15 +167,15 @@ class Media { ...@@ -167,15 +167,15 @@ class Media {
}else { }else {
echo " Film wurde nicht Aktualisiert".PHP_EOL; echo " Film wurde nicht Aktualisiert".PHP_EOL;
} }
//NFO
$this->GenerateNFO($array, $Pfad.$FilenameOrg);
}else if($action == "checkmd5"){ }else if($action == "checkmd5"){
if( $this->updateMovie($array, $Pfad.$FilenameOrg, true, true)){ if( $this->updateMovie($array, $Pfad.$FilenameOrg, true, true)){
echo "Film wurde geprüft und Query angelegt".PHP_EOL; echo "Film wurde geprüft und Query angelegt".PHP_EOL;
}else { }else {
echo "Film wurde geprüft, keine Änderung".PHP_EOL; echo "Film wurde geprüft, keine Änderung".PHP_EOL;
} }
}else if($action == "nfo"){
//NFO //NFO
$this->GenerateNFO($array, $Pfad.$FilenameOrg); $this->GenerateNFO($array, $Pfad.$FilenameOrg);
} }
...@@ -307,7 +307,7 @@ class Media { ...@@ -307,7 +307,7 @@ class Media {
} }
//return $counterNotFound; //return $counterNotFound;
} }
private function parseMovie($Pfad, $Filename){ private function parseMovie($Pfad, $Filename, $minimal = false){
/*TODO mehrere Sachen /*TODO mehrere Sachen
* Auf weitere Saplten die für nfo gebraucht werden erweitern * Auf weitere Saplten die für nfo gebraucht werden erweitern
* *
...@@ -348,93 +348,90 @@ class Media { ...@@ -348,93 +348,90 @@ class Media {
$array["name"] = trim(substr($Filename, 0, strripos( $Filename,"("))); $array["name"] = trim(substr($Filename, 0, strripos( $Filename,"(")));
//TODO wird hier nicht gebraucht? //TODO wird hier nicht gebraucht?
//$Endung = trim(substr($Filename,strripos( $Filename,".")+1)); //$Endung = trim(substr($Filename,strripos( $Filename,".")+1));
if(!$minimal){
echo " Hole Daten von imdb... "; echo " Hole Daten von imdb... ";
// Werte aus IMdb Auslesen... // Werte aus IMdb Auslesen...
$imdb = new IMDB("http://www.imdb.com/title/tt".$array["imdbID"]."/"); $imdb = new IMDB("http://www.imdb.com/title/tt".$array["imdbID"]."/");
if ($imdb->isReady) { if ($imdb->isReady) {
echo " done!".PHP_EOL; echo " done!".PHP_EOL;
//var_dump($imdb->getAll()); $array["year"] = $imdb->getYear();
$array["year"] = $imdb->getYear(); $array["size"] = $this->getfileSize($Pfad.$FilenameOrg);
$array["size"] = $this->getfileSize($Pfad.$FilenameOrg); $array["rating"] = $imdb->getRating();
$array["rating"] = $imdb->getRating();
$array["Genre"] = $imdb->getGenre();
$array["Schauspieler"] = $imdb->getCastAsOwn(0, false);
$array["fsk"] = $this->gibFSK ($imdb,$array["imdbID"]);
if ($array["fsk"] == false){
unset($array["fsk"]);
}
if(!$this->gibTMDBdata ( $array["imdbID"], $array)){
file_put_contents("./phpTestout/".$array["imdbID"].".txt", "Keine Infos auf TMDB gefunden: ".$Pfad.$FilenameOrg.PHP_EOL, FILE_APPEND);
return false; //TODO Abbruch wenn keine Daten auf TMDB gefunden
}
$array["Genre"] = $imdb->getGenre();
$array["Schauspieler"] = $imdb->getCastAsOwn(0, false);
$array["fsk"] = $this->gibFSK ($imdb,$array["imdbID"]);
if ($array["fsk"] == false){
unset($array["fsk"]);
}
if(!$this->gibTMDBdata ( $array["imdbID"], $array)){
file_put_contents("./phpTestout/".$array["imdbID"].".txt", "Keine Infos auf TMDB gefunden: ".$Pfad.$FilenameOrg.PHP_EOL, FILE_APPEND);
return false; //TODO Abbruch wenn keine Daten auf TMDB gefunden
}
} else{
echo $this->Console->error("imdbID (".$array["imdbID"].") nicht bei imdb gefunden!").PHP_EOL;
file_put_contents("./phpTestout/".$array["imdbID"].".txt", "Keine Infos auf imdbID gefunden: ".$Pfad.$FilenameOrg.PHP_EOL, FILE_APPEND);
return false;
}
} else{
echo $this->Console->error("imdbID (".$array["imdbID"].") nicht bei imdb gefunden!").PHP_EOL;
file_put_contents("./phpTestout/".$array["imdbID"].".txt", "Keine Infos auf imdbID gefunden: ".$Pfad.$FilenameOrg.PHP_EOL, FILE_APPEND);
return false;
}
// werte von MediaInfo holen...
// werte von MediaInfo holen... echo " Hole Daten von mediainfo... ";
echo " Hole Daten von mediainfo... "; if(!file_exists('/tmp/'.$array["imdbID"].'.xml')){
if(!file_exists('/tmp/'.$array["imdbID"].'.xml')){ $befehl = 'mediainfo --Output=XML "'.$Pfad.$FilenameOrg.'" > /tmp/'.$array["imdbID"].'.xml';
$befehl = 'mediainfo --Output=XML "'.$Pfad.$FilenameOrg.'" > /tmp/'.$array["imdbID"].'.xml'; exec($befehl);
exec($befehl); }
} $xmlstring = file_get_contents('/tmp/'.$array["imdbID"].'.xml');
$xmlstring = file_get_contents('/tmp/'.$array["imdbID"].'.xml'); $xml = simplexml_load_string($xmlstring);
$xml = simplexml_load_string($xmlstring); $json = json_encode($xml,JSON_PRETTY_PRINT);
$json = json_encode($xml,JSON_PRETTY_PRINT); $array2 = json_decode($json,TRUE);
$array2 = json_decode($json,TRUE); foreach ($array2["File"]["track"] as $key => $value) {
foreach ($array2["File"]["track"] as $key => $value) { //echo " ".$key." ".$value["@attributes"]["type"].PHP_EOL;
//echo " ".$key." ".$value["@attributes"]["type"].PHP_EOL; switch ($value["@attributes"]["type"]) {
switch ($value["@attributes"]["type"]) { case "General":
case "General": $array["vcodec"] = str_replace("Matroska", "mkv", $value["Format"]);
$array["vcodec"] = str_replace("Matroska", "mkv", $value["Format"]); $array["duration"] = $this->getRunTime($value["Duration"]);
$array["duration"] = $this->getRunTime($value["Duration"]); $array["totalbitrate"] = round(trim(str_replace(" ", "",str_replace("Mbps", "", $value["Overall_bit_rate"])))*1024,0);
$array["totalbitrate"] = round(trim(str_replace(" ", "",str_replace("Mbps", "", $value["Overall_bit_rate"])))*1024,0); break;
break; case "Video":
case "Video": $array["width"] = trim(str_replace(" ", "",str_replace("pixels", "",$value["Width"])));
$array["width"] = trim(str_replace(" ", "",str_replace("pixels", "",$value["Width"]))); //TODO Resolution aus diesen werten neusetzen
//TODO Resolution aus diesen werten neusetzen $array["height"] = trim(str_replace(" ", "",str_replace("pixels", "",$value["Height"])));
$array["height"] = trim(str_replace(" ", "",str_replace("pixels", "",$value["Height"]))); break;
break; case "Audio":
case "Audio": if(isset($value["Language"])){
if(isset($value["Language"])){ if(($value["Language"] == "Deutsch") OR ($value["Language"] == "German")){
if(($value["Language"] == "Deutsch") OR ($value["Language"] == "German")){ $array["acodecger"] = $value["Format"];
$array["acodecger"] = $value["Format"]; $array["abitrateger"] = round(trim(str_replace(" ", "",str_replace("Kbps", "",$value["Bit_rate"]))),0);
$array["abitrateger"] = round(trim(str_replace(" ", "",str_replace("Kbps", "",$value["Bit_rate"]))),0); $array["channelsger"] = str_replace(" channels", "",$value["Channel_s_"]);
$array["channelsger"] = str_replace(" channels", "",$value["Channel_s_"]);
if(!is_numeric($array["channelsger"])){
$array["channelsger"] = substr($array["channelsger"],strripos( $array["channelsger"],"/")+1);
if(!is_numeric($array["channelsger"])){ if(!is_numeric($array["channelsger"])){
echo $this->Console->error("channelsger ist nicht Numerisch!").PHP_EOL; $array["channelsger"] = substr($array["channelsger"],strripos( $array["channelsger"],"/")+1);
file_put_contents("./phpTestout/".$array["imdbID"].".txt", "channelsger ist nicht Numerisch!".PHP_EOL, FILE_APPEND); if(!is_numeric($array["channelsger"])){
return false; echo $this->Console->error("channelsger ist nicht Numerisch!").PHP_EOL;
file_put_contents("./phpTestout/".$array["imdbID"].".txt", "channelsger ist nicht Numerisch!".PHP_EOL, FILE_APPEND);
return false;
}
} }
} }
} else if(($value["Language"] == "Englisch") OR ($value["Language"] == "English")){
else if(($value["Language"] == "Englisch") OR ($value["Language"] == "English")){ $array["acodeceng"] = $value["Format"];
$array["acodeceng"] = $value["Format"]; $array["abitrateeng"] = round(trim(str_replace(" ", "",str_replace("Kbps", "",$value["Bit_rate"]))),0);
$array["abitrateeng"] = round(trim(str_replace(" ", "",str_replace("Kbps", "",$value["Bit_rate"]))),0); $array["channelseng"] = str_replace(" channels", "",$value["Channel_s_"]);
$array["channelseng"] = str_replace(" channels", "",$value["Channel_s_"]);
if(!is_numeric($array["channelseng"])){
$array["channelseng"] = substr($array["channelseng"],strripos( $array["channelseng"],"/")+1);
if(!is_numeric($array["channelseng"])){ if(!is_numeric($array["channelseng"])){
echo $this->Console->error("channelseng ist nicht Numerisch!").PHP_EOL; $array["channelseng"] = substr($array["channelseng"],strripos( $array["channelseng"],"/")+1);
file_put_contents("./phpTestout/".$array["imdbID"].".txt", "channelseng ist nicht Numerisch!".PHP_EOL, FILE_APPEND); if(!is_numeric($array["channelseng"])){
return false; echo $this->Console->error("channelseng ist nicht Numerisch!").PHP_EOL;
file_put_contents("./phpTestout/".$array["imdbID"].".txt", "channelseng ist nicht Numerisch!".PHP_EOL, FILE_APPEND);
return false;
}
} }
} }
} }
} break;
break; }
} }
echo " done!".PHP_EOL;
} }
echo " done!".PHP_EOL;
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
if((($value == 'n/A') OR ($value == false)) AND !($Key = '3d')){ if((($value == 'n/A') OR ($value == false)) AND !($Key = '3d')){
unset($array[$key]); unset($array[$key]);
...@@ -450,60 +447,77 @@ class Media { ...@@ -450,60 +447,77 @@ class Media {
} }
private function GenerateNFO($DataArr, $File){ private function GenerateNFO($DataArr, $File){
$nfoFile = substr($File,0,strripos($File,".")).".nfo"; // Echte NFO Ausgabe Pfad $nfoFile = substr($File,0,strripos($File,".")).".nfo"; // Echte NFO Ausgabe Pfad
$mediaDBurl = "http://mediadb.ivaya.de/api.php?key=".$this->config["ApiKeys"]['MediaDB_Key']."&action=GetDataList&Tabelle=Filme&Spalten=imdbID,name,views,added,lastView,Genre,Schauspieler&imdbID=".$DataArr["imdbID"]; $Query = "SELECT * FROM Filme WHERE imdbID = '".$DataArr['imdbID']."' AND 3d ".(!($DataArr['3d']=="")?"!=":"=").'""';
//echo $mediaDBurl.PHP_EOL; echo $Query.PHP_EOL;
$mediaDB = $this->jsonCacheDecoder($mediaDBurl);
//$nfoFile = str_replace("/media/QNAP/Filme", "./phpTestout", $nfoFile); // nur für Testausgaben drin....
$co = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'.PHP_EOL;
$co.= '<movie>'.PHP_EOL;
$co.= ' <title>'.$DataArr['name'].'</title>'.PHP_EOL;
//originaltitle
$co.= ' <rating>'.$DataArr['rating'].'</rating>'.PHP_EOL;
$co.= ' <year>'.$DataArr['year'].'</year>'.PHP_EOL;
$co.= ' <plot>'.$DataArr['summary'].'</plot>'.PHP_EOL;
$co.= ' <runtime>'.($DataArr['duration']/60).'</runtime>'.PHP_EOL;
if(file_exists($this->config["CoverDir"]."Filme/full/".$DataArr["imdbID"].".jpg")){
$co.= ' <thumb aspect="poster" preview="http://mediadb.ivaya.de/cover/Filme/high/'.$DataArr['imdbID'].'.jpg">'.
'http://mediadb.ivaya.de/cover/Filme/high/'.$DataArr['imdbID'].'.jpg</thumb>'.PHP_EOL;
}
if(file_exists($this->config["CoverDir"]."Filme/background/".$DataArr["imdbID"].".jpg")){
$co.= ' <fanart>'.PHP_EOL;
$co.= ' <thumb preview="http://mediadb.ivaya.de/cover/Filme/background/'.$DataArr['imdbID'].'.jpg">'.
'http://mediadb.ivaya.de/cover/Filme/background/'.$DataArr['imdbID'].'.jpg</thumb>'.PHP_EOL;
$co.= ' </fanart>'.PHP_EOL;
}
if(isset($DataArr['fsk'])){
$co.= ' <mpaa>FSK '.$DataArr['fsk'].'</mpaa>'.PHP_EOL;
}
$co.= ' <playcount>'.$mediaDB['Antwort']['Data'][0]['views'].'</playcount>'.PHP_EOL;
$co.= ' <lastplayed>'.$mediaDB['Antwort']['Data'][0]['lastView'].'</lastplayed>'.PHP_EOL;
$co.= ' <id>tt'.$DataArr['imdbID'].'</id>'.PHP_EOL;
foreach ($mediaDB['Antwort']['Data'][0]['Genre'] as $value) {
$co.= ' <genre>'.$value.'</genre>'.PHP_EOL;
}
// <set> **** Filmreihe
if(isset($DataArr['youtube'])){
$youtube = explode(":", $DataArr['youtube']);
$co.= ' <trailer>plugin://plugin.video.youtube/?action=play_video&amp;videoid='.$youtube[1].'</trailer>'.PHP_EOL;
}
// <fileinfo> .....
$counter = 0;
foreach ($mediaDB['Antwort']['Data'][0]['Schauspieler'] as $value) {
$co.= ' <actor>'.PHP_EOL;
$co.= ' <name>'.$value.'</name>'.PHP_EOL;
$co.= ' <order>'.$counter.'</order>'.PHP_EOL;
$co.= ' </actor>'.PHP_EOL;
$counter++;
}
$co.= ' <dateadded>'.$mediaDB['Antwort']['Data'][0]['added'].'</dateadded>'.PHP_EOL; echo "Generiere NFO Datei ...";
$mysqli = new mysqli($this->config["DB_Server"],$this->config["DB_Username"],$this->config["DB_Passwort"],$this->config["DB_Database"]);
if($mysqli->connect_error != ""){ echo "Mysql-Fehler: ".$mysqli->connect_error.PHP_EOL; return false;}
$mysqli->query("SET NAMES 'utf8'");
$co.= '</movie>'.PHP_EOL; $result = $mysqli->query($Query);
file_put_contents($nfoFile, $co); if($mysqli->error != ""){ echo "Mysql-Fehler: ".$mysqli->error.PHP_EOL; return false;}
echo " Fertig, in Datei $nfoFile wurde geschrieben".PHP_EOL; if($result->num_rows==1){
$Film = $result->fetch_assoc();
$mediaDBurl = "http://mediadb.ivaya.de/api.php?key=".$this->config["ApiKeys"]['MediaDB_Key']."&action=GetDataList&Tabelle=Filme&Spalten=imdbID,Genre,Schauspieler&imdbID=".$Film["imdbID"];
//echo $mediaDBurl.PHP_EOL;
$mediaDB = $this->jsonCacheDecoder($mediaDBurl);
$nfoFile = str_replace("/media/QNAP/Filme", "./phpTestout", $nfoFile); // nur für Testausgaben drin....
$co = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'.PHP_EOL;
$co.= '<movie>'.PHP_EOL;
$co.= ' <title>'.$Film['name'].'</title>'.PHP_EOL;
//originaltitle
$co.= ' <rating>'.$Film['rating'].'</rating>'.PHP_EOL;
$co.= ' <year>'.$Film['year'].'</year>'.PHP_EOL;
$co.= ' <plot>'.$Film['summary'].'</plot>'.PHP_EOL;
$co.= ' <runtime>'.($Film['duration']/60).'</runtime>'.PHP_EOL;
if(file_exists($this->config["CoverDir"]."Filme/full/".$Film["imdbID"].".jpg")){
$co.= ' <thumb aspect="poster" preview="http://mediadb.ivaya.de/cover/Filme/high/'.$Film['imdbID'].'.jpg">'.
'http://mediadb.ivaya.de/cover/Filme/high/'.$Film['imdbID'].'.jpg</thumb>'.PHP_EOL;
}
if(file_exists($this->config["CoverDir"]."Filme/background/".$Film["imdbID"].".jpg")){
$co.= ' <fanart>'.PHP_EOL;
$co.= ' <thumb preview="http://mediadb.ivaya.de/cover/Filme/background/'.$Film['imdbID'].'.jpg">'.
'http://mediadb.ivaya.de/cover/Filme/background/'.$Film['imdbID'].'.jpg</thumb>'.PHP_EOL;
$co.= ' </fanart>'.PHP_EOL;
}
if(isset($DataArr['fsk'])){
$co.= ' <mpaa>FSK '.$Film['fsk'].'</mpaa>'.PHP_EOL;
}
$co.= ' <playcount>'.$Film['views'].'</playcount>'.PHP_EOL;
$co.= ' <lastplayed>'.$Film['lastView'].'</lastplayed>'.PHP_EOL;
$co.= ' <id>tt'.$Film['imdbID'].'</id>'.PHP_EOL;
foreach ($mediaDB['Antwort']['Data'][0]['Genre'] as $value) {
$co.= ' <genre>'.$value.'</genre>'.PHP_EOL;
}
// <set> **** Filmreihe
if(isset($Film['youtube'])){
$youtube = explode(":", $Film['youtube']);
$co.= ' <trailer>plugin://plugin.video.youtube/?action=play_video&amp;videoid='.$youtube[1].'</trailer>'.PHP_EOL;
}
// <fileinfo> .....
$counter = 0;
foreach ($mediaDB['Antwort']['Data'][0]['Schauspieler'] as $value) {
$co.= ' <actor>'.PHP_EOL;
$co.= ' <name>'.$value.'</name>'.PHP_EOL;
$co.= ' <order>'.$counter.'</order>'.PHP_EOL;
$co.= ' </actor>'.PHP_EOL;
$counter++;
}
$co.= ' <dateadded>'.$Film['added'].'</dateadded>'.PHP_EOL;
$co.= '</movie>'.PHP_EOL;
file_put_contents($nfoFile, $co);
echo " Done!!".PHP_EOL;
}
} }
private function updateMovie($DataArr, $File, $md5 = true, $CheckOnly=true){ private function updateMovie($DataArr, $File, $md5 = true, $CheckOnly=true){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment