瀏覽代碼

增加下载规则:播放量大于 10W

wangkun 2 年之前
父節點
當前提交
7306e02e55
共有 3 個文件被更改,包括 157 次插入328 次删除
  1. 157 1
      main/hour_list.py
  2. 0 324
      main/play_list.py
  3. 0 3
      main/run_play_list.py

+ 157 - 1
main/hour_list.py

@@ -717,6 +717,9 @@ class HourList:
                         v_upload_time = download_hour_sheet[i][8]
                         v_send_time = int(time.mktime(time.strptime(v_upload_time, "%Y-%m-%d %H:%M:%S")))
 
+                        # 播放量
+                        v_play_cnt = download_hour_sheet[i][10]
+
                         # # 判断视频 ID 长度,不大于 13 位
                         # if len(str(v_id)) > 13:
                         #     Common.logger(log_type).info("视频ID长度大于13位:{}", v_id)
@@ -737,7 +740,160 @@ class HourList:
                         # 从云文档中去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
                         elif v_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "yatRv2") for j in i]:
                             Common.logger(log_type).info("该视频已下载:{}", v_title)
-                            time.sleep(1)
+
+                        # 播放量大于 100000,直接下载
+                        elif int(v_play_cnt) >= 100000:
+                            Common.logger(log_type).info("播放量:{} >= 100000,满足下载规则,开始下载视频", v_play_cnt)
+
+                            try:
+                                url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
+                                headers = {
+                                    "x-b3-traceid": cls.hour_x_b3_traceid,
+                                    "X-Token-Id": cls.hour_x_token_id,
+                                    "uid": cls.hour_uid,
+                                    "content-type": "application/json",
+                                    "Accept-Encoding": "gzip,compress,br,deflate",
+                                    "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
+                                                  ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
+                                                  'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
+                                    "Referer": cls.hour_referer
+                                }
+                                data = {
+                                    "play_src": "1",
+                                    "profile_id": int(p_id),
+                                    "profile_mid": int(p_mid),
+                                    "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
+                                          "!400x400r/crop/400x400/interlace/1/format/jpg",
+                                    "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
+                                            "/!80x80r/crop/80x80/interlace/1/format/jpg",
+                                    "share_width": 625,
+                                    "share_height": 500,
+                                    "no_comments": True,
+                                    "no_follow": True,
+                                    "vid": v_id,
+                                    "hot_l1_comment": True,
+                                    "token": cls.hour_token,
+                                    "uid": cls.hour_uid,
+                                    "proj": "ma",
+                                    "wx_ver": "8.0.20",
+                                    "code_ver": "3.62.0",
+                                    "log_common_params": {
+                                        "e": [{
+                                            "data": {
+                                                "page": "dynamicSharePage"
+                                            }
+                                        }],
+                                        "ext": {
+                                            "brand": "iPhone",
+                                            "device": "iPhone 11",
+                                            "os": "iOS 14.7.1",
+                                            "weixinver": "8.0.20",
+                                            "srcver": "2.24.3",
+                                            "net": "wifi",
+                                            "scene": "1089"
+                                        },
+                                        "pj": "1",
+                                        "pf": "2",
+                                        "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
+                                    }
+                                }
+                                urllib3.disable_warnings()
+                                r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
+                                hour_play_cnt = r.json()["data"]["play_pv"]
+                                hour_cover_url = r.json()["data"]["url"]
+                                hour_video_url = r.json()["data"]["v_url"]
+                                hour_video_duration = r.json()["data"]["du"]
+                                hour_video_comment_cnt = r.json()["data"]["comment_count"]
+                                hour_video_like_cnt = r.json()["data"]["favor"]["total"]
+                                hour_video_share_cnt = r.json()["data"]["share"]
+                                hour_video_width = r.json()["data"]["w"]
+                                hour_video_height = r.json()["data"]["h"]
+                                hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
+                                hour_video_send_time = r.json()["data"]["t"]
+                                hour_user_name = r.json()["data"]["user"]["nick"]
+                                hour_head_url = r.json()["data"]["user"]["hurl"]
+                                Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
+
+                                # 下载封面
+                                Common.download_method(log_type, "cover", v_title, hour_cover_url)
+                                # 下载视频
+                                Common.download_method(log_type, "video", v_title, hour_video_url)
+                                # 保存视频信息至 "./videos/{download_video_title}/info.txt"
+                                with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
+                                    f_a.write(str(v_id) + "\n" +
+                                              str(v_title) + "\n" +
+                                              str(int(int(hour_video_duration) / 1000)) + "\n" +
+                                              str(hour_play_cnt) + "\n" +
+                                              str(hour_video_comment_cnt) + "\n" +
+                                              str(hour_video_like_cnt) + "\n" +
+                                              str(hour_video_share_cnt) + "\n" +
+                                              str(hour_video_resolution) + "\n" +
+                                              str(hour_video_send_time) + "\n" +
+                                              str(hour_user_name) + "\n" +
+                                              str(hour_head_url) + "\n" +
+                                              str(hour_video_url) + "\n" +
+                                              str(hour_cover_url) + "\n" +
+                                              str("90747742180aeb22c0fe3a3c6a38f3d9"))
+                                Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
+
+                                # 上传视频
+                                Common.logger(log_type).info("开始上传视频")
+                                our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
+                                our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
+                                    our_video_id) + "/info"
+                                Common.logger(log_type).info("视频上传完成:{}", v_title)
+                                # 上传完成时间
+                                upload_time = int(time.time())
+
+                                # 保存视频信息到云文档
+                                Common.logger(log_type).info("添加视频到云文档:{}", v_title)
+                                # 插入空行
+                                time.sleep(1)
+                                Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
+                                # 视频信息写入云文档
+                                values = [[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(upload_time))),
+                                           "小时级上升榜",
+                                           v_id,
+                                           v_title,
+                                           our_video_link,
+                                           hour_play_cnt,
+                                           hour_video_comment_cnt,
+                                           hour_video_like_cnt,
+                                           hour_video_share_cnt,
+                                           int(hour_video_duration) / 1000,
+                                           hour_video_resolution,
+                                           time.strftime("%Y-%m-%d %H:%M:%S",
+                                                         time.localtime(int(hour_video_send_time) / 1000)),
+                                           hour_user_name,
+                                           p_id,
+                                           p_mid,
+                                           hour_head_url,
+                                           hour_cover_url,
+                                           hour_video_url]]
+                                time.sleep(1)
+                                Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
+
+                                # 保存视频信息到监控表
+                                Common.logger(log_type).info("添加视频到监控表:{}", v_title)
+                                # 插入空行
+                                time.sleep(1)
+                                Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
+                                # 视频信息写入监控表
+                                values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
+                                           v_id,
+                                           v_title,
+                                           our_video_link,
+                                           p_id,
+                                           p_mid,
+                                           hour_user_name,
+                                           int(hour_video_duration) / 1000,
+                                           time.strftime("%Y/%m/%d %H:%M:%S",
+                                                         time.localtime(int(hour_video_send_time) / 1000)),
+                                           hour_play_cnt]]
+                                time.sleep(1)
+                                Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
+                            except Exception as e:
+                                Common.logger(log_type).error("下载视频异常:{}", e)
 
                         # 上升榜判断逻辑,任意时间段上升量>=5000,连续两个时间段上升量>=2000
                         elif int(ten_cnt) >= 5000 or int(fifteen_cnt) >= 5000 or int(twenty_cnt) >= 5000:

+ 0 - 324
main/play_list.py

@@ -1,324 +0,0 @@
-# -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2022/7/1
-import os
-import sys
-import time
-import requests
-import urllib3
-sys.path.append(os.getcwd())
-from main.common import Common
-from main.feishu_lib import Feishu
-proxies = {"http": None, "https": None}
-
-
-class PlayList:
-    # 配置微信
-    wechat_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "dzcWHw")
-    hour_x_b3_traceid = wechat_sheet[2][1]
-    hour_x_token_id = wechat_sheet[3][1]
-    hour_referer = wechat_sheet[4][1]
-    hour_uid = wechat_sheet[5][1]
-    hour_token = wechat_sheet[6][1]
-
-    # 过滤敏感词
-    @classmethod
-    def sensitive_words(cls, log_type):
-        # 敏感词库列表
-        word_list = []
-        # 从云文档读取所有敏感词,添加到词库列表
-        time.sleep(1)
-        lists = Feishu.get_values_batch(log_type, "xiaoniangao", "DRAnZh")
-        for i in lists:
-            for j in i:
-                # 过滤空的单元格内容
-                if j is None:
-                    pass
-                else:
-                    word_list.append(j)
-        return word_list
-
-    # 视频ID过滤字母
-    @classmethod
-    def sensitive_videoid_words(cls):
-        # 字母列表
-        words_list = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
-                      "t", "u", "v", "w", "x", "y", "z",
-                      "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
-                      "T", "U", "V", "W", "X", "Y", "Z"]
-        return words_list
-
-    # 基础门槛规则
-    @staticmethod
-    def download_rule(d_duration, d_width, d_height, d_play_cnt, d_like_cnt, d_share_cnt, d_send_time):
-        """
-        下载视频的基本规则
-        :param d_duration: 时长
-        :param d_width: 宽
-        :param d_height: 高
-        :param d_play_cnt: 播放量
-        :param d_like_cnt: 点赞量
-        :param d_share_cnt: 分享量
-        :param d_send_time: 发布时间
-        :return: 满足规则,返回 True;反之,返回 False
-        """
-        # 视频时长
-        if int(float(d_duration)) >= 40:
-            # 宽或高
-            if int(d_width) >= 0 or int(d_height) >= 0:
-                # 播放量
-                if int(d_play_cnt) >= 100000:
-                    # 点赞量
-                    if int(d_like_cnt) >= 0:
-                        # 分享量
-                        if int(d_share_cnt) >= 0:
-                            # 发布时间 <= 7 天
-                            if int(time.time()) - int(d_send_time) / 1000 <= 604800:
-                                return True
-                            else:
-                                return False
-                        else:
-                            return False
-                    else:
-                        return False
-                else:
-                    return False
-            return False
-        return False
-
-    # 获取列表
-    @classmethod
-    def get_hour_list_feeds(cls, log_type):
-        """
-        1.从列表获取视频,7 天内,播放量>=5000
-        2.时长 1-10min
-        3.每天10:00、15:00、20:00 把符合规则的视频,写入云文档
-        https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=ba0da4
-        """
-        url = "https://kapi.xiaoniangao.cn/trends/get_recommend_trends"
-        headers = {
-            "x-b3-traceid": cls.hour_x_b3_traceid,
-            "X-Token-Id": cls.hour_x_token_id,
-            "uid": cls.hour_uid,
-            "content-type": "application/json",
-            "Accept-Encoding": "gzip,compress,br,deflate",
-            "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
-                          ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
-                          'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
-            "Referer": cls.hour_referer
-        }
-        data = {
-            "log_params": {
-                "page": "discover_rec",
-                "common": {
-                    "brand": "iPhone",
-                    "device": "iPhone 11",
-                    "os": "iOS 14.7.1",
-                    "weixinver": "8.0.20",
-                    "srcver": "2.24.2",
-                    "net": "wifi",
-                    "scene": 1089
-                }
-            },
-            "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!750x500r/crop/750x500/interlace/1/format/jpg",
-            "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!80x80r/crop/80x80/interlace/1/format/jpg",
-            "share_width": 625,
-            "share_height": 500,
-            "ext": {
-                "fmid": 0,
-                "items": {}
-            },
-            "app": "xng",
-            "rec_scene": "discover_rec",
-            "log_common_params": {
-                "e": [{
-                    "data": {
-                        "page": "discoverIndexPage",
-                        "topic": "recommend"
-                    },
-                    "ab": {}
-                }],
-                "ext": {
-                    "brand": "iPhone",
-                    "device": "iPhone 11",
-                    "os": "iOS 14.7.1",
-                    "weixinver": "8.0.20",
-                    "srcver": "2.24.3",
-                    "net": "wifi",
-                    "scene": "1089"
-                },
-                "pj": "1",
-                "pf": "2",
-                "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
-            },
-            "refresh": False,
-            "token": cls.hour_token,
-            "uid": cls.hour_uid,
-            "proj": "ma",
-            "wx_ver": "8.0.20",
-            "code_ver": "3.62.0"
-        }
-        try:
-            urllib3.disable_warnings()
-            r = requests.post(url=url, headers=headers, json=data, proxies=proxies, verify=False)
-            if "data" not in r.json():
-                Common.logger(log_type).warning("获取视频feeds错误:{}", r.text)
-            elif "list" not in r.json()["data"]:
-                Common.logger(log_type).warning("获取视频feeds无数据,休眠10s:{}", r.json()["data"])
-            else:
-                # 视频列表数据
-                feeds = r.json()["data"]["list"]
-                for i in range(len(feeds)):
-                    # 标题
-                    if "title" in feeds[i]:
-                        video_title = feeds[i]["title"].strip().replace("\n", "") \
-                            .replace("/", "").replace("\r", "").replace("#", "") \
-                            .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
-                            .replace(":", "").replace("*", "").replace("?", "") \
-                            .replace("?", "").replace('"', "").replace("<", "") \
-                            .replace(">", "").replace("|", "").replace(" ", "")
-                    else:
-                        video_title = 0
-
-                    # 视频 ID
-                    if "vid" in feeds[i]:
-                        video_id = feeds[i]["vid"]
-                    else:
-                        video_id = 0
-
-                    # 播放量
-                    if "play_pv" in feeds[i]:
-                        video_play_cnt = feeds[i]["play_pv"]
-                    else:
-                        video_play_cnt = 0
-
-                    # 点赞量
-                    if "favor" in feeds[i]:
-                        video_like_cnt = feeds[i]["favor"]["total"]
-                    else:
-                        video_like_cnt = 0
-
-                    # 分享量
-                    if "share" in feeds[i]:
-                        video_share_cnt = feeds[i]["share"]
-                    else:
-                        video_share_cnt = 0
-
-                    # # 评论量
-                    # if "comment_count" in feeds[i]:
-                    #     video_comment_cnt = feeds[i]["comment_count"]
-                    # else:
-                    #     video_comment_cnt = 0
-
-                    # 时长
-                    if "du" in feeds[i]:
-                        video_duration = int(feeds[i]["du"] / 1000)
-                    else:
-                        video_duration = 0
-
-                    # 宽和高
-                    if "w" or "h" in feeds[i]:
-                        video_width = feeds[i]["w"]
-                        video_height = feeds[i]["h"]
-                    else:
-                        video_width = 0
-                        video_height = 0
-
-                    # 发布时间
-                    if "t" in feeds[i]:
-                        video_send_time = feeds[i]["t"]
-                    else:
-                        video_send_time = 0
-
-                    # 用户名 / 头像
-                    if "user" in feeds[i]:
-                        user_name = feeds[i]["user"]["nick"].strip().replace("\n", "") \
-                            .replace("/", "").replace("快手", "").replace(" ", "") \
-                            .replace(" ", "").replace("&NBSP", "").replace("\r", "")
-                        head_url = feeds[i]["user"]["hurl"]
-                    else:
-                        user_name = 0
-                        head_url = 0
-
-                    # 用户 ID
-                    profile_id = feeds[i]["id"]
-
-                    # 用户 mid
-                    profile_mid = feeds[i]["user"]["mid"]
-
-                    # 视频封面
-                    if "url" in feeds[i]:
-                        cover_url = feeds[i]["url"]
-                    else:
-                        cover_url = 0
-
-                    # 视频播放地址
-                    if "v_url" in feeds[i]:
-                        video_url = feeds[i]["v_url"]
-                    else:
-                        video_url = 0
-
-                    Common.logger(log_type).info("标题:{}", video_title)
-                    Common.logger(log_type).info("视频ID:{}", video_id)
-                    Common.logger(log_type).info("播放量:{}", video_play_cnt)
-                    # Common.logger(log_type).info("点赞量:{}", video_like_cnt)
-                    # Common.logger(log_type).info("分享量:{}", video_share_cnt)
-                    # Common.logger(log_type).info("评论数:{}", video_comment_cnt)
-                    Common.logger(log_type).info("时长:{}秒", video_duration)
-                    # Common.logger(log_type).info("宽高:{}*{}", video_width, video_height)
-                    Common.logger(log_type).info(
-                        "视频发布时间:{}", time.strftime(
-                            "%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)))
-                    Common.logger(log_type).info("用户名:{}", user_name)
-                    # Common.logger(log_type).info("用户头像:{}", head_url)
-                    # Common.logger(log_type).info("封面:{}", cover_url)
-                    Common.logger(log_type).info("播放地址:{}", video_url)
-
-                    # 过滤无效视频
-                    if video_title == 0 or video_id == 0 or video_duration == 0 \
-                            or video_send_time == 0 or user_name == 0 or head_url == 0 \
-                            or cover_url == 0 or video_url == 0:
-                        Common.logger(log_type).warning("无效视频")
-
-                    elif cls.download_rule(video_duration, video_width, video_height, video_play_cnt,
-                                           video_like_cnt, video_share_cnt, video_send_time) is False:
-                        Common.logger(log_type).info("不满足基础门槛规则")
-
-                    # 过滤敏感词
-                    elif any(word if word in video_title else False for word in
-                             cls.sensitive_words(log_type)) is True:
-                        Common.logger(log_type).info("视频已中敏感词:{}".format(video_title))
-                        time.sleep(1)
-
-                    # 从云文档中去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
-                    elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "yatRv2") for j in
-                                      i]:
-                        Common.logger(log_type).info("该视频已下载:{}", video_title)
-                        time.sleep(1)
-
-                    else:
-                        Common.logger(log_type).info("该视频未下载,添加至feeds中:{}".format(video_title))
-                        # feeds工作表,插入空行
-                        time.sleep(1)
-                        Feishu.insert_columns(log_type, "xiaoniangao", "ba0da4", "ROWS", 2, 3)
-
-                        # 获取当前时间
-                        get_feeds_time = int(time.time())
-                        # 看一看云文档,工作表中写入数据
-                        values = [[profile_id,
-                                   profile_mid,
-                                   video_id,
-                                   video_title,
-                                   user_name,
-                                   video_duration,
-                                   cover_url,
-                                   video_url,
-                                   time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)),
-                                   str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(get_feeds_time))),
-                                   video_play_cnt]]
-                        # 等待 1s,防止操作云文档太频繁,导致报错
-                        time.sleep(1)
-                        Feishu.update_values(log_type, "xiaoniangao", "ba0da4", "A3:K3", values)
-
-        except Exception as e:
-            Common.logger(log_type).error("获取小时榜视频列表异常:{}", e)

+ 0 - 3
main/run_play_list.py

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