recommend_kuaishou.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/2/24
  4. import os
  5. import random
  6. import shutil
  7. import sys
  8. import time
  9. import string
  10. from hashlib import md5
  11. import requests
  12. import json
  13. import urllib3
  14. from requests.adapters import HTTPAdapter
  15. sys.path.append(os.getcwd())
  16. from common.common import Common
  17. from common.feishu import Feishu
  18. from common.getuser import getUser
  19. from common.db import MysqlHelper
  20. from common.publish import Publish
  21. from common.public import get_user_from_mysql
  22. from common.userAgent import get_random_user_agent
  23. class KuaiShouRecommend:
  24. platform = "快手"
  25. tag = "快手爬虫,推荐爬虫策略"
  26. @classmethod
  27. def get_rule(cls, log_type, crawler):
  28. try:
  29. rule_sheet = Feishu.get_values_batch(log_type, crawler, "NQ6CZN")
  30. rule_dict = {
  31. "play_cnt": f"{rule_sheet[0][1]}{rule_sheet[0][2]}",
  32. "video_width": f"{rule_sheet[1][1]}{rule_sheet[1][2]}",
  33. "video_height": f"{rule_sheet[2][1]}{rule_sheet[2][2]}",
  34. "like_cnt": f"{rule_sheet[5][1]}{rule_sheet[5][2]}",
  35. "duration": f"{rule_sheet[3][1]}{rule_sheet[3][2]}",
  36. "publish_time": f"{rule_sheet[4][1]}{rule_sheet[4][2]}",
  37. }
  38. return rule_dict
  39. except Exception as e:
  40. Common.logger(log_type, crawler).error(f"get_rule:{e}\n")
  41. @classmethod
  42. def download_rule(cls, video_dict, rule_dict):
  43. if eval(f"{video_dict['video_width']}{rule_dict['video_width']}") is True \
  44. and eval(f"{video_dict['play_cnt']}{rule_dict['play_cnt']}") is True \
  45. and eval(f"{video_dict['video_height']}{rule_dict['video_height']}") is True \
  46. and eval(f"{video_dict['like_cnt']}{rule_dict['like_cnt']}") is True \
  47. and eval(f"{video_dict['duration']}{rule_dict['duration']}") is True \
  48. and eval(f"{video_dict['publish_time']}{rule_dict['publish_time']}") is True:
  49. return True
  50. else:
  51. return False
  52. # 过滤词库
  53. @classmethod
  54. def filter_words(cls, log_type, crawler):
  55. try:
  56. while True:
  57. filter_words_sheet = Feishu.get_values_batch(log_type, crawler, 'HIKVvs')
  58. if filter_words_sheet is None:
  59. Common.logger(log_type, crawler).warning(f"filter_words_sheet:{filter_words_sheet} 10秒钟后重试")
  60. continue
  61. filter_words_list = []
  62. for x in filter_words_sheet:
  63. for y in x:
  64. if y is None:
  65. pass
  66. else:
  67. filter_words_list.append(y)
  68. return filter_words_list
  69. except Exception as e:
  70. Common.logger(log_type, crawler).error(f'filter_words异常:{e}\n')
  71. # 万能标题
  72. @classmethod
  73. def random_title(cls, log_type, crawler):
  74. try:
  75. while True:
  76. random_title_sheet = Feishu.get_values_batch(log_type, crawler, '0DiyXe')
  77. if random_title_sheet is None:
  78. Common.logger(log_type, crawler).warning(f"filter_words_sheet:{random_title_sheet} 10秒钟后重试")
  79. continue
  80. random_title_list = []
  81. for x in random_title_sheet:
  82. for y in x:
  83. if y is None:
  84. pass
  85. else:
  86. random_title_list.append(y)
  87. return random.choice(random_title_list)
  88. except Exception as e:
  89. Common.logger(log_type, crawler).error(f'random_title:{e}\n')
  90. # 获取用户信息列表
  91. @classmethod
  92. def get_user_list(cls, log_type, crawler, sheetid, env, machine):
  93. try:
  94. while True:
  95. user_sheet = Feishu.get_values_batch(log_type, crawler, sheetid)
  96. if user_sheet is None:
  97. Common.logger(log_type, crawler).warning(f"user_sheet:{user_sheet} 10秒钟后重试")
  98. continue
  99. our_user_list = []
  100. for i in range(1, len(user_sheet)):
  101. # for i in range(1, 2):
  102. out_uid = user_sheet[i][2]
  103. user_name = user_sheet[i][3]
  104. our_uid = user_sheet[i][6]
  105. our_user_link = user_sheet[i][7]
  106. if out_uid is None or user_name is None:
  107. Common.logger(log_type, crawler).info("空行\n")
  108. else:
  109. Common.logger(log_type, crawler).info(f"正在更新 {user_name} 用户信息\n")
  110. if our_uid is None:
  111. out_user_info = cls.get_out_user_info(log_type, crawler, out_uid)
  112. out_user_dict = {
  113. "out_uid": out_uid,
  114. "user_name": user_name,
  115. "out_avatar_url": out_user_info["out_avatar_url"],
  116. "out_create_time": '',
  117. "out_tag": '',
  118. "out_play_cnt": 0,
  119. "out_fans": out_user_info["out_fans"],
  120. "out_follow": out_user_info["out_follow"],
  121. "out_friend": 0,
  122. "out_like": 0,
  123. "platform": cls.platform,
  124. "tag": cls.tag,
  125. }
  126. our_user_dict = getUser.create_user(log_type=log_type, crawler=crawler,
  127. out_user_dict=out_user_dict, env=env, machine=machine)
  128. our_uid = our_user_dict['our_uid']
  129. our_user_link = our_user_dict['our_user_link']
  130. Feishu.update_values(log_type, crawler, sheetid, f'G{i + 1}:H{i + 1}',
  131. [[our_uid, our_user_link]])
  132. Common.logger(log_type, crawler).info(f'站内用户信息写入飞书成功!\n')
  133. our_user_list.append(our_user_dict)
  134. else:
  135. our_user_dict = {
  136. 'out_uid': out_uid,
  137. 'user_name': user_name,
  138. 'our_uid': our_uid,
  139. 'our_user_link': our_user_link,
  140. }
  141. our_user_list.append(our_user_dict)
  142. return our_user_list
  143. except Exception as e:
  144. Common.logger(log_type, crawler).error(f'get_user_list:{e}\n')
  145. # 处理视频标题
  146. @classmethod
  147. def video_title(cls, log_type, crawler, title):
  148. title_split1 = title.split(" #")
  149. if title_split1[0] != "":
  150. title1 = title_split1[0]
  151. else:
  152. title1 = title_split1[-1]
  153. title_split2 = title1.split(" #")
  154. if title_split2[0] != "":
  155. title2 = title_split2[0]
  156. else:
  157. title2 = title_split2[-1]
  158. title_split3 = title2.split("@")
  159. if title_split3[0] != "":
  160. title3 = title_split3[0]
  161. else:
  162. title3 = title_split3[-1]
  163. video_title = title3.strip().replace("\n", "") \
  164. .replace("/", "").replace("快手", "").replace(" ", "") \
  165. .replace(" ", "").replace("&NBSP", "").replace("\r", "") \
  166. .replace("#", "").replace(".", "。").replace("\\", "") \
  167. .replace(":", "").replace("*", "").replace("?", "") \
  168. .replace("?", "").replace('"', "").replace("<", "") \
  169. .replace(">", "").replace("|", "").replace("@", "")[:40]
  170. if video_title.replace(" ", "") == "" or video_title == "。。。" or video_title == "...":
  171. return cls.random_title(log_type, crawler)
  172. else:
  173. return video_title
  174. @classmethod
  175. def get_videoList(cls, log_type, crawler, strategy, our_uid, oss_endpoint, env, machine):
  176. rule_dict_1 = cls.get_rule(log_type, crawler)
  177. if rule_dict_1 is None:
  178. Common.logger(log_type, crawler).warning(f"rule_dict is None")
  179. return
  180. for i in range(100):
  181. url = "https://www.kuaishou.com/graphql"
  182. payload = json.dumps({
  183. "operationName": "visionNewRecoFeed",
  184. "variables": {
  185. "dailyFirstPage": False
  186. },
  187. "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"
  188. })
  189. s = string.ascii_lowercase
  190. r = random.choice(s)
  191. headers = {
  192. 'Accept-Language': 'zh-CN,zh;q=0.9',
  193. 'Connection': 'keep-alive',
  194. 'Cookie': 'kpf=PC_WEB; clientid=3; did=web_aba004b1780f4d7174d0a2ff42da1f{r}7; kpn=KUAISHOU_VISION;'.format(r=r),
  195. 'Origin': 'https://www.kuaishou.com',
  196. 'Referer': 'https://www.kuaishou.com/new-reco',
  197. 'Sec-Fetch-Dest': 'empty',
  198. 'Sec-Fetch-Mode': 'cors',
  199. 'Sec-Fetch-Site': 'same-origin',
  200. 'User-Agent': get_random_user_agent('pc'),
  201. 'accept': '*/*',
  202. 'content-type': 'application/json',
  203. 'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
  204. 'sec-ch-ua-mobile': '?0',
  205. 'sec-ch-ua-platform': '"macOS"'
  206. }
  207. try:
  208. urllib3.disable_warnings()
  209. s = requests.session()
  210. # max_retries=3 重试3次
  211. s.mount('http://', HTTPAdapter(max_retries=3))
  212. s.mount('https://', HTTPAdapter(max_retries=3))
  213. response = s.post(url=url, headers=headers, data=payload, proxies=Common.tunnel_proxies(), verify=False,
  214. timeout=10)
  215. response.close()
  216. except Exception as e:
  217. Common.logger(log_type, crawler).error(f"get_videoList:{e}\n")
  218. continue
  219. # Common.logger(log_type, crawler).info(f"get_videoList:{response.text}\n")
  220. if response.status_code != 200:
  221. Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.text}\n")
  222. continue
  223. elif 'data' not in response.json():
  224. Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.json()}\n")
  225. continue
  226. elif 'visionNewRecoFeed' not in response.json()['data']:
  227. Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.json()['data']}\n")
  228. continue
  229. elif 'feeds' not in response.json()['data']['visionNewRecoFeed']:
  230. Common.logger(log_type, crawler).warning(
  231. f"get_videoList_response:{response.json()['data']['visionNewRecoFeed']}\n")
  232. continue
  233. elif len(response.json()['data']['visionNewRecoFeed']['feeds']) == 0:
  234. Common.logger(log_type, crawler).info("没有更多视频啦 ~\n")
  235. continue
  236. else:
  237. feeds = response.json()['data']['visionNewRecoFeed']['feeds']
  238. # pcursor = response.json()['data']['visionNewRecoFeed']['pcursor']
  239. for i in range(len(feeds)):
  240. if 'photo' not in feeds[i]:
  241. Common.logger(log_type, crawler).warning(f"get_videoList:{feeds[i]}\n")
  242. continue
  243. # video_title
  244. if 'caption' not in feeds[i]['photo']:
  245. video_title = cls.random_title(log_type, crawler)
  246. elif feeds[i]['photo']['caption'].strip() == "":
  247. video_title = cls.random_title(log_type, crawler)
  248. else:
  249. video_title = cls.video_title(log_type, crawler, feeds[i]['photo']['caption'])
  250. if 'videoResource' not in feeds[i]['photo'] \
  251. and 'manifest' not in feeds[i]['photo'] \
  252. and 'manifestH265' not in feeds[i]['photo']:
  253. Common.logger(log_type, crawler).warning(f"get_videoList:{feeds[i]['photo']}\n")
  254. continue
  255. videoResource = feeds[i]['photo']['videoResource']
  256. if 'h264' not in videoResource and 'hevc' not in videoResource:
  257. Common.logger(log_type, crawler).warning(f"get_videoList:{videoResource}\n")
  258. continue
  259. # video_id
  260. if 'h264' in videoResource and 'videoId' in videoResource['h264']:
  261. video_id = videoResource['h264']['videoId']
  262. elif 'hevc' in videoResource and 'videoId' in videoResource['hevc']:
  263. video_id = videoResource['hevc']['videoId']
  264. else:
  265. video_id = ""
  266. # play_cnt
  267. if 'viewCount' not in feeds[i]['photo']:
  268. play_cnt = 0
  269. else:
  270. play_cnt = int(feeds[i]['photo']['viewCount'])
  271. # like_cnt
  272. if 'realLikeCount' not in feeds[i]['photo']:
  273. like_cnt = 0
  274. else:
  275. like_cnt = feeds[i]['photo']['realLikeCount']
  276. # publish_time
  277. if 'timestamp' not in feeds[i]['photo']:
  278. publish_time_stamp = 0
  279. publish_time_str = ''
  280. publish_time = 0
  281. else:
  282. publish_time_stamp = int(int(feeds[i]['photo']['timestamp']) / 1000)
  283. publish_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(publish_time_stamp))
  284. publish_time = int((int(time.time()) - publish_time_stamp) / (3600 * 24))
  285. # duration
  286. if 'duration' not in feeds[i]['photo']:
  287. duration = 0
  288. else:
  289. duration = int(int(feeds[i]['photo']['duration']) / 1000)
  290. # video_width / video_height / video_url
  291. mapping = {}
  292. for item in ['width', 'height']:
  293. try:
  294. val = str(videoResource['h264']['adaptationSet'][0]['representation'][0][item])
  295. except Exception:
  296. val = str(videoResource['hevc']['adaptationSet'][0]['representation'][0][item])
  297. except:
  298. val = ''
  299. mapping[item] = val
  300. video_width = int(mapping['width']) if mapping['width'] != '' else 0
  301. video_height = int(mapping['height']) if mapping['height'] != '' else 0
  302. # cover_url
  303. if 'coverUrl' not in feeds[i]['photo']:
  304. cover_url = ""
  305. else:
  306. cover_url = feeds[i]['photo']['coverUrl']
  307. # user_name / avatar_url
  308. try:
  309. user_name = feeds[i]['author']['name']
  310. avatar_url = feeds[i]['author']['headerUrl']
  311. user_id = feeds[i]['author']['id']
  312. except Exception:
  313. user_name = ''
  314. avatar_url = ''
  315. user_id = ''
  316. video_url = feeds[i]['photo']['photoUrl']
  317. video_dict = {'video_title': video_title,
  318. 'video_id': video_id,
  319. 'play_cnt': play_cnt,
  320. 'comment_cnt': 0,
  321. 'like_cnt': like_cnt,
  322. 'share_cnt': 0,
  323. 'video_width': video_width,
  324. 'video_height': video_height,
  325. 'duration': duration,
  326. 'publish_time': publish_time,
  327. 'publish_time_stamp': publish_time_stamp,
  328. 'publish_time_str': publish_time_str,
  329. 'user_name': user_name,
  330. 'user_id': user_id,
  331. 'avatar_url': avatar_url,
  332. 'cover_url': cover_url,
  333. 'video_url': video_url,
  334. 'session': f"kuaishou{int(time.time())}"}
  335. rule_1 = cls.download_rule(video_dict, rule_dict_1)
  336. Common.logger(log_type, crawler).info(f"video_title:{video_title}")
  337. Common.logger(log_type, crawler).info(f"video_id:{video_id}\n")
  338. Common.logger(log_type, crawler).info(
  339. f"play_cnt:{video_dict['play_cnt']}{rule_dict_1['play_cnt']}, {eval(str(video_dict['play_cnt']) + str(rule_dict_1['play_cnt']))}")
  340. Common.logger(log_type, crawler).info(
  341. f"like_cnt:{video_dict['like_cnt']}{rule_dict_1['like_cnt']}, {eval(str(video_dict['like_cnt']) + str(rule_dict_1['like_cnt']))}")
  342. Common.logger(log_type, crawler).info(
  343. f"video_width:{video_dict['video_width']}{rule_dict_1['video_width']}, {eval(str(video_dict['video_width']) + str(rule_dict_1['video_width']))}")
  344. Common.logger(log_type, crawler).info(
  345. f"video_height:{video_dict['video_height']}{rule_dict_1['video_height']}, {eval(str(video_dict['video_height']) + str(rule_dict_1['video_height']))}")
  346. Common.logger(log_type, crawler).info(
  347. f"duration:{video_dict['duration']}{rule_dict_1['duration']}, {eval(str(video_dict['duration']) + str(rule_dict_1['duration']))}")
  348. Common.logger(log_type, crawler).info(
  349. f"publish_time:{video_dict['publish_time']}{rule_dict_1['publish_time']}, {eval(str(video_dict['publish_time']) + str(rule_dict_1['publish_time']))}")
  350. Common.logger(log_type, crawler).info(f"rule_1:{rule_1}\n")
  351. if video_title == "" or video_url == "":
  352. Common.logger(log_type, crawler).info("无效视频\n")
  353. continue
  354. elif rule_1 is True:
  355. cls.download_publish(log_type=log_type,
  356. crawler=crawler,
  357. strategy=strategy,
  358. video_dict=video_dict,
  359. rule_dict=rule_dict_1,
  360. our_uid=our_uid,
  361. oss_endpoint=oss_endpoint,
  362. env=env,
  363. machine=machine)
  364. else:
  365. Common.logger(log_type, crawler).info("不满足下载规则\n")
  366. @classmethod
  367. def repeat_video(cls, log_type, crawler, video_id, video_title, publish_time, env, machine):
  368. 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}") """
  369. repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env, machine)
  370. return len(repeat_video)
  371. @classmethod
  372. def download_publish(cls, log_type, crawler, strategy, video_dict, rule_dict, our_uid, oss_endpoint, env, machine):
  373. try:
  374. download_finished = False
  375. if cls.repeat_video(log_type, crawler, video_dict['video_id'], video_dict['video_title'],
  376. video_dict['publish_time_str'], env, machine) != 0:
  377. Common.logger(log_type, crawler).info('视频已下载\n')
  378. elif any(word if word in video_dict['video_title'] else False for word in
  379. cls.filter_words(log_type, crawler)) is True:
  380. Common.logger(log_type, crawler).info('标题已中过滤词\n')
  381. else:
  382. # 下载视频
  383. Common.download_method(log_type=log_type, crawler=crawler, text='video',
  384. title=video_dict['video_title'], url=video_dict['video_url'])
  385. md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
  386. if os.path.getsize(f"./{crawler}/videos/{md_title}/video.mp4") == 0:
  387. # 删除视频文件夹
  388. shutil.rmtree(f"./{crawler}/videos/{md_title}")
  389. Common.logger(log_type, crawler).info("视频size=0,删除成功\n")
  390. return
  391. # 下载封面
  392. Common.download_method(log_type=log_type, crawler=crawler, text='cover',
  393. title=video_dict['video_title'], url=video_dict['cover_url'])
  394. # 保存视频信息至txt
  395. Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
  396. # 上传视频
  397. Common.logger(log_type, crawler).info("开始上传视频...")
  398. our_video_id = Publish.upload_and_publish(log_type=log_type,
  399. crawler=crawler,
  400. strategy=strategy,
  401. our_uid=our_uid,
  402. env=env,
  403. oss_endpoint=oss_endpoint)
  404. if env == 'dev':
  405. our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  406. else:
  407. our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  408. Common.logger(log_type, crawler).info("视频上传完成")
  409. if our_video_id is None:
  410. Common.logger(log_type, crawler).warning(f"our_video_id:{our_video_id} 删除该视频文件夹")
  411. # 删除视频文件夹
  412. shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
  413. return download_finished
  414. # 视频信息保存数据库
  415. insert_sql = f""" insert into crawler_video(video_id,
  416. user_id,
  417. out_user_id,
  418. platform,
  419. strategy,
  420. out_video_id,
  421. video_title,
  422. cover_url,
  423. video_url,
  424. duration,
  425. publish_time,
  426. play_cnt,
  427. crawler_rule,
  428. width,
  429. height)
  430. values({our_video_id},
  431. {our_uid},
  432. "{video_dict['user_id']}",
  433. "{cls.platform}",
  434. "{strategy}",
  435. "{video_dict['video_id']}",
  436. "{video_dict['video_title']}",
  437. "{video_dict['cover_url']}",
  438. "{video_dict['video_url']}",
  439. {int(video_dict['duration'])},
  440. "{video_dict['publish_time_str']}",
  441. {int(video_dict['play_cnt'])},
  442. '{json.dumps(rule_dict)}',
  443. {int(video_dict['video_width'])},
  444. {int(video_dict['video_height'])}) """
  445. Common.logger(log_type, crawler).info(f"insert_sql:{insert_sql}")
  446. MysqlHelper.update_values(log_type, crawler, insert_sql, env, machine)
  447. Common.logger(log_type, crawler).info('视频信息插入数据库成功!\n')
  448. # 视频写入飞书
  449. Feishu.insert_columns(log_type, 'kuaishou', "Aps2BI", "ROWS", 1, 2)
  450. upload_time = int(time.time())
  451. values = [[our_video_id,
  452. time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(upload_time)),
  453. strategy,
  454. str(video_dict['video_id']),
  455. video_dict['video_title'],
  456. our_video_link,
  457. video_dict['play_cnt'],
  458. video_dict['comment_cnt'],
  459. video_dict['like_cnt'],
  460. video_dict['share_cnt'],
  461. video_dict['duration'],
  462. f"{video_dict['video_width']}*{video_dict['video_height']}",
  463. video_dict['publish_time_str'],
  464. video_dict['user_name'],
  465. video_dict['user_id'],
  466. video_dict['avatar_url'],
  467. video_dict['cover_url'],
  468. video_dict['video_url']]]
  469. time.sleep(1)
  470. Feishu.update_values(log_type, 'kuaishou', "Aps2BI", "E2:Z2", values)
  471. Common.logger(log_type, crawler).info(f"视频已保存至云文档\n")
  472. download_finished = True
  473. return download_finished
  474. except Exception as e:
  475. Common.logger(log_type, crawler).error(f"download_publish:{e}\n")
  476. if __name__ == "__main__":
  477. KuaiShouRecommend.get_videoList('recommend', 'kuaishou', '推荐抓取策略', 55440319, 'outer', 'prod', 'aliyun')