zhangyong há 1 ano atrás
pai
commit
274aa85392

+ 4 - 3
common/common.py

@@ -26,17 +26,18 @@ class Common:
 
     # 使用 logger 模块生成日志
     @staticmethod
-    def logger():
+    def logger(log_type):
         """
         使用 logger 模块生成日志
         """
         # 日志路径
-        log_dir = f"./logs/"
+        log_dir = f"./{log_type}/logs/"
         log_path = os.getcwd() + os.sep + log_dir
         if not os.path.isdir(log_path):
             os.makedirs(log_path)
         # 日志文件名
-        log_name = f"{datetime.now().date().strftime('%Y-%m-%d')}.log"
+        log_name = f"{log_type}-{datetime.now().date().strftime('%Y-%m-%d')}.log"
+
         # 日志不打印到控制台
         logger.remove(handler_id=None)
         # 初始化日志

+ 1 - 1
main.py

@@ -61,7 +61,7 @@ def job_kuaishou_data():
 schedule.every(5).hours.do(job_douyin_data)
 
 # 每3个小时执行一次
-schedule.every(3).hours.do(job_kuaishou_data)
+schedule.every(5).hours.do(job_kuaishou_data)
 
 # 每15分钟执行一次
 schedule.every(15).minutes.do(job_video_stitching)

+ 9 - 9
video_capture/douyin/douyin_author/douyin_author.py

@@ -71,7 +71,7 @@ class douyinAuthor():
                 return
             for i in user_list:
                 account_id = i[0].replace('(', '').replace(')', '').replace(',', '')
-                Common.logger().info(f"用户主页ID:{account_id}")
+                Common.logger("douyin").info(f"用户主页ID:{account_id}")
                 next_cursor = 0
                 while True:
                     if next_cursor == None:
@@ -117,21 +117,21 @@ class douyinAuthor():
                     data = obj.get('aweme_list', [])
                     response.close()
                     if response.status_code != 200:
-                        Common.logger().info(
+                        Common.logger("douyin").info(
                             f"接口请求失败,请更换cookie,{response.status_code}")
                         Feishu.bot('recommend', '抖音', '抖音cookie失效,请及时更换~')
                         # 如果返回空信息,则随机睡眠 600, 1200 秒
                         time.sleep(random.randint(600, 1200))
                         continue
                     elif len(data) == 0:
-                        Common.logger().info(
+                        Common.logger("douyin").info(
                             f"接口请求失败,请更换cookie")
                         continue
                     count = 0
                     for i in range(len(data)):
                         try:
                             entity_type = data[i].get('search_impr').get('entity_type')
-                            Common.logger().info(
+                            Common.logger("douyin").info(
                                 f"非视频:{entity_type}")
                             if entity_type == 'GENERAL':
                                 count += 1
@@ -139,7 +139,7 @@ class douyinAuthor():
                                 id = cls.select_videoUrl_id(video_id)
                                 if id:
                                     if count > 5:
-                                        Common.logger().info(
+                                        Common.logger("douyin").info(
                                             f"重复视频不在抓取该用户,用户主页id:{account_id}")
                                         break
                                     continue
@@ -148,16 +148,16 @@ class douyinAuthor():
                                 status = oss_object_key.get("status")
                                 # 发送 oss
                                 oss_object_key = oss_object_key.get("oss_object_key")
-                                Common.logger().info(f"抖音视频链接oss发送成功,oss地址:{oss_object_key}")
+                                Common.logger("douyin").info(f"抖音视频链接oss发送成功,oss地址:{oss_object_key}")
                                 # 发送成功 存入数据库
                                 if status == 200:
                                     cls.insert_videoUrl(video_id, account_id, oss_object_key)
-                                    Common.logger().info(f"视频地址插入数据库成功,视频id:{video_id},用户主页id:{account_id},视频储存地址:{oss_object_key}")
+                                    Common.logger("douyin").info(f"视频地址插入数据库成功,视频id:{video_id},用户主页id:{account_id},视频储存地址:{oss_object_key}")
                         except Exception as e:
-                            Common.logger().warning(f"抓取单条视频异常:{e}\n")
+                            Common.logger("douyin").warning(f"抓取单条视频异常:{e}\n")
                             continue
         except Exception as e:
-            Common.logger().warning(f"抓取异常:{e}\n")
+            Common.logger("douyin").warning(f"抓取异常:{e}\n")
             return
 
 if __name__ == '__main__':

+ 9 - 9
video_capture/kuaishou/kuaishou_author/kuaishou_author.py

@@ -68,7 +68,7 @@ class kuaishouAuthor():
                 return
             for i in user_list:
                 account_id = i[0].replace('(', '').replace(')', '').replace(',', '')
-                Common.logger().info(f"用户主页ID:{account_id}")
+                Common.logger("kuaishou").info(f"用户主页ID:{account_id}")
                 pcursor = ""
                 while True:
                     time.sleep(random.randint(10, 50))
@@ -104,16 +104,16 @@ class kuaishouAuthor():
                                       timeout=10)
                     response.close()
                     if response.status_code != 200:
-                        Common.logger().info(
+                        Common.logger("kuaishou").info(
                             f"接口请求失败,请更换cookie,{response.status_code}")
                         Feishu.bot('recommend', '快手', '快手cookie失效,请及时更换~')
                         return
                     elif "feeds" not in response.json()["data"]["visionProfilePhotoList"]:
-                        Common.logger().info(
+                        Common.logger("kuaishou").info(
                             f'数据为空{response.json()["data"]["visionProfilePhotoList"]}')
                         break
                     elif len(response.json()["data"]["visionProfilePhotoList"]["feeds"]) == 0:
-                        Common.logger().info(
+                        Common.logger("kuaishou").info(
                             f'数据为空{response.json()["data"]["visionProfilePhotoList"]["feeds"]}')
                         break
                     pcursor = response.json()['data']['visionProfilePhotoList']['pcursor']
@@ -130,7 +130,7 @@ class kuaishouAuthor():
                             id = cls.select_videoUrl_id(video_id)
                             if id:
                                 if count > 5:
-                                    Common.logger().info(
+                                    Common.logger("kuaishou").info(
                                         f"重复视频不在抓取该用户,用户主页id:{account_id}")
                                     break
                                 continue
@@ -138,16 +138,16 @@ class kuaishouAuthor():
                             status = oss_object_key.get("status")
                             # 发送 oss
                             oss_object_key = oss_object_key.get("oss_object_key")
-                            Common.logger().info(f"抖音视频链接oss发送成功,oss地址:{oss_object_key}")
+                            Common.logger("kuaishou").info(f"抖音视频链接oss发送成功,oss地址:{oss_object_key}")
                             # 发送成功 存入数据库
                             if status == 200:
                                 cls.insert_videoUrl(video_id, account_id, oss_object_key)
-                                Common.logger().info(f"视频地址插入数据库成功,视频id:{video_id},用户主页id:{account_id},视频储存地址:{oss_object_key}")
+                                Common.logger("kuaishou").info(f"视频地址插入数据库成功,视频id:{video_id},用户主页id:{account_id},视频储存地址:{oss_object_key}")
                         except Exception as e:
-                            Common.logger().warning(f"抓取单条视频异常:{e}\n")
+                            Common.logger("kuaishou").warning(f"抓取单条视频异常:{e}\n")
                             continue
         except Exception as e:
-            Common.logger().warning(f"抓取异常:{e}\n")
+            Common.logger("kuaishou").warning(f"抓取异常:{e}\n")
             return
 
 if __name__ == '__main__':

+ 23 - 23
video_stitching/video_stitching.py

@@ -244,13 +244,13 @@ class VideoStitching():
         color_clip = editor.ColorClip(size=(final_width, 90),
                                       color=(255, 255, 0)).set_duration(duration_limit)
         final_clip = editor.CompositeVideoClip([final_clip, color_clip.set_position(("center", final_height - 80))])
-        Common.logger().info(f"字幕内容为:{srt}")
+        Common.logger("video").info(f"字幕内容为:{srt}")
         if srt != None:
-            Common.logger().info(f"处理字幕文件")
+            Common.logger("video").info(f"处理字幕文件")
             # 使用正则表达式提取时间码和字幕内容
             pattern = r"(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})\n([\s\S]+?(?=\n\d|$))"
             matches = re.findall(pattern, srt)
-            Common.logger().info(f"字幕{matches}")
+            Common.logger("video").info(f"字幕{matches}")
             # 获取字幕
             subtitle_clips = []
             for match in matches:
@@ -260,17 +260,17 @@ class VideoStitching():
                 text = cls.split_text(text, 10)
                 # /System/Library/Fonts/Hiragino Sans GB.ttc 本地字体
                 # /usr/share/fonts/truetype/wqy/wqy-zenhei.ttc 服务器地址
-                Common.logger().info(f"字幕:{text}")
+                Common.logger("video").info(f"字幕:{text}")
                 sub = editor.TextClip(text, font="/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc",
                                       fontsize=18, color="black").set_duration(end - start).set_start(
                     start).set_position(
                     ("center", final_height - 60)).set_opacity(0.8)
                 subtitle_clips.append(sub)
-            Common.logger().info(f"将字幕添加到视频上")
+            Common.logger("video").info(f"将字幕添加到视频上")
             # 将字幕添加到视频上
             video_with_subtitles = editor.CompositeVideoClip([final_clip] + subtitle_clips)
         else:
-            Common.logger().info(f"添加固定字幕")
+            Common.logger("video").info(f"添加固定字幕")
             text_clip = (
                 editor.TextClip("分享、转发给群友", font="/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc",
                                 fontsize=30, color="black").
@@ -283,10 +283,10 @@ class VideoStitching():
         # 生成视频
         video_with_subtitles.write_videofile(output_path, fps=35)
         if os.path.isfile(output_path):
-            Common.logger().info("视频生成成功!生成路径为:", output_path)
+            Common.logger("video").info("视频生成成功!生成路径为:", output_path)
             return included_videos, video_with_subtitles, clips
         else:
-            Common.logger().info("视频生成失败,请检查代码和文件路径。")
+            Common.logger("video").info("视频生成失败,请检查代码和文件路径。")
             return "", video_with_subtitles, clips
 
 
@@ -317,7 +317,7 @@ class VideoStitching():
         try:
             code = data["code"]
             if code != 0:
-                Common.logger().info(
+                Common.logger("video").info(
                     f"未登录,请更换cookie,{data}")
                 Feishu.bot('recommend', '管理后台', '管理后台cookie失效,请及时更换~')
                 return ""
@@ -325,7 +325,7 @@ class VideoStitching():
             print(audio_url)
             return audio_url
         except Exception as e:
-            Common.logger().warning(f"获取音频视频链接失败:{e}\n")
+            Common.logger("video").warning(f"获取音频视频链接失败:{e}\n")
             return ""
 
     @classmethod
@@ -338,9 +338,9 @@ class VideoStitching():
             return
         audio = cls.get_audio_url(audio_id, cookie)
         if audio == "":
-            Common.logger().info(f"获取音频地址为空")
+            Common.logger("video").info(f"获取音频地址为空")
             return
-        Common.logger().info(f"获取音频地址:{audio},获取用户id:{audio_id}")
+        Common.logger("video").info(f"获取音频地址:{audio},获取用户id:{audio_id}")
         if video_type == "口播--美文类":
             # 获取已入库的口播视频
             audio_list = cls.get_audio_list()
@@ -349,18 +349,18 @@ class VideoStitching():
             # 判断该视频+音频是否生成过视频
             video = VideoStitching.get_audio_url_list(videos, audio_id)
             if video:
-                Common.logger().info(f"该视频+音频已经生成过视频,不做视频拼接")
+                Common.logger("video").info(f"该视频+音频已经生成过视频,不做视频拼接")
                 return
         else:
             # 获取已入库的用户id
             account_id = cls.get_account_id(channel_type)
             account = random.choice(account_id)
             account = str(account).replace('(', '').replace(')', '').replace(',', '')
-            Common.logger().info(f"获取用户ID:{account}")
+            Common.logger("video").info(f"获取用户ID:{account}")
             # 获取 未使用的视频链接
             url_list = cls.get_url_list(audio_id, account)
             if url_list == None:
-                Common.logger().info(f"未使用视频链接为空:{url_list}")
+                Common.logger("video").info(f"未使用视频链接为空:{url_list}")
                 return
             videos = [list(item) for item in url_list]
         videos = Oss.get_oss_url(video_type, videos)
@@ -368,16 +368,16 @@ class VideoStitching():
         try:
             audio_url, video_with_subtitles, clips = cls.concatenate_videos(videos, str(audio), srt, video_type)
             if len(audio_url) == 0:
-                Common.logger().info(f"视频生成失败")
+                Common.logger("video").info(f"视频生成失败")
             # 随机生成视频id
             id = cls.random_id()
-            Common.logger().info(f"生成视频id为:{id}")
+            Common.logger("video").info(f"生成视频id为:{id}")
             # 上传 oss
             oss_object_key = Oss.stitching_sync_upload_oss(output_path, id)
             status = oss_object_key.get("status")
             # 获取 oss 视频地址
             oss_object_key = oss_object_key.get("oss_object_key")
-            Common.logger().info(f"新拼接视频,oss发送成功,oss地址:{oss_object_key}")
+            Common.logger("video").info(f"新拼接视频,oss发送成功,oss地址:{oss_object_key}")
             if status == 200:
                 time.sleep(10)
                 # 发送成功 已使用视频存入数据库
@@ -385,12 +385,12 @@ class VideoStitching():
                     cls.insert_video_typeAudio(videos[0], audio_id)
                 else:
                     cls.insert_videoAudio(audio_url, audio_id, channel_type)
-                Common.logger().info(f"发送成功 已使用视频存入数据库完成")
+                Common.logger("video").info(f"发送成功 已使用视频存入数据库完成")
                 if os.path.isfile(output_path):
                     os.remove(output_path)
-                    Common.logger().info(f"文件删除成功{output_path}")
+                    Common.logger("video").info(f"文件删除成功{output_path}")
                 else:
-                    Common.logger().info(f"文件不存在{output_path}")
+                    Common.logger("video").info(f"文件不存在{output_path}")
                 if video_type == "口播--美文类":
                     os.remove("./video_stitching/video_material/koubo.mp4")
                 else:
@@ -399,7 +399,7 @@ class VideoStitching():
                         os.remove(f'./video_stitching/video_material/{filename}.mp4')
                 piaoquantv = cls.insert_piaoquantv(oss_object_key, title_list, video_type, channel_type)
                 if piaoquantv:
-                    Common.logger().info(f"视频添加到对应用户成功")
+                    Common.logger("video").info(f"视频添加到对应用户成功")
                     # 关闭视频文件
                     for clip in clips:
                         clip.close()
@@ -407,7 +407,7 @@ class VideoStitching():
                     video_with_subtitles.close()
 
         except Exception as e:
-            Common.logger().warning(f"新拼接视频发送oss失败:{e}\n")
+            Common.logger("video").warning(f"新拼接视频发送oss失败:{e}\n")
             return