Browse Source

升级版本

mead 1 month ago
parent
commit
1dc24d95f4
2 changed files with 284 additions and 90 deletions
  1. 69 90
      app/Console/Commands/InitCourseCommand.php
  2. 215 0
      data/zhongyao.json

+ 69 - 90
app/Console/Commands/InitCourseCommand.php

@@ -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'],

+ 215 - 0
data/zhongyao.json

@@ -0,0 +1,215 @@
+{
+    "marker": "",
+    "items": [
+        {
+            "fsize": 0,
+            "hash": "Fto5o-5ea0sNMlW_75VgGJCv2AcJ",
+            "key": "2024-01-14/zhongyao/",
+            "md5": "d41d8cd98f00b204e9800998ecf8427e",
+            "mimeType": "application/octet-stream",
+            "putTime": 17368372942999320,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 897962048,
+            "hash": "nhyKf5in-TMihAWamrBtl0D9xnTU",
+            "key": "2024-01-14/zhongyao/丁香.mp4",
+            "md5": "acc3a5246e938b9b88233d4f9f2b0451",
+            "mimeType": "video/mp4",
+            "putTime": 17368384788516816,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 594855300,
+            "hash": "nvhQkRjab7Of4y2qmZZI95elg-9v",
+            "key": "2024-01-14/zhongyao/佛手.mp4",
+            "md5": "5bead7232d953446a055f58bb92a800d",
+            "mimeType": "video/mp4",
+            "putTime": 17368386227157952,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 902322955,
+            "hash": "nsiu3N2A8W1hbArLAdgfKNwFgQOr",
+            "key": "2024-01-14/zhongyao/八角.mp4",
+            "md5": "6ce4b387c8325dfda01a5191e0891933",
+            "mimeType": "video/mp4",
+            "putTime": 17368374326056306,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 1018813010,
+            "hash": "njV7aSliOwSmqgfoR6dQNuDhqoxP",
+            "key": "2024-01-14/zhongyao/刀豆.mp4",
+            "md5": "397c23eaeb6a3245e8aade3ddb76898c",
+            "mimeType": "video/mp4",
+            "putTime": 17368383653152612,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 885749097,
+            "hash": "npKjpBluVxz7MU-WBN_6NnUVWZr0",
+            "key": "2024-01-14/zhongyao/大枣.mp4",
+            "md5": "563c6469b02cb580dec40369e3d96bb3",
+            "mimeType": "video/mp4",
+            "putTime": 17368381456075088,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 626276128,
+            "hash": "nqHGJfQGnmb04QDA_OyvfR108L3b",
+            "key": "2024-01-14/zhongyao/姜黄.mp4",
+            "md5": "51870a9adbf6da6273ce560b6413a2e0",
+            "mimeType": "video/mp4",
+            "putTime": 17368393627912636,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 498844388,
+            "hash": "nnEa7Zdc69N3oVfuZ8HLnIrOJyAq",
+            "key": "2024-01-14/zhongyao/干姜.mp4",
+            "md5": "1609be76e7775e454d553489e73018ea",
+            "mimeType": "video/mp4",
+            "putTime": 17368388763046178,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 702655114,
+            "hash": "nu5DL2Knd7n1oUJ_QiktQQ-sV_Sj",
+            "key": "2024-01-14/zhongyao/当归.mp4",
+            "md5": "9e105fa2c537dfc2b4bc157b94a16bf8",
+            "mimeType": "video/mp4",
+            "putTime": 17368382349858028,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 1252255154,
+            "hash": "nu9hp1siRLbuuMLqPNk_q3tCNkuF",
+            "key": "2024-01-14/zhongyao/扁豆.mp4",
+            "md5": "67498ba8ae0ad149deef8fd2cb93c4ea",
+            "mimeType": "video/mp4",
+            "putTime": 17368379177872428,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 535944913,
+            "hash": "npNFSfO13a1kJUWnsZUg0LZnUJUs",
+            "key": "2024-01-14/zhongyao/杜仲.mp4",
+            "md5": "27e2f8485120ba212df040326d5efd72",
+            "mimeType": "video/mp4",
+            "putTime": 17368385479681756,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 730405802,
+            "hash": "no1c2IINRdBSZiyetDu2byefxYuA",
+            "key": "2024-01-14/zhongyao/白芷.mp4",
+            "md5": "b61ff958731caf1eac38dee308300a18",
+            "mimeType": "video/mp4",
+            "putTime": 17368375478591756,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 661563408,
+            "hash": "nmg7omexNW1q2LHwb-WVvtdC1jbj",
+            "key": "2024-01-14/zhongyao/胡椒.mp4",
+            "md5": "b75a3493e0378de975b95c898247f05d",
+            "mimeType": "video/mp4",
+            "putTime": 17368389600170536,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 1853703142,
+            "hash": "nnfW9bizm57gmY0Xtj6mPUTnbTC7",
+            "key": "2024-01-14/zhongyao/良姜.mp4",
+            "mimeType": "video/mp4",
+            "putTime": 17368396007175176,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 547396240,
+            "hash": "niKhCponWfPjV9pCMY7yNX2EmJyD",
+            "key": "2024-01-14/zhongyao/花椒.mp4",
+            "md5": "5aff9dd0bbe64def48a540aa9b94c641",
+            "mimeType": "video/mp4",
+            "putTime": 17368390298579796,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 914959964,
+            "hash": "noq97FZk9ITmi2ZSOArHxOXpWOEc",
+            "key": "2024-01-14/zhongyao/草果.mp4",
+            "md5": "c0f6391cf0760ecdf106a4cd68c3ec46",
+            "mimeType": "video/mp4",
+            "putTime": 17368380338180390,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 1209065622,
+            "hash": "nhPgHxld6zW_rzDUfqGHfoPLgLL4",
+            "key": "2024-01-14/zhongyao/荜茇.mp4",
+            "md5": "e112b5e08a128dcf35191fdea5056791",
+            "mimeType": "video/mp4",
+            "putTime": 17368377536277228,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 812533210,
+            "hash": "nospDeGIIdmVL5zaV-axmbBsKWYg",
+            "key": "2024-01-14/zhongyao/藿香.mp4",
+            "md5": "c1ae245740f529f3a9394a6b162d04e8",
+            "mimeType": "video/mp4",
+            "putTime": 17368392519197856,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 1474977784,
+            "hash": "niiQVDDBSEpn1DetoscbAb13VcCb",
+            "key": "2024-01-14/zhongyao/覆盆子.mp4",
+            "mimeType": "video/mp4",
+            "putTime": 17368388137106490,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 528608060,
+            "hash": "nozXY9D9zcj4obn9lxJSqWf8ZVwC",
+            "key": "2024-01-14/zhongyao/黄芪.mp4",
+            "md5": "c055416c5357ba43d10bd006f74e852a",
+            "mimeType": "video/mp4",
+            "putTime": 17368391078991624,
+            "status": 0,
+            "type": 0
+        },
+        {
+            "fsize": 825450763,
+            "hash": "np1yQJsuZ_LpMQbB32Sp0CortAhu",
+            "key": "2024-01-14/zhongyao/龙眼.mp4",
+            "md5": "c3121be4234bddb838ffe34dc1abf4f3",
+            "mimeType": "video/mp4",
+            "putTime": 17368397044162344,
+            "status": 0,
+            "type": 0
+        }
+    ],
+    "commonPrefixes": null,
+    "has_sensitive_words": false
+}