improved poster on player page

improved tile sizes for preview
This commit is contained in:
lukas 2020-06-04 00:15:06 +02:00
parent dd2e5b68a6
commit cb5c366641
7 changed files with 73 additions and 62 deletions

View File

@ -2,13 +2,13 @@
class Database class Database
{ {
private static $instance = null; private static ?Database $instance = null;
private $conn; private mysqli $conn;
private $servername = "192.168.0.30"; private string $servername = "192.168.0.30";
private $username = "root"; private string $username = "root";
private $password = "1qayxsw2"; private string $password = "1qayxsw2";
private $dbname = "mediacenter"; private string $dbname = "mediacenter";
// The db connection is established in the private constructor. // The db connection is established in the private constructor.
private function __construct() private function __construct()
@ -34,4 +34,8 @@ class Database
{ {
return $this->conn; return $this->conn;
} }
public function getDatabaseName(){
return $this->dbname;
}
} }

View File

@ -26,48 +26,73 @@ foreach ($arr as $elem) {
// 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 // try to fetch data from TMDB
$poster = -1;
if (!is_null($dta = $tmdb->searchMovie($moviename))) { if (!is_null($dta = $tmdb->searchMovie($moviename))) {
$pic = file_get_contents($tmdb->picturebase . $dta->poster_path); $pic = file_get_contents($tmdb->picturebase . $dta->poster_path);
$poster = 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");
} else { } else {
echo "nothing found with TMDB!\n"; 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");
} }
//convert video to base64
$image_base64 = base64_encode($pic); $image_base64 = base64_encode($pic);
// add base64 fileinfo
$image = 'data:image/jpeg;base64,' . $image_base64; $image = 'data:image/jpeg;base64,' . $image_base64;
// extract other video attributes
$video_attributes = _get_video_attributes($elem); $video_attributes = _get_video_attributes($elem);
$duration = 0;
$size = 0;
$width = 0;
$duration = 60 * $video_attributes['hours'] + $video_attributes['mins']; if ($video_attributes) {
$duration = $video_attributes->media->track[0]->Duration; // in seconds
$size = $video_attributes->media->track[0]->FileSize; // in Bytes
$width = $video_attributes->media->track[1]->Width; // width
}
if ($poster != -1) {
$poster_base64 = 'data:image/jpeg;base64,' . base64_encode($poster);
$query = "INSERT INTO videos(movie_name,movie_url,poster,thumbnail,quality,length)
VALUES ('" . mysqli_real_escape_string($conn, $moviename) . "',
'" . mysqli_real_escape_string($conn, 'videos/prn/' . $elem) . "',
'$poster_base64',
'$image',
'$width',
'$duration')";
} else {
$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, $moviename) . "', 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'] . "', '$width',
'$duration')"; '$duration')";
}
if ($conn->query($query) === TRUE) { if ($conn->query($query) === TRUE) {
echo('successfully added ' . $elem . " to video gravity\n"); echo('successfully added ' . $elem . " to video gravity\n");
$last_id = $conn->insert_id; $last_id = $conn->insert_id;
// full hd // full hd
if ($video_attributes['height'] >= 1080) { if ($width >= 1900) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,2)"; $query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,2)";
if ($conn->query($query) !== TRUE) { if ($conn->query($query) !== TRUE) {
echo "failed to add default tag here.\n"; echo "failed to add default tag here.\n";
} }
} }
if ($video_attributes['height'] >= 720 && $video_attributes['height'] < 1080) { if ($width >= 1250 && $width < 1900) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,4)"; $query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,4)";
if ($conn->query($query) !== TRUE) { if ($conn->query($query) !== TRUE) {
echo "failed to add default tag here.\n"; echo "failed to add default tag here.\n";
} }
} }
if ($video_attributes['height'] < 720) { if ($width < 1250) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,3)"; $query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,3)";
if ($conn->query($query) !== TRUE) { if ($conn->query($query) !== TRUE) {
echo "failed to add default tag here.\n"; echo "failed to add default tag here.\n";
@ -83,7 +108,7 @@ foreach ($arr as $elem) {
} else { } else {
$all++; $all++;
} }
}else{ } else {
echo($elem . " does not contain a .mp4 extension! - skipping \n"); echo($elem . " does not contain a .mp4 extension! - skipping \n");
} }
} }
@ -119,7 +144,7 @@ $size = -1;
$query = "SELECT table_schema AS \"Database\", $query = "SELECT table_schema AS \"Database\",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 3) AS \"Size\" ROUND(SUM(data_length + index_length) / 1024 / 1024, 3) AS \"Size\"
FROM information_schema.TABLES FROM information_schema.TABLES
WHERE TABLE_SCHEMA='hub' WHERE TABLE_SCHEMA='" . Database::getInstance()->getDatabaseName() . "'
GROUP BY table_schema;"; GROUP BY table_schema;";
$result = $conn->query($query); $result = $conn->query($query);
if ($result->num_rows == 1) { if ($result->num_rows == 1) {
@ -135,41 +160,7 @@ echo "errored in this run: " . $failed . "\n";
function _get_video_attributes($video) function _get_video_attributes($video)
{ {
global $ffmpeg; $command = "mediainfo \"../videos/prn/$video\" --Output=JSON";
$command = "$ffmpeg -i \"../videos/prn/$video\" -vstats 2>&1";
$output = shell_exec($command); $output = shell_exec($command);
return json_decode($output);
$codec = "null";
$width = 0;
$height = 0;
$regex_sizes = "/Video: ([^,]*), ([^,]*), ([0-9]{1,4})x([0-9]{1,4})/"; // or : $regex_sizes = "/Video: ([^\r\n]*), ([^,]*), ([0-9]{1,4})x([0-9]{1,4})/"; (code from @1owk3y)
if (preg_match($regex_sizes, $output, $regs)) {
$codec = $regs [1] ? $regs [1] : "null";
$width = $regs [3] ? $regs [3] : 0;
$height = $regs [4] ? $regs [4] : 0;
}
$hours = 0;
$mins = 0;
$secs = 0;
$ms = 0;
$regex_duration = "/Duration: ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}).([0-9]{1,2})/";
if (preg_match($regex_duration, $output, $regs)) {
$hours = $regs [1] ? $regs [1] : 0;
$mins = $regs [2] ? $regs [2] : 0;
$secs = $regs [3] ? $regs [3] : 0;
$ms = $regs [4] ? $regs [4] : 0;
}
return array('codec' => $codec,
'width' => $width,
'height' => $height,
'hours' => $hours,
'mins' => $mins,
'secs' => $secs,
'ms' => $ms
);
} }

View File

@ -55,13 +55,18 @@ if (isset($_POST['action'])) {
echo(json_encode($return)); echo(json_encode($return));
break; break;
case "loadVideo": case "loadVideo":
$query = "SELECT movie_name,movie_url,thumbnail,likes,quality,length FROM videos WHERE movie_id='" . $_POST['movieid'] . "'"; $query = "SELECT movie_name,movie_url,thumbnail,poster,likes,quality,length FROM videos WHERE movie_id='" . $_POST['movieid'] . "'";
$result = $conn->query($query); $result = $conn->query($query);
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
$arr = array(); $arr = array();
if($row["poster"] == null){
$arr["thumbnail"] = $row["thumbnail"]; $arr["thumbnail"] = $row["thumbnail"];
}else{
$arr["thumbnail"] = $row["poster"];
}
$arr["movie_name"] = $row["movie_name"]; $arr["movie_name"] = $row["movie_name"];
$arr["movie_url"] = $row["movie_url"]; $arr["movie_url"] = $row["movie_url"];
$arr["likes"] = $row["likes"]; $arr["likes"] = $row["likes"];

View File

@ -12,10 +12,11 @@ create table if not exists videos
movie_name varchar(200) null, movie_name varchar(200) null,
movie_url varchar(250) null, movie_url varchar(250) null,
thumbnail mediumblob null, thumbnail mediumblob null,
poster mediumblob null,
likes int default 0 null, likes int default 0 null,
create_date datetime default CURRENT_TIMESTAMP null,
quality int null, quality int null,
length int null comment 'in seconds' length int null comment 'in seconds',
create_date datetime default CURRENT_TIMESTAMP null
); );
create table if not exists video_tags create table if not exists video_tags
@ -27,3 +28,10 @@ create table if not exists video_tags
constraint video_tags_videos_movie_id_fk constraint video_tags_videos_movie_id_fk
foreign key (video_id) references videos (movie_id) foreign key (video_id) references videos (movie_id)
); );
INSERT INTO tags (tag_id, tag_name)
VALUES (2, 'fullhd');
INSERT INTO tags (tag_id, tag_name)
VALUES (3, 'lowquality');
INSERT INTO tags (tag_id, tag_name)
VALUES (4, 'hd');

View File

@ -57,7 +57,7 @@ class HomePage extends React.Component {
selectionnr: this.data.length selectionnr: this.data.length
}); });
this.loadindex = 0; this.loadindex = 0;
this.loadPreviewBlock(12); this.loadPreviewBlock(16);
})) }))
.catch(() => { .catch(() => {
console.log("no connection to backend"); console.log("no connection to backend");
@ -176,7 +176,7 @@ class HomePage extends React.Component {
// comparison if current scroll position is on bottom // comparison if current scroll position is on bottom
// 200 stands for bottom offset to trigger load // 200 stands for bottom offset to trigger load
if (window.innerHeight + document.documentElement.scrollTop + 200 >= document.documentElement.offsetHeight) { if (window.innerHeight + document.documentElement.scrollTop + 200 >= document.documentElement.offsetHeight) {
this.loadPreviewBlock(6); this.loadPreviewBlock(8);
} }
} }
} }

View File

@ -15,7 +15,7 @@ class RandomPage extends React.Component {
} }
componentDidMount() { componentDidMount() {
this.loadShuffledvideos(6); this.loadShuffledvideos(4);
} }
render() { render() {
@ -50,7 +50,7 @@ class RandomPage extends React.Component {
} }
shuffleclick() { shuffleclick() {
this.loadShuffledvideos(6); this.loadShuffledvideos(4);
} }
loadShuffledvideos(nr) { loadShuffledvideos(nr) {

View File

@ -3,6 +3,7 @@
color: #3d3d3d; color: #3d3d3d;
text-align: center; text-align: center;
font-weight: bold; font-weight: bold;
max-width: 266px;
} }
.previewpic { .previewpic {
@ -11,13 +12,15 @@
} }
.previewimage { .previewimage {
width: 100%; max-width: 100%;
overflow: hidden; max-height: 100%;
} }
.videopreview { .videopreview {
height: 500px; height: 500px;
width: 250px; min-width: 266px;
max-width: 410px;
/*width: 250px;*/
float: left; float: left;
margin-left: 25px; margin-left: 25px;
margin-top: 25px; margin-top: 25px;