|
@@ -150,41 +150,41 @@ class InitCourseCommand extends Command
|
|
|
$data = [
|
|
|
//推拿
|
|
|
[
|
|
|
- 'url' => 'youjihuaxueshuangyu',
|
|
|
+ 'name' => 'zhongyao',
|
|
|
'lang' => 'zh_CN',
|
|
|
'course_id' => 0,
|
|
|
'is_close_chapter' => 1,
|
|
|
- 'title' => '有机化学双语',
|
|
|
+ 'title' => '药食同源疗百病·一带一路送健康',
|
|
|
],
|
|
|
[
|
|
|
- 'url' => 'youjihuaxueshuangyu',
|
|
|
+ 'name' => 'zhongyao',
|
|
|
'lang' => 'en',
|
|
|
'course_id' => 0,
|
|
|
'is_close_chapter' => 1,
|
|
|
- 'title' => '有机化学双语',
|
|
|
- ],
|
|
|
- //中医诊断
|
|
|
- [
|
|
|
- 'url' => 'zhongyiwenhua-jingluoshuxuanxue',
|
|
|
- 'lang' => 'zh_CN',
|
|
|
- 'course_id' => 0,
|
|
|
- 'is_close_chapter' => 0,
|
|
|
- 'title' => '中医文化《经络腧穴学》',
|
|
|
- ],
|
|
|
- [
|
|
|
- 'url' => 'zhongyiwenhua-jingluoshuxuanxue',
|
|
|
- 'lang' => 'en',
|
|
|
- 'course_id' => 0,
|
|
|
- 'is_close_chapter' => 0,
|
|
|
- 'title' => '中医文化《经络腧穴学》 ',
|
|
|
+ 'title' => '药食同源疗百病·一带一路送健康',
|
|
|
],
|
|
|
+// //中医诊断
|
|
|
+// [
|
|
|
+// 'url' => 'zhongyiwenhua-jingluoshuxuanxue',
|
|
|
+// 'lang' => 'zh_CN',
|
|
|
+// 'course_id' => 0,
|
|
|
+// 'is_close_chapter' => 0,
|
|
|
+// 'title' => '中医文化《经络腧穴学》',
|
|
|
+// ],
|
|
|
+// [
|
|
|
+// 'url' => 'zhongyiwenhua-jingluoshuxuanxue',
|
|
|
+// 'lang' => 'en',
|
|
|
+// 'course_id' => 0,
|
|
|
+// 'is_close_chapter' => 0,
|
|
|
+// 'title' => '中医文化《经络腧穴学》 ',
|
|
|
+// ],
|
|
|
];
|
|
|
//
|
|
|
-// foreach ($data as $da) {
|
|
|
-//// $this->loadLocalFiles($da['url'], $da['lang'], $da['course_id'], $da['is_close_chapter'], $da['title']);
|
|
|
-//// $this->loadLocalFiles('/Users/mead/Downloads/2024-12-16 中马上传视频', $da['url'], $da['lang'], $da['course_id'], $da['is_close_chapter'], $da['title']);
|
|
|
-// $this->readJson('/Users/mead/Downloads/2024-12-16 中马上传视频', $da['url'], $da['lang'], $da['course_id'], $da['is_close_chapter'], $da['title']);
|
|
|
-// }
|
|
|
+ foreach ($data as $da) {
|
|
|
+// $this->loadLocalFiles($da['url'], $da['lang'], $da['course_id'], $da['is_close_chapter'], $da['title']);
|
|
|
+// $this->loadLocalFiles($da['name'], $da['lang'], $da['course_id'], $da['is_close_chapter'], $da['title']);
|
|
|
+ $this->readJson($da['name'], $da['lang'], $da['course_id'], $da['is_close_chapter'], $da['title']);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// $data = file_get_contents(base_path('data/zhongyiwenhua-jingluoshuxuanxue.json'));
|
|
@@ -194,50 +194,47 @@ class InitCourseCommand extends Command
|
|
|
// dd(1);
|
|
|
|
|
|
|
|
|
- $courses = [12, 13];
|
|
|
- $t = Video::query()->where('course_id', 12)->count();
|
|
|
- $this->line("total:{$t}");
|
|
|
- $data = file_get_contents(base_path('data/youjihuaxueshuangyu.json'));
|
|
|
- $data = json_decode($data, true);
|
|
|
- foreach ($data['Videos'] as $k => $v) {
|
|
|
- $sort = $t - $k;
|
|
|
- $this->line("{$v['name']}==>{$sort}");
|
|
|
- Video::query()->whereIn('course_id', $courses)->where('title', $v['name'])->update(['sort' => $sort]);
|
|
|
- }
|
|
|
-
|
|
|
- $courses = [14, 15];
|
|
|
- $t = Video::query()->where('course_id', 12)->count();
|
|
|
- $this->line("total:{$t}");
|
|
|
- $data = file_get_contents(base_path('data/zhongyiwenhua-jingluoshuxuanxue.json'));
|
|
|
- $data = json_decode($data, true);
|
|
|
- foreach ($data['Videos'] as $k => $v) {
|
|
|
- $sort = $t - $k;
|
|
|
- $this->line("{$v['name']}==>{$sort}");
|
|
|
- Video::query()->whereIn('course_id', $courses)->where('title', $v['name'])->update(['sort' => $sort]);
|
|
|
- }
|
|
|
+// $courses = [12, 13];
|
|
|
+// $t = Video::query()->where('course_id', 12)->count();
|
|
|
+// $this->line("total:{$t}");
|
|
|
+// $data = file_get_contents(base_path('data/youjihuaxueshuangyu.json'));
|
|
|
+// $data = json_decode($data, true);
|
|
|
+// foreach ($data['Videos'] as $k => $v) {
|
|
|
+// $sort = $t - $k;
|
|
|
+// $this->line("{$v['name']}==>{$sort}");
|
|
|
+// Video::query()->whereIn('course_id', $courses)->where('title', $v['name'])->update(['sort' => $sort]);
|
|
|
+// }
|
|
|
+//
|
|
|
+// $courses = [14, 15];
|
|
|
+// $t = Video::query()->where('course_id', 12)->count();
|
|
|
+// $this->line("total:{$t}");
|
|
|
+// $data = file_get_contents(base_path('data/zhongyiwenhua-jingluoshuxuanxue.json'));
|
|
|
+// $data = json_decode($data, true);
|
|
|
+// foreach ($data['Videos'] as $k => $v) {
|
|
|
+// $sort = $t - $k;
|
|
|
+// $this->line("{$v['name']}==>{$sort}");
|
|
|
+// Video::query()->whereIn('course_id', $courses)->where('title', $v['name'])->update(['sort' => $sort]);
|
|
|
+// }
|
|
|
|
|
|
|
|
|
$this->line('ok');
|
|
|
}
|
|
|
|
|
|
- public function loadLocalFiles($localPath, $url_path, $lang, $course_id, $is_close_chapter, $title)
|
|
|
+ public function loadLocalFiles($url_path, $lang)
|
|
|
{
|
|
|
$base_lang = $lang;
|
|
|
- $base_url = 'http://zhongma.qiniu.xmnk.cn/' . $url_path;
|
|
|
- $base_course_id = $course_id;
|
|
|
+ $base_url = 'http://zhongma.qiniu.xmnk.cn/';
|
|
|
|
|
|
$videos = [];
|
|
|
$sections = [];
|
|
|
- $i = 0;
|
|
|
- $files = [];
|
|
|
|
|
|
//读取文件
|
|
|
- foreach (glob("{$localPath}/{$url_path}/*") as $file) {
|
|
|
- $files[] = pathinfo($file);
|
|
|
- }
|
|
|
+ $files_json = js2php(file_get_contents(base_path("data/{$url_path}.json")));
|
|
|
+ $files = $files_json['items'];
|
|
|
|
|
|
//处理章节
|
|
|
foreach ($files as $file) {
|
|
|
+ if (!$file['fsize']) continue;
|
|
|
$video = [
|
|
|
'section' => 0,
|
|
|
'video' => false,
|
|
@@ -245,37 +242,26 @@ class InitCourseCommand extends Command
|
|
|
'srt' => false,
|
|
|
];
|
|
|
|
|
|
- if (array_key_exists('extension', $file)) {
|
|
|
- $this->line($file['filename']);
|
|
|
- switch (strtolower($file['extension'])) {
|
|
|
+ $fileArr = pathinfo($file['key']);
|
|
|
+ if (array_key_exists('extension', $fileArr)) {
|
|
|
+ switch (strtolower($fileArr['extension'])) {
|
|
|
case 'txt':
|
|
|
- $file_data = str2arr0($file['filename'], '-');
|
|
|
- $name = $file_data[1];
|
|
|
- if ($base_lang == 'en') $name = $file_data[2];
|
|
|
- $sections[$file_data[0]] = [
|
|
|
- 'name' => $name,
|
|
|
- 'en_name' => $file_data[2],
|
|
|
- ];
|
|
|
+// $file_data = str2arr0($file['key'], '-');
|
|
|
+// $name = $file_data[1];
|
|
|
+// if ($base_lang == 'en') $name = $file_data[2];
|
|
|
+// $sections[$file_data[0]] = [
|
|
|
+// 'name' => $name,
|
|
|
+// 'en_name' => $file_data[2],
|
|
|
+// ];
|
|
|
break;
|
|
|
case 'mp4':
|
|
|
-// $file_data = str2arr0($file['filename'], '-');
|
|
|
-// if (count($file_data) == 2) {
|
|
|
-// list($index, $name
|
|
|
-// ) = str2arr0($file['filename'], '-');
|
|
|
-// $s = str2arr0($index, '.');
|
|
|
-// $en_name = $name;
|
|
|
-// } else {
|
|
|
-// list($index, $name, $en_name) = str2arr0($file['filename'], '-');
|
|
|
-// $s = str2arr0($index, '.');
|
|
|
-// if ($base_lang == 'en') $name = $en_name;
|
|
|
-// }
|
|
|
- $name = $file['filename'];
|
|
|
+ $name = $file['key'];
|
|
|
$s[0] = 'Videos';
|
|
|
$videos[$s[0]][] = [
|
|
|
'section' => $s[0],
|
|
|
'name' => $name,
|
|
|
'en_name' => $name,
|
|
|
- 'path' => "{$base_url}/" . $file['filename'] . '.mp4',
|
|
|
+ 'path' => "{$base_url}" . $file['key'],
|
|
|
'srt' => false
|
|
|
];
|
|
|
break;
|
|
@@ -301,23 +287,16 @@ class InitCourseCommand extends Command
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- file_put_contents(base_path('data/' . $url_path . '.json'), json_encode($videos, true));
|
|
|
- return;
|
|
|
+ return $videos;
|
|
|
}
|
|
|
|
|
|
- public function readJson($localPath, $url_path, $lang, $course_id, $is_close_chapter, $title)
|
|
|
+ public function readJson($url_path, $lang, $course_id, $is_close_chapter, $title)
|
|
|
{
|
|
|
$base_lang = $lang;
|
|
|
$base_course_id = $course_id;
|
|
|
|
|
|
- $videos = [];
|
|
|
-
|
|
|
+ $videos = $this->loadLocalFiles($url_path, $lang);
|
|
|
|
|
|
- $data = file_get_contents(base_path('data/' . $url_path . '.json'));
|
|
|
- $data = json_decode($data, true);
|
|
|
-
|
|
|
-
|
|
|
- $videos = $data;
|
|
|
//保存数据
|
|
|
if ($base_course_id) {
|
|
|
$course = Course::query()->find($base_course_id);
|
|
@@ -339,7 +318,7 @@ class InitCourseCommand extends Command
|
|
|
foreach ($videos as $s => $vs) {
|
|
|
$section['name'] = $s;
|
|
|
|
|
|
- $chapter = Chapter::query()->updateOrCreate([
|
|
|
+ $chapter = Chapter::query()->withoutGlobalScope('language')->updateOrCreate([
|
|
|
'course_id' => $course->id,
|
|
|
'title' => $section['name'],
|
|
|
'language' => $base_lang,
|
|
@@ -347,7 +326,7 @@ class InitCourseCommand extends Command
|
|
|
'status' => ModelStatusEnum::OK
|
|
|
]);
|
|
|
foreach ($vs as $video) {
|
|
|
- $resource = Resource::query()->updateOrCreate([
|
|
|
+ $resource = Resource::query()->withoutGlobalScope('language')->updateOrCreate([
|
|
|
'name' => $video['name'],
|
|
|
'original_name' => $video['name'],
|
|
|
'path' => $video['path'],
|
|
@@ -360,7 +339,7 @@ class InitCourseCommand extends Command
|
|
|
]);
|
|
|
$subtitle_resource = null;
|
|
|
if ($video['srt']) {
|
|
|
- $subtitle_resource = Resource::query()->updateOrCreate([
|
|
|
+ $subtitle_resource = Resource::query()->withoutGlobalScope('language')->updateOrCreate([
|
|
|
'path' => $video['srt']['path'],
|
|
|
], [
|
|
|
'name' => Str::random(8) . '.srt',
|
|
@@ -373,7 +352,7 @@ class InitCourseCommand extends Command
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- Video::query()->updateOrCreate([
|
|
|
+ Video::query()->withoutGlobalScope('language')->updateOrCreate([
|
|
|
'course_id' => $course->id,
|
|
|
'course_chapter_id' => $chapter->id,
|
|
|
'title' => $video['name'],
|