parse videos with TMDB

better size of video tiles
This commit is contained in:
lukas 2020-06-03 18:26:30 +02:00
parent 0171133d40
commit dd2e5b68a6
3 changed files with 90 additions and 40 deletions

34
api/TMDBMovie.php Normal file
View File

@ -0,0 +1,34 @@
<?php
class TMDBMovie
{
private $apikey = "9fd90530b11447f5646f8e6fb4733fb4";
private $baseurl = "https://api.themoviedb.org/3/";
public $picturebase = "https://image.tmdb.org/t/p/w500";
public function searchMovie($moviename)
{
$reply = json_decode(file_get_contents($this->baseurl . "search/movie?api_key=" . $this->apikey . "&query=" . urlencode($moviename)));
if ($reply->total_results == 0) {
// no results found
// todo maybe parse first pictures somehow
return null;
} else {
return $reply->results[0];
// $image_base64 = base64_encode(file_get_contents($this->posterbase . $reply->results[0]->poster_path));
// $image = 'data:image/jpeg;base64,' . $image_base64;
// // Insert record
// $conn = Database::getInstance()->getConnection();
// $query = "insert into Movie(name,url,poster) values('" . pathinfo($i)['filename'] . "','/data/$i','" . $image . "')";
// if ($conn->query($query) === TRUE) {
// echo('{"data":"successfully created entry"}');
// } else {
// echo('{"data":"' . $conn->error . '"}');
// }
}
}
}
$temp = new TMDBMovie();
$temp->searchMovie("007 - Ein quantum Trost");

View File

@ -1,10 +1,14 @@
<?php <?php
require 'Database.php'; require 'Database.php';
require 'TMDBMovie.php';
$ffmpeg = 'ffmpeg'; //or: /usr/bin/ffmpeg , or /usr/local/bin/ffmpeg - depends on your installation (type which ffmpeg into a console to find the install path) $ffmpeg = 'ffmpeg'; //or: /usr/bin/ffmpeg , or /usr/local/bin/ffmpeg - depends on your installation (type which ffmpeg into a console to find the install path)
$tmdb = new TMDBMovie();
$conn = Database::getInstance()->getConnection(); $conn = Database::getInstance()->getConnection();
$arr = scandir("../videos/prn/"); $scandir = "../videos/prn/";
$arr = scandir($scandir);
$all = 0; $all = 0;
$added = 0; $added = 0;
@ -13,13 +17,21 @@ $failed = 0;
foreach ($arr as $elem) { foreach ($arr as $elem) {
if ($elem != "." && $elem != "..") { if ($elem != "." && $elem != "..") {
if (strpos($elem, '.mp4') !== false) {
$moviename = substr($elem, 0, -4);
$query = "SELECT * FROM videos WHERE movie_name = '" . mysqli_real_escape_string($conn, $elem) . "'"; $query = "SELECT * FROM videos WHERE movie_name = '" . mysqli_real_escape_string($conn, $moviename) . "'";
$result = $conn->query($query); $result = $conn->query($query);
// insert if not available in db // insert if not available in db
if (!mysqli_fetch_assoc($result)) { if (!mysqli_fetch_assoc($result)) {
// try to fetch data from TMDB
if (!is_null($dta = $tmdb->searchMovie($moviename))) {
$pic = file_get_contents($tmdb->picturebase . $dta->poster_path);
} else {
echo "nothing found with TMDB!\n";
$pic = shell_exec("ffmpeg -hide_banner -loglevel panic -ss 00:04:00 -i \"../videos/prn/$elem\" -vframes 1 -q:v 2 -f singlejpeg pipe:1 2>/dev/null"); $pic = shell_exec("ffmpeg -hide_banner -loglevel panic -ss 00:04:00 -i \"../videos/prn/$elem\" -vframes 1 -q:v 2 -f singlejpeg pipe:1 2>/dev/null");
}
$image_base64 = base64_encode($pic); $image_base64 = base64_encode($pic);
@ -30,7 +42,7 @@ foreach ($arr as $elem) {
$duration = 60 * $video_attributes['hours'] + $video_attributes['mins']; $duration = 60 * $video_attributes['hours'] + $video_attributes['mins'];
$query = "INSERT INTO videos(movie_name,movie_url,thumbnail,quality,length) $query = "INSERT INTO videos(movie_name,movie_url,thumbnail,quality,length)
VALUES ('" . mysqli_real_escape_string($conn, $elem) . "', VALUES ('" . mysqli_real_escape_string($conn, $moviename) . "',
'" . mysqli_real_escape_string($conn, 'videos/prn/' . $elem) . "', '" . mysqli_real_escape_string($conn, 'videos/prn/' . $elem) . "',
'$image', '$image',
'" . $video_attributes['height'] . "', '" . $video_attributes['height'] . "',
@ -71,6 +83,9 @@ foreach ($arr as $elem) {
} else { } else {
$all++; $all++;
} }
}else{
echo($elem . " does not contain a .mp4 extension! - skipping \n");
}
} }
} }

View File

@ -7,16 +7,17 @@
.previewpic { .previewpic {
height: 80%; height: 80%;
overflow: hidden;
} }
.previewimage { .previewimage {
width: 100%; width: 100%;
height: 100%; overflow: hidden;
} }
.videopreview { .videopreview {
height: 300px; height: 500px;
width: 30%; width: 250px;
float: left; float: left;
margin-left: 25px; margin-left: 25px;
margin-top: 25px; margin-top: 25px;