321 lines
7.3 KiB
PHP
321 lines
7.3 KiB
PHP
<?php
|
|
|
|
setlocale (LC_TIME, 'fr_FR.utf8');
|
|
|
|
$images_folder = '/img';
|
|
|
|
$bdd = '../bdd.db';
|
|
|
|
$output_video_folder = 'vid/';
|
|
|
|
|
|
function convert($id, $video, $audio) {
|
|
|
|
global $output_video_folder;
|
|
|
|
$result = sql(NULL, $id);
|
|
if(! $result)
|
|
return false;
|
|
|
|
$file = $result[0]['file_path'];
|
|
|
|
$info = MediaInfo($file);
|
|
if(! $info)
|
|
return false;
|
|
|
|
$allow_codec = array('h264', 'aac');
|
|
|
|
$out=$output_video_folder.$result[0]['id'];
|
|
|
|
if (in_array($info['video'][$video]['codec_name'], $allow_codec))
|
|
$video_codec = 'copy';
|
|
else
|
|
$video_codec = 'h264';
|
|
|
|
if (in_array($info['audio'][$audio]['codec_name'], $allow_codec))
|
|
$audio_codec = 'copy';
|
|
else
|
|
$audio_codec = 'aac';
|
|
|
|
$commande = 'ffmpeg -hide_banner -i "'.$file.'" -y -map 0:'.$video.' -map 0:'.$audio.' -c:v '.$video_codec.' -c:a '.$audio_codec.' '.$out.'.mp4 2>&1';
|
|
|
|
//echo "Commande : ".$commande."<br>";
|
|
|
|
exec($commande, $output);
|
|
|
|
if(array_key_exists("subtitle", $info)) {
|
|
|
|
foreach ($info['subtitle'] as $key => $value) {
|
|
$commande = 'ffmpeg -hide_banner -i "'.$file.'" -y -map 0:'.$key.' '.$out.'_'.$key.'.vtt 2>&1';
|
|
|
|
if (! file_exists($out.'_'.$key.'.vtt'))
|
|
exec($commande, $output);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
function MediaInfo($file) {
|
|
|
|
require '../vendor/autoload.php';
|
|
|
|
$ffprobe = FFMpeg\FFProbe::create();
|
|
|
|
if (file_exists($file)) {
|
|
|
|
$info = array();
|
|
|
|
$format=$ffprobe->format($file);
|
|
|
|
$format_tags=$format->get('tags');
|
|
|
|
$info['format']['duration'] = $duree=$format->get('duration');
|
|
|
|
if (isset($format_tags['title']))
|
|
$info['format']['title'] = $format_tags['title'];
|
|
else
|
|
$info['format']['title'] = "No Title";
|
|
|
|
$streams=$ffprobe->streams($file);
|
|
|
|
$all=$streams->all();
|
|
|
|
$nb=$streams->count();
|
|
|
|
for ($i=0; $i<$nb; $i++) {
|
|
$type = $all[$i]->get('codec_type');
|
|
|
|
$info[$type][$i]['codec_name'] = $all[$i]->get('codec_name');
|
|
|
|
if($type == "video"){
|
|
$info[$type][$i]['width'] = $all[$i]->get('width');
|
|
$info[$type][$i]['height'] = $all[$i]->get('height');
|
|
$info[$type][$i]['display_aspect_ratio'] = $all[$i]->get('display_aspect_ratio');
|
|
|
|
|
|
}
|
|
|
|
|
|
if($type == "audio")
|
|
$info[$type][$i]['channel_layout'] = $all[$i]->get('channel_layout');
|
|
|
|
$tags=$all[$i]->get('tags');
|
|
$disposition=$all[$i]->get('disposition');
|
|
|
|
if($tags!=NULL){
|
|
if (array_key_exists("title", $tags)) {
|
|
$info[$type][$i]['title'] = $tags['title'];
|
|
}
|
|
if (array_key_exists("language", $tags)) {
|
|
$info[$type][$i]['language'] = $tags['language'];
|
|
}
|
|
}
|
|
if($disposition!=NULL){
|
|
if (array_key_exists("default", $disposition)) {
|
|
$info[$type][$i]['default'] = $disposition['default'];
|
|
}
|
|
if (array_key_exists("forced", $disposition)) {
|
|
$info[$type][$i]['forced'] = $disposition['forced'];
|
|
}
|
|
}
|
|
}
|
|
|
|
return $info;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
function saga_list()
|
|
{
|
|
|
|
global $bdd, $images_folder;
|
|
|
|
try {
|
|
|
|
$conn = new PDO('sqlite:'.$bdd);
|
|
#$bdd = new PDO('sqlite:/home/user/video/bdd.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
|
|
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
} catch (Exception $e) {
|
|
die('Erreur : '.$e->getMessage());
|
|
}
|
|
|
|
$req = $conn->query("SELECT * FROM sagas ORDER BY name ASC");
|
|
|
|
$result = $req->fetchAll();
|
|
|
|
for($i = 0; $i < count($result); $i++) {
|
|
$result[$i]['poster_path'] = $images_folder.$result[$i]['poster_path'];
|
|
$result[$i]['poster_path'] = $images_folder.'/cover.jpg';
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
function saga_name($saga)
|
|
{
|
|
|
|
global $bdd;
|
|
|
|
try {
|
|
|
|
$conn = new PDO('sqlite:'.$bdd);
|
|
#$bdd = new PDO('sqlite:/home/user/video/bdd.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
|
|
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
} catch (Exception $e) {
|
|
die('Erreur : '.$e->getMessage());
|
|
}
|
|
|
|
$req = $conn->prepare("SELECT name FROM sagas WHERE id=:sagaID");
|
|
|
|
$req->execute(['sagaID' => $saga]);
|
|
|
|
$result = $req->fetch()[0];
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
function movies_full_list()
|
|
{
|
|
|
|
global $bdd, $images_folder;
|
|
|
|
try {
|
|
|
|
$conn = new PDO('sqlite:'.$bdd);
|
|
#$bdd = new PDO('sqlite:/home/user/video/bdd.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
|
|
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
} catch (Exception $e) {
|
|
die('Erreur : '.$e->getMessage());
|
|
}
|
|
|
|
$req = $conn->query("SELECT id,title,poster_path,original_title FROM movies ORDER BY title ASC");
|
|
|
|
$result = $req->fetchAll();
|
|
|
|
for($i = 0; $i < count($result); $i++) {
|
|
$result[$i]['poster_path'] = $images_folder.$result[$i]['poster_path'];
|
|
$result[$i]['poster_path'] = $images_folder.'/cover.jpg';
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
function movie_list($saga)
|
|
{
|
|
|
|
global $bdd, $images_folder;
|
|
|
|
try {
|
|
|
|
$conn = new PDO('sqlite:'.$bdd);
|
|
#$bdd = new PDO('sqlite:/home/user/video/bdd.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
|
|
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
} catch (Exception $e) {
|
|
die('Erreur : '.$e->getMessage());
|
|
}
|
|
|
|
if ($saga == 0) {
|
|
$req = $conn->prepare("SELECT id,title,poster_path,original_title FROM movies WHERE sagaID=:sagaID ORDER BY title ASC");
|
|
}
|
|
else {
|
|
$req = $conn->prepare("SELECT id,title,poster_path,original_title FROM movies WHERE sagaID=:sagaID ORDER BY release_date ASC");
|
|
}
|
|
|
|
$req->execute(['sagaID' => $saga]);
|
|
|
|
$result = $req->fetchAll();
|
|
|
|
for($i = 0; $i < count($result); $i++) {
|
|
$result[$i]['poster_path'] = $images_folder.$result[$i]['poster_path'];
|
|
$result[$i]['poster_path'] = $images_folder.'/cover.jpg';
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
function movie_detail($movie)
|
|
{
|
|
|
|
global $bdd, $images_folder;
|
|
|
|
try {
|
|
|
|
$conn = new PDO('sqlite:'.$bdd);
|
|
#$bdd = new PDO('sqlite:/home/user/video/bdd.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
|
|
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
} catch (Exception $e) {
|
|
die('Erreur : '.$e->getMessage());
|
|
}
|
|
|
|
$req = $conn->prepare("SELECT * FROM movies WHERE id=:id");
|
|
|
|
$req->execute(['id' => $movie]);
|
|
|
|
$result = $req->fetchAll()[0];
|
|
|
|
$result['poster_path'] = $images_folder.$result['poster_path'];
|
|
$result['poster_path'] = $images_folder.'/cover.jpg';
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
function file_path($movie)
|
|
{
|
|
|
|
global $bdd, $images_folder;
|
|
|
|
try {
|
|
|
|
$conn = new PDO('sqlite:'.$bdd);
|
|
#$bdd = new PDO('sqlite:/home/user/video/bdd.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
|
|
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
} catch (Exception $e) {
|
|
die('Erreur : '.$e->getMessage());
|
|
}
|
|
|
|
$req = $conn->prepare("SELECT * FROM movies WHERE id=:id");
|
|
|
|
$req->execute(['id' => $movie]);
|
|
|
|
$result = $req->fetchAll()[0];
|
|
|
|
print_r($result);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
function human_filesize($bytes, $dec = 2)
|
|
{
|
|
$size = array('B', 'kiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
|
|
$factor = floor((strlen($bytes) - 1) / 3);
|
|
|
|
return sprintf("%.{$dec}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
|
|
}
|
|
|
|
function time_to_str($time,$precision=2){
|
|
if($time=abs(intval($time))){
|
|
$s=['an'=>31556926,'mois'=>2629743,'semaine'=>604800,'jour'=>86400,'heure'=>3600,'minute'=>60,'seconde'=>1];
|
|
foreach($s as $a=>$b){if($time>=$b && $c=$time/$b){$c=intval($c);$time-=$b*$c;
|
|
$r[]="$c $a".($c>1?($a=='mois'?'':'s'):'');if(++$d==$precision)break;}}
|
|
return count($r)==1?$r[0]:(implode(' ',array_slice($r,0,-1)).' et '.array_shift(array_slice($r,-1,1)));}
|
|
return 'un instant';
|
|
}
|
|
|
|
|
|
?>
|