|
@@ -1,3 +1,85 @@
|
|
|
+import random
|
|
|
+import time
|
|
|
+import requests
|
|
|
+import json
|
|
|
+import urllib3
|
|
|
+from requests.adapters import HTTPAdapter
|
|
|
+
|
|
|
+from common import Feishu, Material, Common
|
|
|
+from common.sql_help import sqlCollect
|
|
|
+from data_channel.data_help import dataHelp
|
|
|
+
|
|
|
|
|
|
class KS:
|
|
|
- pass
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def get_ks_url(cls, task_mark, url_id, number, mark, feishu_id, cookie_sheet, channel_id, name):
|
|
|
+ list = []
|
|
|
+ pcursor = ""
|
|
|
+ url = "https://www.kuaishou.com/graphql"
|
|
|
+
|
|
|
+ for i in range(3):
|
|
|
+ cookie = Material.get_cookie_data(feishu_id, cookie_sheet, channel_id)
|
|
|
+ time.sleep(random.randint(5, 10))
|
|
|
+ payload = json.dumps({
|
|
|
+ "operationName": "visionProfilePhotoList",
|
|
|
+ "variables": {
|
|
|
+ "userId": url_id,
|
|
|
+ "pcursor": pcursor,
|
|
|
+ "page": "profile"
|
|
|
+ },
|
|
|
+ "query": "fragment photoContent on PhotoEntity {\n __typename\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 riskTagContent\n riskTagUrl\n}\n\nfragment recoPhotoFragment on recoPhotoEntity {\n __typename\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 riskTagContent\n riskTagUrl\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 ...recoPhotoFragment\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': cookie,
|
|
|
+ 'Accept-Language': 'zh-CN,zh;q=0.9',
|
|
|
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
|
|
|
+ 'Referer': f'https://www.kuaishou.com/profile/{url_id}',
|
|
|
+ 'Accept-Encoding': 'gzip, deflate, br',
|
|
|
+ 'Connection': 'keep-alive'
|
|
|
+ }
|
|
|
+ urllib3.disable_warnings()
|
|
|
+ s = requests.session()
|
|
|
+ s.mount('http://', HTTPAdapter(max_retries=3))
|
|
|
+ s.mount('https://', HTTPAdapter(max_retries=3))
|
|
|
+ # response = requests.request("POST", url, headers=headers, data=payload, timeout=10)
|
|
|
+
|
|
|
+ response = s.post(url=url, headers=headers, data=payload, verify=False, timeout=10)
|
|
|
+ response.close()
|
|
|
+ if response.status_code != 200:
|
|
|
+ return list
|
|
|
+ elif "visionProfilePhotoList" not in response.json()["data"]:
|
|
|
+ Feishu.bot(mark, '机器自动改造消息通知', f'快手cookie过期,请及时更换', name)
|
|
|
+ time.sleep(900)
|
|
|
+ continue
|
|
|
+ elif "feeds" not in response.json()["data"]["visionProfilePhotoList"]:
|
|
|
+ Feishu.bot(mark, '机器自动改造消息通知', f'快手cookie过期,请及时更换', name)
|
|
|
+ time.sleep(900)
|
|
|
+ continue
|
|
|
+ elif len(response.json()["data"]["visionProfilePhotoList"]["feeds"]) == 0:
|
|
|
+ Feishu.bot(mark, '机器自动改造消息通知', f'快手cookie使用频繁无法获取到数据,请及时更换', name)
|
|
|
+ time.sleep(900)
|
|
|
+ continue
|
|
|
+ pcursor = response.json()['data']['visionProfilePhotoList']['pcursor']
|
|
|
+ feeds = response.json()['data']['visionProfilePhotoList']['feeds']
|
|
|
+ for i in range(len(feeds)):
|
|
|
+ try:
|
|
|
+ video_id = feeds[i].get("photo", {}).get("videoResource").get("h264", {}).get("videoId", "")
|
|
|
+ except KeyError:
|
|
|
+ video_id = feeds[i].get("photo", {}).get("videoResource").get("hevc", {}).get("videoId", "")
|
|
|
+ status = sqlCollect.is_used(task_mark, video_id, mark, channel_id)
|
|
|
+ if status:
|
|
|
+ cover_url = feeds[i].get('photo', {}).get('coverUrl', "")
|
|
|
+ video_url = feeds[i].get('photo', {}).get('photoUrl', "")
|
|
|
+ duration = dataHelp.video_duration(video_url)
|
|
|
+ if int(duration) >= 45:
|
|
|
+ all_data = {"video_id": video_id, "cover": cover_url, "video_url": video_url}
|
|
|
+ list.append(all_data)
|
|
|
+ if len(list) == int(number):
|
|
|
+ Common.logger("log").info(f"获取快手视频总数:{len(list)}\n")
|
|
|
+ return list
|
|
|
+ return list
|
|
|
+
|