123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import random
- import time
- import requests
- import json
- from utils.aliyun_log import AliyunLogger
- from utils.feishu_form import Material
- from utils.sql_help import sqlCollect
- class KS:
- @classmethod
- def get_ks_list(cls, task, fs_channel_name):
- # 快手app
- list = []
- url = "http://8.217.192.46:8889/crawler/kuai_shou/blogger"
- try:
- if not task["channel_url"] or not task["channel_url"].strip():
- return []
- if "历史" in task['channel']:
- sort_type = "最热"
- else:
- sort_type = "最新"
- next_cursor = ""
- for i in range(5):
- payload = json.dumps({
- "account_id": task["channel_url"],
- "sort_type": sort_type,
- "cursor": next_cursor
- })
- headers = {
- 'Content-Type': 'application/json'
- }
- time.sleep(random.randint(1, 5))
- response = requests.request("POST", url, headers=headers, data=payload, timeout=30)
- response = response.json()
- data_all_list = response["data"]
- has_more = data_all_list["has_more"]
- next_cursor = str(data_all_list["next_cursor"])
- data_list = data_all_list["data"]
- for data in data_list:
- photo_id = data["photo_id"]
- day_count = Material.get_count_restrict(task["channel"])
- if day_count:
- status = sqlCollect.is_used_days(photo_id, task['channel'], day_count)
- else:
- status = sqlCollect.is_used(photo_id, task['channel'])
- view_count = data["view_count"]
- share_count = data["share_count"]
- old_title = data["caption"] # 标题
- video_percent = '%.4f' % (int(share_count) / (view_count))
- duration = data["duration"]
- duration = int(duration)/1000
- special = float(0.0001)
- log_data = f"user:{task['channel_url']},,video_id:{photo_id},,video_url:'',original_title:{old_title},,share_count:{share_count},,view_count:{view_count},,duration:{duration}"
- AliyunLogger.logging(task['channel'], fs_channel_name, task['channel_url'], photo_id, "扫描到一条视频", "2001", log_data)
- if status:
- AliyunLogger.logging(task['channel'], fs_channel_name, task['channel_url'], photo_id, "该视频已改造过", "2002", log_data)
- continue
- if float(video_percent) < special:
- AliyunLogger.logging(task['channel'], fs_channel_name, task['channel_url'], photo_id, "不符合规则:分享/浏览小于0.0001", "2003", log_data)
- continue
- if int(share_count) < 500:
- AliyunLogger.logging(task['channel'], fs_channel_name, task['channel_url'], photo_id, "不符合规则:分享小于500", "2003", log_data)
- continue
- if int(duration) < 30 or (duration) > 720:
- AliyunLogger.logging(task['channel'], fs_channel_name, task['channel_url'], photo_id, "不符合规则:时长不符合规则大于720秒/小于30秒", "2003", log_data)
- continue
- video_url, image_url = cls.get_video(photo_id)
- if video_url:
- log_data = f"user:{task['channel']},,video_id:{photo_id},,video_url:{video_url},,original_title:{old_title},,share_count:{share_count},,view_count:{view_count},,duration:{duration}"
- all_data = {"video_id": photo_id, "cover": image_url, "video_url": video_url,
- "rule": video_percent,
- "old_title": old_title}
- list.append(all_data)
- AliyunLogger.logging(task['channel'], fs_channel_name, task['channel_url'], photo_id, "符合规则等待改造", "2004", log_data)
- if len(list) == int(task['count']):
- return list
- else:
- AliyunLogger.logging(task['channel'], fs_channel_name, task['channel_url'], photo_id, "无法获取到视频链接", "2003", log_data)
- continue
- if has_more == False:
- return list
- return list
- except Exception as exc:
- return list
- @classmethod
- def get_video(cls, video_id):
- url = "http://8.217.192.46:8889/crawler/kuai_shou/detail"
- payload = json.dumps({
- "content_id": str(video_id)
- })
- headers = {
- 'Content-Type': 'application/json'
- }
- time.sleep(random.uniform(1, 10))
- response = requests.request("POST", url, headers=headers, data=payload, timeout=30)
- response = response.json()
- data = response["data"]["data"]
- video_url = data["video_url_list"][0]["video_url"]
- image_url = data["image_url_list"][0]["image_url"]
- return video_url, image_url
|