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
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)
$tmdb = new TMDBMovie();
$conn = Database::getInstance()->getConnection();
$arr = scandir("../videos/prn/");
$scandir = "../videos/prn/";
$arr = scandir($scandir);
$all = 0;
$added = 0;
@ -13,63 +17,74 @@ $failed = 0;
foreach ($arr as $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) . "'";
$result = $conn->query($query);
$query = "SELECT * FROM videos WHERE movie_name = '" . mysqli_real_escape_string($conn, $moviename) . "'";
$result = $conn->query($query);
// insert if not available in db
if (!mysqli_fetch_assoc($result)) {
$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");
// insert if not available in db
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");
}
$image_base64 = base64_encode($pic);
$image_base64 = base64_encode($pic);
$image = 'data:image/jpeg;base64,' . $image_base64;
$image = 'data:image/jpeg;base64,' . $image_base64;
$video_attributes = _get_video_attributes($elem);
$video_attributes = _get_video_attributes($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)
VALUES ('" . mysqli_real_escape_string($conn, $elem) . "',
$query = "INSERT INTO videos(movie_name,movie_url,thumbnail,quality,length)
VALUES ('" . mysqli_real_escape_string($conn, $moviename) . "',
'" . mysqli_real_escape_string($conn, 'videos/prn/' . $elem) . "',
'$image',
'" . $video_attributes['height'] . "',
'$duration')";
if ($conn->query($query) === TRUE) {
echo('successfully added ' . $elem . " to video gravity\n");
$last_id = $conn->insert_id;
if ($conn->query($query) === TRUE) {
echo('successfully added ' . $elem . " to video gravity\n");
$last_id = $conn->insert_id;
// full hd
if ($video_attributes['height'] >= 1080) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,2)";
if ($conn->query($query) !== TRUE) {
echo "failed to add default tag here.\n";
// full hd
if ($video_attributes['height'] >= 1080) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,2)";
if ($conn->query($query) !== TRUE) {
echo "failed to add default tag here.\n";
}
}
}
if ($video_attributes['height'] >= 720 && $video_attributes['height'] < 1080) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,4)";
if ($conn->query($query) !== TRUE) {
echo "failed to add default tag here.\n";
if ($video_attributes['height'] >= 720 && $video_attributes['height'] < 1080) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,4)";
if ($conn->query($query) !== TRUE) {
echo "failed to add default tag here.\n";
}
}
}
if ($video_attributes['height'] < 720) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,3)";
if ($conn->query($query) !== TRUE) {
echo "failed to add default tag here.\n";
if ($video_attributes['height'] < 720) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,3)";
if ($conn->query($query) !== TRUE) {
echo "failed to add default tag here.\n";
}
}
$added++;
$all++;
} else {
echo('errored item: ' . $elem . "\n");
echo('{"data":"' . $conn->error . '"}\n');
$failed++;
}
$added++;
$all++;
} else {
echo('errored item: ' . $elem . "\n");
echo('{"data":"' . $conn->error . '"}\n');
$failed++;
$all++;
}
} else {
$all++;
}else{
echo($elem . " does not contain a .mp4 extension! - skipping \n");
}
}
}

View File

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