wangkun 1 vuosi sitten
vanhempi
commit
00e1b9394b

+ 23 - 22
youtube/youtube_follow/youtube_follow_api.py

@@ -12,8 +12,9 @@ import shutil
 import sys
 import time
 import json
-import requests
+from hashlib import md5
 
+import requests
 sys.path.append(os.getcwd())
 from common.common import Common
 from common.db import MysqlHelper
@@ -968,21 +969,30 @@ class YoutubeFollow:
                 Common.logger(log_type, crawler).info('无效视频\n')
             elif video_dict['duration'] > 1200 or video_dict['duration'] < 60:
                 Common.logger(log_type, crawler).info(f"时长:{video_dict['duration']}不满足规则\n")
-            # elif repeat_video is not None and len(repeat_video) != 0:
             elif cls.repeat_video(log_type, crawler, video_dict['video_id'], env, machine) != 0:
                 Common.logger(log_type, crawler).info('视频已下载\n')
-            elif video_dict['video_id'] in [x for y in Feishu.get_values_batch(log_type, crawler, 'GVxlYk') for x in y]:
-                Common.logger(log_type, crawler).info('视频已下载\n')
             else:
                 # 下载视频
                 Common.logger(log_type, crawler).info('开始下载视频...')
-                # Common.download_method(log_type, crawler, 'video', video_dict['video_title'], video_dict['video_url'])
-                Common.download_method(log_type, crawler, 'youtube_video', video_dict['video_title'],
-                                       video_dict['video_url'])
+                Common.download_method(log_type, crawler, 'youtube_video', video_dict['video_title'], video_dict['video_url'])
                 # ffmpeg_dict = Common.ffmpeg(log_type, crawler, f"./{crawler}/videos/{video_dict['video_title']}/video.mp4")
                 # video_width = int(ffmpeg_dict['width'])
                 # video_height = int(ffmpeg_dict['height'])
                 # video_size = int(ffmpeg_dict['size'])
+
+                md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
+                try:
+                    if os.path.getsize(f"./{crawler}/videos/{md_title}/video.mp4") == 0:
+                        # 删除视频文件夹
+                        shutil.rmtree(f"./{crawler}/videos/{md_title}")
+                        Common.logger(log_type, crawler).info("视频size=0,删除成功\n")
+                        return
+                except FileNotFoundError:
+                    # 删除视频文件夹
+                    shutil.rmtree(f"./{crawler}/videos/{md_title}")
+                    Common.logger(log_type, crawler).info("视频文件不存在,删除文件夹成功\n")
+                    return
+
                 video_width = 1280
                 video_height = 720
                 duration = int(video_dict['duration'])
@@ -990,7 +1000,6 @@ class YoutubeFollow:
                 Common.logger(log_type, crawler).info(f'video_width:{video_width}')
                 Common.logger(log_type, crawler).info(f'video_height:{video_height}')
                 Common.logger(log_type, crawler).info(f'duration:{duration}')
-                # Common.logger(log_type, crawler).info(f'video_size:{video_size}\n')
 
                 video_dict['video_width'] = video_width
                 video_dict['video_height'] = video_height
@@ -1001,17 +1010,6 @@ class YoutubeFollow:
                 video_dict['avatar_url'] = video_dict['cover_url']
                 video_dict['session'] = f'youtube{int(time.time())}'
                 rule = '1,2'
-                # if duration < 60 or duration > 600:
-                #     # 删除视频文件夹
-                #     shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}/")
-                #     Common.logger(log_type, crawler).info(f"时长:{video_dict['duration']}不满足抓取规则,删除成功\n")
-                #     return
-                # if duration == 0  or duration is None:
-                #     # 删除视频文件夹
-                #     shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}/")
-                #     Common.logger(log_type, crawler).info(f"视频下载出错,删除成功\n")
-                #     return
-                # else:
                 # 下载封面
                 Common.download_method(log_type, crawler, 'cover', video_dict['video_title'], video_dict['cover_url'])
                 # 保存视频文本信息
@@ -1028,9 +1026,12 @@ class YoutubeFollow:
                 Common.logger(log_type, crawler).info("视频上传完成")
 
                 if our_video_id is None:
-                    # 删除视频文件夹
-                    shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}/")
-                    return
+                    try:
+                        # 删除视频文件夹
+                        shutil.rmtree(f"./{crawler}/videos/{md_title}")
+                        return
+                    except FileNotFoundError:
+                        return
 
                 # 视频信息保存至飞书
                 Feishu.insert_columns(log_type, crawler, "GVxlYk", "ROWS", 1, 2)

+ 0 - 3
youtube/youtube_search/__init__.py

@@ -1,3 +0,0 @@
-# -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2023/2/3

+ 0 - 3
youtube/youtube_search/youtube_search.py

@@ -1,3 +0,0 @@
-# -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2023/2/3