浏览代码

标题灵活支持

zhangyong 11 月之前
父节点
当前提交
a72214558f
共有 2 个文件被更改,包括 68 次插入11 次删除
  1. 13 3
      common/material.py
  2. 55 8
      video_agc/agc_video_method.py

+ 13 - 3
common/material.py

@@ -228,7 +228,11 @@ class Material():
                 cover = None
             else:
                 cover = row[3]
-            number = {"uid": uid, "text": text, "cover": cover}
+            if len(row) <= 4:
+                title = None
+            else:
+                title = row[4]
+            number = {"uid": uid, "text": text, "cover": cover, "title": title}
             if uid:
                 list.append(number)
             if video:
@@ -238,9 +242,11 @@ class Material():
             uid1 = list1['uid']
             srt = list1['text']
             cover = list1['cover']
+            title = list1['title']
+
             id_list = cls.get_uid(uid1, mark)
             if len(id_list) < 2:
-                return uid1, srt, video_list, cover
+                return uid1, srt, video_list, cover, title
 
     # 获取音频类型+字幕+标题
     @classmethod
@@ -264,7 +270,11 @@ class Material():
                 cover = None
             else:
                 cover = row[3]
-            number = {"uid": uid, "text": text, "video": video, "cover": cover}
+            if len(row) <= 4:
+                title = None
+            else:
+                title = row[4]
+            number = {"uid": uid, "text": text, "video": video, "cover": cover, "title": title}
             if uid:
                 list_data.append(number)
             else:

+ 55 - 8
video_agc/agc_video_method.py

@@ -227,10 +227,56 @@ class AgcVidoe():
                 selected_cover_url = item["coverUrl"]
         return selected_cover_url
 
+    @classmethod
+    def get_title(cls, uid):
+        url = "https://admin.piaoquantv.com/manager/video/multiTitleV2/listV2"
+
+        payload = json.dumps({
+            "videoId": uid,
+            "range": "4h"
+        })
+        headers = {
+            'accept': 'application/json',
+            'accept-language': 'zh-CN,zh;q=0.9',
+            'cache-control': 'no-cache',
+            'content-type': 'application/json',
+            'cookie': 'SESSION=YjU3MzgwNTMtM2QyYi00YjljLWI3YWUtZTBjNWYwMGQzYWNl',
+            'origin': 'https://admin.piaoquantv.com',
+            'pragma': 'no-cache',
+            'priority': 'u=1, i',
+            'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
+            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
+        }
+        response = requests.request("POST", url, headers=headers, data=payload)
+        data = response.json()
+        content = data["content"]
+        if len(content) == 1:
+            return content[0]["title"]
+        max_share_count = 0
+        selected_title = ""
+        for item in content:
+            share_count = item.get("shareWeight")
+            if share_count is not None and share_count > max_share_count:
+                max_share_count = share_count
+                selected_title = item["title"]
+            elif share_count == max_share_count and item["createUser"] == "用户":
+                selected_title = item["title"]
+        return selected_title
+
+
 
     # 新生成视频上传到对应账号下
     @classmethod
     def insert_piaoquantv(cls, oss_object_key, audio_title, pq_ids_list, cover, uid):
+        if audio_title == '' or None == audio_title:
+            title = cls.get_title(uid)
+        else:
+            if '/' in audio_title:
+                new_titles = audio_title.split('/')
+            else:
+                new_titles = [audio_title]
+            title = random.choice(new_titles)
+
         cover_url = ''
         if None == cover or cover == '':
             cover_url = cls.get_cover(uid)
@@ -254,7 +300,7 @@ class AgcVidoe():
                 'requestId': 'fb972cbd4f390afcfd3da1869cd7d001',
                 'sessionId': '362290597725ce1fa870d7be4f46dcc2',
                 'subSessionId': '362290597725ce1fa870d7be4f46dcc2',
-                'title': audio_title,
+                'title': title,
                 'token': '524a8bc871dbb0f4d4717895083172ab37c02d2f',
                 'uid': pq_ids_list[i],
                 'versionCode': '486',
@@ -301,8 +347,8 @@ class AgcVidoe():
                 Feishu.bot('recommend', '管理后台', '管理后台cookie失效,请及时更换~', mark, mark_name)
                 return ""
             audio_url = data["content"]["transedVideoPath"]
-            audio_title = data["content"]['title']
-            return audio_url, audio_title
+            # audio_title = data["content"]['title']
+            return audio_url
         except Exception as e:
             Common.logger("video").warning(f"获取音频视频链接失败:{e}\n")
             return ""
@@ -560,7 +606,7 @@ class AgcVidoe():
                         Feishu.bot('recommend', 'AGC完成通知', '今日常规自制视频拼接任务完成啦~', mark, mark_name)
                         return mark
                 # 获取音频类型+字幕+标题
-                uid, srt, video_list, cover_status = Material.get_all_data(feishu_id, link, mark)
+                uid, srt, video_list, cover_status, audio_title = Material.get_all_data(feishu_id, link, mark)
                 # 获取已入库的用户id
                 user_id = cls.get_user_id(platform, mark)
                 # 获取 未使用的视频链接
@@ -577,7 +623,7 @@ class AgcVidoe():
                     cls.create_subtitle_file(srt, s_path)
                     Common.logger("video").info(f"S{mark}的{platform}渠道RT 文件目录创建成功")
                 # 获取音频
-                audio_video, audio_title = cls.get_audio_url(uid, mark, mark_name)
+                audio_video = cls.get_audio_url(uid, mark, mark_name)
                 Common.logger("video").info(f"{mark}的{platform}渠道获取需要拼接的音频成功")
                 # 获取音频秒数
                 audio_duration = cls.get_audio_duration(audio_video)
@@ -655,7 +701,7 @@ class AgcVidoe():
         #     Feishu.bot('recommend', 'AGC完成通知', '今日脚本跟随视频拼接任务完成啦~', mark.split("-")[0], mark_name)
         #     return mark
         # 获取音频类型+字幕+标题
-        uid, srt, video_list, cover = Material.get_all_data(feishu_id, link, mark)
+        uid, srt, video_list, cover, audio_title = Material.get_all_data(feishu_id, link, mark)
         platform_list = ex_list["platform_list"] # 渠道
         # 如果没有该文件目录则创建,有文件目录的话 则删除文件
         s_path, v_path, video_path_url, v_oss_path = cls.create_folders(mark)
@@ -694,7 +740,7 @@ class AgcVidoe():
                 cls.create_subtitle_file(srt, s_path)
                 Common.logger("gs_video").info(f"S{mark}的{platform}渠道RT 文件目录创建成功")
             # 获取音频
-            audio_video, audio_title = cls.get_audio_url(uid, mark, mark_name)
+            audio_video = cls.get_audio_url(uid, mark, mark_name)
             Common.logger("gs_video").info(f"{mark}的{platform}渠道获取需要拼接的音频成功")
             # 获取音频秒数
             audio_duration = cls.get_audio_duration(audio_video)
@@ -770,6 +816,7 @@ class AgcVidoe():
                 srt = data['text']  # srt
                 videos = data['video']
                 cover = data['cover']
+                audio_title = data['title']
                 if ',' in videos:
                     videos = videos.split(',')
                 else:
@@ -779,7 +826,7 @@ class AgcVidoe():
                     cls.create_subtitle_file(srt, s_path)
                     Common.logger("bk_video").info(f"S{mark} 文件目录创建成功")
                     # 获取音频
-                audio_video, audio_title = cls.get_audio_url(uid, mark, mark_name)
+                audio_video = cls.get_audio_url(uid, mark, mark_name)
                 Common.logger("bk_video").info(f"{mark}获取需要拼接的音频成功")
                 # 获取音频秒数
                 audio_duration = cls.get_audio_duration(audio_video)