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

API update

This commit is contained in:
DanielnetoDotCom 2020-07-19 19:05:34 -03:00
parent af98a6f3f4
commit b514beaaab
5 changed files with 94 additions and 25 deletions

View file

@ -4,7 +4,7 @@ if (file_exists("../videos/configuration.php")) {
exit;
}
$installationVersion = "9.1";
$installationVersion = "9.2";
header('Content-Type: application/json');

View file

@ -379,6 +379,79 @@ class API extends PluginAbstract {
}
}
/**
* @param type $parameters
* 'videos_id' the video id that will be deleted
* ['APISecret' if passed will not require user and pass]
* ['user' usename of the user that will like the video]
* ['pass' password of the user that will like the video]
* @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&videos_id=1&user=admin&pass=123&APISecret={APISecret}
* @return \ApiObject
*/
public function get_api_video_delete($parameters) {
global $global;
require_once $global['systemRootPath'] . 'objects/video.php';
$obj = $this->startResponseObject($parameters);
$dataObj = $this->getDataObject();
if (!empty($parameters['videos_id'])) {
if (!User::canUpload()) {
return new ApiObject("Access denied");
}
if (!empty($_GET['APISecret']) && $dataObj->APISecret !== $_GET['APISecret']) {
return new ApiObject("Secret does not match");
}
$obj = new Video("", "", $parameters['videos_id']);
if (!$obj->userCanManageVideo()) {
return new ApiObject("User cannot manage the video");
}
$id = $obj->delete();
return new ApiObject("", !$id, $id);
} else {
return new ApiObject("Video ID is required");
}
}
/**
* @param type $parameters
* 'videos_id' the video id that will be deleted
* 'title' the video title
* 'status' the video status
* ['APISecret' if passed will not require user and pass]
* ['user' usename of the user that will like the video]
* ['pass' password of the user that will like the video]
* @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&videos_id=1&user=admin&pass=123&APISecret={APISecret}
* @return \ApiObject
*/
public function get_api_video_save($parameters) {
global $global;
require_once $global['systemRootPath'] . 'objects/video.php';
$obj = $this->startResponseObject($parameters);
$dataObj = $this->getDataObject();
if (!empty($parameters['videos_id'])) {
if (!User::canUpload()) {
return new ApiObject("Access denied");
}
if (!empty($_GET['APISecret']) && $dataObj->APISecret !== $_GET['APISecret']) {
return new ApiObject("Secret does not match");
}
$obj = new Video("", "", $parameters['videos_id']);
if (!$obj->userCanManageVideo()) {
return new ApiObject("User cannot manage the video");
}
if(!empty($parameters['title'])){
$obj->setTitle($parameters['title']);
}
if(!empty($parameters['status'])){
$obj->setStatus($parameters['status']);
}
$id = $obj->save();
return new ApiObject("", !$id, $id);
} else {
return new ApiObject("Video ID is required");
}
}
/**
* @param type $parameters
* @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}

View file

@ -0,0 +1,7 @@
<?php
require_once '../../videos/configuration.php';
session_write_close();
header('Content-Type: application/json');
$obj = AVideoPlugin::getObjectData("CustomizeUser");
echo json_encode($obj);
include $global['systemRootPath'].'objects/include_end.php';

View file

@ -28,31 +28,18 @@ $video = $liveLink->getLink();
if (preg_match("/\b(?:(?:https?):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $video)) {
$url = $config->getEncoderURL() . "getImage/" . base64_encode($video) . "/{$_GET['format']}";
if (empty($_SESSION[$url]['expire']) || $_SESSION[$url]['expire'] < time()) {
//_error_log("LiveLink: getImage.php: " . $url);
$content = url_get_contents($url);
if (session_status() == PHP_SESSION_NONE) {
session_start();
$name = "liveLinks_getImage_".md5($url);
$content = ObjectYPT::getCache($name, 600);
if(empty($content)){
$content = url_get_contents($url, "", 2);
if(!empty($content)){
ObjectYPT::setCache($name, $content);
}
//_error_log(" Image Expired in " . date("d/m/Y H:i:s", @$_SESSION[$url]['expire']) . " NOW is " . date("d/m/Y H:i:s"));
$_SESSION[$url] = array('content' => $content, 'expire' => strtotime("+2 min"));
//_error_log(" New Image will Expired in " . date("d/m/Y H:i:s", $_SESSION[$url]['expire']) . " NOW is " . date("d/m/Y H:i:s"));
}
if (!empty($_SESSION[$url]['content'])) {
ob_end_clean();
echo $_SESSION[$url]['content'];
//_error_log(" Cached Good until " . date("d/m/Y H:i:s", $_SESSION[$url]['expire']) . " NOW is " . date("d/m/Y H:i:s"));
} else {
ob_end_clean();
echo url_get_contents($filename);
//_error_log(" Get default image ");
}
} else {
ob_end_clean();
echo local_get_contents($filename);
//_error_log(" Invalid URL ");
}
$p = AVideoPlugin::loadPluginIfEnabled("Cache");
if (!empty($p)) {
$p->getEnd();
if(!empty($content)){
echo $content;
}else{
echo local_get_contents($filename);
}

View file

@ -0,0 +1,2 @@
-- new API features
UPDATE configurations SET version = '9.2', modified = now() WHERE id = 1;