mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
88 lines
2.8 KiB
PHP
88 lines
2.8 KiB
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);
|
|
header('Content-Type: application/json');
|
|
if (!isset($global['systemRootPath'])) {
|
|
require_once '../../videos/configuration.php';
|
|
}
|
|
|
|
$obj = new stdClass();
|
|
$obj->error = true;
|
|
$obj->msg = array();
|
|
|
|
if (!User::canUpload()) {
|
|
$obj->msg[] = __("Permission denied");
|
|
} else if (!empty($_POST['itemsToSave'])) {
|
|
|
|
foreach ($_POST['itemsToSave'] as $value) {
|
|
//$info = url_get_contents($config->getEncoderURL() . "getLinkInfo/" . base64_encode($value));
|
|
//$infoObj = json_decode($info);
|
|
$filename = uniqid("_YPTuniqid_", true);
|
|
$videos = new Video();
|
|
$videos->setFilename($filename);
|
|
$videos->setTitle($value['title']);
|
|
$videos->setClean_title($value['title']);
|
|
$videos->setDuration(ISO8601ToDuration($value['duration']));
|
|
$videos->setDescription($value['description']);
|
|
file_put_contents($global['systemRootPath'] . "videos/{$filename}.jpg", url_get_contents($value['thumbs']));
|
|
$videos->setVideoLink($value['link']);
|
|
$videos->setType('embed');
|
|
|
|
$videos->setStatus('a');
|
|
try {
|
|
$resp = $videos->save(true);
|
|
} catch (Exception $exc) {
|
|
try {
|
|
$videos->setTitle(preg_replace("/[^A-Za-z0-9 ]/", '', $videos->getTitle()));
|
|
$videos->setDescription(preg_replace("/[^A-Za-z0-9 ]/", '', $videos->getDescription()));
|
|
$resp = $videos->save(true);
|
|
} catch (Exception $exc) {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
YouPHPTubePlugin::afterNewVideo($resp);
|
|
|
|
YouPHPTubePlugin::saveVideosAddNew($_POST, $resp);
|
|
|
|
$obj->msg[] = Video::getVideoLight($resp);
|
|
}
|
|
|
|
$obj->error = false;
|
|
}
|
|
echo json_encode($obj);
|