From c2991bcd50f7e14f45bc6c9193f9460d241d4c07 Mon Sep 17 00:00:00 2001 From: Lukas Heiligenbrunner Date: Sun, 27 Sep 2020 20:22:14 +0200 Subject: [PATCH] fix bug of non existing insert query --- api/src/VideoParser.php | 50 ++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/api/src/VideoParser.php b/api/src/VideoParser.php index 982371a..f09aed9 100644 --- a/api/src/VideoParser.php +++ b/api/src/VideoParser.php @@ -54,7 +54,7 @@ class VideoParser { $arr = scandir($foldername); foreach ($arr as $elem) { - if($elem == '.' || $elem == '..') continue; + if ($elem == '.' || $elem == '..') continue; $ext = pathinfo($elem, PATHINFO_EXTENSION); if ($ext == "mp4") { @@ -136,45 +136,39 @@ class VideoParser { // convert video to base64 $backpic64 = 'data:image/jpeg;base64,' . base64_encode($backpic); + // set default insert query without tmdb poster + $insert_query = "INSERT INTO videos(movie_name,movie_url,thumbnail,quality,length) + VALUES ('" . mysqli_real_escape_string($this->conn, $moviename) . "', + '" . mysqli_real_escape_string($this->conn, $this->videopath . $filename) . "', + '$backpic64', + '$width', + '$duration')"; + // check if tmdb grabbing is enabled if ($this->TMDBenabled) { // search in tmdb api - try { - if (!is_null($dta = $this->tmdb->searchMovie($moviename, $year))) { - $poster = file_get_contents($this->tmdb->picturebase . $dta->poster_path); + if (!is_null($dta = $this->tmdb->searchMovie($moviename, $year))) { + $poster = file_get_contents($this->tmdb->picturebase . $dta->poster_path); - // error handling for download error - if ($poster) { - $poster_base64 = 'data:image/jpeg;base64,' . base64_encode($poster); + // error handling for download error + if ($poster) { + $poster_base64 = 'data:image/jpeg;base64,' . base64_encode($poster); - $insert_query = "INSERT INTO videos(movie_name,movie_url,poster,thumbnail,quality,length) + // override insert query if pic loaded correctly + $insert_query = "INSERT INTO videos(movie_name,movie_url,poster,thumbnail,quality,length) VALUES ('" . mysqli_real_escape_string($this->conn, $moviename) . "', '" . mysqli_real_escape_string($this->conn, $this->videopath . $filename) . "', '$backpic64', '$poster_base64', '$width', '$duration')"; - } else { - throw new Exception("faild to load pic"); - } - // store genre ids for parsing later - $genres = $dta->genre_ids; - } else { - // nothing found with tmdb - echo "my moviename: " . $moviename; - - $this->writeLog("nothing found with TMDB! -- $moviename\n"); - throw new Exception("nothing found with TMDB! -- $moviename"); } - } catch (Exception $e) { - echo $e->getMessage(); - - $insert_query = "INSERT INTO videos(movie_name,movie_url,thumbnail,quality,length) - VALUES ('" . mysqli_real_escape_string($this->conn, $moviename) . "', - '" . mysqli_real_escape_string($this->conn, $this->videopath . $filename) . "', - '$backpic64', - '$width', - '$duration')"; + // store genre ids for parsing later + $genres = $dta->genre_ids; + } else { + // nothing found with tmdb + echo "my moviename: " . $moviename; + $this->writeLog("nothing found with TMDB! -- $moviename\n"); } }