1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
Adding webp support
Command line to get all videos webp images
This commit is contained in:
daniel 2019-10-17 14:48:51 -03:00
parent 1d0af784f4
commit 3897e6e36a

77
install/getAllWebp.php Normal file
View file

@ -0,0 +1,77 @@
<?php
//streamer config
require_once '../videos/configuration.php';
if (!isCommandLineInterface()) {
return die('Command Line only');
}
$videos = video::getAllVideosLight("", false, true);
foreach ($videos as $value) {
if($value['type']!='video'){
continue;
}
echo "\nStart: ".$value['title'];
$videoFileName = $value['filename'];
$destination = "{$global['systemRootPath']}videos/{$videoFileName}.webp";
if (!file_exists($destination)) {
echo "\nGet webp";
$videosURL = getFirstVideoURL($videoFileName);
$videoPath = getFirstVideoPath($videoFileName);
$duration = (Video::getItemDurationSeconds(Video::getDurationFromFile($videoPath)) / 2);
if (!empty($videosURL)) {
$url = $videosURL;
$file_headers = @get_headers($url);
if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
echo "\nGet webp not found {$url}";
continue;
} else {
$url = $config->getEncoderURL() . "getImageMP4/" . base64_encode($url) . "/webp/{$duration}";
$image = url_get_contents($url);
file_put_contents($destination, $image);
}
}else{
echo "\nVideo URL empty";
}
echo "\nGet done";
}else{
echo "\nFile exists: ".$value['title'];
}
echo "\nFinish: ".$value['title'];
echo "\n******\n";
}
function getFirstVideoURL($videoFileName) {
$types = array('', '_Low', '_SD', '_HD');
$videosList = getVideosURL($videoFileName);
if (!empty($videosList['m3u8']["url"])) {
return $videosList['m3u8']["url"];
}
foreach ($types as $value) {
if (!empty($videosList['mp4' . $value]["url"])) {
return $videosList['mp4' . $value]["url"];
} else if (!empty($videosList['webm' . $value]["url"])) {
return $videosList['webm' . $value]["url"];
}
}
return false;
}
function getFirstVideoPath($videoFileName) {
$types = array('', '_Low', '_SD', '_HD');
$videosList = getVideosURL($videoFileName);
if (!empty($videosList['m3u8']["path"])) {
return $videosList['m3u8']["path"];
}
foreach ($types as $value) {
if (!empty($videosList['mp4' . $value]["path"])) {
return $videosList['mp4' . $value]["path"];
} else if (!empty($videosList['webm' . $value]["path"])) {
return $videosList['webm' . $value]["path"];
}
}
return false;
}