1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00

Bulk embed youtube videos

This commit is contained in:
daniel 2019-07-13 20:41:30 -03:00
parent b3f5626c1e
commit 9302cb17ae

View file

@ -1,5 +1,39 @@
<?php <?php
/**
* Convert ISO 8601 values like PT15M33S
* to a total value of seconds.
*
* @param string $ISO8601
*/
function ISO8601ToSeconds($ISO8601)
{
preg_match('/\d{1,2}[H]/', $ISO8601, $hours);
preg_match('/\d{1,2}[M]/', $ISO8601, $minutes);
preg_match('/\d{1,2}[S]/', $ISO8601, $seconds);
$duration = [
'hours' => $hours ? $hours[0] : 0,
'minutes' => $minutes ? $minutes[0] : 0,
'seconds' => $seconds ? $seconds[0] : 0,
];
$hours = substr($duration['hours'], 0, -1);
$minutes = substr($duration['minutes'], 0, -1);
$seconds = substr($duration['seconds'], 0, -1);
$hours = intval(@$hours);
$minutes = intval(@$minutes);
$seconds = intval(@$seconds);
$toltalSeconds = ($hours * 60 * 60) + ($minutes * 60) + $seconds;
return $toltalSeconds;
}
function ISO8601ToDuration($ISO8601){
$seconds = ISO8601ToSeconds($ISO8601);
return secondsToVideoTime($seconds);
}
//error_reporting(0); //error_reporting(0);
header('Content-Type: application/json'); header('Content-Type: application/json');
if (!isset($global['systemRootPath'])) { if (!isset($global['systemRootPath'])) {
@ -22,9 +56,9 @@ if (!User::canUpload()) {
$videos->setFilename($filename); $videos->setFilename($filename);
$videos->setTitle($value['title']); $videos->setTitle($value['title']);
$videos->setClean_title($value['title']); $videos->setClean_title($value['title']);
$videos->setDuration($value['duration']); $videos->setDuration(ISO8601ToDuration($value['duration']));
$videos->setDescription($value['description']); $videos->setDescription($value['description']);
file_put_contents($global['systemRootPath'] . "videos/{$filename}.jpg", $value['thumbs']); file_put_contents($global['systemRootPath'] . "videos/{$filename}.jpg", url_get_contents($value['thumbs']));
$videos->setVideoLink($value['link']); $videos->setVideoLink($value['link']);
$videos->setType('embed'); $videos->setType('embed');
@ -35,7 +69,7 @@ if (!User::canUpload()) {
YouPHPTubePlugin::saveVideosAddNew($_POST, $resp); YouPHPTubePlugin::saveVideosAddNew($_POST, $resp);
$obj->msg[] = $resp; $obj->msg[] = Video::getVideoLight($resp);
} }
$obj->error = false; $obj->error = false;