improved poster on player page
improved tile sizes for preview
This commit is contained in:
parent
dd2e5b68a6
commit
cb5c366641
@ -2,13 +2,13 @@
|
||||
|
||||
class Database
|
||||
{
|
||||
private static $instance = null;
|
||||
private $conn;
|
||||
private static ?Database $instance = null;
|
||||
private mysqli $conn;
|
||||
|
||||
private $servername = "192.168.0.30";
|
||||
private $username = "root";
|
||||
private $password = "1qayxsw2";
|
||||
private $dbname = "mediacenter";
|
||||
private string $servername = "192.168.0.30";
|
||||
private string $username = "root";
|
||||
private string $password = "1qayxsw2";
|
||||
private string $dbname = "mediacenter";
|
||||
|
||||
// The db connection is established in the private constructor.
|
||||
private function __construct()
|
||||
@ -34,4 +34,8 @@ class Database
|
||||
{
|
||||
return $this->conn;
|
||||
}
|
||||
|
||||
public function getDatabaseName(){
|
||||
return $this->dbname;
|
||||
}
|
||||
}
|
||||
|
@ -26,48 +26,73 @@ foreach ($arr as $elem) {
|
||||
// insert if not available in db
|
||||
if (!mysqli_fetch_assoc($result)) {
|
||||
// try to fetch data from TMDB
|
||||
$poster = -1;
|
||||
if (!is_null($dta = $tmdb->searchMovie($moviename))) {
|
||||
$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 {
|
||||
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");
|
||||
}
|
||||
|
||||
//convert video to base64
|
||||
$image_base64 = base64_encode($pic);
|
||||
|
||||
// add base64 fileinfo
|
||||
$image = 'data:image/jpeg;base64,' . $image_base64;
|
||||
|
||||
// extract other video attributes
|
||||
$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)
|
||||
VALUES ('" . mysqli_real_escape_string($conn, $moviename) . "',
|
||||
'" . mysqli_real_escape_string($conn, 'videos/prn/' . $elem) . "',
|
||||
'$image',
|
||||
'" . $video_attributes['height'] . "',
|
||||
'$width',
|
||||
'$duration')";
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
if ($width >= 1900) {
|
||||
$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) {
|
||||
if ($width >= 1250 && $width < 1900) {
|
||||
$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) {
|
||||
if ($width < 1250) {
|
||||
$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";
|
||||
@ -83,7 +108,7 @@ foreach ($arr as $elem) {
|
||||
} else {
|
||||
$all++;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
echo($elem . " does not contain a .mp4 extension! - skipping \n");
|
||||
}
|
||||
}
|
||||
@ -119,7 +144,7 @@ $size = -1;
|
||||
$query = "SELECT table_schema AS \"Database\",
|
||||
ROUND(SUM(data_length + index_length) / 1024 / 1024, 3) AS \"Size\"
|
||||
FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA='hub'
|
||||
WHERE TABLE_SCHEMA='" . Database::getInstance()->getDatabaseName() . "'
|
||||
GROUP BY table_schema;";
|
||||
$result = $conn->query($query);
|
||||
if ($result->num_rows == 1) {
|
||||
@ -135,41 +160,7 @@ echo "errored in this run: " . $failed . "\n";
|
||||
|
||||
function _get_video_attributes($video)
|
||||
{
|
||||
global $ffmpeg;
|
||||
|
||||
$command = "$ffmpeg -i \"../videos/prn/$video\" -vstats 2>&1";
|
||||
$command = "mediainfo \"../videos/prn/$video\" --Output=JSON";
|
||||
$output = shell_exec($command);
|
||||
|
||||
$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
|
||||
);
|
||||
return json_decode($output);
|
||||
}
|
||||
|
@ -55,13 +55,18 @@ if (isset($_POST['action'])) {
|
||||
echo(json_encode($return));
|
||||
break;
|
||||
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);
|
||||
$row = $result->fetch_assoc();
|
||||
|
||||
$arr = array();
|
||||
if($row["poster"] == null){
|
||||
$arr["thumbnail"] = $row["thumbnail"];
|
||||
}else{
|
||||
$arr["thumbnail"] = $row["poster"];
|
||||
}
|
||||
|
||||
$arr["movie_name"] = $row["movie_name"];
|
||||
$arr["movie_url"] = $row["movie_url"];
|
||||
$arr["likes"] = $row["likes"];
|
||||
|
12
database.sql
12
database.sql
@ -12,10 +12,11 @@ create table if not exists videos
|
||||
movie_name varchar(200) null,
|
||||
movie_url varchar(250) null,
|
||||
thumbnail mediumblob null,
|
||||
poster mediumblob null,
|
||||
likes int default 0 null,
|
||||
create_date datetime default CURRENT_TIMESTAMP 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
|
||||
@ -27,3 +28,10 @@ create table if not exists video_tags
|
||||
constraint video_tags_videos_movie_id_fk
|
||||
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');
|
||||
|
@ -57,7 +57,7 @@ class HomePage extends React.Component {
|
||||
selectionnr: this.data.length
|
||||
});
|
||||
this.loadindex = 0;
|
||||
this.loadPreviewBlock(12);
|
||||
this.loadPreviewBlock(16);
|
||||
}))
|
||||
.catch(() => {
|
||||
console.log("no connection to backend");
|
||||
@ -176,7 +176,7 @@ class HomePage extends React.Component {
|
||||
// comparison if current scroll position is on bottom
|
||||
// 200 stands for bottom offset to trigger load
|
||||
if (window.innerHeight + document.documentElement.scrollTop + 200 >= document.documentElement.offsetHeight) {
|
||||
this.loadPreviewBlock(6);
|
||||
this.loadPreviewBlock(8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class RandomPage extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.loadShuffledvideos(6);
|
||||
this.loadShuffledvideos(4);
|
||||
}
|
||||
|
||||
render() {
|
||||
@ -50,7 +50,7 @@ class RandomPage extends React.Component {
|
||||
}
|
||||
|
||||
shuffleclick() {
|
||||
this.loadShuffledvideos(6);
|
||||
this.loadShuffledvideos(4);
|
||||
}
|
||||
|
||||
loadShuffledvideos(nr) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
color: #3d3d3d;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
max-width: 266px;
|
||||
}
|
||||
|
||||
.previewpic {
|
||||
@ -11,13 +12,15 @@
|
||||
}
|
||||
|
||||
.previewimage {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.videopreview {
|
||||
height: 500px;
|
||||
width: 250px;
|
||||
min-width: 266px;
|
||||
max-width: 410px;
|
||||
/*width: 250px;*/
|
||||
float: left;
|
||||
margin-left: 25px;
|
||||
margin-top: 25px;
|
||||
|
Loading…
Reference in New Issue
Block a user