EditVideoMp4.php
3.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* @remark :
* @name :EditVideoMp4.php
* @author :lyh
* @method :post
* @time :2024/4/16 9:44
*/
namespace App\Console\Commands\Test;
use App\Models\Project\Project;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class EditVideoMp4 extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'edit_video';
/**
* The console command description.
*
* @var string
*/
protected $description = 'edit_mp4';
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['is_upgrade'=>0,'delete_status'=>0,'type'=>['!=',0],'id'=>['<=',82]]);
$data = [];
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->copyTable();
$this->getHtml();
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @remark :获取需要替换的html
* @name :getHtml
* @author :lyh
* @method :post
* @time :2024/4/16 10:17
*/
public function getHtml(){
$templateModel = new BTemplate();
$templateList = $templateModel->list();
if(!empty($templateList)){
foreach ($templateList as $v1){
$this->getVideoSrc($v1['id'],$v1['main_html'],'main_html',$templateModel);
}
}
return true;
}
/**
* @remark :获取video的src
* @name :getVideoSrc
* @author :lyh
* @method :post
* @time :2024/4/16 9:46
*/
public function getVideoSrc($id,$html,$filed,$model){
$pattern = '/<video.*?src="([^"]+)"[^>]*>/i';
preg_match_all($pattern, $html, $matches);
$srcLinks = $matches[1];
if(!empty($srcLinks)){
foreach ($srcLinks as $link) {
$newLink = str_replace('ecdn6.globalso.com','v6-file.globalso.com', $link);
$html = str_replace($link, $newLink, $html);
}
$model->edit([$filed=>$html],['id'=>$id]);
}
return true;
}
/**
* @remark :复制表
* @name :copyTable
* @author :lyh
* @method :post
* @time :2024/4/16 9:51
*/
public function copyTable(){
// 原始表名和新表名
$originalTableName = "gl_web_template";
$newTableName = "gl_web_template_c";
// 检查原始表是否存在
DB::connection('custom_mysql')->select("SHOW TABLES LIKE '{$originalTableName}'");
DB::connection('custom_mysql')->statement("CREATE TABLE {$newTableName} LIKE {$originalTableName}");
DB::connection('custom_mysql')->statement("INSERT INTO {$newTableName} SELECT * FROM {$originalTableName}");
}
}