6 Achegas 7fe0013b03 ... 95cebd014e

Autor SHA1 Mensaxe Data
  lierqiang 95cebd014e add youtube接入调度器 %!s(int64=2) %!d(string=hai) anos
  lierqiang 1a57a5b299 add kuaishou 推荐接入调度器 %!s(int64=2) %!d(string=hai) anos
  lierqiang 53cda1f5dd add 快手作者接入调度器 %!s(int64=2) %!d(string=hai) anos
  lierqiang 5a2c4aa111 add xigua作者接入调度器 %!s(int64=2) %!d(string=hai) anos
  lierqiang af138109f9 add douyin推荐接入调度 %!s(int64=2) %!d(string=hai) anos
  lierqiang 1955754332 update dy接入调度器 %!s(int64=2) %!d(string=hai) anos

+ 328 - 0
douyin/douyin_follow/dy_author_scheduling.py

@@ -0,0 +1,328 @@
+# -*- coding: utf-8 -*-
+# @Author: lierqiang
+# @Time: 2023/4/12
+import json
+import os
+import random
+import shutil
+import sys
+import time
+import requests
+from hashlib import md5
+
+from douyin.douyin_recommend import get_xb
+
+sys.path.append(os.getcwd())
+from common.common import Common
+# from common.db import MysqlHelper
+from common.scheduling_db import MysqlHelper
+from common.feishu import Feishu
+from common.publish import Publish
+from common.public import random_title
+from common.userAgent import get_random_user_agent
+from common.public import get_user_from_mysql, get_config_from_mysql
+
+
+class DyAuthorScheduling(object):
+    platform = "抖音"
+    tag = "抖音定向爬虫策略"
+
+    @classmethod
+    def download_rule(cls, video_info_dict, rule_dict):
+        if video_info_dict['like_cnt'] >= rule_dict['like_cnt']['min']:
+            if video_info_dict['duration'] >= rule_dict['duration']['min']:
+                if video_info_dict['video_width'] >= rule_dict['width']['min'] \
+                        or video_info_dict['video_height'] >= rule_dict['height']['min']:
+                    return True
+                else:
+                    return False
+            else:
+                return False
+        else:
+            return False
+
+    # 过滤词库
+    @classmethod
+    def filter_words(cls, log_type, crawler):
+        try:
+            while True:
+                filter_words_sheet = Feishu.get_values_batch(log_type, crawler, '6BS2RR')
+                if filter_words_sheet is None:
+                    Common.logger(log_type, crawler).warning(f"filter_words_sheet:{filter_words_sheet} 10秒钟后重试")
+                    continue
+                filter_words_list = []
+                for x in filter_words_sheet:
+                    for y in x:
+                        if y is None:
+                            pass
+                        else:
+                            filter_words_list.append(y)
+                return filter_words_list
+        except Exception as e:
+            Common.logger(log_type, crawler).error(f'filter_words异常:{e}\n')
+
+    @classmethod
+    def video_title(cls, log_type, env, crawler, title):
+        title_split1 = title.split(" #")
+        if title_split1[0] != "":
+            title1 = title_split1[0]
+        else:
+            title1 = title_split1[-1]
+
+        title_split2 = title1.split(" #")
+        if title_split2[0] != "":
+            title2 = title_split2[0]
+        else:
+            title2 = title_split2[-1]
+
+        title_split3 = title2.split("@")
+        if title_split3[0] != "":
+            title3 = title_split3[0]
+        else:
+            title3 = title_split3[-1]
+
+        video_title = title3.strip().split('#')[0].replace("\n", "") \
+                          .replace("/", "").replace("抖音", "").replace(" ", "") \
+                          .replace(" ", "").replace("&NBSP", "").replace("\r", "") \
+                          .replace(".", "。").replace("\\", "") \
+                          .replace(":", "").replace("*", "").replace("?", "") \
+                          .replace("?", "").replace('"', "").replace("<", "") \
+                          .replace(">", "").replace("|", "").replace("@", "").replace('"', '').replace("'", '')[:40]
+        if video_title.replace(" ", "") == "" or video_title == "。。。" or video_title == "...":
+            return random_title(log_type, crawler, env, text='title')
+        else:
+            return video_title
+
+    @classmethod
+    def get_videoList(cls, log_type, crawler, strategy, task, our_uid, out_uid, oss_endpoint, env):
+        try:
+            max_cursor = ''
+            url = "https://www.douyin.com/aweme/v1/web/aweme/post/?device_platform=webapp&aid=6383&channel=channel_pc_web&sec_user_id={sec_user_id}&max_cursor={max_cursor}&show_live_replay_strategy=1&count=10&publish_video_strategy_type=2&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1440&screen_height=900&browser_language=zh-CN&browser_platform=MacIntel&browser_name=Chrome&browser_version=112.0.0.0&browser_online=true&engine_name=Blink&engine_version=112.0.0.0&os_name=Mac+OS&os_version=10.15.7&cpu_core_num=8&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50".format(
+                sec_user_id=out_uid, max_cursor=max_cursor)
+            headers = {
+                'authority': 'www.douyin.com',
+                'accept': 'application/json, text/plain, */*',
+                'accept-language': 'zh-CN,zh;q=0.9',
+                # 'cookie': '__ac_nonce=06437a18000f23ad954f0; __ac_signature=_02B4Z6wo00f01Sb71TAAAIDCsi2OPpjonN0m29GAAC2M85; s_v_web_id=verify_lgeqr3uq_3aDaqQXf_juHS_40Yi_BE8b_tI8FCILZQXPK; _tea_utm_cache_2018=undefined; ttwid=1%7Cq_IBs6hbBUOIEcRR1gxtgY6GiTbTE3U1XhJNLL_9BZA%7C1681367431%7Cf77b36ae4721884fec1c3fa9d6a08c29e308236ae13df58d1be3b0d1f82f8668; strategyABtestKey=%221681367433.454%22; passport_csrf_token=bff0289a5846e58b4b9db6e1f64665f4; passport_csrf_token_default=bff0289a5846e58b4b9db6e1f64665f4; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtY2xpZW50LWNzciI6Ii0tLS0tQkVHSU4gQ0VSVElGSUNBVEUgUkVRVUVTVC0tLS0tXHJcbk1JSUJEVENCdFFJQkFEQW5NUXN3Q1FZRFZRUUdFd0pEVGpFWU1CWUdBMVVFQXd3UFltUmZkR2xqYTJWMFgyZDFcclxuWVhKa01Ga3dFd1lIS29aSXpqMENBUVlJS29aSXpqMERBUWNEUWdBRVhzcHJ5TElFT3E4Z2tPc2l5MTdSS1dEcVxyXG5xTXZkWEt5Y1V5NStiL3JpSmJ6VkMwMlYrU1dNaWtZTlNOK29IU2g2WVVTTmdUUjJrZEhvRUxISmxGdU9scUFzXHJcbk1Db0dDU3FHU0liM0RRRUpEakVkTUJzd0dRWURWUjBSQkJJd0VJSU9kM2QzTG1SdmRYbHBiaTVqYjIwd0NnWUlcclxuS29aSXpqMEVBd0lEUndBd1JBSWdIeW9SblFNK0h0Z3ZOU2dFMVpHdGpmYWQxT3BuWHJRdVFSNXNSaDkwakRJQ1xyXG5JRG1tVkthRkN5djBLemtpZ0J0RExaTVJSNndURzRBWUVoNUlWUmlZUU9UVVxyXG4tLS0tLUVORCBDRVJUSUZJQ0FURSBSRVFVRVNULS0tLS1cclxuIn0=; msToken=ZPkeAqCnLbjDWCkWcWf36ZZIoZTl07X33ca0xcNGk3tZPoMvgx-lo28oNb5JhbCKsXLgLNIoojAbocBrjdAv54Hwf-Tk3_yAjLW7WJxxSa0=; ttcid=54b98e03a03e43e09211ee28db90fdd126; home_can_add_dy_2_desktop=%221%22; msToken=nqMSwn8xJAXLZk2AikdOeJ6P3JvoCsbYjHROoR55KXMDvWs8auYCMpZFGQSClHhitgB0l_vwg8m0-lE-aWQovfN7Ga1QupM3SpdNktiamFRiHMdJExREc9_uxS1ln8E=; tt_scid=DnO5GFg1oLONpPMFuFeL-OveKBn43mRynRVTvHsh1KUQm283ocN6JX6qPKDDrFHbfdf1; download_guide=%222%2F20230413%22; msToken=b9haS5RjLaFgqVDoGp5xSqc8B4kl-miQB5Nku0BSIvHVutKT81Nzk_pPb0wm7xYlAp_nz1gytQng5gYeIRNxcMgZJ_MB7lhejt_093miXlHtvqAaxL0FNg==',
+                'referer': 'https://www.douyin.com/user/{}?showTab=post'.format(out_uid),
+                'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
+                'sec-ch-ua-mobile': '?0',
+                'sec-ch-ua-platform': '"macOS"',
+                'sec-fetch-dest': 'empty',
+                'sec-fetch-mode': 'cors',
+                'sec-fetch-site': 'same-origin',
+                'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
+            }
+            x_bogus = get_xb(url, headers['user-agent'])
+            url = url + '&X-Bogus={}'.format(x_bogus)
+            if not x_bogus:
+                return
+            res = requests.get(url=url, headers=headers, data={}, proxies=Common.tunnel_proxies(), timeout=10).json()
+            aweme_list = res.get('aweme_list', [])
+        except Exception as e:
+            Common.logger(log_type, crawler).error(f"获取抖音作者:{out_uid},视频列表失败:{e}")
+            return
+        if not aweme_list:
+            Common.logger(log_type, crawler).warning(f"抖音作者没有获取到更多数据")
+            return
+        for info in aweme_list:
+            if info.get('is_ads'):
+                continue
+            publish_time = info.get('create_time')
+            if not publish_time:
+                continue
+            publish_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(publish_time))
+            publish_day = int((int(time.time()) - publish_time) / (3600 * 24))
+
+            video_title = cls.video_title(log_type, env, crawler, info['desc'])
+            if not video_title:
+                video_title = random_title(log_type, crawler, env, text='title')
+
+            video_dict = {'video_title': video_title,
+                          'video_id': info['aweme_id'],
+                          'play_cnt': info['statistics']['play_count'],
+                          'comment_cnt': info['statistics']['comment_count'],
+                          'like_cnt': info['statistics']['digg_count'],
+                          'share_cnt': info['statistics']['share_count'],
+                          'video_width': info['video']['width'],
+                          'video_height': info['video']['height'],
+                          'duration': round(info['video']['duration'] / 1000),
+                          'publish_time': publish_day,
+                          'publish_time_stamp': publish_time * 1000,
+                          'publish_time_str': publish_time_str,
+                          'user_name': info['author']['nickname'],
+                          'user_id': info['author_user_id'],
+                          'user_sec_id': info['author']['sec_uid'],
+                          'avatar_url': info['author']['avatar_thumb']['url_list'][0],
+                          'cover_url': info['video']['origin_cover']['url_list'][0].replace('\u0026', '&'),
+                          'video_url': info['video']['play_addr']['url_list'][0],
+                          'session': f"douyin{int(time.time())}"
+                          }
+
+            for k, v in video_dict.items():
+                Common.logger(log_type, crawler).info(f"{k}:{v}")
+                # log_type, crawler, strategy, task, video_dict, rule_dict, our_uid, oss_endpoint, env
+            cls.download_publish(log_type=log_type,
+                                 crawler=crawler,
+                                 strategy=strategy,
+                                 task=task,
+                                 video_dict=video_dict,
+                                 our_uid=our_uid,
+                                 oss_endpoint=oss_endpoint,
+                                 env=env,
+                                 )
+
+    @classmethod
+    def repeat_video(cls, log_type, crawler, video_id, env):
+        sql = f""" select * from crawler_video where platform="{cls.platform}" and out_video_id="{video_id}"; """
+        repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env)
+        return len(repeat_video)
+
+    # 下载 / 上传
+    @classmethod
+    def download_publish(cls, log_type, crawler, strategy, task, video_dict, our_uid, oss_endpoint, env):
+        try:
+            filter_words = get_config_from_mysql(log_type, crawler, env, text='filter')
+            for filter_word in filter_words:
+                if filter_word in video_dict['video_title']:
+                    Common.logger(log_type, crawler).info('标题已中过滤词:{}\n', video_dict['video_title'])
+                    return
+            if cls.download_rule(video_dict, task['rule_dict']) is False:
+                Common.logger(log_type, crawler).info('不满足抓取规则\n')
+            elif cls.repeat_video(log_type, crawler, video_dict['video_id'], env) != 0:
+                Common.logger(log_type, crawler).info('视频已下载\n')
+            else:
+                # 下载视频
+                Common.download_method(log_type=log_type, crawler=crawler, text='video',
+                                       title=video_dict['video_title'], url=video_dict['video_url'])
+                md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
+                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
+                # ffmpeg_dict = Common.ffmpeg(log_type, crawler, f"./{crawler}/videos/{video_dict['video_title']}/video.mp4")
+                # if ffmpeg_dict is None or ffmpeg_dict['size'] == 0:
+                #     Common.logger(log_type, crawler).warning(f"下载的视频无效,已删除\n")
+                #     # 删除视频文件夹
+                #     shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
+                #     return
+                # 下载封面
+                Common.download_method(log_type=log_type, crawler=crawler, text='cover',
+                                       title=video_dict['video_title'], url=video_dict['cover_url'])
+                # 保存视频信息至txt
+                Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
+
+                # 上传视频
+                Common.logger(log_type, crawler).info("开始上传视频...")
+                our_video_id = Publish.upload_and_publish(log_type=log_type,
+                                                          crawler=crawler,
+                                                          strategy=strategy,
+                                                          our_uid=our_uid,
+                                                          env=env,
+                                                          oss_endpoint=oss_endpoint)
+                if env == 'dev':
+                    our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
+                else:
+                    our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
+                Common.logger(log_type, crawler).info("视频上传完成")
+
+                if our_video_id is None:
+                    # 删除视频文件夹
+                    shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
+                    return
+
+                # 视频写入飞书
+                upload_time = int(time.time())
+                values = [[
+                    our_video_id,
+                    time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(upload_time)),
+                    strategy,
+                    str(video_dict['video_id']),
+                    video_dict['video_title'],
+                    our_video_link,
+                    # video_dict['gid'],
+                    video_dict['play_cnt'],
+                    video_dict['comment_cnt'],
+                    video_dict['like_cnt'],
+                    video_dict['share_cnt'],
+                    video_dict['duration'],
+                    str(video_dict['video_width']) + '*' + str(video_dict['video_height']),
+                    video_dict['publish_time_str'],
+                    video_dict['user_name'],
+                    video_dict['user_id'],
+                    video_dict['avatar_url'],
+                    video_dict['cover_url'],
+                    video_dict['video_url']
+                ]]
+                # time.sleep(1)
+                Feishu.insert_columns(log_type, 'douyin', "qV9VC0", "ROWS", 1, 2)
+                Feishu.update_values(log_type, 'douyin', "qV9VC0", "A2:Z2", values)
+                Common.logger(log_type, crawler).info(f"视频已保存至云文档\n")
+
+                # 视频信息保存数据库
+                insert_sql = f""" insert into crawler_video(video_id,
+                                user_id,
+                                out_user_id,
+                                platform,
+                                strategy,
+                                out_video_id,
+                                video_title,
+                                cover_url,
+                                video_url,
+                                duration,
+                                publish_time,
+                                play_cnt,
+                                comment_cnt,
+                                like_cnt,
+                                share_cnt,
+                                crawler_rule,
+                                width,
+                                height)
+                                values({our_video_id},
+                                {our_uid},
+                                "{video_dict['user_id']}",
+                                "{cls.platform}",
+                                "{strategy}",
+                                "{video_dict['video_id']}",
+                                "{video_dict['video_title']}",
+                                "{video_dict['cover_url']}",
+                                "{video_dict['video_url']}",
+                                {int(video_dict['duration'])},
+                                "{video_dict['publish_time_str']}",
+                                {int(video_dict['play_cnt'])},
+                                {int(video_dict['comment_cnt'])},
+                                {int(video_dict['like_cnt'])},
+                                {int(video_dict['share_cnt'])},
+                                '{json.dumps(task["rule_dict"])}',
+                                {int(video_dict['video_width'])},
+                                {int(video_dict['video_height'])}) """
+                Common.logger(log_type, crawler).info(f"insert_sql:{insert_sql}")
+                MysqlHelper.update_values(log_type, crawler, insert_sql, env)
+                Common.logger(log_type, crawler).info('视频信息插入数据库成功!\n')
+        except Exception as e:
+            Common.logger(log_type, crawler).error(f'download_publish异常:{e}\n')
+
+    @classmethod
+    def get_follow_videos(cls, log_type, crawler, task, oss_endpoint, env):
+        user_list = get_user_from_mysql(log_type, crawler, crawler, env)
+        strategy = '定向抓取策略'
+
+        for user in user_list:
+            spider_link = user["link"]
+            out_uid = spider_link
+            user_name = user["nick_name"]
+            our_uid = user["uid"]
+            Common.logger(log_type, crawler).info(f"开始抓取 {user_name} 用户主页视频\n")
+            cls.get_videoList(log_type=log_type,
+                              crawler=crawler,
+                              strategy=strategy,
+                              task=task,
+                              our_uid=our_uid,
+                              out_uid=out_uid,
+                              oss_endpoint=oss_endpoint,
+                              env=env)
+
+
+if __name__ == '__main__':
+    DyAuthorScheduling.get_follow_videos('author', 'douyin', '定向抓取策略', 'outer', 'prod')

+ 57 - 0
douyin/douyin_main/run_dy_author_scheduling.py

@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+# @Author: lierqiang
+# @Time: 2023/4/21
+import argparse
+import os
+import sys
+
+sys.path.append(os.getcwd())
+from common.common import Common
+from douyin.douyin_follow.dy_author_scheduling import DyAuthorScheduling
+from common.public import task_fun
+
+
+def main(log_type, crawler, task, oss_endpoint, env):
+    task = task_fun(task)
+    try:
+        Common.logger(log_type, crawler).info(f'开始抓取 {crawler}视频 定向榜\n')
+        DyAuthorScheduling.get_follow_videos(log_type=log_type,
+                                             crawler=crawler,
+                                             task=task,
+                                             oss_endpoint=oss_endpoint,
+                                             env=env)
+        Common.del_logs(log_type, crawler)
+        Common.logger(log_type, crawler).info('抓取任务结束\n')
+    except Exception as e:
+        Common.logger(log_type, crawler).info(f"{crawler}视频异常,触发报警:{e}\n")
+        # Feishu.bot(log_type, crawler, f"{e}")
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()  ## 新建参数解释器对象
+    parser.add_argument('--log_type', default='author')  ## 添加参数,注明参数类型
+    parser.add_argument('--crawler', default='douyin')  ## 添加参数
+    parser.add_argument('--strategy', default='定向抓取')  ## 添加参数
+    parser.add_argument('--task')  ## 添加参数
+    parser.add_argument('--oss_endpoint', default='outer')  ## 添加参数
+    parser.add_argument('--env', default='dev')  ## 添加参数
+    # parser.add_argument('--machine')  ## 添加参数
+    args = parser.parse_args()  ### 参数赋值,也可以通过终端赋值
+    task = {
+        'task_dict': {'task_id': '17', 'task_name': '西瓜测试4.21', 'source': 'douyin', 'start_time': '1682010720000',
+                      'interval': '24', 'mode': 'author',
+                      'rule': {'duration': {'min': 40, 'max': 0}, 'play_cnt': {'min': 4000, 'max': 0},
+                               'period': {'min': 10, 'max': 0}, 'fans_cnt': {'min': 0, 'max': 0},
+                               'videos_cnt': {'min': 0, 'max': 0}, 'like_cnt': {'min': 0, 'max': 0},
+                               'width': {'min': 0, 'max': 0}, 'height': {'min': 0, 'max': 0}},
+                      'spider_name': 'run_dy_author_scheduling', 'machine': 'aliyun', 'status': '0',
+                      'create_time': '1682048632396', 'update_time': '1682048632396', 'operator': ''},
+        'rule_dict': {'duration': {'min': 0, 'max': 0}, 'play_cnt': {'min': 0, 'max': 0},
+                      'period': {'min': 0, 'max': 0}, 'fans_cnt': {'min': 0, 'max': 0}, 'videos_cnt': {'min': 0, 'max': 0},
+                      'like_cnt': {'min': 0, 'max': 0}, 'width': {'min': 0, 'max': 0},
+                      'height': {'min': 0, 'max': 0}}}
+    main(log_type=args.log_type,
+         crawler=args.crawler,
+         task=task,
+         oss_endpoint=args.oss_endpoint,
+         env=args.env)

+ 58 - 0
douyin/douyin_main/run_dy_recommend_scheduling.py

@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+# @Author: lierqiang
+# @Time: 2023/4/21
+import argparse
+import os
+import sys
+
+sys.path.append(os.getcwd())
+from common.common import Common
+from douyin.douyin_recommend.dy_recommend_scheduling import DyRecommendScheduling
+from common.public import task_fun
+
+
+def main(log_type, crawler, task, oss_endpoint, env):
+    task = task_fun(task)
+    try:
+        Common.logger(log_type, crawler).info(f'开始抓取 {crawler}视频 定向榜\n')
+        DyRecommendScheduling.get_recommend_videos(log_type=log_type,
+                                                   crawler=crawler,
+                                                   task=task,
+                                                   oss_endpoint=oss_endpoint,
+                                                   env=env)
+        Common.del_logs(log_type, crawler)
+        Common.logger(log_type, crawler).info('抓取任务结束\n')
+    except Exception as e:
+        Common.logger(log_type, crawler).info(f"{crawler}视频异常,触发报警:{e}\n")
+        # Feishu.bot(log_type, crawler, f"{e}")
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()  ## 新建参数解释器对象
+    parser.add_argument('--log_type', default='recommend')  ## 添加参数,注明参数类型
+    parser.add_argument('--crawler', default='douyin')  ## 添加参数
+    parser.add_argument('--strategy', default='推荐')  ## 添加参数
+    parser.add_argument('--task')  ## 添加参数
+    parser.add_argument('--oss_endpoint', default='outer')  ## 添加参数
+    parser.add_argument('--env', default='dev')  ## 添加参数
+    # parser.add_argument('--machine')  ## 添加参数
+    args = parser.parse_args()  ### 参数赋值,也可以通过终端赋值
+    task = {
+        'task_dict': {'task_id': '17', 'task_name': '西瓜测试4.21', 'source': 'douyin', 'start_time': '1682010720000',
+                      'interval': '24', 'mode': 'author',
+                      'rule': {'duration': {'min': 40, 'max': 0}, 'play_cnt': {'min': 4000, 'max': 0},
+                               'period': {'min': 10, 'max': 0}, 'fans_cnt': {'min': 0, 'max': 0},
+                               'videos_cnt': {'min': 0, 'max': 0}, 'like_cnt': {'min': 0, 'max': 0},
+                               'width': {'min': 0, 'max': 0}, 'height': {'min': 0, 'max': 0}},
+                      'spider_name': 'run_dy_author_scheduling', 'machine': 'aliyun', 'status': '0',
+                      'create_time': '1682048632396', 'update_time': '1682048632396', 'operator': ''},
+        'rule_dict': {'duration': {'min': 0, 'max': 0}, 'play_cnt': {'min': 0, 'max': 0},
+                      'period': {'min': 0, 'max': 0}, 'fans_cnt': {'min': 0, 'max': 0},
+                      'videos_cnt': {'min': 0, 'max': 0},
+                      'like_cnt': {'min': 0, 'max': 0}, 'width': {'min': 0, 'max': 0},
+                      'height': {'min': 0, 'max': 0}}}
+    main(log_type=args.log_type,
+         crawler=args.crawler,
+         task=task,
+         oss_endpoint=args.oss_endpoint,
+         env=args.env)

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 81 - 0
douyin/douyin_recommend/dy_recommend_scheduling.py


+ 248 - 449
kuaishou/kuaishou_follow/kuaishou_follow_scheduling.py

@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# @Author: wangkun
+# @Author: lierqiang
 # @Time: 2023/2/24
 import os
 import random
@@ -13,69 +13,70 @@ import json
 
 import urllib3
 from requests.adapters import HTTPAdapter
-from selenium import webdriver
-from selenium.webdriver import DesiredCapabilities
-from selenium.webdriver.chrome.service import Service
 
 sys.path.append(os.getcwd())
 from common.common import Common
 from common.feishu import Feishu
 from common.getuser import getUser
-from common.db import MysqlHelper
+# from common.db import MysqlHelper
+from common.scheduling_db import MysqlHelper
 from common.publish import Publish
+from common.public import random_title, get_config_from_mysql
+from common.public import get_user_from_mysql
+from common.userAgent import get_random_user_agent
 
 
-class Follow:
+class KuaiShouFollowScheduling:
     platform = "快手"
     tag = "快手爬虫,定向爬虫策略"
 
     @classmethod
     def get_rule(cls, log_type, crawler, index):
         try:
-            while True:
-                rule_sheet = Feishu.get_values_batch(log_type, crawler, "3iqG4z")
-                if rule_sheet is None:
-                    Common.logger(log_type, crawler).warning("rule_sheet is None! 10秒后重新获取")
-                    time.sleep(10)
-                    continue
-                if index == 1:
-                    rule_dict = {
-                        "play_cnt": f"{rule_sheet[1][1]}{rule_sheet[1][2]}",
-                        "video_width": f"{rule_sheet[2][1]}{rule_sheet[2][2]}",
-                        "video_height": f"{rule_sheet[3][1]}{rule_sheet[3][2]}",
-                        "like_cnt": f"{rule_sheet[4][1]}{rule_sheet[4][2]}",
-                        "duration": f"{rule_sheet[5][1]}{rule_sheet[5][2]}",
-                        "download_cnt": f"{rule_sheet[6][1]}{rule_sheet[6][2]}",
-                        "publish_time": f"{rule_sheet[7][1]}{rule_sheet[7][2]}",
-                    }
-                    # for k, v in rule_dict.items():
-                    #     Common.logger(log_type, crawler).info(f"{k}:{v}")
-                    return rule_dict
-                elif index == 2:
-                    rule_dict = {
-                        "play_cnt": f"{rule_sheet[9][1]}{rule_sheet[9][2]}",
-                        "video_width": f"{rule_sheet[10][1]}{rule_sheet[10][2]}",
-                        "video_height": f"{rule_sheet[11][1]}{rule_sheet[11][2]}",
-                        "like_cnt": f"{rule_sheet[12][1]}{rule_sheet[12][2]}",
-                        "duration": f"{rule_sheet[13][1]}{rule_sheet[13][2]}",
-                        "download_cnt": f"{rule_sheet[14][1]}{rule_sheet[14][2]}",
-                        "publish_time": f"{rule_sheet[15][1]}{rule_sheet[15][2]}",
-                    }
-                    # for k, v in rule_dict.items():
-                    #     Common.logger(log_type, crawler).info(f"{k}:{v}")
-                    return rule_dict
+            rule_sheet = Feishu.get_values_batch(log_type, crawler, "3iqG4z")
+            if index == 1:
+                rule_dict = {
+                    "play_cnt": f"{rule_sheet[1][1]}{rule_sheet[1][2]}",
+                    "video_width": f"{rule_sheet[2][1]}{rule_sheet[2][2]}",
+                    "video_height": f"{rule_sheet[3][1]}{rule_sheet[3][2]}",
+                    "like_cnt": f"{rule_sheet[4][1]}{rule_sheet[4][2]}",
+                    "duration": f"{rule_sheet[5][1]}{rule_sheet[5][2]}",
+                    "download_cnt": f"{rule_sheet[6][1]}{rule_sheet[6][2]}",
+                    "publish_time": f"{rule_sheet[7][1]}{rule_sheet[7][2]}",
+                }
+                # for k, v in rule_dict.items():
+                #     Common.logger(log_type, crawler).info(f"{k}:{v}")
+                return rule_dict
+            elif index == 2:
+                rule_dict = {
+                    "play_cnt": f"{rule_sheet[9][1]}{rule_sheet[9][2]}",
+                    "video_width": f"{rule_sheet[10][1]}{rule_sheet[10][2]}",
+                    "video_height": f"{rule_sheet[11][1]}{rule_sheet[11][2]}",
+                    "like_cnt": f"{rule_sheet[12][1]}{rule_sheet[12][2]}",
+                    "duration": f"{rule_sheet[13][1]}{rule_sheet[13][2]}",
+                    "download_cnt": f"{rule_sheet[14][1]}{rule_sheet[14][2]}",
+                    "publish_time": f"{rule_sheet[15][1]}{rule_sheet[15][2]}",
+                }
+                # for k, v in rule_dict.items():
+                #     Common.logger(log_type, crawler).info(f"{k}:{v}")
+                return rule_dict
         except Exception as e:
             Common.logger(log_type, crawler).error(f"get_rule:{e}\n")
 
     @classmethod
     def download_rule(cls, video_dict, rule_dict):
-        if eval(f"{video_dict['play_cnt']}{rule_dict['play_cnt']}") is True \
-                and eval(f"{video_dict['video_width']}{rule_dict['video_width']}") is True \
-                and eval(f"{video_dict['video_height']}{rule_dict['video_height']}") is True \
-                and eval(f"{video_dict['like_cnt']}{rule_dict['like_cnt']}") is True \
-                and eval(f"{video_dict['duration']}{rule_dict['duration']}") is True \
-                and eval(f"{video_dict['publish_time']}{rule_dict['publish_time']}") is True:
-            return True
+        if video_dict['like_cnt'] >= rule_dict['like_cnt']['min']:
+            if video_dict['publish_time'] >= rule_dict['publish_time']['min']:
+                if video_dict['duration'] >= rule_dict['duration']['min']:
+                    if video_dict['video_width'] >= rule_dict['width']['min'] \
+                            or video_dict['video_height'] >= rule_dict['height']['min']:
+                        return True
+                    else:
+                        return False
+                else:
+                    return False
+            else:
+                return False
         else:
             return False
 
@@ -99,56 +100,31 @@ class Follow:
         except Exception as e:
             Common.logger(log_type, crawler).error(f'filter_words异常:{e}\n')
 
-    # 万能标题
-    @classmethod
-    def random_title(cls, log_type, crawler):
-        try:
-            while True:
-                random_title_sheet = Feishu.get_values_batch(log_type, crawler, '0DiyXe')
-                if random_title_sheet is None:
-                    Common.logger(log_type, crawler).warning(f"filter_words_sheet:{random_title_sheet} 10秒钟后重试")
-                    continue
-                random_title_list = []
-                for x in random_title_sheet:
-                    for y in x:
-                        if y is None:
-                            pass
-                        else:
-                            random_title_list.append(y)
-                return random.choice(random_title_list)
-        except Exception as e:
-            Common.logger(log_type, crawler).error(f'random_title:{e}\n')
-
     # 获取站外用户信息
     @classmethod
     def get_out_user_info(cls, log_type, crawler, out_uid):
         try:
             url = "https://www.kuaishou.com/graphql"
+
             payload = json.dumps({
                 "operationName": "visionProfile",
                 "variables": {
-                    "userId": str(out_uid)
+                    "userId": out_uid
                 },
                 "query": "query visionProfile($userId: String) {\n  visionProfile(userId: $userId) {\n    result\n    hostName\n    userProfile {\n      ownerCount {\n        fan\n        photo\n        follow\n        photo_public\n        __typename\n      }\n      profile {\n        gender\n        user_name\n        user_id\n        headurl\n        user_text\n        user_profile_bg_url\n        __typename\n      }\n      isFollowing\n      __typename\n    }\n    __typename\n  }\n}\n"
             })
             headers = {
-                # 'Cookie': f'kpf=PC_WEB; clientid=3; did=web_e2901e1c5a13c60af81ba88bc7a3ee24; userId={"".join(str(random.choice(range(1, 10))) for _ in range(10))}; kpn=KUAISHOU_VISION; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABE4wGjnJauApJelOpl9Xqo8TVDAyra7Pvo0rZtVgMSZxgVuw4Z6P2UtHv_CHOk2Ne2el1hdE_McCptWs8tRdtYlhXFlVOu8rQX7CwexzOBudJAfB3lDN8LPc4o4qHNwqFxy5J5j_WzdllbqMmaDUK9yUxX6XA-JFezzq9jvBwtGv7_hzB7pFrUcH39z0EYOQaZo5lDl-pE09Gw7wr8NvlZRoSdWlbobCW6oJxuQLJTUr9oj_uIiBhkeb1psaIIc3VwfYQ1UfvobrXAP_WpnRabE_3UZUBOygFMAE; kuaishou.server.web_ph=2b981e2051d7130c977fd31df97fe6f5ad54',
-                'Cookie': f'kpf=PC_WEB; clientid=3; did=web_e2901e1c5a13c60af81ba88bc7a3ee24; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABszwASP0eGT2ym0NUdGf1PTi8_gDYrDms9otf5FKMUrx0V7MOTT1hhvpVJijmgku8KYtu3a6g3X1hZODMpX0ebZUip44txWPoY3VRqbsnBKEOs9Qkmx3uLaX33nq8KevOKLoO0cIE8nfwMJISe_BtCHr22cbJkofI0xfJXBt_ZgPqJIqWsUwdgwKzqRYn47ROkIqzeDfEjbxaZxiXy22ZhhoSlCobbmtjkvjpY9x730BPP_C5IiAl9EBaCTyvMw5IIcnkmcjMeWC8w6LKzeFMCNhcqrfkgCgFMAE; kuaishou.server.web_ph=19ae269a54f619c49def39ef5b54ae6d4353; kpn=KUAISHOU_VISION',
-                'Referer': f'https://www.kuaishou.com/profile/{out_uid}',
-                'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.41',
-                'content-type': 'application/json',
-                'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
-                'Cache-Control': 'no-cache',
-                'Connection': 'keep-alive',
+                'Accept': '*/*',
+                'Content-Type': 'application/json',
                 'Origin': 'https://www.kuaishou.com',
-                'Pragma': 'no-cache',
-                'Sec-Fetch-Dest': 'empty',
-                'Sec-Fetch-Mode': 'cors',
-                'Sec-Fetch-Site': 'same-origin',
-                'accept': '*/*',
-                'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Microsoft Edge";v="110"',
-                'sec-ch-ua-mobile': '?0',
-                'sec-ch-ua-platform': '"macOS"'
+                'Cookie': 'did=web_5d4d0dff78b7819f8b015e7a81e2ca98;; clientid=3; kpf=PC_WEB; kpn=KUAISHOU_VISION',
+                'Content-Length': '552',
+                'Accept-Language': 'zh-CN,zh-Hans;q=0.9',
+                'Host': 'www.kuaishou.com',
+                'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15',
+                'Referer': 'https://www.kuaishou.com/profile/{}'.format(out_uid),
+                'Accept-Encoding': 'gzip, deflate, br',
+                'Connection': 'keep-alive'
             }
             urllib3.disable_warnings()
             s = requests.session()
@@ -216,7 +192,7 @@ class Follow:
 
     # 获取用户信息列表
     @classmethod
-    def get_user_list(cls, log_type, crawler, sheetid, env, machine):
+    def get_user_list(cls, log_type, crawler, sheetid, env):
         try:
             while True:
                 user_sheet = Feishu.get_values_batch(log_type, crawler, sheetid)
@@ -251,7 +227,7 @@ class Follow:
                                 "tag": cls.tag,
                             }
                             our_user_dict = getUser.create_user(log_type=log_type, crawler=crawler,
-                                                              out_user_dict=out_user_dict, env=env, machine=machine)
+                                                                out_user_dict=out_user_dict, env=env)
                             our_uid = our_user_dict['our_uid']
                             our_user_link = our_user_dict['our_user_link']
                             Feishu.update_values(log_type, crawler, sheetid, f'G{i + 1}:H{i + 1}',
@@ -272,7 +248,7 @@ class Follow:
 
     # 处理视频标题
     @classmethod
-    def video_title(cls, log_type, crawler, title):
+    def video_title(cls, log_type, crawler, env, title):
         title_split1 = title.split(" #")
         if title_split1[0] != "":
             title1 = title_split1[0]
@@ -297,361 +273,186 @@ class Follow:
                           .replace("#", "").replace(".", "。").replace("\\", "") \
                           .replace(":", "").replace("*", "").replace("?", "") \
                           .replace("?", "").replace('"', "").replace("<", "") \
-                          .replace(">", "").replace("|", "").replace("@", "")[:40]
+                          .replace(">", "").replace("|", "").replace("@", "").replace('"', '').replace("'", '')[:40]
         if video_title.replace(" ", "") == "" or video_title == "。。。" or video_title == "...":
-            return cls.random_title(log_type, crawler)
+            return random_title(log_type, crawler, env, text='title')
         else:
             return video_title
 
     @classmethod
-    def get_cookie(cls, log_type, crawler, out_uid, machine):
+    def get_videoList(cls, log_type, crawler, strategy, task, our_uid, out_uid, oss_endpoint, env, pcursor=""):
+        rule_dict_1 = task['rule_dict']
+        url = "https://www.kuaishou.com/graphql"
+        payload = json.dumps({
+            "operationName": "visionProfilePhotoList",
+            "variables": {
+                "userId": out_uid,
+                "pcursor": "",
+                "page": "profile"
+            },
+            "query": "fragment photoContent on PhotoEntity {\n  id\n  duration\n  caption\n  originCaption\n  likeCount\n  viewCount\n  commentCount\n  realLikeCount\n  coverUrl\n  photoUrl\n  photoH265Url\n  manifest\n  manifestH265\n  videoResource\n  coverUrls {\n    url\n    __typename\n  }\n  timestamp\n  expTag\n  animatedCoverUrl\n  distance\n  videoRatio\n  liked\n  stereoType\n  profileUserTopPhoto\n  musicBlocked\n  __typename\n}\n\nfragment feedContent on Feed {\n  type\n  author {\n    id\n    name\n    headerUrl\n    following\n    headerUrls {\n      url\n      __typename\n    }\n    __typename\n  }\n  photo {\n    ...photoContent\n    __typename\n  }\n  canAddComment\n  llsid\n  status\n  currentPcursor\n  tags {\n    type\n    name\n    __typename\n  }\n  __typename\n}\n\nquery visionProfilePhotoList($pcursor: String, $userId: String, $page: String, $webPageArea: String) {\n  visionProfilePhotoList(pcursor: $pcursor, userId: $userId, page: $page, webPageArea: $webPageArea) {\n    result\n    llsid\n    webPageArea\n    feeds {\n      ...feedContent\n      __typename\n    }\n    hostName\n    pcursor\n    __typename\n  }\n}\n"
+        })
+        headers = {
+            'Accept': '*/*',
+            'Content-Type': 'application/json',
+            'Origin': 'https://www.kuaishou.com',
+            'Cookie': 'kpf=PC_WEB; clientid=3; did=web_44b06f828a7810da393092aa6bb8dde0; kpn=KUAISHOU_VISION',
+            'Content-Length': '1260',
+            'Accept-Language': 'zh-CN,zh-Hans;q=0.9',
+            'Host': 'www.kuaishou.com',
+            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15',
+            'Referer': 'https://www.kuaishou.com/profile/{}'.format(out_uid),
+            'Accept-Encoding': 'gzip, deflate, br',
+            'Connection': 'keep-alive'
+        }
         try:
-            # 打印请求配置
-            ca = DesiredCapabilities.CHROME
-            ca["goog:loggingPrefs"] = {"performance": "ALL"}
-
-            # 不打开浏览器运行
-            chrome_options = webdriver.ChromeOptions()
-            chrome_options.add_argument("headless")
-            chrome_options.add_argument(
-                f'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36')
-            chrome_options.add_argument("--no-sandbox")
-
-            # driver初始化
-            if machine == "aliyun":
-                driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options)
-            elif machine == "macpro":
-                driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options,
-                                          service=Service('/Users/lieyunye/Downloads/chromedriver_v107/chromedriver'))
-            elif machine == "macair":
-                driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options,
-                                          service=Service('/Users/piaoquan/Downloads/chromedriver_v108/chromedriver'))
-            else:
-                driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options, service=Service(
-                    '/Users/wangkun/Downloads/chromedriver/chromedriver_v109/chromedriver'))
-
-            driver.implicitly_wait(10)
-            # print('打开个人主页')
-            driver.get(f'https://www.kuaishou.com/profile/{out_uid}')
-            time.sleep(1)
-
-            # print('解析cookies')
-            logs = driver.get_log("performance")
-            # Common.logger(log_type, crawler).info('已获取logs:{}\n', logs)
-            # print('退出浏览器')
-            driver.quit()
-            for line in logs:
-                msg = json.loads(line['message'])
-                # Common.logger(log_type, crawler).info(f"{msg}\n\n")
-                if 'message' not in msg:
-                    pass
-                elif 'params' not in msg['message']:
-                    pass
-                elif 'headers' not in msg['message']['params']:
-                    pass
-                elif 'Cookie' not in msg['message']['params']['headers']:
-                    pass
-                elif msg['message']['params']['headers']['Host'] != 'www.kuaishou.com':
-                    pass
-                else:
-                    cookie = msg['message']['params']['headers']['Cookie']
-                    # Common.logger(log_type, crawler).info(f"{cookie}")
-                    return cookie
+            response = requests.post(url=url, headers=headers, data=payload, proxies=Common.tunnel_proxies(),
+                                     verify=False, timeout=10)
+            feeds = response.json()['data']['visionProfilePhotoList']['feeds']
         except Exception as e:
-            Common.logger(log_type, crawler).error(f"get_cookie:{e}\n")
-
-    @classmethod
-    def get_videoList(cls, log_type, crawler, strategy, our_uid, out_uid, oss_endpoint, env, machine):
-        try:
-            download_cnt_1, download_cnt_2 = 0, 0
-            pcursor = ""
+            Common.logger(log_type, crawler).error(f"get_videoList:{e},response:{response.text}")
+            return
+        if not feeds:
+            Common.logger(log_type, crawler).info("没有更多视频啦 ~\n")
+            return
+        pcursor = response.json()['data']['visionProfilePhotoList']['pcursor']
+        for i in range(len(feeds)):
+            # video_title
+            if 'caption' not in feeds[i]['photo']:
+                video_title = random_title(log_type, crawler, env, text='title')
+            elif feeds[i]['photo']['caption'].strip() == "":
+                video_title = random_title(log_type, crawler, env, text='title')
+            else:
+                video_title = cls.video_title(log_type, crawler, env, feeds[i]['photo']['caption'])
+
+            if 'videoResource' not in feeds[i]['photo'] \
+                    and 'manifest' not in feeds[i]['photo'] \
+                    and 'manifestH265' not in feeds[i]['photo']:
+                Common.logger(log_type, crawler).warning(f"get_videoList:{feeds[i]['photo']}\n")
+                break
+            videoResource = feeds[i]['photo']['videoResource']
+
+            if 'h264' not in videoResource and 'hevc' not in videoResource:
+                Common.logger(log_type, crawler).warning(f"get_videoList:{videoResource}\n")
+                break
+
+            # video_id
+            if 'h264' in videoResource and 'videoId' in videoResource['h264']:
+                video_id = videoResource['h264']['videoId']
+            elif 'hevc' in videoResource and 'videoId' in videoResource['hevc']:
+                video_id = videoResource['hevc']['videoId']
+            else:
+                video_id = ""
 
-            while True:
-                rule_dict_1 = cls.get_rule(log_type, crawler, 1)
-                rule_dict_2 = cls.get_rule(log_type, crawler, 2)
-                if rule_dict_1 is None or rule_dict_2 is None:
-                    Common.logger(log_type, crawler).warning(f"rule_dict is None, 10秒后重试")
-                    time.sleep(10)
-                else:
-                    break
+            # play_cnt
+            if 'viewCount' not in feeds[i]['photo']:
+                play_cnt = 0
+            else:
+                play_cnt = int(feeds[i]['photo']['viewCount'])
 
-            while True:
-                if download_cnt_1 >= int(
-                        rule_dict_1['download_cnt'].replace("=", "")[-1].replace("<", "")[-1].replace(">", "")[
-                            -1]) and download_cnt_2 >= int(
-                        rule_dict_2['download_cnt'].replace("=", "")[-1].replace("<", "")[-1].replace(">", "")[-1]):
-                    Common.logger(log_type, crawler).info(
-                        f"规则1已下载{download_cnt_1}条视频,规则2已下载{download_cnt_2}条视频\n")
-                    return
+            # like_cnt
+            if 'realLikeCount' not in feeds[i]['photo']:
+                like_cnt = 0
+            else:
+                like_cnt = feeds[i]['photo']['realLikeCount']
 
-                url = "https://www.kuaishou.com/graphql"
-                payload = json.dumps({
-                    "operationName": "visionProfilePhotoList",
-                    "variables": {
-                        "userId": out_uid,
-                        "pcursor": pcursor,
-                        "page": "profile"
-                    },
-                    "query": "fragment photoContent on PhotoEntity {\n  id\n  duration\n  caption\n  originCaption\n  likeCount\n  viewCount\n  realLikeCount\n  coverUrl\n  photoUrl\n  photoH265Url\n  manifest\n  manifestH265\n  videoResource\n  coverUrls {\n    url\n    __typename\n  }\n  timestamp\n  expTag\n  animatedCoverUrl\n  distance\n  videoRatio\n  liked\n  stereoType\n  profileUserTopPhoto\n  musicBlocked\n  __typename\n}\n\nfragment feedContent on Feed {\n  type\n  author {\n    id\n    name\n    headerUrl\n    following\n    headerUrls {\n      url\n      __typename\n    }\n    __typename\n  }\n  photo {\n    ...photoContent\n    __typename\n  }\n  canAddComment\n  llsid\n  status\n  currentPcursor\n  tags {\n    type\n    name\n    __typename\n  }\n  __typename\n}\n\nquery visionProfilePhotoList($pcursor: String, $userId: String, $page: String, $webPageArea: String) {\n  visionProfilePhotoList(pcursor: $pcursor, userId: $userId, page: $page, webPageArea: $webPageArea) {\n    result\n    llsid\n    webPageArea\n    feeds {\n      ...feedContent\n      __typename\n    }\n    hostName\n    pcursor\n    __typename\n  }\n}\n"
-                })
-                # get_cookie = cls.get_cookie(log_type, crawler, out_uid, machine)
-                # if get_cookie is None:
-                #     cookie = 'kpf=PC_WEB; clientid=3; did=web_e2901e1c5a13c60af81ba88bc7a3ee24; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABszwASP0eGT2ym0NUdGf1PTi8_gDYrDms9otf5FKMUrx0V7MOTT1hhvpVJijmgku8KYtu3a6g3X1hZODMpX0ebZUip44txWPoY3VRqbsnBKEOs9Qkmx3uLaX33nq8KevOKLoO0cIE8nfwMJISe_BtCHr22cbJkofI0xfJXBt_ZgPqJIqWsUwdgwKzqRYn47ROkIqzeDfEjbxaZxiXy22ZhhoSlCobbmtjkvjpY9x730BPP_C5IiAl9EBaCTyvMw5IIcnkmcjMeWC8w6LKzeFMCNhcqrfkgCgFMAE; kuaishou.server.web_ph=19ae269a54f619c49def39ef5b54ae6d4353; kpn=KUAISHOU_VISION'
-                # else:
-                #     cookie = get_cookie
-                # Common.logger(log_type, crawler).info(f"cookie:{cookie}")
-                headers = {
-                    # 'Cookie': f'kpf=PC_WEB; clientid=3; did=web_e2901e1c5a13c60af81ba88bc7a3ee24; userId={"".join(str(random.choice(range(1, 10))) for _ in range(10))}; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABOLgYYcIJ5ilxU46Jc-HLWThY8sppX3V0htC_KhSGOzAjP2hAOdegzfkZGAxS5rf6rCBS487FkxfYzLkV__I6b1lK16rDjvv94Kkoo4z7mgf8y8rFgWoqrp81JAWTtx00y-wrc1XXPf9RAVQoET70wWaeNG2r5bxtZEiNwpK_zPi0ZdUo0BW13dFKfVssAy2xKYh0UlJ8VSd_vBvyMKSxVBoSf061Kc3w5Nem7YdpVBmH39ceIiBpiGioLzbZqlHiSbwkH_LhUhNXz3o7LITj098KUytk2CgFMAE; kuaishou.server.web_ph=f1033957981996a7d50e849a9ded4cf4adff; kpn=KUAISHOU_VISION',
-                    # 'Cookie': cookie,
-                    'Cookie': 'kpf=PC_WEB; clientid=3; did=web_e2901e1c5a13c60af81ba88bc7a3ee24; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABszwASP0eGT2ym0NUdGf1PTi8_gDYrDms9otf5FKMUrx0V7MOTT1hhvpVJijmgku8KYtu3a6g3X1hZODMpX0ebZUip44txWPoY3VRqbsnBKEOs9Qkmx3uLaX33nq8KevOKLoO0cIE8nfwMJISe_BtCHr22cbJkofI0xfJXBt_ZgPqJIqWsUwdgwKzqRYn47ROkIqzeDfEjbxaZxiXy22ZhhoSlCobbmtjkvjpY9x730BPP_C5IiAl9EBaCTyvMw5IIcnkmcjMeWC8w6LKzeFMCNhcqrfkgCgFMAE; kuaishou.server.web_ph=19ae269a54f619c49def39ef5b54ae6d4353; kpn=KUAISHOU_VISION',
-                    'Referer': f'https://www.kuaishou.com/profile/{out_uid}',
-                    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.41',
-                    'content-type': 'application/json',
-                    # 'accept': '*/*',
-                    # 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
-                    # 'Cache-Control': 'no-cache',
-                    # 'Connection': 'keep-alive',
-                    # 'Origin': 'https://www.kuaishou.com',
-                    # 'Pragma': 'no-cache',
-                    # 'Sec-Fetch-Dest': 'empty',
-                    # 'Sec-Fetch-Mode': 'cors',
-                    # 'Sec-Fetch-Site': 'same-origin',
-                    # 'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Microsoft Edge";v="110"',
-                    # 'sec-ch-ua-mobile': '?0',
-                    # 'sec-ch-ua-platform': '"macOS"'
-                }
-                urllib3.disable_warnings()
-                s = requests.session()
-                # max_retries=3 重试3次
-                s.mount('http://', HTTPAdapter(max_retries=3))
-                s.mount('https://', HTTPAdapter(max_retries=3))
-                response = s.post(url=url, headers=headers, data=payload, proxies=Common.tunnel_proxies(), verify=False,
-                                  timeout=5)
-                response.close()
-                # Common.logger(log_type, crawler).info(f"get_videoList:{response.text}\n")
-                if response.status_code != 200:
-                    Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.text}\n")
-                    return
-                elif 'data' not in response.json():
-                    Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.json()}\n")
-                    return
-                elif 'visionProfilePhotoList' not in response.json()['data']:
-                    Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.json()['data']}\n")
-                    return
-                elif 'feeds' not in response.json()['data']['visionProfilePhotoList']:
-                    Common.logger(log_type, crawler).warning(
-                        f"get_videoList_response:{response.json()['data']['visionProfilePhotoList']}\n")
-                    return
-                elif len(response.json()['data']['visionProfilePhotoList']['feeds']) == 0:
-                    Common.logger(log_type, crawler).info("没有更多视频啦 ~\n")
-                    return
-                else:
-                    feeds = response.json()['data']['visionProfilePhotoList']['feeds']
-                    pcursor = response.json()['data']['visionProfilePhotoList']['pcursor']
-                    # Common.logger(log_type, crawler).info(f"feeds0: {feeds}\n")
-                    for i in range(len(feeds)):
-                        if 'photo' not in feeds[i]:
-                            Common.logger(log_type, crawler).warning(f"get_videoList:{feeds[i]}\n")
-                            break
-
-                        # video_title
-                        if 'caption' not in feeds[i]['photo']:
-                            video_title = cls.random_title(log_type, crawler)
-                        elif feeds[i]['photo']['caption'].strip() == "":
-                            video_title = cls.random_title(log_type, crawler)
-                        else:
-                            video_title = cls.video_title(log_type, crawler, feeds[i]['photo']['caption'])
-
-                        if 'videoResource' not in feeds[i]['photo'] \
-                                and 'manifest' not in feeds[i]['photo'] \
-                                and 'manifestH265' not in feeds[i]['photo']:
-                            Common.logger(log_type, crawler).warning(f"get_videoList:{feeds[i]['photo']}\n")
-                            break
-                        videoResource = feeds[i]['photo']['videoResource']
-
-                        if 'h264' not in videoResource and 'hevc' not in videoResource:
-                            Common.logger(log_type, crawler).warning(f"get_videoList:{videoResource}\n")
-                            break
-
-                        # video_id
-                        if 'h264' in videoResource and 'videoId' in videoResource['h264']:
-                            video_id = videoResource['h264']['videoId']
-                        elif 'hevc' in videoResource and 'videoId' in videoResource['hevc']:
-                            video_id = videoResource['hevc']['videoId']
-                        else:
-                            video_id = ""
+            # publish_time
+            if 'timestamp' not in feeds[i]['photo']:
+                publish_time_stamp = 0
+                publish_time_str = ''
+                publish_time = 0
+            else:
+                publish_time_stamp = int(int(feeds[i]['photo']['timestamp']) / 1000)
+                publish_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(publish_time_stamp))
+                publish_time = int((int(time.time()) - publish_time_stamp) / (3600 * 24))
 
-                        # play_cnt
-                        if 'viewCount' not in feeds[i]['photo']:
-                            play_cnt = 0
-                        else:
-                            play_cnt = int(feeds[i]['photo']['viewCount'])
+            # duration
+            if 'duration' not in feeds[i]['photo']:
+                duration = 0
+            else:
+                duration = int(int(feeds[i]['photo']['duration']) / 1000)
 
-                        # like_cnt
-                        if 'realLikeCount' not in feeds[i]['photo']:
-                            like_cnt = 0
-                        else:
-                            like_cnt = feeds[i]['photo']['realLikeCount']
+            # video_width / video_height / video_url
+            mapping = {}
+            for item in ['width', 'height']:
+                try:
+                    val = str(videoResource['h264']['adaptationSet'][0]['representation'][0][item])
+                except:
+                    val = str(videoResource['hevc']['adaptationSet'][0]['representation'][0][item])
+                mapping[item] = val
+            video_width = int(mapping['width']) if mapping['width'] else 0
+            video_height = int(mapping['height']) if mapping['height'] else 0
+            # cover_url
+            if 'coverUrl' not in feeds[i]['photo']:
+                cover_url = ""
+            else:
+                cover_url = feeds[i]['photo']['coverUrl']
+
+            # user_name / avatar_url
+            user_name = feeds[i]['author']['name']
+            avatar_url = feeds[i]['author']['headerUrl']
+
+            video_url = feeds[i]['photo']['photoUrl']
+            video_dict = {'video_title': video_title,
+                          'video_id': video_id,
+                          'play_cnt': play_cnt,
+                          'comment_cnt': 0,
+                          'like_cnt': like_cnt,
+                          'share_cnt': 0,
+                          'video_width': video_width,
+                          'video_height': video_height,
+                          'duration': duration,
+                          'publish_time': publish_time,
+                          'publish_time_stamp': publish_time_stamp,
+                          'publish_time_str': publish_time_str,
+                          'user_name': user_name,
+                          'user_id': out_uid,
+                          'avatar_url': avatar_url,
+                          'cover_url': cover_url,
+                          'video_url': video_url,
+                          'session': f"kuaishou{int(time.time())}"}
+            for k, v in video_dict.items():
+                Common.logger(log_type, crawler).info(f"{k}:{v}")
+            rule_1 = cls.download_rule(video_dict, rule_dict_1)
+            if rule_1 is True:
+                cls.download_publish(log_type=log_type,
+                                     crawler=crawler,
+                                     strategy=strategy,
+                                     video_dict=video_dict,
+                                     rule_dict=rule_dict_1,
+                                     our_uid=our_uid,
+                                     oss_endpoint=oss_endpoint,
+                                     env=env,
+                                     )
 
-                        # publish_time
-                        if 'timestamp' not in feeds[i]['photo']:
-                            publish_time_stamp = 0
-                            publish_time_str = ''
-                            publish_time = 0
-                        else:
-                            publish_time_stamp = int(int(feeds[i]['photo']['timestamp']) / 1000)
-                            publish_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(publish_time_stamp))
-                            publish_time = int((int(time.time()) - publish_time_stamp) / (3600 * 24))
 
-                        # duration
-                        if 'duration' not in feeds[i]['photo']:
-                            duration = 0
-                        else:
-                            duration = int(int(feeds[i]['photo']['duration']) / 1000)
-
-                        # video_width / video_height / video_url
-                        mapping = {}
-                        for item in ['width', 'height', 'url']:
-                            try:
-                                val = str(videoResource['h264']['adaptationSet'][0]['representation'][0][item])
-                            except Exception:
-                                val = str(videoResource['hevc']['adaptationSet'][0]['representation'][0][item])
-                            except:
-                                val = ''
-                            mapping[item] = val
-                        video_width = int(mapping['width']) if mapping['width'] != '' else 0
-                        video_height = int(mapping['height']) if mapping['height'] != '' else 0
-                        video_url = mapping['url']
-
-                        # cover_url
-                        if 'coverUrl' not in feeds[i]['photo']:
-                            cover_url = ""
-                        else:
-                            cover_url = feeds[i]['photo']['coverUrl']
-
-                        # user_name / avatar_url
-                        try:
-                            user_name = feeds[i]['author']['name']
-                            avatar_url = feeds[i]['author']['headerUrl']
-                        except Exception:
-                            user_name = ''
-                            avatar_url = ''
-
-                        video_dict = {'video_title': video_title,
-                                      'video_id': video_id,
-                                      'play_cnt': play_cnt,
-                                      'comment_cnt': 0,
-                                      'like_cnt': like_cnt,
-                                      'share_cnt': 0,
-                                      'video_width': video_width,
-                                      'video_height': video_height,
-                                      'duration': duration,
-                                      'publish_time': publish_time,
-                                      'publish_time_stamp': publish_time_stamp,
-                                      'publish_time_str': publish_time_str,
-                                      'user_name': user_name,
-                                      'user_id': out_uid,
-                                      'avatar_url': avatar_url,
-                                      'cover_url': cover_url,
-                                      'video_url': video_url,
-                                      'session': f"kuaishou{int(time.time())}"}
-
-                        rule_1 = cls.download_rule(video_dict, rule_dict_1)
-                        Common.logger(log_type, crawler).info(f"video_title:{video_title}")
-                        Common.logger(log_type, crawler).info(f"video_id:{video_id}\n")
-
-                        Common.logger(log_type, crawler).info(
-                            f"play_cnt:{video_dict['play_cnt']}{rule_dict_1['play_cnt']}, {eval(str(video_dict['play_cnt']) + str(rule_dict_1['play_cnt']))}")
-                        Common.logger(log_type, crawler).info(
-                            f"like_cnt:{video_dict['like_cnt']}{rule_dict_1['like_cnt']}, {eval(str(video_dict['like_cnt']) + str(rule_dict_1['like_cnt']))}")
-                        Common.logger(log_type, crawler).info(
-                            f"video_width:{video_dict['video_width']}{rule_dict_1['video_width']}, {eval(str(video_dict['video_width']) + str(rule_dict_1['video_width']))}")
-                        Common.logger(log_type, crawler).info(
-                            f"video_height:{video_dict['video_height']}{rule_dict_1['video_height']}, {eval(str(video_dict['video_height']) + str(rule_dict_1['video_height']))}")
-                        Common.logger(log_type, crawler).info(
-                            f"duration:{video_dict['duration']}{rule_dict_1['duration']}, {eval(str(video_dict['duration']) + str(rule_dict_1['duration']))}")
-                        Common.logger(log_type, crawler).info(
-                            f"publish_time:{video_dict['publish_time']}{rule_dict_1['publish_time']}, {eval(str(video_dict['publish_time']) + str(rule_dict_1['publish_time']))}")
-                        Common.logger(log_type, crawler).info(f"rule_1:{rule_1}\n")
-
-                        rule_2 = cls.download_rule(video_dict, rule_dict_2)
-                        Common.logger(log_type, crawler).info(
-                            f"play_cnt:{video_dict['play_cnt']}{rule_dict_2['play_cnt']}, {eval(str(video_dict['play_cnt']) + str(rule_dict_2['play_cnt']))}")
-                        Common.logger(log_type, crawler).info(
-                            f"like_cnt:{video_dict['like_cnt']}{rule_dict_2['like_cnt']}, {eval(str(video_dict['like_cnt']) + str(rule_dict_2['like_cnt']))}")
-                        Common.logger(log_type, crawler).info(
-                            f"video_width:{video_dict['video_width']}{rule_dict_2['video_width']}, {eval(str(video_dict['video_width']) + str(rule_dict_2['video_width']))}")
-                        Common.logger(log_type, crawler).info(
-                            f"video_height:{video_dict['video_height']}{rule_dict_2['video_height']}, {eval(str(video_dict['video_height']) + str(rule_dict_2['video_height']))}")
-                        Common.logger(log_type, crawler).info(
-                            f"duration:{video_dict['duration']}{rule_dict_2['duration']}, {eval(str(video_dict['duration']) + str(rule_dict_2['duration']))}")
-                        Common.logger(log_type, crawler).info(
-                            f"publish_time:{video_dict['publish_time']}{rule_dict_2['publish_time']}, {eval(str(video_dict['publish_time']) + str(rule_dict_2['publish_time']))}")
-                        Common.logger(log_type, crawler).info(f"rule_2:{rule_2}\n")
-
-                        if video_title == "" or video_url == "":
-                            Common.logger(log_type, crawler).info("无效视频\n")
-                            break
-                        elif rule_1 is True:
-                            if download_cnt_1 < int(
-                                    rule_dict_1['download_cnt'].replace("=", "")[-1].replace("<", "")[-1].replace(">",
-                                                                                                                  "")[
-                                        -1]):
-                                download_finished = cls.download_publish(log_type=log_type,
-                                                                         crawler=crawler,
-                                                                         strategy=strategy,
-                                                                         video_dict=video_dict,
-                                                                         rule_dict=rule_dict_1,
-                                                                         our_uid=our_uid,
-                                                                         oss_endpoint=oss_endpoint,
-                                                                         env=env,
-                                                                         machine=machine)
-                                if download_finished is True:
-                                    download_cnt_1 += 1
-                        elif rule_2 is True:
-                            if download_cnt_2 < int(
-                                    rule_dict_2['download_cnt'].replace("=", "")[-1].replace("<", "")[-1].replace(">",
-                                                                                                                  "")[
-                                        -1]):
-                                download_finished = cls.download_publish(log_type=log_type,
-                                                                         crawler=crawler,
-                                                                         strategy=strategy,
-                                                                         video_dict=video_dict,
-                                                                         rule_dict=rule_dict_2,
-                                                                         our_uid=our_uid,
-                                                                         oss_endpoint=oss_endpoint,
-                                                                         env=env,
-                                                                         machine=machine)
-                                if download_finished is True:
-                                    download_cnt_2 += 1
-                        else:
-                            Common.logger(log_type, crawler).info("不满足下载规则\n")
-                            # Common.logger(log_type, crawler).info(f"feeds: {feeds}\n")
+            else:
+                Common.logger(log_type, crawler).info("不满足下载规则\n")
 
-                    if pcursor == "no_more":
-                        Common.logger(log_type, crawler).info("已经到底了,没有更多内容了\n")
-                        return
-        except Exception as e:
-            Common.logger(log_type, crawler).error(f"get_videoList:{e}\n")
+            # if pcursor == "no_more":
+            #     Common.logger(log_type, crawler).info(f"作者,{out_uid},已经到底了,没有更多内容了\n")
+            #     return
+            # cls.get_videoList(log_type, crawler, strategy, our_uid, out_uid, oss_endpoint, env,
+            #               pcursor=pcursor)
+            # time.sleep(random.randint(1, 3))
 
     @classmethod
-    def repeat_video(cls, log_type, crawler, video_id, video_title, publish_time, env, machine):
+    def repeat_video(cls, log_type, crawler, video_id, video_title, publish_time, env):
         sql = f""" select * from crawler_video where platform="{cls.platform}" and out_video_id="{video_id}" or (platform="{cls.platform}" and video_title="{video_title}" and publish_time="{publish_time}") """
-        repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env, machine)
+        repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env)
         return len(repeat_video)
 
     @classmethod
-    def download_publish(cls, log_type, crawler, strategy, video_dict, rule_dict, our_uid, oss_endpoint, env, machine):
+    def download_publish(cls, log_type, crawler, strategy, video_dict, rule_dict, our_uid, oss_endpoint, env):
         try:
-            download_finished = False
+            filter_words = get_config_from_mysql(log_type, crawler, env, text='filter')
+            for filter_word in filter_words:
+                if filter_word in video_dict['video_title']:
+                    Common.logger(log_type, crawler).info('标题已中过滤词:{}\n', video_dict['video_title'])
+                    return
             if cls.repeat_video(log_type, crawler, video_dict['video_id'], video_dict['video_title'],
-                                video_dict['publish_time_str'], 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, "3cd128") for x in y]:
+                                video_dict['publish_time_str'], env) != 0:
                 Common.logger(log_type, crawler).info('视频已下载\n')
-            elif any(word if word in video_dict['video_title'] else False for word in
-                     cls.filter_words(log_type, crawler)) is True:
-                Common.logger(log_type, crawler).info('标题已中过滤词\n')
             else:
                 # 下载视频
                 Common.download_method(log_type=log_type, crawler=crawler, text='video',
@@ -693,7 +494,7 @@ class Follow:
                     Common.logger(log_type, crawler).warning(f"our_video_id:{our_video_id} 删除该视频文件夹")
                     # 删除视频文件夹
                     shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
-                    return download_finished
+                    return
 
                 # 视频信息保存数据库
                 insert_sql = f""" insert into crawler_video(video_id,
@@ -727,7 +528,7 @@ class Follow:
                                                         {int(video_dict['video_width'])},
                                                         {int(video_dict['video_height'])}) """
                 Common.logger(log_type, crawler).info(f"insert_sql:{insert_sql}")
-                MysqlHelper.update_values(log_type, crawler, insert_sql, env, machine)
+                MysqlHelper.update_values(log_type, crawler, insert_sql, env)
                 Common.logger(log_type, crawler).info('视频信息插入数据库成功!\n')
 
                 # 视频写入飞书
@@ -755,43 +556,41 @@ class Follow:
                 Feishu.update_values(log_type, 'kuaishou', "fYdA8F", "E2:Z2", values)
                 Common.logger(log_type, crawler).info(f"视频已保存至云文档\n")
                 download_finished = True
-            return download_finished
+            return
         except Exception as e:
             Common.logger(log_type, crawler).error(f"download_publish:{e}\n")
 
     @classmethod
-    def get_follow_videos(cls, log_type, crawler, strategy, oss_endpoint, env, machine):
-        user_list = cls.get_user_list(log_type=log_type, crawler=crawler, sheetid="bTSzxW", env=env, machine=machine)
+    def get_follow_videos(cls, log_type, crawler, task, oss_endpoint, env):
+        user_list = get_user_from_mysql(log_type, crawler, crawler, env)
+        strategy = '定向抓取策略'
         for user in user_list:
-            out_uid = user["out_uid"]
-            user_name = user["user_name"]
-            our_uid = user["our_uid"]
-            Common.logger(log_type, crawler).info(f"开始抓取 {user_name} 用户主页视频\n")
-            cls.get_videoList(log_type=log_type,
-                              crawler=crawler,
-                              strategy=strategy,
-                              our_uid=our_uid,
-                              out_uid=out_uid,
-                              oss_endpoint=oss_endpoint,
-                              env=env,
-                              machine=machine)
-            sleep_time = 120
-            Common.logger(log_type, crawler).info(f"休眠{sleep_time}秒\n")
-            time.sleep(sleep_time)
+            try:
+                spider_link = user["link"]
+                out_uid = spider_link.split('/')[-1]
+                user_name = user["nick_name"]
+                our_uid = user["uid"]
+                Common.logger(log_type, crawler).info(f"开始抓取 {user_name} 用户主页视频\n")
+                cls.get_videoList(log_type=log_type,
+                                  crawler=crawler,
+                                  strategy=strategy,
+                                  task=task,
+                                  our_uid=our_uid,
+                                  out_uid=out_uid,
+                                  oss_endpoint=oss_endpoint,
+                                  env=env)
+            except Exception as e:
+                continue
 
 
 if __name__ == "__main__":
-    # Follow.get_videoList(log_type="follow",
-    #                      crawler="kuaishou",
-    #                      strategy="定向爬虫策略",
-    #                      our_uid="6282431",
-    #                      out_uid="3xws7ydsnmp5mgq",
-    #                      oss_endpoint="out",
-    #                      env="dev",
-    #                      machine="local")
-    # print(Follow.get_out_user_info("follow", "kuaishou", "3xgh4ja9be3wcaw"))
+    KuaiShouFollowScheduling.get_follow_videos(
+        log_type="follow",
+        crawler="kuaishou",
+        task="",
+        oss_endpoint="out",
+        env="dev",
+    )
+
+    # print(KuaiShouFollow.get_out_user_info("follow", "kuaishou", "3xnk3wbm3vfiha6"))
     # print(Follow.get_out_user_info("follow", "kuaishou", "3x5wgjhfc7tx8ue"))
-    print(Follow.get_cookie("cookies", "kuaishou", "3xvp5w6twj77xeq", "local"))
-    print(Follow.get_cookie("cookies", "kuaishou", "3xgh4ja9be3wcaw", "local"))
-    print(Follow.get_cookie("cookies", "kuaishou", "3x5wgjhfc7tx8ue", "local"))
-    pass

+ 40 - 32
kuaishou/kuaishou_main/run_kuaishou_follow_scheduling.py

@@ -1,49 +1,57 @@
 # -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2023/2/27
+# @Author: lierqiang
+# @Time: 2023/4/21
 import argparse
 import os
 import sys
-# import time
 
 sys.path.append(os.getcwd())
 from common.common import Common
-# from common.feishu import Feishu
-from kuaishou.kuaishou_follow.kuaishou_follow_scheduling import Follow
+from kuaishou.kuaishou_follow.kuaishou_follow_scheduling import KuaiShouFollowScheduling
+from common.public import task_fun
 
 
-def main(log_type, crawler, strategy, oss_endpoint, env, machine):
-    while True:
-        try:
-            Common.logger(log_type, crawler).info('开始抓取 快手 定向榜\n')
-            Follow.get_follow_videos(log_type=log_type,
-                                     crawler=crawler,
-                                     strategy=strategy,
-                                     oss_endpoint=oss_endpoint,
-                                     env=env,
-                                     machine=machine)
-            Common.del_logs(log_type, crawler)
-            Common.logger(log_type, crawler).info('抓取完一轮\n')
-            break
-        except Exception as e:
-            Common.logger(log_type, crawler).info(f"快手定向榜异常,触发报警:{e}\n")
-            # Feishu.bot(log_type, crawler, f"快手定向榜异常,触发报警:{e}")
+def main(log_type, crawler, task, oss_endpoint, env):
+    task = task_fun(task)
+    try:
+        Common.logger(log_type, crawler).info(f'开始抓取 {crawler}视频 定向榜\n')
+        KuaiShouFollowScheduling.get_follow_videos(log_type=log_type,
+                                             crawler=crawler,
+                                             task=task,
+                                             oss_endpoint=oss_endpoint,
+                                             env=env)
+        Common.del_logs(log_type, crawler)
+        Common.logger(log_type, crawler).info('抓取任务结束\n')
+    except Exception as e:
+        Common.logger(log_type, crawler).info(f"{crawler}视频异常,触发报警:{e}\n")
+        # Feishu.bot(log_type, crawler, f"{e}")
 
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()  ## 新建参数解释器对象
-    parser.add_argument('--log_type', type=str)  ## 添加参数,注明参数类型
-    parser.add_argument('--crawler')  ## 添加参数
-    parser.add_argument('--strategy')  ## 添加参数
-    parser.add_argument('--our_uid')  ## 添加参数
-    parser.add_argument('--oss_endpoint')  ## 添加参数
-    parser.add_argument('--env')  ## 添加参数
-    parser.add_argument('--machine')  ## 添加参数
+    parser.add_argument('--log_type', default='author')  ## 添加参数,注明参数类型
+    parser.add_argument('--crawler', default='kuaishou')  ## 添加参数
+    parser.add_argument('--strategy', default='定向抓取')  ## 添加参数
+    parser.add_argument('--task')  ## 添加参数
+    parser.add_argument('--oss_endpoint', default='outer')  ## 添加参数
+    parser.add_argument('--env', default='dev')  ## 添加参数
+    # parser.add_argument('--machine')  ## 添加参数
     args = parser.parse_args()  ### 参数赋值,也可以通过终端赋值
-    # print(args)
+    task = {
+        'task_dict': {'task_id': '17', 'task_name': '西瓜测试4.21', 'source': 'kuaishou', 'start_time': '1682010720000',
+                      'interval': '24', 'mode': 'author',
+                      'rule': {'duration': {'min': 40, 'max': 0}, 'play_cnt': {'min': 4000, 'max': 0},
+                               'period': {'min': 10, 'max': 0}, 'fans_cnt': {'min': 0, 'max': 0},
+                               'videos_cnt': {'min': 0, 'max': 0}, 'like_cnt': {'min': 0, 'max': 0},
+                               'width': {'min': 0, 'max': 0}, 'height': {'min': 0, 'max': 0}},
+                      'spider_name': 'run_dy_author_scheduling', 'machine': 'aliyun', 'status': '0',
+                      'create_time': '1682048632396', 'update_time': '1682048632396', 'operator': ''},
+        'rule_dict': {'duration': {'min': 0, 'max': 0}, 'play_cnt': {'min': 0, 'max': 0},
+                      'period': {'min': 0, 'max': 0}, 'fans_cnt': {'min': 0, 'max': 0}, 'videos_cnt': {'min': 0, 'max': 0},
+                      'like_cnt': {'min': 0, 'max': 0}, 'width': {'min': 0, 'max': 0},
+                      'height': {'min': 0, 'max': 0},'publish_time':{'min':0}}}
     main(log_type=args.log_type,
          crawler=args.crawler,
-         strategy=args.strategy,
+         task=task,
          oss_endpoint=args.oss_endpoint,
-         env=args.env,
-         machine=args.machine)
+         env=args.env)

+ 57 - 0
kuaishou/kuaishou_main/run_kuaishou_recommend_scheduling.py

@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+# @Author: lierqiang
+# @Time: 2023/4/21
+import argparse
+import os
+import sys
+
+sys.path.append(os.getcwd())
+from common.common import Common
+from kuaishou.kuaishou_recommend.kuaishou_recommend_shceduling import KuaiShouRecommendScheduling
+from common.public import task_fun
+
+
+def main(log_type, crawler, task, oss_endpoint, env):
+    task = task_fun(task)
+    try:
+        Common.logger(log_type, crawler).info(f'开始抓取 {crawler}视频 推荐榜\n')
+        KuaiShouRecommendScheduling.get_recommend_videos(log_type=log_type,
+                                             crawler=crawler,
+                                             task=task,
+                                             oss_endpoint=oss_endpoint,
+                                             env=env)
+        Common.del_logs(log_type, crawler)
+        Common.logger(log_type, crawler).info('抓取任务结束\n')
+    except Exception as e:
+        Common.logger(log_type, crawler).info(f"{crawler}视频异常,触发报警:{e}\n")
+        # Feishu.bot(log_type, crawler, f"{e}")
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()  ## 新建参数解释器对象
+    parser.add_argument('--log_type', default='author')  ## 添加参数,注明参数类型
+    parser.add_argument('--crawler', default='kuaishou')  ## 添加参数
+    parser.add_argument('--strategy', default='定向抓取')  ## 添加参数
+    parser.add_argument('--task')  ## 添加参数
+    parser.add_argument('--oss_endpoint', default='outer')  ## 添加参数
+    parser.add_argument('--env', default='dev')  ## 添加参数
+    # parser.add_argument('--machine')  ## 添加参数
+    args = parser.parse_args()  ### 参数赋值,也可以通过终端赋值
+    task = {
+        'task_dict': {'task_id': '17', 'task_name': '西瓜测试4.21', 'source': 'kuaishou', 'start_time': '1682010720000',
+                      'interval': '24', 'mode': 'author',
+                      'rule': {'duration': {'min': 40, 'max': 0}, 'play_cnt': {'min': 4000, 'max': 0},
+                               'period': {'min': 10, 'max': 0}, 'fans_cnt': {'min': 0, 'max': 0},
+                               'videos_cnt': {'min': 0, 'max': 0}, 'like_cnt': {'min': 0, 'max': 0},
+                               'width': {'min': 0, 'max': 0}, 'height': {'min': 0, 'max': 0}},
+                      'spider_name': 'run_dy_author_scheduling', 'machine': 'aliyun', 'status': '0',
+                      'create_time': '1682048632396', 'update_time': '1682048632396', 'operator': ''},
+        'rule_dict': {'duration': {'min': 0, 'max': 0}, 'play_cnt': {'min': 0, 'max': 0},
+                      'period': {'min': 0, 'max': 0}, 'fans_cnt': {'min': 0, 'max': 0}, 'videos_cnt': {'min': 0, 'max': 0},
+                      'like_cnt': {'min': 0, 'max': 0}, 'width': {'min': 0, 'max': 0},
+                      'height': {'min': 0, 'max': 0},'publish_time':{'min':0}}}
+    main(log_type=args.log_type,
+         crawler=args.crawler,
+         task=task,
+         oss_endpoint=args.oss_endpoint,
+         env=args.env)

+ 503 - 0
kuaishou/kuaishou_recommend/kuaishou_recommend_shceduling.py

@@ -0,0 +1,503 @@
+# -*- coding: utf-8 -*-
+# @Author: wangkun
+# @Time: 2023/2/24
+import os
+import random
+import shutil
+import sys
+import time
+import string
+from hashlib import md5
+
+import requests
+import json
+
+import urllib3
+from requests.adapters import HTTPAdapter
+
+sys.path.append(os.getcwd())
+from common.common import Common
+from common.feishu import Feishu
+from common.getuser import getUser
+# from common.db import MysqlHelper
+from common.scheduling_db import MysqlHelper
+from common.publish import Publish
+from common.public import get_user_from_mysql, random_title, get_config_from_mysql
+from common.userAgent import get_random_user_agent
+
+
+class KuaiShouRecommendScheduling:
+    platform = "快手"
+    tag = "快手爬虫,推荐爬虫策略"
+
+    @classmethod
+    def get_rule(cls, log_type, crawler):
+        try:
+            rule_sheet = Feishu.get_values_batch(log_type, crawler, "NQ6CZN")
+            rule_dict = {
+                "play_cnt": f"{rule_sheet[0][1]}{rule_sheet[0][2]}",
+                "video_width": f"{rule_sheet[1][1]}{rule_sheet[1][2]}",
+                "video_height": f"{rule_sheet[2][1]}{rule_sheet[2][2]}",
+                "like_cnt": f"{rule_sheet[5][1]}{rule_sheet[5][2]}",
+                "duration": f"{rule_sheet[3][1]}{rule_sheet[3][2]}",
+                "publish_time": f"{rule_sheet[4][1]}{rule_sheet[4][2]}",
+            }
+            return rule_dict
+        except Exception as e:
+            Common.logger(log_type, crawler).error(f"get_rule:{e}\n")
+
+    @classmethod
+    def download_rule(cls, video_dict, rule_dict):
+        if video_dict['like_cnt'] >= rule_dict['like_cnt']['min']:
+            if video_dict['publish_time'] >= rule_dict['publish_time']['min']:
+                if video_dict['duration'] >= rule_dict['duration']['min']:
+                    if video_dict['video_width'] >= rule_dict['width']['min'] \
+                            or video_dict['video_height'] >= rule_dict['height']['min']:
+                        return True
+                    else:
+                        return False
+                else:
+                    return False
+            else:
+                return False
+        else:
+            return False
+
+    # 过滤词库
+    @classmethod
+    def filter_words(cls, log_type, crawler):
+        try:
+            while True:
+                filter_words_sheet = Feishu.get_values_batch(log_type, crawler, 'HIKVvs')
+                if filter_words_sheet is None:
+                    Common.logger(log_type, crawler).warning(f"filter_words_sheet:{filter_words_sheet} 10秒钟后重试")
+                    continue
+                filter_words_list = []
+                for x in filter_words_sheet:
+                    for y in x:
+                        if y is None:
+                            pass
+                        else:
+                            filter_words_list.append(y)
+                return filter_words_list
+        except Exception as e:
+            Common.logger(log_type, crawler).error(f'filter_words异常:{e}\n')
+
+    # 获取用户信息列表
+    @classmethod
+    def get_user_list(cls, log_type, crawler, sheetid, env):
+        try:
+            while True:
+                user_sheet = Feishu.get_values_batch(log_type, crawler, sheetid)
+                if user_sheet is None:
+                    Common.logger(log_type, crawler).warning(f"user_sheet:{user_sheet} 10秒钟后重试")
+                    continue
+                our_user_list = []
+                for i in range(1, len(user_sheet)):
+                    # for i in range(1, 2):
+                    out_uid = user_sheet[i][2]
+                    user_name = user_sheet[i][3]
+                    our_uid = user_sheet[i][6]
+                    our_user_link = user_sheet[i][7]
+                    if out_uid is None or user_name is None:
+                        Common.logger(log_type, crawler).info("空行\n")
+                    else:
+                        Common.logger(log_type, crawler).info(f"正在更新 {user_name} 用户信息\n")
+                        if our_uid is None:
+                            out_user_info = cls.get_out_user_info(log_type, crawler, out_uid)
+                            out_user_dict = {
+                                "out_uid": out_uid,
+                                "user_name": user_name,
+                                "out_avatar_url": out_user_info["out_avatar_url"],
+                                "out_create_time": '',
+                                "out_tag": '',
+                                "out_play_cnt": 0,
+                                "out_fans": out_user_info["out_fans"],
+                                "out_follow": out_user_info["out_follow"],
+                                "out_friend": 0,
+                                "out_like": 0,
+                                "platform": cls.platform,
+                                "tag": cls.tag,
+                            }
+                            our_user_dict = getUser.create_user(log_type=log_type, crawler=crawler,
+                                                                out_user_dict=out_user_dict, env=env)
+                            our_uid = our_user_dict['our_uid']
+                            our_user_link = our_user_dict['our_user_link']
+                            Feishu.update_values(log_type, crawler, sheetid, f'G{i + 1}:H{i + 1}',
+                                                 [[our_uid, our_user_link]])
+                            Common.logger(log_type, crawler).info(f'站内用户信息写入飞书成功!\n')
+                            our_user_list.append(our_user_dict)
+                        else:
+                            our_user_dict = {
+                                'out_uid': out_uid,
+                                'user_name': user_name,
+                                'our_uid': our_uid,
+                                'our_user_link': our_user_link,
+                            }
+                            our_user_list.append(our_user_dict)
+                return our_user_list
+        except Exception as e:
+            Common.logger(log_type, crawler).error(f'get_user_list:{e}\n')
+
+    # 处理视频标题
+    @classmethod
+    def video_title(cls, log_type, crawler, env, title):
+        title_split1 = title.split(" #")
+        if title_split1[0] != "":
+            title1 = title_split1[0]
+        else:
+            title1 = title_split1[-1]
+
+        title_split2 = title1.split(" #")
+        if title_split2[0] != "":
+            title2 = title_split2[0]
+        else:
+            title2 = title_split2[-1]
+
+        title_split3 = title2.split("@")
+        if title_split3[0] != "":
+            title3 = title_split3[0]
+        else:
+            title3 = title_split3[-1]
+
+        video_title = title3.strip().replace("\n", "") \
+                          .replace("/", "").replace("快手", "").replace(" ", "") \
+                          .replace(" ", "").replace("&NBSP", "").replace("\r", "") \
+                          .replace("#", "").replace(".", "。").replace("\\", "") \
+                          .replace(":", "").replace("*", "").replace("?", "") \
+                          .replace("?", "").replace('"', "").replace("<", "") \
+                          .replace(">", "").replace("|", "").replace("@", "").replace('"', '').replace("'", '')[:40]
+        if video_title.replace(" ", "") == "" or video_title == "。。。" or video_title == "...":
+            return random_title(log_type, crawler, env, text='title')
+        else:
+            return video_title
+
+    @classmethod
+    def get_videoList(cls, log_type, crawler, strategy, task, our_uid, oss_endpoint, env):
+        rule_dict_1 = task['rule_dict']
+        for i in range(100):
+            url = "https://www.kuaishou.com/graphql"
+
+            payload = json.dumps({
+                "operationName": "visionNewRecoFeed",
+                "variables": {
+                    "dailyFirstPage": False
+                },
+                "query": "fragment photoContent on PhotoEntity {\n  id\n  duration\n  caption\n  originCaption\n  likeCount\n  viewCount\n  realLikeCount\n  coverUrl\n  photoUrl\n  photoH265Url\n  manifest\n  manifestH265\n  videoResource\n  coverUrls {\n    url\n    __typename\n  }\n  timestamp\n  expTag\n  animatedCoverUrl\n  distance\n  videoRatio\n  liked\n  stereoType\n  profileUserTopPhoto\n  musicBlocked\n  __typename\n}\n\nfragment feedContent on Feed {\n  type\n  author {\n    id\n    name\n    headerUrl\n    following\n    headerUrls {\n      url\n      __typename\n    }\n    __typename\n  }\n  photo {\n    ...photoContent\n    __typename\n  }\n  canAddComment\n  llsid\n  status\n  currentPcursor\n  tags {\n    type\n    name\n    __typename\n  }\n  __typename\n}\n\nfragment photoResult on PhotoResult {\n  result\n  llsid\n  expTag\n  serverExpTag\n  pcursor\n  feeds {\n    ...feedContent\n    __typename\n  }\n  webPageArea\n  __typename\n}\n\nquery visionNewRecoFeed($semKeyword: String, $semCrowd: String, $utmSource: String, $utmMedium: String, $utmCampaign: String, $dailyFirstPage: Boolean) {\n  visionNewRecoFeed(semKeyword: $semKeyword, semCrowd: $semCrowd, utmSource: $utmSource, utmMedium: $utmMedium, utmCampaign: $utmCampaign, dailyFirstPage: $dailyFirstPage) {\n    ...photoResult\n    __typename\n  }\n}\n"
+            })
+            s = string.ascii_lowercase
+            r = random.choice(s)
+
+            headers = {
+                'Accept-Language': 'zh-CN,zh;q=0.9',
+                'Connection': 'keep-alive',
+                'Cookie': 'kpf=PC_WEB; clientid=3; did=web_aba004b1780f4d7174d0a2ff42da1f{r}7; kpn=KUAISHOU_VISION;'.format(
+                    r=r),
+                'Origin': 'https://www.kuaishou.com',
+                'Referer': 'https://www.kuaishou.com/new-reco',
+                'Sec-Fetch-Dest': 'empty',
+                'Sec-Fetch-Mode': 'cors',
+                'Sec-Fetch-Site': 'same-origin',
+                'User-Agent': get_random_user_agent('pc'),
+                'accept': '*/*',
+                'content-type': 'application/json',
+                'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
+                'sec-ch-ua-mobile': '?0',
+                'sec-ch-ua-platform': '"macOS"'
+            }
+
+            try:
+                urllib3.disable_warnings()
+                s = requests.session()
+                # max_retries=3 重试3次
+                s.mount('http://', HTTPAdapter(max_retries=3))
+                s.mount('https://', HTTPAdapter(max_retries=3))
+                response = s.post(url=url, headers=headers, data=payload, proxies=Common.tunnel_proxies(), verify=False,
+                                  timeout=10)
+                response.close()
+            except Exception as e:
+                Common.logger(log_type, crawler).error(f"get_videoList:{e}\n")
+                continue
+            # Common.logger(log_type, crawler).info(f"get_videoList:{response.text}\n")
+            if response.status_code != 200:
+                Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.text}\n")
+                continue
+            elif 'data' not in response.json():
+                Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.json()}\n")
+                continue
+            elif 'visionNewRecoFeed' not in response.json()['data']:
+                Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.json()['data']}\n")
+                continue
+            elif 'feeds' not in response.json()['data']['visionNewRecoFeed']:
+                Common.logger(log_type, crawler).warning(
+                    f"get_videoList_response:{response.json()['data']['visionNewRecoFeed']}\n")
+                continue
+            elif len(response.json()['data']['visionNewRecoFeed']['feeds']) == 0:
+                Common.logger(log_type, crawler).info("没有更多视频啦 ~\n")
+                continue
+            else:
+                feeds = response.json()['data']['visionNewRecoFeed']['feeds']
+                for i in range(len(feeds)):
+                    if 'photo' not in feeds[i]:
+                        Common.logger(log_type, crawler).warning(f"get_videoList:{feeds[i]}\n")
+                        continue
+
+                    # video_title
+                    if 'caption' not in feeds[i]['photo']:
+                        video_title = random_title(log_type, crawler, env, text='title')
+
+                    elif feeds[i]['photo']['caption'].strip() == "":
+                        video_title = random_title(log_type, crawler, env, text='title')
+                    else:
+                        video_title = cls.video_title(log_type, crawler, env, feeds[i]['photo']['caption'])
+
+                    if 'videoResource' not in feeds[i]['photo'] \
+                            and 'manifest' not in feeds[i]['photo'] \
+                            and 'manifestH265' not in feeds[i]['photo']:
+                        Common.logger(log_type, crawler).warning(f"get_videoList:{feeds[i]['photo']}\n")
+                        continue
+                    videoResource = feeds[i]['photo']['videoResource']
+
+                    if 'h264' not in videoResource and 'hevc' not in videoResource:
+                        Common.logger(log_type, crawler).warning(f"get_videoList:{videoResource}\n")
+                        continue
+
+                    # video_id
+                    if 'h264' in videoResource and 'videoId' in videoResource['h264']:
+                        video_id = videoResource['h264']['videoId']
+                    elif 'hevc' in videoResource and 'videoId' in videoResource['hevc']:
+                        video_id = videoResource['hevc']['videoId']
+                    else:
+                        video_id = ""
+
+                    # play_cnt
+                    if 'viewCount' not in feeds[i]['photo']:
+                        play_cnt = 0
+                    else:
+                        play_cnt = int(feeds[i]['photo']['viewCount'])
+
+                    # like_cnt
+                    if 'realLikeCount' not in feeds[i]['photo']:
+                        like_cnt = 0
+                    else:
+                        like_cnt = feeds[i]['photo']['realLikeCount']
+
+                    # publish_time
+                    if 'timestamp' not in feeds[i]['photo']:
+                        publish_time_stamp = 0
+                        publish_time_str = ''
+                        publish_time = 0
+                    else:
+                        publish_time_stamp = int(int(feeds[i]['photo']['timestamp']) / 1000)
+                        publish_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(publish_time_stamp))
+                        publish_time = int((int(time.time()) - publish_time_stamp) / (3600 * 24))
+
+                    # duration
+                    if 'duration' not in feeds[i]['photo']:
+                        duration = 0
+                    else:
+                        duration = int(int(feeds[i]['photo']['duration']) / 1000)
+
+                    # video_width / video_height / video_url
+                    mapping = {}
+                    for item in ['width', 'height']:
+                        try:
+                            val = str(videoResource['h264']['adaptationSet'][0]['representation'][0][item])
+                        except Exception:
+                            val = str(videoResource['hevc']['adaptationSet'][0]['representation'][0][item])
+                        except:
+                            val = ''
+                        mapping[item] = val
+                    video_width = int(mapping['width']) if mapping['width'] != '' else 0
+                    video_height = int(mapping['height']) if mapping['height'] != '' else 0
+                    # cover_url
+                    if 'coverUrl' not in feeds[i]['photo']:
+                        cover_url = ""
+                    else:
+                        cover_url = feeds[i]['photo']['coverUrl']
+
+                    # user_name / avatar_url
+                    try:
+                        user_name = feeds[i]['author']['name']
+                        avatar_url = feeds[i]['author']['headerUrl']
+                        user_id = feeds[i]['author']['id']
+                    except Exception:
+                        user_name = ''
+                        avatar_url = ''
+                        user_id = ''
+                    video_url = feeds[i]['photo']['photoUrl']
+                    video_dict = {'video_title': video_title,
+                                  'video_id': video_id,
+                                  'play_cnt': play_cnt,
+                                  'comment_cnt': 0,
+                                  'like_cnt': like_cnt,
+                                  'share_cnt': 0,
+                                  'video_width': video_width,
+                                  'video_height': video_height,
+                                  'duration': duration,
+                                  'publish_time': publish_time,
+                                  'publish_time_stamp': publish_time_stamp,
+                                  'publish_time_str': publish_time_str,
+                                  'user_name': user_name,
+                                  'user_id': user_id,
+                                  'avatar_url': avatar_url,
+                                  'cover_url': cover_url,
+                                  'video_url': video_url,
+                                  'session': f"kuaishou{int(time.time())}"}
+
+                    rule_1 = cls.download_rule(video_dict, rule_dict_1)
+
+                    if rule_1 is True:
+                        cls.download_publish(log_type=log_type,
+                                             crawler=crawler,
+                                             strategy=strategy,
+                                             video_dict=video_dict,
+                                             rule_dict=rule_dict_1,
+                                             our_uid=our_uid,
+                                             oss_endpoint=oss_endpoint,
+                                             env=env,
+                                             )
+
+                    else:
+                        Common.logger(log_type, crawler).info("不满足下载规则\n")
+
+    @classmethod
+    def repeat_video(cls, log_type, crawler, video_id, video_title, publish_time, env):
+        sql = f""" select * from crawler_video where platform="{cls.platform}" and out_video_id="{video_id}" or (platform="{cls.platform}" and video_title="{video_title}" and publish_time="{publish_time}") """
+        repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env)
+        return len(repeat_video)
+
+    @classmethod
+    def download_publish(cls, log_type, crawler, strategy, video_dict, rule_dict, our_uid, oss_endpoint, env):
+        try:
+            filter_words = get_config_from_mysql(log_type, crawler, env, text='filter')
+            for filter_word in filter_words:
+                if filter_word in video_dict['video_title']:
+                    Common.logger(log_type, crawler).info('标题已中过滤词:{}\n', video_dict['video_title'])
+                    return
+            download_finished = False
+            if cls.repeat_video(log_type, crawler, video_dict['video_id'], video_dict['video_title'],
+                                video_dict['publish_time_str'], env) != 0:
+                Common.logger(log_type, crawler).info('视频已下载\n')
+            else:
+                # 下载视频
+                Common.download_method(log_type=log_type, crawler=crawler, text='video',
+                                       title=video_dict['video_title'], url=video_dict['video_url'])
+                md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
+                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
+                # 下载封面
+                Common.download_method(log_type=log_type, crawler=crawler, text='cover',
+                                       title=video_dict['video_title'], url=video_dict['cover_url'])
+                # 保存视频信息至txt
+                Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
+
+                # 上传视频
+                Common.logger(log_type, crawler).info("开始上传视频...")
+                our_video_id = Publish.upload_and_publish(log_type=log_type,
+                                                          crawler=crawler,
+                                                          strategy=strategy,
+                                                          our_uid=our_uid,
+                                                          env=env,
+                                                          oss_endpoint=oss_endpoint)
+                if env == 'dev':
+                    our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
+                else:
+                    our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
+                Common.logger(log_type, crawler).info("视频上传完成")
+
+                if our_video_id is None:
+                    Common.logger(log_type, crawler).warning(f"our_video_id:{our_video_id} 删除该视频文件夹")
+                    # 删除视频文件夹
+                    shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
+                    return download_finished
+
+                # 视频信息保存数据库
+                insert_sql = f""" insert into crawler_video(video_id,
+                                                        user_id,
+                                                        out_user_id,
+                                                        platform,
+                                                        strategy,
+                                                        out_video_id,
+                                                        video_title,
+                                                        cover_url,
+                                                        video_url,
+                                                        duration,
+                                                        publish_time,
+                                                        play_cnt,
+                                                        crawler_rule,
+                                                        width,
+                                                        height)
+                                                        values({our_video_id},
+                                                        {our_uid},
+                                                        "{video_dict['user_id']}",
+                                                        "{cls.platform}",
+                                                        "{strategy}",
+                                                        "{video_dict['video_id']}",
+                                                        "{video_dict['video_title']}",
+                                                        "{video_dict['cover_url']}",
+                                                        "{video_dict['video_url']}",
+                                                        {int(video_dict['duration'])},
+                                                        "{video_dict['publish_time_str']}",
+                                                        {int(video_dict['play_cnt'])},
+                                                        '{json.dumps(rule_dict)}',
+                                                        {int(video_dict['video_width'])},
+                                                        {int(video_dict['video_height'])}) """
+                Common.logger(log_type, crawler).info(f"insert_sql:{insert_sql}")
+                MysqlHelper.update_values(log_type, crawler, insert_sql, env)
+                Common.logger(log_type, crawler).info('视频信息插入数据库成功!\n')
+
+                # 视频写入飞书
+                Feishu.insert_columns(log_type, 'kuaishou', "Aps2BI", "ROWS", 1, 2)
+                upload_time = int(time.time())
+                values = [[our_video_id,
+                           time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(upload_time)),
+                           strategy,
+                           str(video_dict['video_id']),
+                           video_dict['video_title'],
+                           our_video_link,
+                           video_dict['play_cnt'],
+                           video_dict['comment_cnt'],
+                           video_dict['like_cnt'],
+                           video_dict['share_cnt'],
+                           video_dict['duration'],
+                           f"{video_dict['video_width']}*{video_dict['video_height']}",
+                           video_dict['publish_time_str'],
+                           video_dict['user_name'],
+                           video_dict['user_id'],
+                           video_dict['avatar_url'],
+                           video_dict['cover_url'],
+                           video_dict['video_url']]]
+                time.sleep(1)
+                Feishu.update_values(log_type, 'kuaishou', "Aps2BI", "E2:Z2", values)
+                Common.logger(log_type, crawler).info(f"视频已保存至云文档\n")
+                download_finished = True
+            return download_finished
+        except Exception as e:
+            Common.logger(log_type, crawler).error(f"download_publish:{e}\n")
+
+    @classmethod
+    def get_recommend_videos(cls, log_type, crawler, task, oss_endpoint, env):
+        user_list = get_user_from_mysql(log_type, crawler, crawler, env)
+        strategy = '推荐抓取策略'
+        for user in user_list:
+            spider_link = user["link"]
+            out_uid = spider_link
+            user_name = user["nick_name"]
+            our_uid = user["uid"]
+            Common.logger(log_type, crawler).info(f"开始抓取 {user_name} 用户主页视频\n")
+            cls.get_videoList(log_type=log_type,
+                              crawler=crawler,
+                              strategy=strategy,
+                              task=task,
+                              our_uid=our_uid,
+                              oss_endpoint=oss_endpoint,
+                              env=env)
+
+
+if __name__ == "__main__":
+    task = ''
+    KuaiShouRecommendScheduling.get_recommend_videos('recommend', 'kuaishou', task, 'outer', 'prod')

+ 148 - 173
xigua/xigua_follow/xigua_follow_scheduling.py

@@ -15,18 +15,40 @@ from hashlib import md5
 import requests
 import urllib3
 from requests.adapters import HTTPAdapter
+
 sys.path.append(os.getcwd())
-from common.scheduling_db import  MysqlHelper
+from common.scheduling_db import MysqlHelper
 from common.common import Common
 from common.feishu import Feishu
 from common.publish import Publish
+from common.public import get_user_from_mysql, get_config_from_mysql, download_rule
 
 
-class SchedulingFollow:
+class ScheduleXiguaFollow:
     # 个人主页视频翻页参数
     offset = 0
     platform = "西瓜视频"
 
+    @classmethod
+    def download_rule(cls, video_info_dict, rule_dict):
+        if video_info_dict['play_cnt'] >= rule_dict['play_cnt']['min']:
+            if video_info_dict['comment_cnt'] >= rule_dict['comment_cnt']['min']:
+                if video_info_dict['like_cnt'] >= rule_dict['like_cnt']['min']:
+                    if video_info_dict['duration'] >= rule_dict['duration']['min']:
+                        if video_info_dict['video_width'] >= rule_dict['width']['min'] \
+                                or video_info_dict['video_height'] >= rule_dict['height']['min']:
+                            return True
+                        else:
+                            return False
+                    else:
+                        return False
+                else:
+                    return False
+            else:
+                return False
+        else:
+            return False
+
     @classmethod
     def get_users(cls, log_type, crawler, task, env):
         link_list = task['spider_link']
@@ -50,64 +72,6 @@ class SchedulingFollow:
         Common.logger(log_type, crawler).info(f"user_list:{user_list}")
         return user_list
 
-    # 下载规则
-    @classmethod
-    def download_rule_scheduling(cls, video_info_dict, task):
-        try:
-            play_cnt_min = int(task['play_cnt']['min'])
-        except:
-            play_cnt_min = 0
-
-        try:
-            video_like_min = int(task['video_like']['min'])
-        except:
-            video_like_min = 0
-
-        try:
-            share_cnt_min = int(task['share_cnt']['min'])
-        except:
-            share_cnt_min = 0
-
-        try:
-            video_width_min = int(task['video_width']['min'])
-        except:
-            video_width_min = 0
-
-        try:
-            video_height_min = task['video_height']['min']
-        except:
-            video_height_min = 0
-
-        try:
-            duration_min = int(task['duration_min'])
-        except:
-            duration_min = 0
-
-        try:
-            duration_max = int(task['duration_max'])
-        except:
-            duration_max = 1000000000
-
-        if int(video_info_dict['play_cnt']) >= play_cnt_min:
-            if int(video_info_dict['like_cnt']) >= video_like_min:
-                if int(video_info_dict['share_cnt']) >= share_cnt_min:
-                    if duration_max >= int(video_info_dict['duration']) >= duration_min:
-                        if int(video_info_dict['video_width']) >= video_width_min:
-                            if int(video_info_dict['video_height']) >= video_height_min:
-                                return True
-                            else:
-                                return False
-                        else:
-                            return False
-                    else:
-                        return False
-                else:
-                    return False
-            else:
-                return False
-        else:
-            return False
-
     # 过滤词库
     @classmethod
     def filter_words(cls, log_type, crawler):
@@ -197,7 +161,8 @@ class SchedulingFollow:
             # max_retries=3 重试3次
             s.mount('http://', HTTPAdapter(max_retries=3))
             s.mount('https://', HTTPAdapter(max_retries=3))
-            response = s.get(url=url, headers=headers, params=params, cookies=cookies, verify=False, proxies=Common.tunnel_proxies(), timeout=5)
+            response = s.get(url=url, headers=headers, params=params, cookies=cookies, verify=False,
+                             proxies=Common.tunnel_proxies(), timeout=5)
             response.close()
             if 'data' not in response.json() or response.json()['data'] == '':
                 Common.logger(log_type, crawler).warning('get_video_info: response: {}', response)
@@ -212,7 +177,8 @@ class SchedulingFollow:
                     video_url_dict["video_height"] = 0
 
                 elif 'dash_120fps' in video_info['videoResource']:
-                    if "video_list" in video_info['videoResource']['dash_120fps'] and 'video_4' in video_info['videoResource']['dash_120fps']['video_list']:
+                    if "video_list" in video_info['videoResource']['dash_120fps'] and 'video_4' in \
+                            video_info['videoResource']['dash_120fps']['video_list']:
                         video_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
                         audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
                         if len(video_url) % 3 == 1:
@@ -231,7 +197,8 @@ class SchedulingFollow:
                         video_url_dict["audio_url"] = audio_url
                         video_url_dict["video_width"] = video_width
                         video_url_dict["video_height"] = video_height
-                    elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_3' in video_info['videoResource']['dash_120fps']['video_list']:
+                    elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_3' in \
+                            video_info['videoResource']['dash_120fps']['video_list']:
                         video_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
                         audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
                         if len(video_url) % 3 == 1:
@@ -250,7 +217,8 @@ class SchedulingFollow:
                         video_url_dict["audio_url"] = audio_url
                         video_url_dict["video_width"] = video_width
                         video_url_dict["video_height"] = video_height
-                    elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_2' in video_info['videoResource']['dash_120fps']['video_list']:
+                    elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_2' in \
+                            video_info['videoResource']['dash_120fps']['video_list']:
                         video_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
                         audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
                         if len(video_url) % 3 == 1:
@@ -269,7 +237,8 @@ class SchedulingFollow:
                         video_url_dict["audio_url"] = audio_url
                         video_url_dict["video_width"] = video_width
                         video_url_dict["video_height"] = video_height
-                    elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_1' in video_info['videoResource']['dash_120fps']['video_list']:
+                    elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_1' in \
+                            video_info['videoResource']['dash_120fps']['video_list']:
                         video_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
                         audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
                         if len(video_url) % 3 == 1:
@@ -292,11 +261,17 @@ class SchedulingFollow:
                     elif 'dynamic_video' in video_info['videoResource']['dash_120fps'] \
                             and 'dynamic_video_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
                             and 'dynamic_audio_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
-                            and len(video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list']) != 0 \
-                            and len(video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list']) != 0:
-
-                        video_url = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1]['backup_url_1']
-                        audio_url = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list'][-1]['backup_url_1']
+                            and len(
+                        video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list']) != 0 \
+                            and len(
+                        video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list']) != 0:
+
+                        video_url = \
+                            video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
+                                'backup_url_1']
+                        audio_url = \
+                            video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list'][-1][
+                                'backup_url_1']
                         if len(video_url) % 3 == 1:
                             video_url += '=='
                         elif len(video_url) % 3 == 2:
@@ -307,8 +282,12 @@ class SchedulingFollow:
                             audio_url += '='
                         video_url = base64.b64decode(video_url).decode('utf8')
                         audio_url = base64.b64decode(audio_url).decode('utf8')
-                        video_width = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1]['vwidth']
-                        video_height = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1]['vheight']
+                        video_width = \
+                            video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
+                                'vwidth']
+                        video_height = \
+                            video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
+                                'vheight']
                         video_url_dict["video_url"] = video_url
                         video_url_dict["audio_url"] = audio_url
                         video_url_dict["video_width"] = video_width
@@ -320,7 +299,8 @@ class SchedulingFollow:
                         video_url_dict["video_height"] = 0
 
                 elif 'dash' in video_info['videoResource']:
-                    if "video_list" in video_info['videoResource']['dash'] and 'video_4' in video_info['videoResource']['dash']['video_list']:
+                    if "video_list" in video_info['videoResource']['dash'] and 'video_4' in \
+                            video_info['videoResource']['dash']['video_list']:
                         video_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
                         audio_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
                         if len(video_url) % 3 == 1:
@@ -339,7 +319,8 @@ class SchedulingFollow:
                         video_url_dict["audio_url"] = audio_url
                         video_url_dict["video_width"] = video_width
                         video_url_dict["video_height"] = video_height
-                    elif "video_list" in video_info['videoResource']['dash'] and 'video_3' in video_info['videoResource']['dash']['video_list']:
+                    elif "video_list" in video_info['videoResource']['dash'] and 'video_3' in \
+                            video_info['videoResource']['dash']['video_list']:
                         video_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
                         audio_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
                         if len(video_url) % 3 == 1:
@@ -358,7 +339,8 @@ class SchedulingFollow:
                         video_url_dict["audio_url"] = audio_url
                         video_url_dict["video_width"] = video_width
                         video_url_dict["video_height"] = video_height
-                    elif "video_list" in video_info['videoResource']['dash'] and 'video_2' in video_info['videoResource']['dash']['video_list']:
+                    elif "video_list" in video_info['videoResource']['dash'] and 'video_2' in \
+                            video_info['videoResource']['dash']['video_list']:
                         video_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
                         audio_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
                         if len(video_url) % 3 == 1:
@@ -377,7 +359,8 @@ class SchedulingFollow:
                         video_url_dict["audio_url"] = audio_url
                         video_url_dict["video_width"] = video_width
                         video_url_dict["video_height"] = video_height
-                    elif "video_list" in video_info['videoResource']['dash'] and 'video_1' in video_info['videoResource']['dash']['video_list']:
+                    elif "video_list" in video_info['videoResource']['dash'] and 'video_1' in \
+                            video_info['videoResource']['dash']['video_list']:
                         video_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
                         audio_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
                         if len(video_url) % 3 == 1:
@@ -403,8 +386,10 @@ class SchedulingFollow:
                             and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list']) != 0 \
                             and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list']) != 0:
 
-                        video_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1]['backup_url_1']
-                        audio_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list'][-1]['backup_url_1']
+                        video_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
+                            'backup_url_1']
+                        audio_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list'][-1][
+                            'backup_url_1']
                         if len(video_url) % 3 == 1:
                             video_url += '=='
                         elif len(video_url) % 3 == 2:
@@ -415,8 +400,10 @@ class SchedulingFollow:
                             audio_url += '='
                         video_url = base64.b64decode(video_url).decode('utf8')
                         audio_url = base64.b64decode(audio_url).decode('utf8')
-                        video_width = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1]['vwidth']
-                        video_height = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1]['vheight']
+                        video_width = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
+                            'vwidth']
+                        video_height = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
+                            'vheight']
                         video_url_dict["video_url"] = video_url
                         video_url_dict["audio_url"] = audio_url
                         video_url_dict["video_width"] = video_width
@@ -555,7 +542,7 @@ class SchedulingFollow:
             Common.logger(log_type, crawler).error(f'get_video_url:{e}\n')
 
     @classmethod
-    def get_videolist(cls, log_type, crawler, task, our_uid, out_uid, oss_endpoint, env):
+    def get_videolist(cls, log_type, crawler, strategy, task, our_uid, out_uid, oss_endpoint, env):
         try:
             signature = cls.random_signature()
             while True:
@@ -567,6 +554,8 @@ class SchedulingFollow:
                     'maxBehotTime': '0',
                     'order': 'new',
                     'isHome': '0',
+                    # 'msToken': 'G0eRzNkw189a8TLaXjc6nTHVMQwh9XcxVAqTbGKi7iPJdQcLwS3-XRrJ3MZ7QBfqErpxp3EX1WtvWOIcZ3NIgr41hgcd-v64so_RRj3YCRw1UsKW8mIssNLlIMspsg==',
+                    # 'X-Bogus': 'DFSzswVuEkUANjW9ShFTgR/F6qHt',
                     '_signature': signature,
                 }
                 headers = {
@@ -578,7 +567,8 @@ class SchedulingFollow:
                 # max_retries=3 重试3次
                 s.mount('http://', HTTPAdapter(max_retries=3))
                 s.mount('https://', HTTPAdapter(max_retries=3))
-                response = s.get(url=url, headers=headers, params=params, proxies=Common.tunnel_proxies(), verify=False, timeout=5)
+                response = s.get(url=url, headers=headers, params=params, proxies=Common.tunnel_proxies(), verify=False,
+                                 timeout=5)
                 response.close()
                 cls.offset += 30
                 if response.status_code != 200:
@@ -589,7 +579,7 @@ class SchedulingFollow:
                     Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.text}\n")
                     cls.offset = 0
                     return
-                elif 'videoList' not in response.json()["data"]:
+                elif not response.json()["data"]['videoList']:
                     Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.json()}\n")
                     cls.offset = 0
                     return
@@ -601,7 +591,7 @@ class SchedulingFollow:
                             video_title = 0
                         else:
                             video_title = videoList[i]['title'].strip().replace('手游', '') \
-                                .replace('/', '').replace('\/', '').replace('\n', '')
+                                .replace('/', '').replace('\/', '').replace('\n', '').replace('"', '').replace("'", '')
 
                         # video_id
                         if 'video_id' not in videoList[i]:
@@ -690,64 +680,44 @@ class SchedulingFollow:
                         elif 'url' in videoList[i]['video_detail_info']['detail_video_large_image']:
                             cover_url = videoList[i]['video_detail_info']['detail_video_large_image']['url']
                         else:
-                            cover_url = videoList[i]['video_detail_info']['detail_video_large_image']['url_list'][0]['url']
-
-                        min_publish_time = int(task["min_publish_time"])
-                        min_publish_day = int(task["min_publish_day"])
-                        min_publish_day = (date.today() + timedelta(days=-min_publish_day)).strftime("%Y-%m-%d")
-                        min_publish_day = int(time.mktime(time.strptime(min_publish_day, "%Y-%m-%d")))
-                        if min_publish_time > 0 and min_publish_day > 0:
-                            publish_time_rule = min_publish_time
-                        elif min_publish_time > 0:
-                            publish_time_rule = min_publish_time
-                        else:
-                            publish_time_rule = min_publish_day
-
-                        if gid == 0 or video_id == 0 or cover_url == 0:
-                            Common.logger(log_type, crawler).info('无效视频\n')
-                        elif is_top is True and int(publish_time) < publish_time_rule:
-                            Common.logger(log_type, crawler).info(f'置顶视频,且发布时间超过抓取时间\n')
-                        elif int(publish_time) < publish_time_rule:
-                            Common.logger(log_type, crawler).info(f'发布时间超过抓取时间\n')
-                            cls.offset = 0
-                            return
-                        else:
-                            video_url_dict = cls.get_video_url(log_type, crawler, gid)
-                            video_url = video_url_dict["video_url"]
-                            audio_url = video_url_dict["audio_url"]
-                            video_width = video_url_dict["video_width"]
-                            video_height = video_url_dict["video_height"]
-
-                            video_dict = {'video_title': video_title,
-                                          'video_id': video_id,
-                                          'gid': gid,
-                                          'play_cnt': play_cnt,
-                                          'comment_cnt': comment_cnt,
-                                          'like_cnt': like_cnt,
-                                          'share_cnt': share_cnt,
-                                          'video_width': video_width,
-                                          'video_height': video_height,
-                                          'duration': video_duration,
-                                          'publish_time_stamp': publish_time,
-                                          'publish_time_str': publish_time_str,
-                                          'is_top': is_top,
-                                          'user_name': user_name,
-                                          'user_id': user_id,
-                                          'avatar_url': avatar_url,
-                                          'cover_url': cover_url,
-                                          'audio_url': audio_url,
-                                          'video_url': video_url,
-                                          'session': signature}
-                            for k, v in video_dict.items():
-                                Common.logger(log_type, crawler).info(f"{k}:{v}")
-                            cls.download_publish(log_type=log_type,
-                                                 crawler=crawler,
-                                                 video_dict=video_dict,
-                                                 task=task,
-                                                 strategy=task["task_name"],
-                                                 our_uid=our_uid,
-                                                 oss_endpoint=oss_endpoint,
-                                                 env=env)
+                            cover_url = videoList[i]['video_detail_info']['detail_video_large_image']['url_list'][0][
+                                'url']
+                        video_url_dict = cls.get_video_url(log_type, crawler, gid)
+                        video_url = video_url_dict["video_url"]
+                        audio_url = video_url_dict["audio_url"]
+                        video_width = video_url_dict["video_width"]
+                        video_height = video_url_dict["video_height"]
+
+                        video_dict = {'video_title': video_title,
+                                      'video_id': video_id,
+                                      'gid': gid,
+                                      'play_cnt': play_cnt,
+                                      'comment_cnt': comment_cnt,
+                                      'like_cnt': like_cnt,
+                                      'share_cnt': share_cnt,
+                                      'video_width': video_width,
+                                      'video_height': video_height,
+                                      'duration': video_duration,
+                                      'publish_time_stamp': publish_time,
+                                      'publish_time_str': publish_time_str,
+                                      'is_top': is_top,
+                                      'user_name': user_name,
+                                      'user_id': user_id,
+                                      'avatar_url': avatar_url,
+                                      'cover_url': cover_url,
+                                      'audio_url': audio_url,
+                                      'video_url': video_url,
+                                      'session': signature}
+                        for k, v in video_dict.items():
+                            Common.logger(log_type, crawler).info(f"{k}:{v}")
+                        cls.download_publish(log_type=log_type,
+                                             crawler=crawler,
+                                             strategy=strategy,
+                                             video_dict=video_dict,
+                                             task=task,
+                                             our_uid=our_uid,
+                                             oss_endpoint=oss_endpoint,
+                                             env=env)
         except Exception as e:
             Common.logger(log_type, crawler).error(f"get_videolist:{e}\n")
 
@@ -761,19 +731,26 @@ class SchedulingFollow:
     @classmethod
     def download_publish(cls, log_type, crawler, strategy, video_dict, task, our_uid, oss_endpoint, env):
         try:
-            if cls.download_rule_scheduling(video_dict, task) is False:
+            filter_words = get_config_from_mysql(log_type, crawler, env, text='filter')
+            for filter_word in filter_words:
+                if filter_word in video_dict['video_title']:
+                    Common.logger(log_type, crawler).info('标题已中过滤词:{}\n', video_dict['video_title'])
+                    return
+            if download_rule(log_type, crawler, video_dict, task['rule_dict']) is False:
                 Common.logger(log_type, crawler).info('不满足抓取规则\n')
-            elif any(word if word in video_dict['video_title'] else False for word in cls.filter_words(log_type, crawler)) is True:
-                Common.logger(log_type, crawler).info('标题已中过滤词:{}\n', video_dict['video_title'])
+
             elif cls.repeat_video(log_type, crawler, video_dict['video_id'], env) != 0:
                 Common.logger(log_type, crawler).info('视频已下载\n')
             else:
                 # 下载视频
-                Common.download_method(log_type=log_type, crawler=crawler, text='xigua_video', title=video_dict['video_title'], url=video_dict['video_url'])
+                Common.download_method(log_type=log_type, crawler=crawler, text='xigua_video',
+                                       title=video_dict['video_title'], url=video_dict['video_url'])
                 # 下载音频
-                Common.download_method(log_type=log_type, crawler=crawler, text='xigua_audio', title=video_dict['video_title'], url=video_dict['audio_url'])
+                Common.download_method(log_type=log_type, crawler=crawler, text='xigua_audio',
+                                       title=video_dict['video_title'], url=video_dict['audio_url'])
                 # 合成音视频
-                Common.video_compose(log_type=log_type, crawler=crawler, video_dir=f"./{crawler}/videos/{video_dict['video_title']}")
+                Common.video_compose(log_type=log_type, crawler=crawler,
+                                     video_dir=f"./{crawler}/videos/{video_dict['video_title']}")
                 md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
                 if os.path.getsize(f"./{crawler}/videos/{md_title}/video.mp4") == 0:
                     # 删除视频文件夹
@@ -787,7 +764,8 @@ class SchedulingFollow:
                 #     shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
                 #     return
                 # 下载封面
-                Common.download_method(log_type=log_type, crawler=crawler, text='cover', title=video_dict['video_title'], url=video_dict['cover_url'])
+                Common.download_method(log_type=log_type, crawler=crawler, text='cover',
+                                       title=video_dict['video_title'], url=video_dict['cover_url'])
                 # 保存视频信息至txt
                 Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
 
@@ -884,29 +862,26 @@ class SchedulingFollow:
 
     @classmethod
     def get_follow_videos(cls, log_type, crawler, task, oss_endpoint, env):
-        try:
-            user_list = cls.get_users(log_type=log_type,
-                                      crawler=crawler,
-                                      task=task,
-                                      env=env)
-            for user in user_list:
-                out_uid = user["out_uid"]
-                our_uid = int(user["our_uid"])
-                if our_uid == 0:
-                    pass
-                else:
-                    Common.logger(log_type, crawler).info(f"开始抓取 {out_uid} 用户主页视频\n")
-                    cls.get_videolist(log_type=log_type,
-                                      crawler=crawler,
-                                      task=task,
-                                      our_uid=our_uid,
-                                      out_uid=out_uid,
-                                      oss_endpoint=oss_endpoint,
-                                      env=env)
-                    cls.offset = 0
-                    time.sleep(1)
-        except Exception as e:
-            Common.logger(log_type, crawler).error(f"get_follow_videos:{e}\n")
+        user_list = get_user_from_mysql(log_type, crawler, crawler, env)
+        strategy = '定向抓取策略'
+        for user in user_list:
+            try:
+                spider_link = user["link"]
+                out_uid = spider_link.split('/')[-1]
+                user_name = user["nick_name"]
+                our_uid = user["uid"]
+                Common.logger(log_type, crawler).info(f"开始抓取 {user_name} 用户主页视频\n")
+                cls.get_videolist(log_type=log_type,
+                                  crawler=crawler,
+                                  strategy=strategy,
+                                  task=task,
+                                  our_uid=our_uid,
+                                  out_uid=out_uid,
+                                  oss_endpoint=oss_endpoint,
+                                  env=env)
+                cls.offset = 0
+            except Exception as e:
+                Common.logger(log_type, crawler).error(f"get_follow_videos:{e}\n")
 
 
 if __name__ == '__main__':
@@ -916,5 +891,5 @@ if __name__ == '__main__':
     #                            env="dev",
     #                            machine="local")
 
-    print(SchedulingFollow.repeat_video("follow", "xigua", "v0201ag10000ce3jcjbc77u8jsplpgrg", "dev"))
+    print(ScheduleXiguaFollow.repeat_video("follow", "xigua", "v0201ag10000ce3jcjbc77u8jsplpgrg", "dev"))
     pass

+ 32 - 18
xigua/xigua_main/run_xigua_follow_scheduling.py

@@ -1,27 +1,28 @@
 # -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2023/2/17
+# @Author: lierqiang
+# @Time: 2023/4/21
 import argparse
 import os
 import sys
 
 sys.path.append(os.getcwd())
 from common.common import Common
-from xigua.xigua_follow.xigua_follow_scheduling import SchedulingFollow
+from xigua.xigua_follow.xigua_follow_scheduling import ScheduleXiguaFollow
+from common.public import task_fun
+
+
 # from common.feishu import Feishu
 
 
 def main(log_type, crawler, task, oss_endpoint, env):
-    task = dict(eval(task))
-    Common.logger(log_type, crawler).info(f"{type(task)}\n")
-    Common.logger(log_type, crawler).info(f"{task}\n")
+    task = task_fun(task)
     try:
         Common.logger(log_type, crawler).info('开始抓取 西瓜视频 定向榜\n')
-        SchedulingFollow.get_follow_videos(log_type=log_type,
-                                           crawler=crawler,
-                                           task=task,
-                                           oss_endpoint=oss_endpoint,
-                                           env=env)
+        ScheduleXiguaFollow.get_follow_videos(log_type=log_type,
+                                              crawler=crawler,
+                                              task=task,
+                                              oss_endpoint=oss_endpoint,
+                                              env=env)
         Common.del_logs(log_type, crawler)
         Common.logger(log_type, crawler).info('抓取任务结束\n')
     except Exception as e:
@@ -31,16 +32,29 @@ def main(log_type, crawler, task, oss_endpoint, env):
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()  ## 新建参数解释器对象
-    parser.add_argument('--log_type', type=str)  ## 添加参数,注明参数类型
-    parser.add_argument('--crawler')  ## 添加参数
-    parser.add_argument('--strategy')  ## 添加参数
+    parser.add_argument('--log_type', default='author')  ## 添加参数,注明参数类型
+    parser.add_argument('--crawler', default='xigua')  ## 添加参数
+    parser.add_argument('--strategy', default='定向抓取')  ## 添加参数
     parser.add_argument('--task')  ## 添加参数
-    parser.add_argument('--oss_endpoint')  ## 添加参数
-    parser.add_argument('--env')  ## 添加参数
+    parser.add_argument('--oss_endpoint', default='outer')  ## 添加参数
+    parser.add_argument('--env', default='dev')  ## 添加参数
     # parser.add_argument('--machine')  ## 添加参数
     args = parser.parse_args()  ### 参数赋值,也可以通过终端赋值
+    task = {
+        'task_dict': {'task_id': '17', 'task_name': '西瓜测试4.21', 'source': 'xigua', 'start_time': '1682010720000',
+                      'interval': '24', 'mode': 'author',
+                      'rule': {'duration': {'min': 40, 'max': 0}, 'playCnt': {'min': 4000, 'max': 0},
+                               'period': {'min': 10, 'max': 0}, 'fans': {'min': 0, 'max': 0},
+                               'videos': {'min': 0, 'max': 0}, 'like': {'min': 0, 'max': 0},
+                               'videoWidth': {'min': 0, 'max': 0}, 'videoHeight': {'min': 0, 'max': 0}},
+                      'spider_name': 'run_xiguan_author_scheduling', 'machine': 'aliyun', 'status': '0',
+                      'create_time': '1682048632396', 'update_time': '1682048632396', 'operator': ''},
+        'rule_dict': {'duration': {'min': 40, 'max': 0}, 'playCnt': {'min': 4000, 'max': 0},
+                      'period': {'min': 10, 'max': 0}, 'fans': {'min': 0, 'max': 0}, 'videos': {'min': 0, 'max': 0},
+                      'like': {'min': 0, 'max': 0}, 'videoWidth': {'min': 0, 'max': 0},
+                      'videoHeight': {'min': 0, 'max': 0}}}
     main(log_type=args.log_type,
          crawler=args.crawler,
-         task=args.task,
+         task=task,
          oss_endpoint=args.oss_endpoint,
-         env=args.env)
+         env=args.env)

+ 213 - 205
youtube/youtube_follow/youtube_follow_scheduling.py

@@ -1,7 +1,11 @@
 # -*- coding: utf-8 -*-
-# @Author: lierqiang
-# @Time: 2023/3/15
-
+# @Author: wangkun
+# @Time: 2023/2/3
+"""
+YouTube 定向榜
+    1. 发布时间<=1个月
+    2. 10分钟>=时长>=1分钟
+"""
 import os
 import re
 import shutil
@@ -12,12 +16,17 @@ import requests
 
 sys.path.append(os.getcwd())
 from common.common import Common
+# from common.db import MysqlHelper
 from common.scheduling_db import MysqlHelper
 from common.feishu import Feishu
 from common.getuser import getUser
 from common.publish import Publish
 from common.translate import Translate
-from common.userAgent import get_random_header, get_random_user_agent
+from common.public import get_user_from_mysql, get_config_from_mysql
+
+headers = {
+    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
+}
 
 
 def format_nums(data):
@@ -35,11 +44,14 @@ def format_nums(data):
     return count
 
 
-class YoutubeFollowSchedule:
+class YoutubeAuthorScheduling:
     # 翻页参数
     continuation = ''
     # 抓取平台
     platform = 'youtube'
+    headers = {
+        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
+    }
 
     @classmethod
     def get_out_user_info(cls, log_type, crawler, browse_id, out_user_id):
@@ -57,12 +69,16 @@ class YoutubeFollowSchedule:
         """
         try:
             url = f'https://www.youtube.com/{out_user_id}/about'
-            res = requests.get(url=url, headers=get_random_header('pc'))
+            res = requests.get(url=url, headers=headers)
             info = re.findall(r'var ytInitialData = (.*?);</script>', res.text, re.S)[0]
             data = json.loads(info)
             header = data['header']['c4TabbedHeaderRenderer']
             tabs = data['contents']['twoColumnBrowseResultsRenderer']['tabs']
-            subsimpleText = header['subscriberCountText']['simpleText'].replace('位订阅者', '')
+            try:
+                subsimpleText = header['subscriberCountText']['simpleText'].replace('位订阅者', '')
+                out_fans = format_nums(subsimpleText)
+            except Exception as e:
+                out_fans = 0
             for tab in tabs:
                 if 'tabRenderer' not in tab or 'content' not in tab['tabRenderer']:
                     continue
@@ -76,7 +92,7 @@ class YoutubeFollowSchedule:
             out_user_dict = {
                 'out_user_name': header['title'],
                 'out_avatar_url': header['avatar']['thumbnails'][-1]['url'],
-                'out_fans': format_nums(subsimpleText),
+                'out_fans': out_fans,
                 'out_play_cnt': int(
                     viewCountText.replace('收看次數:', '').replace('次', '').replace(',', '')) if viewCountText else 0,
                 'out_create_time': out_create_time.replace('年', '-').replace('月', '-').replace('日', ''),
@@ -108,13 +124,17 @@ class YoutubeFollowSchedule:
                 uer_url = user_sheet[i][4]
                 if out_uid is not None and user_name is not None:
                     Common.logger(log_type, crawler).info(f"正在更新 {user_name} 用户信息\n")
+
                     if our_uid is None:
                         sql = f""" select * from crawler_user where platform="{cls.platform}" and out_user_id="{out_uid}" """
                         our_user_info = MysqlHelper.get_values(log_type, crawler, sql, env)
                         # 数据库中(youtube + out_user_id)返回数量 == 0,则创建站内账号UID,并写入定向账号飞书表。并结合站外用户信息,一并写入爬虫账号数据库
-                        if our_user_info is None or len(our_user_info) == 0:
+                        if not our_user_info:
                             # 获取站外账号信息,写入数据库
-                            out_user_dict = cls.get_out_user_info(log_type, crawler, browse_id, out_uid)
+                            try:
+                                out_user_dict = cls.get_out_user_info(log_type, crawler, browse_id, out_uid)
+                            except Exception as e:
+                                continue
                             out_avatar_url = out_user_dict['out_avatar_url']
                             out_create_time = out_user_dict['out_create_time']
                             out_play_cnt = out_user_dict['out_play_cnt']
@@ -127,7 +147,7 @@ class YoutubeFollowSchedule:
                                 'avatarUrl': out_avatar_url,
                                 'tagName': tag,
                             }
-                            our_uid = getUsercreate_uid(log_type, crawler, create_user_dict, env)
+                            our_uid = getUser.create_uid(log_type, crawler, create_user_dict, env)
                             Common.logger(log_type, crawler).info(f'新创建的站内UID:{our_uid}')
                             if env == 'prod':
                                 our_user_link = f'https://admin.piaoquantv.com/ums/user/{our_uid}/post'
@@ -138,22 +158,22 @@ class YoutubeFollowSchedule:
                                                  [[our_uid, our_user_link]])
                             Common.logger(log_type, crawler).info(f'站内用户信息写入飞书成功!')
 
-                            sql = f""" insert into crawler_user(user_id, 
-                                                out_user_id, 
-                                                out_user_name, 
-                                                out_avatar_url, 
-                                                out_create_time, 
-                                                out_play_cnt, 
-                                                out_fans, 
-                                                platform, 
+                            sql = f""" insert into crawler_user(user_id,
+                                                out_user_id,
+                                                out_user_name,
+                                                out_avatar_url,
+                                                out_create_time,
+                                                out_play_cnt,
+                                                out_fans,
+                                                platform,
                                                 tag)
-                                                values({our_uid}, 
-                                                "{out_uid}", 
-                                                "{user_name}", 
-                                                "{out_avatar_url}", 
-                                                "{out_create_time}", 
-                                                {out_play_cnt}, 
-                                                {out_fans}, 
+                                                values({our_uid},
+                                                "{out_uid}",
+                                                "{user_name}",
+                                                "{out_avatar_url}",
+                                                "{out_create_time}",
+                                                {out_play_cnt},
+                                                {out_fans},
                                                 "{cls.platform}",
                                                 "{tag}") """
                             Common.logger(log_type, crawler).info(f'sql:{sql}')
@@ -352,7 +372,7 @@ class YoutubeFollowSchedule:
             'sec-fetch-dest': 'empty',
             'sec-fetch-mode': 'same-origin',
             'sec-fetch-site': 'same-origin',
-            'user-agent': get_random_user_agent('pc'),
+            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
             'x-goog-visitor-id': 'CgtraDZfVnB4NXdIWSi6mIOfBg%3D%3D',
             'x-youtube-bootstrap-logged-in': 'false',
             'x-youtube-client-name': '1',
@@ -369,7 +389,6 @@ class YoutubeFollowSchedule:
             elif 'continuationContents' in response.json():
                 # Common.logger(log_type, crawler).info("'continuationContents' in response.json()\n")
                 if 'richGridContinuation' not in response.json()['continuationContents']:
-                    # Common.logger(log_type, crawler).warning(f"'richGridContinuation' not in response.json()['continuationContents']\n")
                     Common.logger(log_type, crawler).warning(
                         f'get_feeds_response:{response.json()["continuationContents"]}\n')
                 elif 'contents' not in response.json()['continuationContents']['richGridContinuation']:
@@ -407,7 +426,7 @@ class YoutubeFollowSchedule:
     @classmethod
     def get_first_page(cls, user_url):
         try:
-            res = requests.get(url=user_url, headers=get_random_header('pc'))
+            res = requests.get(url=user_url, headers=cls.headers)
             info = re.findall(r'var ytInitialData = (.*?);', res.text, re.S)[0]
             ytInitialData = json.loads(info)
             video_list = \
@@ -418,19 +437,17 @@ class YoutubeFollowSchedule:
         return video_list
 
     @classmethod
-    def get_next_page(cls, log_type, crawler, task, strategy, oss_endpoint, env, our_uid,
-                      out_uid, out_user_url, continuation):
-        min_publish_day = task['min_publish_day']
+    def get_next_page(cls, log_type, crawler, strategy, oss_endpoint, env, out_uid, our_uid, out_user_url, continuation):
         post_url = "https://www.youtube.com/youtubei/v1/browse?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8&prettyPrint=false"
         payload = json.dumps({
             "context": {
                 "client": {
-                    "userAgent": get_random_user_agent('pc'),
+                    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36,gzip(gfe)",
                     "clientName": "WEB",
                     "clientVersion": "2.20230221.06.00",
                     "osName": "Macintosh",
                     "osVersion": "10_15_7",
-                    "originalUrl": "https://www.youtube.com/{}/videos".format(out_uid),
+                    "originalUrl": "https://www.youtube.com/@wongkim728/videos",
                     "screenPixelDensity": 2,
                     "platform": "DESKTOP",
                     "clientFormFactor": "UNKNOWN_FORM_FACTOR",
@@ -480,60 +497,47 @@ class YoutubeFollowSchedule:
             'cookie': 'VISITOR_INFO1_LIVE=HABZsLFdU40; DEVICE_INFO=ChxOekl3TWpVek9UQXpPVE13TnpJd056a3pNZz09EJie0p8GGJie0p8G; PREF=f4=4000000&tz=Asia.Shanghai; HSID=AxFp7ylWWebUZYqrl; SSID=ANHuSQMqvVcV0vVNn; APISID=AkwZgjPvFZ6LZCrE/Aiv0K-2rEUzY1bH1u; SAPISID=8yRrBMHYXAhqkybH/AEFGJvzZ3tPalnTy0; __Secure-1PAPISID=8yRrBMHYXAhqkybH/AEFGJvzZ3tPalnTy0; __Secure-3PAPISID=8yRrBMHYXAhqkybH/AEFGJvzZ3tPalnTy0; SID=TwjWkM4mrKb4o8pRKbyQVqELjNU43ZL0bF8QB2hdTI9z05T4Koo9aQoNQfX1AiGFWeD7WA.; __Secure-1PSID=TwjWkM4mrKb4o8pRKbyQVqELjNU43ZL0bF8QB2hdTI9z05T4bs4qvvXffLLTXq_VYw0XLw.; __Secure-3PSID=TwjWkM4mrKb4o8pRKbyQVqELjNU43ZL0bF8QB2hdTI9z05T4cNwzpudzvCglfQ5A1FJnog.; LOGIN_INFO=AFmmF2swRAIgO4TvR9xxWoHPgrGoGAEVo-P8Slqem__vIdF_oajjRiECIFiq4YtbL_IQGCbkjrHsWkWH6OpzKd8RlgdS6qNurR0Q:QUQ3MjNmejV5WkRVUmZXVlFjbjY0dW1aVGpoZkZQdmxYamIzV01zc0lmT3JiQl9ldVYwc0t4dlNkbWpoVEdJMHVaWjZXVEt3ZERQeUppU3AyNmR6ckFucWltZU5LNmZjQ3lHUEtKTDBzSlo5WXpJQzF3UlNCVlp2Q1ZKVmxtRk05OHRuWFFiWGphcFpPblFOUURWTlVxVGtBazVjcmVtS2pR; YSC=CtX0f3NennA; SIDCC=AFvIBn9aXC4vNCbg5jPzjbC8LMYCBVx_dy8uJO20b-768rmRfP9f5BqQ_xXspPemecVq29qZ7A; __Secure-1PSIDCC=AFvIBn-4TD_lPaKgbmYAGO6hZluLgSgbWgb7XAcaeNG6982LIIpS_Gb9vkqHTBMyCGvb4x7m6jk; __Secure-3PSIDCC=AFvIBn9ypvGX15qq4CsnsuhWTaXa9yMTxWMWbIDXtr6L3XZD81XBUQ0IMUv9ZKh9mf8NEbSvOy0; SIDCC=AFvIBn_DwLbohF2llhq4EQjFDFA3n9-_AK_7ITJsTZtCeYwy43J8KCYUPfY7ghqX9s-Qq5dOIQ; __Secure-1PSIDCC=AFvIBn-7x_HhxbmDkOzXew-sXAEWVuUGpglr8rypU623IyO8Y9OungcqMkuxBZQ2vr6G7x9UcxM; __Secure-3PSIDCC=AFvIBn-7aSYRxZkCKZp7-Mdn9PwbW4CUtXD0ok0nCvPIZXfkFrN9VqN1BHkI1fUaoIo_8YCjwRs',
             'origin': 'https://www.youtube.com',
             'referer': out_user_url,
-            'user-agent': get_random_user_agent('pc'),
+            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
 
         }
         try:
             res = requests.request("POST", post_url, headers=headers, data=payload).json()
             video_infos = res['onResponseReceivedActions'][0]['appendContinuationItemsAction']['continuationItems']
-
             for data in video_infos:
                 if 'richItemRenderer' in data:
                     video_id = data["richItemRenderer"]["content"]['videoRenderer']['videoId']
                     video_dict = cls.get_video_info(log_type, crawler, out_uid, video_id)
-                    # video_dict = cls.parse_video(video_dict, log_type, crawler, out_uid, video_id, machine)
                     # 发布时间<=7天
                     publish_time = int(time.mktime(time.strptime(video_dict['publish_time'], "%Y-%m-%d")))
-                    if int(time.time()) - publish_time <= 3600 * 24 * min_publish_day:
+                    if int(time.time()) - publish_time <= 3600 * 24 * 7:
                         cls.download_publish(log_type, crawler, video_dict, strategy, our_uid, env, oss_endpoint)
                     else:
                         Common.logger(log_type, crawler).info('发布时间超过7天\n')
                         return
                 else:
                     continuation = cls.get_continuation(data)
-                    cls.get_next_page(log_type, crawler, task, strategy, oss_endpoint, env, our_uid, out_uid,
-                                      out_user_url, continuation)
+                    cls.get_next_page(log_type, crawler, strategy, oss_endpoint, env, out_uid, our_uid,out_user_url, continuation)
         except:
             return
 
     @classmethod
-    def get_videos(cls, log_type, crawler, task, oss_endpoint, env, our_uid, out_uid, out_user_url):
+    def get_videos(cls, log_type, crawler, strategy, task, oss_endpoint, env, out_uid, our_uid, out_user_url):
         try:
-            # 修改
-            strategy = task['user_tag']
-            min_publish_day = int(task['min_publish_day'])
             feeds = cls.get_first_page(out_user_url)
             for data in feeds:
                 if 'richItemRenderer' in data:
                     video_id = data["richItemRenderer"]["content"]['videoRenderer']['videoId']
                     video_dict = cls.get_video_info(log_type, crawler, out_uid, video_id)
-                    # 发布时间判断
+                    # 发布时间<=7天
                     publish_time = int(time.mktime(time.strptime(video_dict['publish_time'], "%Y-%m-%d")))
-                    if int(time.time()) - publish_time > 3600 * 24 * min_publish_day:
-                        Common.logger(log_type, crawler).info(f'发布时间超过{min_publish_day}天\n')
-                    elif video_dict['video_title'] == '' or video_dict['video_url'] == '':
-                        Common.logger(log_type, crawler).info('无效视频\n')
-                    elif video_dict['duration'] > task['duration_max'] or video_dict['duration'] < task['duration_min']:
-                        Common.logger(log_type, crawler).info(f"时长:{video_dict['duration']}不满足规则\n")
-                    elif cls.repeat_video(log_type, crawler, video_dict['video_id'], env) != 0:
-                        Common.logger(log_type, crawler).info('视频已下载\n')
-
-                    else:
+                    if int(time.time()) - publish_time <= 3600 * 24 * 7:
                         cls.download_publish(log_type, crawler, video_dict, strategy, our_uid, env, oss_endpoint)
+                    else:
+                        Common.logger(log_type, crawler).info('发布时间超过7天\n')
+                        return
                 else:
                     continuation = cls.get_continuation(data)
-                    cls.get_next_page(log_type, crawler, task, strategy, oss_endpoint, env, our_uid, out_uid,
-                                      out_user_url, continuation=continuation)
+                    cls.get_next_page(log_type, crawler, strategy, oss_endpoint, env, out_uid, our_uid, out_user_url, continuation=continuation)
         except Exception as e:
             Common.logger(log_type, crawler).error(f"get_videos异常:{e}\n")
 
@@ -622,6 +626,15 @@ class YoutubeFollowSchedule:
                 else:
                     cover_url = videoDetails['thumbnail']['thumbnails'][-1]['url']
 
+                # video_url
+                # if 'formats' not in streamingData:
+                #     video_url = ''
+                # elif len(streamingData['formats']) == 0:
+                #     video_url = ''
+                # elif 'url' not in streamingData['formats'][-1]:
+                #     video_url = ''
+                # else:
+                #     video_url = streamingData['formats'][-1]['url']
                 video_url = f"https://www.youtube.com/watch?v={video_id}"
 
                 Common.logger(log_type, crawler).info(f'video_title:{video_title}')
@@ -661,7 +674,7 @@ class YoutubeFollowSchedule:
                         "deviceMake": "Apple",
                         "deviceModel": "",
                         "visitorData": "CgtraDZfVnB4NXdIWSjkzoefBg%3D%3D",
-                        "userAgent": get_random_user_agent('pc'),
+                        "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36,gzip(gfe)",
                         "clientName": "WEB",
                         "clientVersion": "2.20230201.01.00",
                         "osName": "Macintosh",
@@ -820,7 +833,7 @@ class YoutubeFollowSchedule:
                 'sec-fetch-dest': 'empty',
                 'sec-fetch-mode': 'same-origin',
                 'sec-fetch-site': 'same-origin',
-                'user-agent': get_random_user_agent('pc'),
+                'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
                 'x-goog-visitor-id': 'CgtraDZfVnB4NXdIWSjkzoefBg%3D%3D',
                 'x-youtube-bootstrap-logged-in': 'false',
                 'x-youtube-client-name': '1',
@@ -844,7 +857,7 @@ class YoutubeFollowSchedule:
                 if 'title' not in videoDetails:
                     video_title = ''
                 else:
-                    video_title = videoDetails['title']
+                    video_title = videoDetails['title'].replace('"', '').replace("'", '')
                 video_title = cls.filter_emoji(video_title)
                 if not cls.is_contain_chinese(video_title):
                     video_title = Translate.google_translate(video_title) \
@@ -938,167 +951,162 @@ class YoutubeFollowSchedule:
     @classmethod
     def download_publish(cls, log_type, crawler, video_dict, strategy, our_uid, env, oss_endpoint):
         try:
+            filter_words = get_config_from_mysql(log_type, crawler, env, text='filter', action='get_author_map')
+            for filter_word in filter_words:
+                if filter_word in video_dict['video_title']:
+                    Common.logger(log_type, crawler).info('标题已中过滤词:{}\n', video_dict['video_title'])
+                    return
+            if video_dict['video_title'] == '' or video_dict['video_url'] == '':
+                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) != 0:
+                Common.logger(log_type, crawler).info('视频已下载\n')
 
-            # 下载视频
-            Common.logger(log_type, crawler).info('开始下载视频...')
-            Common.download_method(log_type, crawler, 'youtube_video', video_dict['video_title'],
-                                   video_dict['video_url'])
+            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'])
+                # 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'])
+                video_width = 1280
+                video_height = 720
+                duration = int(video_dict['duration'])
 
-            video_width = 1280
-            video_height = 720
-            duration = int(video_dict['duration'])
-            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_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
-            video_dict['duration'] = duration
-            video_dict['comment_cnt'] = 0
-            video_dict['like_cnt'] = 0
-            video_dict['share_cnt'] = 0
-            video_dict['avatar_url'] = video_dict['cover_url']
-            video_dict['session'] = f'youtube{int(time.time())}'
-            rule = '1,2'
-            # 下载封面
-            Common.download_method(log_type, crawler, 'cover', video_dict['video_title'], video_dict['cover_url'])
-            # 保存视频文本信息
-            Common.save_video_info(log_type, crawler, video_dict)
+                video_dict['video_width'] = video_width
+                video_dict['video_height'] = video_height
+                video_dict['duration'] = duration
+                video_dict['comment_cnt'] = 0
+                video_dict['like_cnt'] = 0
+                video_dict['share_cnt'] = 0
+                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'])
+                # 保存视频文本信息
+                Common.save_video_info(log_type, crawler, video_dict)
 
-            # 上传视频
-            Common.logger(log_type, crawler).info(f"开始上传视频")
-            if env == 'dev':
-                our_video_id = Publish.upload_and_publish(log_type, crawler, strategy, our_uid, env, oss_endpoint)
-                our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
-            else:
-                our_video_id = Publish.upload_and_publish(log_type, crawler, strategy, our_uid, env, oss_endpoint)
-                our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
-            Common.logger(log_type, crawler).info("视频上传完成")
+                # 上传视频
+                Common.logger(log_type, crawler).info(f"开始上传视频")
+                if env == 'dev':
+                    our_video_id = Publish.upload_and_publish(log_type, crawler, strategy, our_uid, env, oss_endpoint)
+                    our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
+                else:
+                    our_video_id = Publish.upload_and_publish(log_type, crawler, strategy, our_uid, env, oss_endpoint)
+                    our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
+                Common.logger(log_type, crawler).info("视频上传完成")
 
-            if our_video_id is None:
-                # 删除视频文件夹
-                shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}/")
-                return
+                if our_video_id is None:
+                    # 删除视频文件夹
+                    shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}/")
+                    return
 
-            # 视频信息保存至飞书
-            Feishu.insert_columns(log_type, crawler, "GVxlYk", "ROWS", 1, 2)
-            # 视频ID工作表,首行写入数据
-            upload_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time())))
-            values = [[upload_time,
-                       "定向榜",
-                       video_dict['video_id'],
-                       video_dict['video_title'],
-                       our_video_link,
-                       video_dict['play_cnt'],
-                       video_dict['duration'],
-                       f'{video_width}*{video_height}',
-                       video_dict['publish_time'],
-                       video_dict['user_name'],
-                       video_dict['cover_url'],
-                       video_dict['video_url']
-                       ]]
-            # time.sleep(1)
-            Feishu.update_values(log_type, crawler, "GVxlYk", "F2:Z2", values)
-            Common.logger(log_type, crawler).info('视频信息写入定向_已下载表成功\n')
+                # 视频信息保存至飞书
+                Feishu.insert_columns(log_type, crawler, "GVxlYk", "ROWS", 1, 2)
+                # 视频ID工作表,首行写入数据
+                upload_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time())))
+                values = [[upload_time,
+                           "定向榜",
+                           video_dict['video_id'],
+                           video_dict['video_title'],
+                           our_video_link,
+                           video_dict['play_cnt'],
+                           video_dict['duration'],
+                           f'{video_width}*{video_height}',
+                           video_dict['publish_time'],
+                           video_dict['user_name'],
+                           video_dict['cover_url'],
+                           video_dict['video_url']
+                           ]]
+                # time.sleep(1)
+                Feishu.update_values(log_type, crawler, "GVxlYk", "F2:Z2", values)
+                Common.logger(log_type, crawler).info('视频信息写入定向_已下载表成功\n')
 
-            # 视频信息保存数据库
-            sql = f""" insert into crawler_video(video_id,
-            user_id,
-            out_user_id,
-            platform,
-            strategy,
-            out_video_id,
-            video_title,
-            cover_url,
-            video_url,
-            duration,
-            publish_time,
-            play_cnt,
-            crawler_rule,
-            width,
-            height)
-            values({our_video_id},
-            "{our_uid}",
-            "{video_dict['out_uid']}",
-            "{cls.platform}",
-            "定向爬虫策略",
-            "{video_dict['video_id']}",
-            "{video_dict['video_title']}",
-            "{video_dict['cover_url']}",
-            "{video_dict['video_url']}",
-            {int(duration)},
-            "{video_dict['publish_time']}",
-            {int(video_dict['play_cnt'])},
-            "{rule}",
-            {int(video_width)},
-            {int(video_height)}) """
-            MysqlHelper.update_values(log_type, crawler, sql, env)
-            Common.logger(log_type, crawler).info('视频信息插入数据库成功!\n')
+                # 视频信息保存数据库
+                sql = f""" insert into crawler_video(video_id,
+                user_id,
+                out_user_id,
+                platform,
+                strategy,
+                out_video_id,
+                video_title,
+                cover_url,
+                video_url,
+                duration,
+                publish_time,
+                play_cnt,
+                crawler_rule,
+                width,
+                height)
+                values({our_video_id},
+                "{our_uid}",
+                "{video_dict['out_uid']}",
+                "{cls.platform}",
+                "定向爬虫策略",
+                "{video_dict['video_id']}",
+                "{video_dict['video_title']}",
+                "{video_dict['cover_url']}",
+                "{video_dict['video_url']}",
+                {int(duration)},
+                "{video_dict['publish_time']}",
+                {int(video_dict['play_cnt'])},
+                "{rule}",
+                {int(video_width)},
+                {int(video_height)}) """
+                MysqlHelper.update_values(log_type, crawler, sql, env)
+                Common.logger(log_type, crawler).info('视频信息插入数据库成功!\n')
         except Exception as e:
             Common.logger(log_type, crawler).info(f"download_publish异常:{e}\n")
 
-    @classmethod
-    def get_users(cls, log_type, crawler, task, env):
-        link_list = task['spider_link']
-        user_list = []
-        for link in link_list:
-            out_uid = link.split("/")[3]
-            sql = f""" select * from crawler_author_map where spider_link="{link}" """
-            our_user_info = MysqlHelper.get_values(log_type=log_type, crawler=crawler, sql=sql, env=env, action='get_author_map')
-
-            if len(our_user_info) == 0:
-                our_uid = 0
-                Common.logger(log_type, crawler).info(f"没有站内虚拟账号: {link}\n")
-            else:
-                our_uid = our_user_info[0]["media_id"]
-            user_dict = {
-                "out_uid": out_uid,
-                "out_user_url": link,
-                "our_uid": our_uid
-            }
-            user_list.append(user_dict)
-        Common.logger(log_type, crawler).info(f"user_list:{user_list}")
-        return user_list
-
     @classmethod
     def get_follow_videos(cls, log_type, crawler, task, oss_endpoint, env):
         try:
-            user_list = cls.get_users(log_type, crawler, task, env)
-            if len(user_list) == 0:
-                Common.logger(log_type, crawler).warning('用户列表为空\n')
-            else:
-                for user_dict in user_list:
-                    out_user_url = user_dict['out_user_url']
-                    our_uid = user_dict['our_uid']
-                    out_uid = user_dict['out_uid']
-                    Common.logger(log_type, crawler).info(f'获取 {out_uid} 主页视频\n')
+            user_list = get_user_from_mysql(log_type, crawler, crawler, env, action='get_author_map')
+            strategy = '定向抓取策略'
 
-                    cls.get_videos(log_type=log_type,
-                                   crawler=crawler,
-                                   task=task,
-                                   our_uid=our_uid,
-                                   oss_endpoint=oss_endpoint,
-                                   env=env,
-                                   out_uid=out_uid,
-                                   out_user_url=out_user_url
-                                   )
-                    # Common.logger(log_type, crawler).info('休眠 10 秒')
-                    # time.sleep(random.randint(1, 2))
-                    cls.continuation = ''
+            for user_dict in user_list:
+                out_user_url = user_dict['link']
+                out_uid = out_user_url.split('/')[3]
+                user_name = user_dict['nick_name']
+                our_uid = user_dict['uid']
+                Common.logger(log_type, crawler).info(f'获取 {user_name} 主页视频\n')
+                cls.get_videos(
+                    log_type=log_type,
+                    crawler=crawler,
+                    strategy=strategy,
+                    task=task,
+                    oss_endpoint=oss_endpoint,
+                    env=env,
+                    our_uid=our_uid,
+                    out_uid=out_uid,
+                    out_user_url=out_user_url
+                )
+                cls.continuation = ''
         except Exception as e:
             Common.logger(log_type, crawler).error(f"get_follow_videos异常:{e}\n")
 
 
 if __name__ == "__main__":
-    # print(Follow.get_browse_id('follow', 'youtube', '@chinatravel5971', "local"))
-    # print(Follow.get_user_from_feishu('follow', 'youtube', 'c467d7', 'dev', 'local'))
-    # print(Follow.get_user_from_feishu('follow', 'youtube', 'c467d7', 'prod', 'prod'))
-    # Follow.get_out_user_info('follow', 'youtube', 'UC08jgxf119fzynp2uHCvZIg', '@weitravel')
-    # Follow.get_video_info('follow', 'youtube', 'OGVK0IXBIhI')
-    # Follow.get_follow_videos('follow', 'youtube', 'youtube_follow', 'out', 'dev', 'local')
-    # print(Follow.filter_emoji("姐妹倆一唱一和,完美配合,終於把大慶降服了😅😅#萌娃搞笑日常"))
-    # Follow.repeat_video('follow', 'youtube', 4, "dev", "local")
-    # title = "'西部巡游220丨两人一车环游中国半年,需要花费多少钱? 2万公里吃住行费用总结'"
-    # title = "'Insanely Crowded Shanghai Yu Garden Lantern Festival Walk Tour 2023 人气爆棚的上海豫园元宵节漫步之行 4K'"
-    # print(title.strip().replace("\\", "").replace(" ", "").replace("\n", "").replace("/", "").replace("\r", "").replace("&NBSP", "").replace("&", ""))
-    pass
+    YoutubeAuthorScheduling.get_follow_videos('author', 'youtube', '', 'outer', 'dev')

+ 31 - 18
youtube/youtube_main/run_youtube_follow_scheduling.py

@@ -7,42 +7,55 @@ import sys
 
 sys.path.append(os.getcwd())
 from common.common import Common
-from youtube.youtube_follow.youtube_follow_scheduling import YoutubeFollowSchedule
+from common.public import task_fun
+from youtube.youtube_follow.youtube_follow_scheduling import YoutubeAuthorScheduling
 
 
 def main(log_type, crawler, task, oss_endpoint, env):
-    task = dict(eval(task))
-    Common.logger(log_type, crawler).info(f"{type(task)}\n")
+    task = task_fun(task)
     Common.logger(log_type, crawler).info(f"{task}\n")
     try:
         Common.logger(log_type, crawler).info('开始抓取 youtube视频 定向榜\n')
-        YoutubeFollowSchedule.get_follow_videos(log_type=log_type,
-                                           crawler=crawler,
-                                           task=task,
-                                           oss_endpoint=oss_endpoint,
-                                           env=env,
-                                           )
+        YoutubeAuthorScheduling.get_follow_videos(
+            log_type=log_type,
+            crawler=crawler,
+            task=task,
+            oss_endpoint=oss_endpoint,
+            env=env,
+        )
         Common.del_logs(log_type, crawler)
         Common.logger(log_type, crawler).info('抓取任务结束\n')
     except Exception as e:
         Common.logger(log_type, crawler).info(f"youtube视频异常,触发报警:{e}\n")
-        # Feishu.bot(log_type, crawler, f"{e}")
 
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()  ## 新建参数解释器对象
-    parser.add_argument('--log_type',default='follow', type=str)  ## 添加参数,注明参数类型
+    parser.add_argument('--log_type', default='author', type=str)  ## 添加参数,注明参数类型
     parser.add_argument('--crawler', default='youtube')  ## 添加参数
-    parser.add_argument('--strategy',default='定向')  ## 添加参数
-    parser.add_argument('--task',default="[('task_id','27'),('task_name','youtube测试'),('source','youtube'),('next_time','1678809600'),('interval_piaoquan','36000'),('play_cnt',{'min':100}),('video_width',{'min':100}),('video_height',{'min':100}),('video_like',{'min':100}),('share_cnt',{'min':1}),('duration_min',1),('duration_max',300),('task_type','author'),('spider_link',['https://www.youtube.com/@weitravel/videos']),('spider_name','run_youtube_follw'),('min_publish_time','0'),('min_publish_day','0'),('media_id','0'),('applets_status','0'),('app_status','0'),('user_tag','视频号定向爬虫'),('user_content_tag','搞笑'),('machine','hk')]")  ## 添加参数
-    parser.add_argument('--oss_endpoint',default='out')  ## 添加参数
-    parser.add_argument('--env',default='dev')  ## 添加参数
+    parser.add_argument('--strategy', default='定向')  ## 添加参数
+    parser.add_argument('--task', default='')  ## 添加参数
+    parser.add_argument('--oss_endpoint', default='out')  ## 添加参数
+    parser.add_argument('--env', default='dev')  ## 添加参数
     # parser.add_argument('--machine')  ## 添加参数
     args = parser.parse_args()  ### 参数赋值,也可以通过终端赋值
+    task = {
+        'task_dict': {'task_id': '17', 'task_name': '西瓜测试4.21', 'source': 'douyin', 'start_time': '1682010720000',
+                      'interval': '24', 'mode': 'author',
+                      'rule': {'duration': {'min': 40, 'max': 0}, 'play_cnt': {'min': 4000, 'max': 0},
+                               'period': {'min': 10, 'max': 0}, 'fans_cnt': {'min': 0, 'max': 0},
+                               'videos_cnt': {'min': 0, 'max': 0}, 'like_cnt': {'min': 0, 'max': 0},
+                               'width': {'min': 0, 'max': 0}, 'height': {'min': 0, 'max': 0}},
+                      'spider_name': 'run_dy_author_scheduling', 'machine': 'aliyun', 'status': '0',
+                      'create_time': '1682048632396', 'update_time': '1682048632396', 'operator': ''},
+        'rule_dict': {'duration': {'min': 0, 'max': 0}, 'play_cnt': {'min': 0, 'max': 0},
+                      'period': {'min': 0, 'max': 0}, 'fans_cnt': {'min': 0, 'max': 0},
+                      'videos_cnt': {'min': 0, 'max': 0},
+                      'like_cnt': {'min': 0, 'max': 0}, 'width': {'min': 0, 'max': 0},
+                      'height': {'min': 0, 'max': 0}}}
     main(log_type=args.log_type,
          crawler=args.crawler,
-         task=args.task,
+         task=task,
          oss_endpoint=args.oss_endpoint,
          env=args.env,
-         #machine=args.machine
-         )
+         )

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio