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

Update for better social publish

This commit is contained in:
Daniel Neto 2024-12-18 12:16:40 -03:00
parent 342ee18808
commit e42b866ec8
8 changed files with 123 additions and 30 deletions

View file

@ -1058,7 +1058,8 @@ function getAudioOrVideoURLOnly($fileName, $recreateCache = false)
foreach ($allFiles as $key => $value) { foreach ($allFiles as $key => $value) {
if ( if (
($value['type'] !== 'video' && $value['type'] !== 'audio') || ($value['type'] !== 'video' && $value['type'] !== 'audio') ||
(preg_match('/offline/i', $key) || preg_match('/.lock/i', $key))) { (preg_match('/offline/i', $key) || preg_match('/.lock/i', $key))
) {
unset($allFiles[$key]); unset($allFiles[$key]);
} }
} }
@ -4431,7 +4432,8 @@ function isContentTypeXML()
return preg_match('/xml/i', $contentType); return preg_match('/xml/i', $contentType);
} }
function successJsonMessage($message){ function successJsonMessage($message)
{
$obj = new stdClass(); $obj = new stdClass();
$obj->error = false; $obj->error = false;
$obj->msg = $message; $obj->msg = $message;
@ -5024,6 +5026,77 @@ function pathToRemoteURL($filename, $forceHTTP = false, $ignoreCDN = false)
return $url; return $url;
} }
function pathOrURLToValidURL($filenameOrURL)
{
global $global;
$videosURL = "{$global['webSiteRootURL']}videos/";
$videosPath = getVideosDir();
$relativePath = '';
$filePath = '';
$parts = explode('?', $filenameOrURL);
$filenameOrURL = $parts[0];
$defaultURL = $filenameOrURL;
if (strpos($filenameOrURL, $videosURL) === 0) {
$relativePath = str_replace($videosURL, '', $filenameOrURL);
$filePath = "{$videosPath}{$relativePath}";
$defaultURL = getCDN() . 'videos/'.$relativePath;
}else if(file_exists($filenameOrURL)){
$relativePath = str_replace($videosPath, '', $filenameOrURL);
$filePath = $filenameOrURL;
$defaultURL = getCDN() . 'videos/'.$relativePath;
}else if(file_exists("{$global['systemRootPath']}{$filenameOrURL}")){
$relativePath = str_replace('videos/', '', $filenameOrURL);
$filePath = "{$global['systemRootPath']}videos/{$relativePath}";
$defaultURL = getCDN() . 'videos/'.$relativePath;
}else if(file_exists("{$videosPath}{$filenameOrURL}")){
$relativePath = "{$filenameOrURL}";
$filePath = "{$global['systemRootPath']}videos/{$relativePath}";
$defaultURL = getCDN() . 'videos/'.$relativePath;
}
if (file_exists($filePath)) {
if (!isDummyFile($filePath)) {
return $defaultURL;
}
$obj = AVideoPlugin::getDataObjectIfEnabled('CDN');
if (!empty($obj) && $obj->enable_storage) {
$pz = CDNStorage::getPZ();
return "https://{$pz}{$relativePath}";
}
$yptStorage = AVideoPlugin::loadPluginIfEnabled("YPTStorage");
if (!empty($yptStorage)) {
$source = $yptStorage->getAddress($relativePath);
if(!empty($source['url'])){
return $source['url'];
}
}
if (!preg_match('/index.m3u8$/', $filePath)) {
if ($aws_s3 = AVideoPlugin::loadPluginIfEnabled("AWS_S3")) {
$source = $aws_s3->getAddress("{$filePath}");
if(!empty($source['url'])){
return $source['url'];
}
} elseif ($bb_b2 = AVideoPlugin::loadPluginIfEnabled("Blackblaze_B2")) {
$source = $bb_b2->getAddress("{$filePath}");
if(!empty($source['url'])){
return $source['url'];
}
} elseif ($ftp = AVideoPlugin::loadPluginIfEnabled("FTP_Storage")) {
$source = $ftp->getAddress("{$filePath}");
if(!empty($source['url'])){
return $source['url'];
}
}
}
}
return $defaultURL;
}
function getFilenameFromPath($path) function getFilenameFromPath($path)
{ {
global $global; global $global;
@ -5146,7 +5219,8 @@ function isWindowsServer()
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
} }
function isWindows() { function isWindows()
{
global $global; global $global;
// Check if the HTTP_USER_AGENT is set // Check if the HTTP_USER_AGENT is set
if (isset($_SERVER['HTTP_USER_AGENT'])) { if (isset($_SERVER['HTTP_USER_AGENT'])) {

View file

@ -1186,7 +1186,7 @@ class CDNStorage
global $global; global $global;
require_once $global['systemRootPath'] . 'objects/video.php'; require_once $global['systemRootPath'] . 'objects/video.php';
$file = Video::getPathToFile($filename); $file = Video::getPathToFile($filename);
$address = ['path' => $file, 'url' => $this->getURL($filename)]; $address = ['path' => $file, 'url' => self::getURL($filename)];
return $address; return $address;
} }

View file

@ -242,6 +242,7 @@ class Publisher_video_publisher_logs extends ObjectYPT
$msg[] = "<a href='{$row['json']->mediaResponse->permalink}' target='_blank'>{$row['json']->mediaResponse->permalink}</a>"; $msg[] = "<a href='{$row['json']->mediaResponse->permalink}' target='_blank'>{$row['json']->mediaResponse->permalink}</a>";
} else if ($row['status'] === self::STATUS_UNVERIFIED) { } else if ($row['status'] === self::STATUS_UNVERIFIED) {
$msg[] = '<i class="fa fa-spinner fa-spin"></i> <strong>Video is being processed:</strong> Your video is currently being processed for publishing on Instagram. Please wait.'; $msg[] = '<i class="fa fa-spinner fa-spin"></i> <strong>Video is being processed:</strong> Your video is currently being processed for publishing on Instagram. Please wait.';
$msg[] = '<button class="btn btn-primary btn-xs" onclick="checkInstagram(\'' . $row['json']->response->accessToken . '\', \'' . $row['json']->response->containerId . '\', \'' . $row['json']->response->instagramAccountId . '\')"><i class="fas fa-check-circle"></i> ' . __('Check now') . '</button>';
} elseif ($row['status'] === self::STATUS_VERIFIED) { } elseif ($row['status'] === self::STATUS_VERIFIED) {
$msg[] = '<i class="fa fa-check-circle"></i> <strong>Video successfully published:</strong> Your video has been verified and uploaded to Instagram.'; $msg[] = '<i class="fa fa-check-circle"></i> <strong>Video successfully published:</strong> Your video has been verified and uploaded to Instagram.';
} else { } else {

View file

@ -2,7 +2,7 @@
class SocialUploader class SocialUploader
{ {
public static function upload($publisher_user_preferences_id, $videoPath, $title, $description, $visibility = 'public', $isShort = false) public static function upload($publisher_user_preferences_id, $videoPathMP4, $title, $description, $visibility = 'public', $isShort = false)
{ {
$title = strip_tags($title); $title = strip_tags($title);
$description = strip_tags($description); $description = strip_tags($description);
@ -12,16 +12,18 @@ class SocialUploader
} }
$pub = new Publisher_user_preferences($publisher_user_preferences_id); $pub = new Publisher_user_preferences($publisher_user_preferences_id);
_error_log("SocialMediaPublisher::upload provider=" . $pub->getProviderName()); _error_log("SocialMediaPublisher::upload provider=" . $pub->getProviderName());
$videoPathMP4['url'] = addQueryStringParameter($videoPathMP4['url'], 'globalToken', getToken(30));
try { try {
switch ($pub->getProviderName()) { switch ($pub->getProviderName()) {
case SocialMediaPublisher::SOCIAL_TYPE_YOUTUBE['name']: case SocialMediaPublisher::SOCIAL_TYPE_YOUTUBE['name']:
return SocialUploader::uploadYouTube($accessToken, $videoPath, $title, $description, $visibility, $isShort); return SocialUploader::uploadYouTube($accessToken, $videoPathMP4['path'], $title, $description, $visibility, $isShort);
break; break;
case SocialMediaPublisher::SOCIAL_TYPE_FACEBOOK['name']: case SocialMediaPublisher::SOCIAL_TYPE_FACEBOOK['name']:
$json = json_decode($pub->getJson()); $json = json_decode($pub->getJson());
$pageId = $json->{'restream.ypt.me'}->facebook->broadcaster_id; $pageId = $json->{'restream.ypt.me'}->facebook->broadcaster_id;
_error_log("SocialMediaPublisher::upload json=" . json_encode($json)); _error_log("SocialMediaPublisher::upload json=" . json_encode($json));
return SocialUploader::uploadFacebook($accessToken, $pageId, $videoPath, $title, $description, $visibility, $isShort); return SocialUploader::uploadFacebook($accessToken, $pageId, $videoPathMP4['url'], $title, $description, $visibility, $isShort);
break; break;
case SocialMediaPublisher::SOCIAL_TYPE_INSTAGRAM['name']: case SocialMediaPublisher::SOCIAL_TYPE_INSTAGRAM['name']:
$pub = Publisher_user_preferences::getFromDb($publisher_user_preferences_id); $pub = Publisher_user_preferences::getFromDb($publisher_user_preferences_id);
@ -34,7 +36,7 @@ class SocialUploader
$broadcaster_id = $json->{"restream.ypt.me"}->instagram->broadcaster_id; $broadcaster_id = $json->{"restream.ypt.me"}->instagram->broadcaster_id;
} }
} }
return SocialUploader::uploadInstagram($accessToken, $videoPath, $title, $description, $broadcaster_id); return SocialUploader::uploadInstagram($accessToken, $videoPathMP4['url'], $title, $description, $broadcaster_id);
break; break;
case SocialMediaPublisher::SOCIAL_TYPE_TWITCH['name']: case SocialMediaPublisher::SOCIAL_TYPE_TWITCH['name']:
//return SocialUploader::uploadYouTube($accessToken, $videoPath, $title, $description, $visibility, $isShort); //return SocialUploader::uploadYouTube($accessToken, $videoPath, $title, $description, $visibility, $isShort);
@ -43,7 +45,7 @@ class SocialUploader
$json = json_decode($pub->getJson()); $json = json_decode($pub->getJson());
$urn = $json->{'restream.ypt.me'}->linkedin->urn; $urn = $json->{'restream.ypt.me'}->linkedin->urn;
$id = $json->{'restream.ypt.me'}->linkedin->profile_id; $id = $json->{'restream.ypt.me'}->linkedin->profile_id;
$upload = SocialUploader::uploadLinkedIn($accessToken, $urn, $id, $videoPath, $title, $description, $visibility, $isShort); $upload = SocialUploader::uploadLinkedIn($accessToken, $urn, $id, $videoPathMP4['path'], $title, $description, $visibility, $isShort);
return $upload; return $upload;
break; break;
} }
@ -196,8 +198,6 @@ class FacebookUploader
// Upload a local video directly // Upload a local video directly
$videoUrl = str_replace($global['systemRootPath'], $global['webSiteRootURL'], $videoPath); $videoUrl = str_replace($global['systemRootPath'], $global['webSiteRootURL'], $videoPath);
$videoUrl = addQueryStringParameter($videoUrl, 'globalToken', getToken(30));
$VideoUploadResponse = FacebookUploader::uploadDirectHostedVideo($pageId, $accessToken, $videoUrl, $title, PHP_EOL . $description); $VideoUploadResponse = FacebookUploader::uploadDirectHostedVideo($pageId, $accessToken, $videoUrl, $title, PHP_EOL . $description);
//$VideoUploadResponse = FacebookUploader::uploadDirectLocalVideo($pageId, $accessToken, $videoPath); //$VideoUploadResponse = FacebookUploader::uploadDirectLocalVideo($pageId, $accessToken, $videoPath);

View file

@ -257,7 +257,7 @@ class SocialMediaPublisher extends PluginAbstract
} }
$providerName = $o->getProviderName(); $providerName = $o->getProviderName();
/*
$fromFileLocation = $paths['mp4']['url']; $fromFileLocation = $paths['mp4']['url'];
if (!isDummyFile($paths['mp4']['path'])) { if (!isDummyFile($paths['mp4']['path'])) {
$videoPath = $paths['mp4']['path']; $videoPath = $paths['mp4']['path'];
@ -270,7 +270,7 @@ class SocialMediaPublisher extends PluginAbstract
_error_log("SocialMediaPublisher::upload($publisher_user_preferences_id, $videos_id) $providerName end conversion "); _error_log("SocialMediaPublisher::upload($publisher_user_preferences_id, $videos_id) $providerName end conversion ");
} }
_error_log("SocialMediaPublisher::upload($publisher_user_preferences_id, $videos_id) $providerName Upload start "); _error_log("SocialMediaPublisher::upload($publisher_user_preferences_id, $videos_id) $providerName Upload start ");
*/
if (!empty($_REQUEST['title'])) { if (!empty($_REQUEST['title'])) {
$title = $_REQUEST['title']; $title = $_REQUEST['title'];
} else { } else {
@ -287,10 +287,7 @@ class SocialMediaPublisher extends PluginAbstract
$visibility = 'public'; $visibility = 'public';
} }
$response = SocialUploader::upload($publisher_user_preferences_id, $videoPath, $title, $description, $visibility); $response = SocialUploader::upload($publisher_user_preferences_id, $paths['mp4'], $title, $description, $visibility);
if (!empty($videoPathToYouTube)) {
//unlink($videoPathToYouTube);
}
_error_log("SocialMediaPublisher::upload($publisher_user_preferences_id, $videos_id) $providerName complete " . json_encode($response)); _error_log("SocialMediaPublisher::upload($publisher_user_preferences_id, $videos_id) $providerName complete " . json_encode($response));
self::saveLog($publisher_social_medias_id, $videos_id, array('publisher_user_preferences_id' => $publisher_user_preferences_id, 'response' => $response)); self::saveLog($publisher_social_medias_id, $videos_id, array('publisher_user_preferences_id' => $publisher_user_preferences_id, 'response' => $response));
return $response; return $response;

View file

@ -9,6 +9,8 @@ $obj->msg = '';
$plugin = AVideoPlugin::loadPluginIfEnabled('SocialMediaPublisher'); $plugin = AVideoPlugin::loadPluginIfEnabled('SocialMediaPublisher');
$obj = SocialMediaPublisher::scanInstagam(); //$obj = SocialMediaPublisher::scanInstagam();
$obj = InstagramUploader::publishMediaIfIsReady($_REQUEST['accessToken'], $_REQUEST['containerId'], $_REQUEST['instagramAccountId']);
die(json_encode($obj)); die(json_encode($obj));

View file

@ -96,3 +96,22 @@ function reloadSocialAccountsTables() {
} }
} }
function checkInstagram(accessToken, containerId, instagramAccountId) {
var url = webSiteRootURL + 'plugin/SocialMediaPublisher/publishInstagram.json.php';
url = addQueryStringParameter(url, 'accessToken', accessToken);
url = addQueryStringParameter(url, 'containerId', containerId);
url = addQueryStringParameter(url, 'instagramAccountId', instagramAccountId);
modal.showPleaseWait();
$.ajax({
url: url,
complete: function(response) {
modal.hidePleaseWait();
if (response.error) {
avideoAlertError(response.msg);
} else {
reloadSocialAccountsTables();
}
}
});
}

View file

@ -24,7 +24,6 @@ if (empty($videos_id)) {
.social-network .btn { .social-network .btn {
margin: 20px 0; margin: 20px 0;
} }
</style> </style>
<div class="container-fluid"> <div class="container-fluid">
<div class="panel panel-default "> <div class="panel panel-default ">
@ -73,6 +72,7 @@ if (empty($videos_id)) {
</div> </div>
<script> <script>
$(document).ready(function() {}); $(document).ready(function() {});
</script> </script>
<?php <?php
$_page->print(); $_page->print();