Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Sep 7, 2024
1 parent 85a6a85 commit d246ee5
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ objects/ezyang/
/plugin/TestOnly/
view/videoComments_bkp.php
/.compose/
test.php
/plugin/JosephZ/
/Encoder/
/.env
Expand All @@ -105,4 +104,4 @@ install/bulkCreateUser.php
/plugin/CertifyComplete/
plugin/WebAuthnLogin/
plugin/UserOTPLogin/
test2.php
test*
2 changes: 2 additions & 0 deletions objects/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3672,13 +3672,15 @@ function getPlayListCurrentVideosId($setVideos_id = true)
$playListData = getPlayListData();
$playlist_index = getPlayListIndex();
if (empty($playListData) && !empty($_REQUEST['playlist_id']) && class_exists('PlayList')) {
_error_log('line='.__LINE__." playlist_id={$_REQUEST['playlist_id']} playlist_index={$playlist_index}");
$videosArrayId = PlayList::getVideosIdFromPlaylist($_REQUEST['playlist_id']);
$videos_id = $videosArrayId[$playlist_index];
} else {
if (empty($playListData[$playlist_index])) {
//var_dump($playlist_index, $playListData);
return false;
} else {
_error_log('line='.__LINE__." playlist_id={$_REQUEST['playlist_id']} playlist_index={$playlist_index}");
$videos_id = $playListData[$playlist_index]->getVideos_id();
}
}
Expand Down
14 changes: 9 additions & 5 deletions objects/functionsFFMPEG.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ function convertVideoToMP3FileIfNotExists($videos_id, $forceTry = 0)
}

$paths = Video::getPaths($video['filename']);
$mp3HLSFile = "{$paths['path']}index.mp3";
$mp3File = "{$paths['path']}{$video['filename']}.mp3";
if (!file_exists($mp3File)) {
if(file_exists($mp3HLSFile) || file_exists($mp3File)){
return Video::getSourceFile($video['filename'], ".mp3", true);
}else {
$f = convertVideoFileWithFFMPEGIsLockedInfo($mp3File);
if ($f['isUnlocked']) {
$sources = getVideosURLOnly($video['filename'], false);

if (!empty($sources)) {
$source = end($sources);
if(!empty($sources['m3u8'])){
$source = $sources['m3u8'];
}else{
$source = end($sources);
}
convertVideoFileWithFFMPEG($source['url'], $mp3File, '', $forceTry);
if (file_exists($mp3File)) {
return Video::getSourceFile($video['filename'], ".mp3", true);
Expand All @@ -76,8 +82,6 @@ function convertVideoToMP3FileIfNotExists($videos_id, $forceTry = 0)
_error_log("convertVideoToMP3FileIfNotExists: is locked");
}
return false;
} else {
return Video::getSourceFile($video['filename'], ".mp3", true);
}
}

Expand Down
20 changes: 15 additions & 5 deletions objects/video.php
Original file line number Diff line number Diff line change
Expand Up @@ -4059,7 +4059,7 @@ public static function getSourceFile($filename, $type = ".jpg", $includeS3 = fal

TimeLogEnd($timeLog1, __LINE__, $timeLog1Limit);
$cacheName = md5($filename . $type . $includeS3);
if (isset($VideoGetSourceFile[$cacheName]) && is_array($VideoGetSourceFile[$cacheName])) {
if (isset($VideoGetSourceFile[$cacheName]) && is_array($VideoGetSourceFile[$cacheName]) ) {
if (!preg_match("/token=/", $VideoGetSourceFile[$cacheName]['url'])) {
return $VideoGetSourceFile[$cacheName];
}
Expand Down Expand Up @@ -4110,6 +4110,14 @@ public static function getSourceFile($filename, $type = ".jpg", $includeS3 = fal
if ($type == ".m3u8") {
$source['path'] = self::getStoragePath() . "{$filename}/index{$type}";
}
$indexMP3Exits = false;
if ($type == ".mp3") {
$exits = self::getStoragePath() . "{$filename}/index{$type}";
$indexMP3Exits = file_exists($exits);
if($indexMP3Exits){
$source['path'] = $exits;
}
}
TimeLogEnd($timeLog1, __LINE__, $timeLog1Limit);
$cleanFileName = self::getCleanFilenameFromFile($filename);
TimeLogEnd($timeLog1, __LINE__, $timeLog1Limit);
Expand All @@ -4133,7 +4141,9 @@ public static function getSourceFile($filename, $type = ".jpg", $includeS3 = fal
if (!empty($cdn_obj->enable_storage) && $isValidType && $fsize < 20 && !empty($site) && (empty($yptStorage) || $site->getUrl() == 'url/')) {
if ($type == ".m3u8") {
$f = "{$filename}/index{$type}";
} else {
} else if($indexMP3Exits){
$f = "{$filename}/index{$type}";
}else {
$f = "{$paths['relative']}{$filename}{$type}";
}
TimeLogEnd($timeLog1, __LINE__, $timeLog1Limit);
Expand All @@ -4146,22 +4156,22 @@ public static function getSourceFile($filename, $type = ".jpg", $includeS3 = fal
TimeLogEnd($timeLog1, __LINE__, $timeLog1Limit);
$source['url'] = "{$siteURL}{$paths['relative']}{$filename}{$type}";
$source['url_noCDN'] = $site->getUrl() . "{$paths['relative']}{$filename}{$type}";
if ($type == ".m3u8") {
if ($type == ".m3u8" || $indexMP3Exits) {
$source['url'] = "{$siteURL}videos/{$filename}/index{$type}";
$source['url_noCDN'] = "{$global['webSiteRootURL']}videos/{$filename}/index{$type}";
}
} elseif (!empty($advancedCustom->videosCDN) && $canUseCDN) {
$advancedCustom->videosCDN = addLastSlash($advancedCustom->videosCDN);
$source['url'] = "{$advancedCustom->videosCDN}{$paths['relative']}{$filename}{$type}";
$source['url_noCDN'] = "{$global['webSiteRootURL']}{$paths['relative']}{$filename}{$type}";
if ($type == ".m3u8") {
if ($type == ".m3u8" || $indexMP3Exits) {
$source['url'] = "{$advancedCustom->videosCDN}videos/{$filename}/index{$type}";
$source['url_noCDN'] = "{$global['webSiteRootURL']}videos/{$filename}/index{$type}";
}
} else {
$source['url'] = getCDN() . "{$paths['relative']}{$filename}{$type}";
$source['url_noCDN'] = "{$global['webSiteRootURL']}{$paths['relative']}{$filename}{$type}";
if ($type == ".m3u8") {
if ($type == ".m3u8" || $indexMP3Exits) {
$source['url'] = getCDN() . "videos/{$filename}/index{$type}";
$source['url_noCDN'] = "{$global['webSiteRootURL']}videos/{$filename}/index{$type}";
}
Expand Down
99 changes: 92 additions & 7 deletions plugin/AI/AI.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class AI extends PluginAbstract
static $typeTranscription = 'transcription';
static $typeBasic = 'basic';
static $typeShorts = 'shorts';
static $typeDubbing = 'dubbing';

static $languages = [
const LANGS = [
'en' => 'English',
'es' => 'Spanish',
'fr' => 'French',
Expand Down Expand Up @@ -51,6 +52,39 @@ class AI extends PluginAbstract
'vi' => 'Vietnamese'
];


const DubbingLANGS = [
['name' => 'English', 'code' => 'en'],
['name' => 'Hindi', 'code' => 'hi'],
['name' => 'Portuguese', 'code' => 'pt'],
['name' => 'Chinese', 'code' => 'zh'],
['name' => 'Spanish', 'code' => 'es'],
['name' => 'French', 'code' => 'fr'],
['name' => 'German', 'code' => 'de'],
['name' => 'Japanese', 'code' => 'ja'],
['name' => 'Arabic', 'code' => 'ar'],
['name' => 'Russian', 'code' => 'ru'],
['name' => 'Korean', 'code' => 'ko'],
['name' => 'Indonesian', 'code' => 'id'],
['name' => 'Italian', 'code' => 'it'],
['name' => 'Dutch', 'code' => 'nl'],
['name' => 'Turkish', 'code' => 'tr'],
['name' => 'Polish', 'code' => 'pl'],
['name' => 'Swedish', 'code' => 'sv'],
['name' => 'Filipino', 'code' => 'fil'],
['name' => 'Malay', 'code' => 'ms'],
['name' => 'Romanian', 'code' => 'ro'],
['name' => 'Ukrainian', 'code' => 'uk'],
['name' => 'Greek', 'code' => 'el'],
['name' => 'Czech', 'code' => 'cs'],
['name' => 'Danish', 'code' => 'da'],
['name' => 'Finnish', 'code' => 'fi'],
['name' => 'Bulgarian', 'code' => 'bg'],
['name' => 'Croatian', 'code' => 'hr'],
['name' => 'Slovak', 'code' => 'sk'],
['name' => 'Tamil', 'code' => 'ta'],
];

static $isTest = 0;
static $url = 'https://ai.ypt.me/';
static $url_test = 'http://192.168.0.2:81/AI/';
Expand Down Expand Up @@ -120,6 +154,8 @@ public function getEmptyDataObject()
self::addDataObjectHelper('priceForTranslation', 'Price for Translation Service', "Enter the charge amount for AI processing. Insufficient wallet balance will prevent processing. Successful charges apply to both your and the admin's CDN wallet on the marketplace.");
$obj->priceForShorts = 0;
self::addDataObjectHelper('priceForShorts', 'Price for Shorts Service', "Enter the charge amount for AI processing. Insufficient wallet balance will prevent processing. Successful charges apply to both your and the admin's CDN wallet on the marketplace.");
$obj->priceForDubbing = 0;
self::addDataObjectHelper('priceForDubbing', 'Price for Dubbing Service', "Enter the charge amount for AI processing. Insufficient wallet balance will prevent processing. Successful charges apply to both your and the admin's CDN wallet on the marketplace.");


$obj->autoProcessAll = false;
Expand Down Expand Up @@ -304,6 +340,48 @@ static function getVideoTranscriptionMetadata($videos_id, $lang)
return $obj;
}

static function getVideoDubbingMetadata($videos_id, $lang)
{
$obj = new stdClass();
$obj->error = true;
$obj->msg = '';
$obj->response = array();

if (empty($videos_id)) {
$obj->msg = 'empty videos id';
return $obj;
}

if (!isCommandLineInterface() && !Video::canEdit($videos_id)) {
$obj->msg = 'you cannot edit this video';
return $obj;
}

$video = new Video('', '', $videos_id);
$mp3 = false;

$paths = AI::getMP3Path($videos_id);
$fsize = 0;
if ($paths['url']) {
$mp3 = $paths['url'];
$fsize = filesize($paths['path']);
}

//var_dump($paths);exit;
$obj->response = array(
'type' => AI::$typeDubbing,
'videos_id' => $videos_id,
'mp3' => $mp3,
'filesize' => $fsize,
'language' => $lang,
'filesizeHuman' => humanFileSize($fsize),
'duration_in_seconds' => $video->getDuration_in_seconds(),
);

$obj->error = false;
return $obj;
}

static function getTokenForVideo($videos_id, $ai_responses_id, $param)
{
global $global;
Expand Down Expand Up @@ -422,9 +500,9 @@ static function getMP3RegularAndLower($videos_id)
$pathsLower = self::getMP3LowerPath($videos_id);
if (!empty($pathsLower)) {
$duration = getDurationFromFile($pathsLower['path']);
if($duration == "EE:EE:EE" && !empty($pathsLower['url'])){
if ($duration == "EE:EE:EE" && !empty($pathsLower['url'])) {
$duration = getDurationFromFile($pathsLower['url']);
if($duration == "EE:EE:EE"){
if ($duration == "EE:EE:EE") {
$pathsLower['url'] = str_replace('_Low.mp3', '.mp3', $pathsLower['url']);
$duration = getDurationFromFile($pathsLower['url']);
}
Expand All @@ -445,15 +523,15 @@ static function getMP3RegularAndLower($videos_id)
$isValid = false;
if ($arrayRegular['isValid'] && $arrayLower['isValid']) {
$f = convertVideoFileWithFFMPEGIsLockedInfo($arrayRegular['paths']['path']);
_error_log("convertVideoFileWithFFMPEGIsLockedInfo({$arrayRegular['paths']['path']}) arrayRegular ".json_encode($f));
_error_log("convertVideoFileWithFFMPEGIsLockedInfo({$arrayRegular['paths']['path']}) arrayRegular " . json_encode($f));
if (!$f['isUnlocked']) {
$msg = "The original audio is processing";
}else{
} else {
$f = convertVideoFileWithFFMPEGIsLockedInfo($arrayLower['paths']['path']);
_error_log("convertVideoFileWithFFMPEGIsLockedInfo({$arrayLower['paths']['path']}) arrayLower ".json_encode($f));
_error_log("convertVideoFileWithFFMPEGIsLockedInfo({$arrayLower['paths']['path']}) arrayLower " . json_encode($f));
if (!$f['isUnlocked']) {
$msg = "The audio is processing";
}else{
} else {
$diff = abs($arrayRegular['durationInSeconds'] - $arrayLower['durationInSeconds']);
if ($diff <= 2) {
$isValid = true;
Expand Down Expand Up @@ -688,6 +766,9 @@ static function chargeUser($type, $users_id, $videos_id)
case AI::$typeShorts:
$price = $obj->priceForShorts;
break;
case AI::$typeDubbing:
$price = $obj->priceForDubbing;
break;
}
if (empty($price)) {
_error_log("AI:asyncVideosId there is no price set for it");
Expand Down Expand Up @@ -749,6 +830,10 @@ static function asyncVideosId($videos_id, $type, $users_id)
_error_log('AI:asyncVideosId ' . basename(__FILE__) . ' line=' . __LINE__);
$obj = AI::getVideoShortsMetadata($videos_id);
break;
case AI::$typeDubbing:
_error_log('AI:asyncVideosId ' . basename(__FILE__) . ' line=' . __LINE__);
$obj = AI::getVideoDubbingMetadata($videos_id, @$_REQUEST['language']);
break;
default:
_error_log('AI:asyncVideosId ' . basename(__FILE__) . ' line=' . __LINE__);
$obj = new stdClass();
Expand Down
13 changes: 13 additions & 0 deletions plugin/AI/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
$priceForTranscription = $objAI->priceForTranscription;
$priceForTranslation = $objAI->priceForTranslation;
$priceForShorts = $objAI->priceForShorts;
$priceForDubbing = $objAI->priceForDubbing;
$priceForAll = $priceForTranscription + $priceForBasic + $priceForShorts;

$priceForBasicText = YPTWallet::formatCurrency($priceForBasic);
$priceForTranscriptionText = YPTWallet::formatCurrency($priceForTranscription);
$priceForTranslationText = YPTWallet::formatCurrency($priceForTranslation);
$priceForShortsText = YPTWallet::formatCurrency($priceForShorts);
$priceForAllText = YPTWallet::formatCurrency($priceForAll);
$priceForDubbingText = YPTWallet::formatCurrency($priceForDubbing);
/*
if (User::isAdmin()) {
$_1hour = 60 * 60;
Expand Down Expand Up @@ -168,6 +170,12 @@
<?php echo __("Shorts"); ?>
</a>
</li>
<li>
<a data-toggle="tab" href="#pDubbing">
<i class="fa-solid fa-headphones"></i>
<?php echo __("Dubbing"); ?>
</a>
</li>
<?php
if (User::isAdmin()) {
?>
Expand Down Expand Up @@ -205,6 +213,11 @@
include $global['systemRootPath'] . 'plugin/AI/tabs/shorts.php';
?>
</div>
<div id="pDubbing" class="tab-pane fade">
<?php
include $global['systemRootPath'] . 'plugin/AI/tabs/Dubbing.php';
?>
</div>
<?php
if (User::isAdmin()) {
?>
Expand Down
25 changes: 22 additions & 3 deletions plugin/AI/receiveAsync.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
header('Content-Type: application/json');

if (empty($_REQUEST['response'])) {
_error_log('AI: ' . basename(__FILE__) . ' line=' . __LINE__);
_error_log('AI: ' . basename(__FILE__) . ' line=' . __LINE__ . ' ' . json_encode($_REQUEST));
forbiddenPage('Response is empty');
}

Expand Down Expand Up @@ -130,13 +130,32 @@
$jsonDecoded->shorts = $shorts;
$jsonDecoded->Ai_responses_json = $o->save();
$jsonDecoded->error = empty($jsonDecoded->Ai_responses_json);
}else{
} else {
_error_log('AI: shorts ERROR' . basename(__FILE__) . ' line=' . __LINE__);
}
}else{
} else {
_error_log('AI: ERROR ' . basename(__FILE__) . ' line=' . __LINE__ . json_encode($_REQUEST));
}
break;
case AI::$typeDubbing:
_error_log('AI: ' . basename(__FILE__) . ' line=' . __LINE__);
if (!empty($_REQUEST['response']['relativeFile'])) {
_error_log('Start line=' . __LINE__);
require_once __DIR__ . '/../../plugin/VideoHLS/HLSAudioManager.php';
$mp3URL = AI::getMetadataURL() . $_REQUEST['response']['relativeFile'];

$language = 'Default';
foreach (AI::DubbingLANGS as $key => $value) {
if ($value['code'] == $_REQUEST['response']['language']) {
$language = $value['name'];
}
}

$jsonDecoded->addAudioTrack = HLSAudioManager::addAudioTrack($token->videos_id, $mp3URL, $language);
_error_log('End line=' . __LINE__.' '.json_encode($jsonDecoded->addAudioTrack));
//$jsonDecoded->lines[] = __LINE__;
}
break;

default:
_error_log('AI: ' . basename(__FILE__) . ' line=' . __LINE__);
Expand Down
Loading

0 comments on commit d246ee5

Please sign in to comment.