mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Update for better social publish
This commit is contained in:
parent
342ee18808
commit
e42b866ec8
8 changed files with 123 additions and 30 deletions
|
@ -333,11 +333,11 @@ function safeString($text, $strict = false, $try = 0)
|
|||
|
||||
if (empty($try) && empty($text) && function_exists('mb_convert_encoding')) {
|
||||
$originalText2 = preg_replace('/[^\PC\s]/u', '', $originalText);
|
||||
if(empty($originalText2)){
|
||||
if (empty($originalText2)) {
|
||||
$originalText2 = mb_convert_encoding($originalText, 'UTF-8', 'auto');
|
||||
$originalText2 = preg_replace('/[^\PC\s]/u', '', $originalText2);
|
||||
}
|
||||
if(!empty($originalText2)){
|
||||
if (!empty($originalText2)) {
|
||||
$originalText = $originalText2;
|
||||
}
|
||||
// Remove leading and trailing whitespace
|
||||
|
@ -1058,7 +1058,8 @@ function getAudioOrVideoURLOnly($fileName, $recreateCache = false)
|
|||
foreach ($allFiles as $key => $value) {
|
||||
if (
|
||||
($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]);
|
||||
}
|
||||
}
|
||||
|
@ -1217,12 +1218,12 @@ function getVideosURL_V2($fileName, $recreateCache = false, $checkFiles = true)
|
|||
}
|
||||
|
||||
$_filename = "{$parts['filename']}.{$parts['extension']}";
|
||||
if($parts['basename'] == 'index.mp4' ){
|
||||
if ($parts['basename'] == 'index.mp4') {
|
||||
$_filename = "index.mp4";
|
||||
$source['url'] = str_replace("{$parts['filename']}.mp4", 'index.mp4', $source['url']);
|
||||
$source['url_noCDN'] = str_replace("{$parts['filename']}.mp4", 'index.mp4', $source['url_noCDN']);
|
||||
}
|
||||
if($parts['basename'] == 'index.mp3' ){
|
||||
if ($parts['basename'] == 'index.mp3') {
|
||||
$_filename = "index.mp3";
|
||||
$source['url'] = str_replace("{$parts['filename']}.mp3", 'index.mp3', $source['url']);
|
||||
$source['url_noCDN'] = str_replace("{$parts['filename']}.mp3", 'index.mp3', $source['url_noCDN']);
|
||||
|
@ -2649,7 +2650,7 @@ function rrmdir($dir)
|
|||
function getAdsDebugTag($adCode)
|
||||
{
|
||||
global $global;
|
||||
if(!empty($_REQUEST['AdsDebug']) && User::isAdmin()){
|
||||
if (!empty($_REQUEST['AdsDebug']) && User::isAdmin()) {
|
||||
$function = debug_backtrace()[1]["function"];
|
||||
$function = str_replace('get', '', $function);
|
||||
$adCode = "<div class=\"AdsDebug\">{$function}<br>{$global['lastAdsCodeReason']}<br>$adCode</div>";
|
||||
|
@ -3169,7 +3170,7 @@ function verifyToken($token, $salt = "")
|
|||
_error_log("verifyToken salt fail");
|
||||
return false;
|
||||
}
|
||||
if(!empty($obj->videos_id) && $obj->videos_id != getVideos_id()){
|
||||
if (!empty($obj->videos_id) && $obj->videos_id != getVideos_id()) {
|
||||
_error_log("This is not to this videos ID");
|
||||
return false;
|
||||
}
|
||||
|
@ -4431,7 +4432,8 @@ function isContentTypeXML()
|
|||
return preg_match('/xml/i', $contentType);
|
||||
}
|
||||
|
||||
function successJsonMessage($message){
|
||||
function successJsonMessage($message)
|
||||
{
|
||||
$obj = new stdClass();
|
||||
$obj->error = false;
|
||||
$obj->msg = $message;
|
||||
|
@ -5024,6 +5026,77 @@ function pathToRemoteURL($filename, $forceHTTP = false, $ignoreCDN = false)
|
|||
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)
|
||||
{
|
||||
global $global;
|
||||
|
@ -5146,7 +5219,8 @@ function isWindowsServer()
|
|||
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
|
||||
}
|
||||
|
||||
function isWindows() {
|
||||
function isWindows()
|
||||
{
|
||||
global $global;
|
||||
// Check if the HTTP_USER_AGENT is set
|
||||
if (isset($_SERVER['HTTP_USER_AGENT'])) {
|
||||
|
|
|
@ -1186,7 +1186,7 @@ class CDNStorage
|
|||
global $global;
|
||||
require_once $global['systemRootPath'] . 'objects/video.php';
|
||||
$file = Video::getPathToFile($filename);
|
||||
$address = ['path' => $file, 'url' => $this->getURL($filename)];
|
||||
$address = ['path' => $file, 'url' => self::getURL($filename)];
|
||||
return $address;
|
||||
}
|
||||
|
||||
|
|
|
@ -238,10 +238,11 @@ class Publisher_video_publisher_logs extends ObjectYPT
|
|||
}
|
||||
break;
|
||||
case SocialMediaPublisher::SOCIAL_TYPE_INSTAGRAM["name"]:
|
||||
if(!empty($row['json']->mediaResponse->permalink)){
|
||||
if (!empty($row['json']->mediaResponse->permalink)) {
|
||||
$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[] = '<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) {
|
||||
$msg[] = '<i class="fa fa-check-circle"></i> <strong>Video successfully published:</strong> Your video has been verified and uploaded to Instagram.';
|
||||
} else {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
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);
|
||||
$description = strip_tags($description);
|
||||
|
@ -12,16 +12,18 @@ class SocialUploader
|
|||
}
|
||||
$pub = new Publisher_user_preferences($publisher_user_preferences_id);
|
||||
_error_log("SocialMediaPublisher::upload provider=" . $pub->getProviderName());
|
||||
|
||||
$videoPathMP4['url'] = addQueryStringParameter($videoPathMP4['url'], 'globalToken', getToken(30));
|
||||
try {
|
||||
switch ($pub->getProviderName()) {
|
||||
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;
|
||||
case SocialMediaPublisher::SOCIAL_TYPE_FACEBOOK['name']:
|
||||
$json = json_decode($pub->getJson());
|
||||
$pageId = $json->{'restream.ypt.me'}->facebook->broadcaster_id;
|
||||
_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;
|
||||
case SocialMediaPublisher::SOCIAL_TYPE_INSTAGRAM['name']:
|
||||
$pub = Publisher_user_preferences::getFromDb($publisher_user_preferences_id);
|
||||
|
@ -34,7 +36,7 @@ class SocialUploader
|
|||
$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;
|
||||
case SocialMediaPublisher::SOCIAL_TYPE_TWITCH['name']:
|
||||
//return SocialUploader::uploadYouTube($accessToken, $videoPath, $title, $description, $visibility, $isShort);
|
||||
|
@ -43,7 +45,7 @@ class SocialUploader
|
|||
$json = json_decode($pub->getJson());
|
||||
$urn = $json->{'restream.ypt.me'}->linkedin->urn;
|
||||
$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;
|
||||
break;
|
||||
}
|
||||
|
@ -196,8 +198,6 @@ class FacebookUploader
|
|||
// Upload a local video directly
|
||||
$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::uploadDirectLocalVideo($pageId, $accessToken, $videoPath);
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ class SocialMediaPublisher extends PluginAbstract
|
|||
}
|
||||
|
||||
$providerName = $o->getProviderName();
|
||||
|
||||
/*
|
||||
$fromFileLocation = $paths['mp4']['url'];
|
||||
if (!isDummyFile($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 Upload start ");
|
||||
|
||||
*/
|
||||
if (!empty($_REQUEST['title'])) {
|
||||
$title = $_REQUEST['title'];
|
||||
} else {
|
||||
|
@ -287,10 +287,7 @@ class SocialMediaPublisher extends PluginAbstract
|
|||
$visibility = 'public';
|
||||
}
|
||||
|
||||
$response = SocialUploader::upload($publisher_user_preferences_id, $videoPath, $title, $description, $visibility);
|
||||
if (!empty($videoPathToYouTube)) {
|
||||
//unlink($videoPathToYouTube);
|
||||
}
|
||||
$response = SocialUploader::upload($publisher_user_preferences_id, $paths['mp4'], $title, $description, $visibility);
|
||||
_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));
|
||||
return $response;
|
||||
|
|
|
@ -9,6 +9,8 @@ $obj->msg = '';
|
|||
|
||||
$plugin = AVideoPlugin::loadPluginIfEnabled('SocialMediaPublisher');
|
||||
|
||||
$obj = SocialMediaPublisher::scanInstagam();
|
||||
//$obj = SocialMediaPublisher::scanInstagam();
|
||||
|
||||
$obj = InstagramUploader::publishMediaIfIsReady($_REQUEST['accessToken'], $_REQUEST['containerId'], $_REQUEST['instagramAccountId']);
|
||||
|
||||
die(json_encode($obj));
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
|
@ -24,7 +24,6 @@ if (empty($videos_id)) {
|
|||
.social-network .btn {
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
</style>
|
||||
<div class="container-fluid">
|
||||
<div class="panel panel-default ">
|
||||
|
@ -73,6 +72,7 @@ if (empty($videos_id)) {
|
|||
</div>
|
||||
<script>
|
||||
$(document).ready(function() {});
|
||||
|
||||
</script>
|
||||
<?php
|
||||
$_page->print();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue