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

Improve autoplay

This commit is contained in:
daniel 2020-01-13 17:53:40 -03:00
parent bb895db49c
commit f8bbc93392

189
plugin/DiscordNotify/DiscordNotify.php Normal file → Executable file
View file

@ -6,130 +6,125 @@ if (!isset($global['systemRootPath'])) {
} }
require_once $global['systemRootPath'] . 'plugin/Plugin.abstract.php'; require_once $global['systemRootPath'] . 'plugin/Plugin.abstract.php';
class DiscordNotify extends PluginAbstract class DiscordNotify extends PluginAbstract {
{
public function getDescription() {
public function getDescription()
{
return "Send video upload notifications to discord webhook"; return "Send video upload notifications to discord webhook";
} }
public function getName() public function getName() {
{
return "DiscordNotify"; return "DiscordNotify";
} }
public function getUUID() public function getUUID() {
{
return "cf145581-7d5e-4bb6-8c12-848a19j1564g"; return "cf145581-7d5e-4bb6-8c12-848a19j1564g";
} }
public function getTags()
{ public function getTags() {
return array( return array(
'free', 'free',
'notifications', 'notifications',
'webhook' 'webhook'
); );
} }
public function getPluginVersion() {
public function getPluginVersion() {
return "1.0"; return "1.0";
} }
public function getEmptyDataObject() { public function getEmptyDataObject() {
global $global; global $global;
$server = parse_url($global['webSiteRootURL']); $server = parse_url($global['webSiteRootURL']);
$obj = new stdClass(); $obj = new stdClass();
$obj->webhook_url = ""; $obj->webhook_url = "";
$obj->avatar_url = ""; $obj->avatar_url = "";
$obj->bot_username = ""; $obj->bot_username = "";
$obj->footer_image = ""; $obj->footer_image = "";
return $obj; return $obj;
} }
public function afterNewVideo($videos_id)
{ public function afterNewVideo($videos_id) {
global $global; global $global;
$o = $this->getDataObject(); $o = $this->getDataObject();
$users_id = Video::getOwner($videos_id); $users_id = Video::getOwner($videos_id);
$user = new User($users_id); $user = new User($users_id);
$username = $user->getNameIdentification(); $username = $user->getNameIdentification();
$channelName = $user->getChannelName(); $channelName = $user->getChannelName();
$video = new Video("","",$videos_id); $video = new Video("", "", $videos_id);
$videoName = $video->getTitle(); $videoName = $video->getTitle();
$images = Video::getImageFromFilename($video->getFilename()); $images = Video::getImageFromFilename($video->getFilename());
$videoThumbs = $images->thumbsJpg; $videoThumbs = $images->thumbsJpg;
$videoLink = Video::getPermaLink($videos_id); $videoLink = Video::getPermaLink($videos_id);
$videoDuration = $video->getDuration(); $videoDuration = $video->getDuration();
$videoDescription = $video->getDescription(); $videoDescription = $video->getDescription();
$url = $o->webhook_url; $url = $o->webhook_url;
$avatar_url = $o->avatar_url; $avatar_url = $o->avatar_url;
$bot_username = $o->bot_username; $bot_username = $o->bot_username;
$footer_image = $o->footer_image; $footer_image = $o->footer_image;
$hookObject = json_encode([ $hookObject = json_encode([
"content" => "", "content" => "",
"username" => $bot_username, "username" => $bot_username,
"avatar_url" => $avatar_url, "avatar_url" => $avatar_url,
"tts" => false, "tts" => false,
"embeds" => [ "embeds" => [
[
"title" => $username . " just uploaded a video",
"type" => "rich",
"description" => "",
"url" => $global['webSiteRootURL'] . $channelName,
"timestamp" => "",
"color" => hexdec( "FF0000" ),
"footer" => [
"text" => $bot_username,
"icon_url" => $footer_image
],
"image" => [
"url" => $videoThumbs,
],
//"thumbnail" => [
// "url" => $userThumbnail
//],
"fields" => [
[ [
"name" => "Video Name", "title" => $username . " just uploaded a video",
"value" => $videoName, "type" => "rich",
"inline" => true "description" => "",
], "url" => $global['webSiteRootURL'] . $channelName,
[ "timestamp" => "",
"name" => "Video Link", "color" => hexdec("FF0000"),
"value" => $videoLink, "footer" => [
"inline" => true "text" => $bot_username,
], "icon_url" => $footer_image
[ ],
"name" => "Video Duration", "image" => [
"value" => $videoDuration, "url" => $videoThumbs,
"inline" => true ],
], //"thumbnail" => [
[ // "url" => $userThumbnail
"name" => "Video Description", //],
"value" => "N/A", "fields" => [
"inline" => true [
"name" => "Video Name",
"value" => $videoName,
"inline" => true
],
[
"name" => "Video Link",
"value" => $videoLink,
"inline" => true
],
[
"name" => "Video Duration",
"value" => $videoDuration,
"inline" => true
],
[
"name" => "Video Description",
"value" => "N/A",
"inline" => true
]
]
] ]
] ]
] ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
]
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); $ch = curl_init();
$ch = curl_init(); curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $hookObject,
CURLOPT_HTTPHEADER => [
"Length" => strlen($hookObject),
"Content-Type" => "application/json"
]
]);
curl_setopt_array( $ch, [ return curl_exec($ch);
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $hookObject,
CURLOPT_HTTPHEADER => [
"Length" => strlen( $hookObject ),
"Content-Type" => "application/json"
]
]);
return curl_exec( $ch );
} }
} }