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("@", "").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(
  195. r=r),
  196. 'Origin': 'https://www.kuaishou.com',
  197. 'Referer': 'https://www.kuaishou.com/new-reco',
  198. 'Sec-Fetch-Dest': 'empty',
  199. 'Sec-Fetch-Mode': 'cors',
  200. 'Sec-Fetch-Site': 'same-origin',
  201. 'User-Agent': get_random_user_agent('pc'),
  202. 'accept': '*/*',
  203. 'content-type': 'application/json',
  204. 'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
  205. 'sec-ch-ua-mobile': '?0',
  206. 'sec-ch-ua-platform': '"macOS"'
  207. }
  208. try:
  209. urllib3.disable_warnings()
  210. s = requests.session()
  211. # max_retries=3 重试3次
  212. s.mount('http://', HTTPAdapter(max_retries=3))
  213. s.mount('https://', HTTPAdapter(max_retries=3))
  214. response = s.post(url=url, headers=headers, data=payload, proxies=Common.tunnel_proxies(), verify=False,
  215. timeout=10)
  216. response.close()
  217. except Exception as e:
  218. Common.logger(log_type, crawler).error(f"get_videoList:{e}\n")
  219. continue
  220. # Common.logger(log_type, crawler).info(f"get_videoList:{response.text}\n")
  221. if response.status_code != 200:
  222. Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.text}\n")
  223. continue
  224. elif 'data' not in response.json():
  225. Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.json()}\n")
  226. continue
  227. elif 'visionNewRecoFeed' not in response.json()['data']:
  228. Common.logger(log_type, crawler).warning(f"get_videoList_response:{response.json()['data']}\n")
  229. continue
  230. elif 'feeds' not in response.json()['data']['visionNewRecoFeed']:
  231. Common.logger(log_type, crawler).warning(
  232. f"get_videoList_response:{response.json()['data']['visionNewRecoFeed']}\n")
  233. continue
  234. elif len(response.json()['data']['visionNewRecoFeed']['feeds']) == 0:
  235. Common.logger(log_type, crawler).info("没有更多视频啦 ~\n")
  236. continue
  237. else:
  238. feeds = response.json()['data']['visionNewRecoFeed']['feeds']
  239. # pcursor = response.json()['data']['visionNewRecoFeed']['pcursor']
  240. for i in range(len(feeds)):
  241. if 'photo' not in feeds[i]:
  242. Common.logger(log_type, crawler).warning(f"get_videoList:{feeds[i]}\n")
  243. continue
  244. # video_title
  245. if 'caption' not in feeds[i]['photo']:
  246. video_title = cls.random_title(log_type, crawler)
  247. elif feeds[i]['photo']['caption'].strip() == "":
  248. video_title = cls.random_title(log_type, crawler)
  249. else:
  250. video_title = cls.video_title(log_type, crawler, feeds[i]['photo']['caption'])
  251. if 'videoResource' not in feeds[i]['photo'] \
  252. and 'manifest' not in feeds[i]['photo'] \
  253. and 'manifestH265' not in feeds[i]['photo']:
  254. Common.logger(log_type, crawler).warning(f"get_videoList:{feeds[i]['photo']}\n")
  255. continue
  256. videoResource = feeds[i]['photo']['videoResource']
  257. if 'h264' not in videoResource and 'hevc' not in videoResource:
  258. Common.logger(log_type, crawler).warning(f"get_videoList:{videoResource}\n")
  259. continue
  260. # video_id
  261. if 'h264' in videoResource and 'videoId' in videoResource['h264']:
  262. video_id = videoResource['h264']['videoId']
  263. elif 'hevc' in videoResource and 'videoId' in videoResource['hevc']:
  264. video_id = videoResource['hevc']['videoId']
  265. else:
  266. video_id = ""
  267. # play_cnt
  268. if 'viewCount' not in feeds[i]['photo']:
  269. play_cnt = 0
  270. else:
  271. play_cnt = int(feeds[i]['photo']['viewCount'])
  272. # like_cnt
  273. if 'realLikeCount' not in feeds[i]['photo']:
  274. like_cnt = 0
  275. else:
  276. like_cnt = feeds[i]['photo']['realLikeCount']
  277. # publish_time
  278. if 'timestamp' not in feeds[i]['photo']:
  279. publish_time_stamp = 0
  280. publish_time_str = ''
  281. publish_time = 0
  282. else:
  283. publish_time_stamp = int(int(feeds[i]['photo']['timestamp']) / 1000)
  284. publish_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(publish_time_stamp))
  285. publish_time = int((int(time.time()) - publish_time_stamp) / (3600 * 24))
  286. # duration
  287. if 'duration' not in feeds[i]['photo']:
  288. duration = 0
  289. else:
  290. duration = int(int(feeds[i]['photo']['duration']) / 1000)
  291. # video_width / video_height / video_url
  292. mapping = {}
  293. for item in ['width', 'height']:
  294. try:
  295. val = str(videoResource['h264']['adaptationSet'][0]['representation'][0][item])
  296. except Exception:
  297. val = str(videoResource['hevc']['adaptationSet'][0]['representation'][0][item])
  298. except:
  299. val = ''
  300. mapping[item] = val
  301. video_width = int(mapping['width']) if mapping['width'] != '' else 0
  302. video_height = int(mapping['height']) if mapping['height'] != '' else 0
  303. # cover_url
  304. if 'coverUrl' not in feeds[i]['photo']:
  305. cover_url = ""
  306. else:
  307. cover_url = feeds[i]['photo']['coverUrl']
  308. # user_name / avatar_url
  309. try:
  310. user_name = feeds[i]['author']['name']
  311. avatar_url = feeds[i]['author']['headerUrl']
  312. user_id = feeds[i]['author']['id']
  313. except Exception:
  314. user_name = ''
  315. avatar_url = ''
  316. user_id = ''
  317. video_url = feeds[i]['photo']['photoUrl']
  318. video_dict = {'video_title': video_title,
  319. 'video_id': video_id,
  320. 'play_cnt': play_cnt,
  321. 'comment_cnt': 0,
  322. 'like_cnt': like_cnt,
  323. 'share_cnt': 0,
  324. 'video_width': video_width,
  325. 'video_height': video_height,
  326. 'duration': duration,
  327. 'publish_time': publish_time,
  328. 'publish_time_stamp': publish_time_stamp,
  329. 'publish_time_str': publish_time_str,
  330. 'user_name': user_name,
  331. 'user_id': user_id,
  332. 'avatar_url': avatar_url,
  333. 'cover_url': cover_url,
  334. 'video_url': video_url,
  335. 'session': f"kuaishou{int(time.time())}"}
  336. rule_1 = cls.download_rule(video_dict, rule_dict_1)
  337. Common.logger(log_type, crawler).info(f"video_title:{video_title}")
  338. Common.logger(log_type, crawler).info(f"video_id:{video_id}\n")
  339. Common.logger(log_type, crawler).info(
  340. f"play_cnt:{video_dict['play_cnt']}{rule_dict_1['play_cnt']}, {eval(str(video_dict['play_cnt']) + str(rule_dict_1['play_cnt']))}")
  341. Common.logger(log_type, crawler).info(
  342. f"like_cnt:{video_dict['like_cnt']}{rule_dict_1['like_cnt']}, {eval(str(video_dict['like_cnt']) + str(rule_dict_1['like_cnt']))}")
  343. Common.logger(log_type, crawler).info(
  344. f"video_width:{video_dict['video_width']}{rule_dict_1['video_width']}, {eval(str(video_dict['video_width']) + str(rule_dict_1['video_width']))}")
  345. Common.logger(log_type, crawler).info(
  346. f"video_height:{video_dict['video_height']}{rule_dict_1['video_height']}, {eval(str(video_dict['video_height']) + str(rule_dict_1['video_height']))}")
  347. Common.logger(log_type, crawler).info(
  348. f"duration:{video_dict['duration']}{rule_dict_1['duration']}, {eval(str(video_dict['duration']) + str(rule_dict_1['duration']))}")
  349. Common.logger(log_type, crawler).info(
  350. f"publish_time:{video_dict['publish_time']}{rule_dict_1['publish_time']}, {eval(str(video_dict['publish_time']) + str(rule_dict_1['publish_time']))}")
  351. Common.logger(log_type, crawler).info(f"rule_1:{rule_1}\n")
  352. if video_title == "" or video_url == "":
  353. Common.logger(log_type, crawler).info("无效视频\n")
  354. continue
  355. elif rule_1 is True:
  356. cls.download_publish(log_type=log_type,
  357. crawler=crawler,
  358. strategy=strategy,
  359. video_dict=video_dict,
  360. rule_dict=rule_dict_1,
  361. our_uid=our_uid,
  362. oss_endpoint=oss_endpoint,
  363. env=env,
  364. machine=machine)
  365. else:
  366. Common.logger(log_type, crawler).info("不满足下载规则\n")
  367. @classmethod
  368. def repeat_video(cls, log_type, crawler, video_id, video_title, publish_time, env, machine):
  369. 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}") """
  370. repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env, machine)
  371. return len(repeat_video)
  372. @classmethod
  373. def download_publish(cls, log_type, crawler, strategy, video_dict, rule_dict, our_uid, oss_endpoint, env, machine):
  374. try:
  375. download_finished = False
  376. if cls.repeat_video(log_type, crawler, video_dict['video_id'], video_dict['video_title'],
  377. video_dict['publish_time_str'], env, machine) != 0:
  378. Common.logger(log_type, crawler).info('视频已下载\n')
  379. elif any(word if word in video_dict['video_title'] else False for word in
  380. cls.filter_words(log_type, crawler)) is True:
  381. Common.logger(log_type, crawler).info('标题已中过滤词\n')
  382. else:
  383. # 下载视频
  384. Common.download_method(log_type=log_type, crawler=crawler, text='video',
  385. title=video_dict['video_title'], url=video_dict['video_url'])
  386. md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
  387. if os.path.getsize(f"./{crawler}/videos/{md_title}/video.mp4") == 0:
  388. # 删除视频文件夹
  389. shutil.rmtree(f"./{crawler}/videos/{md_title}")
  390. Common.logger(log_type, crawler).info("视频size=0,删除成功\n")
  391. return
  392. # 下载封面
  393. Common.download_method(log_type=log_type, crawler=crawler, text='cover',
  394. title=video_dict['video_title'], url=video_dict['cover_url'])
  395. # 保存视频信息至txt
  396. Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
  397. # 上传视频
  398. Common.logger(log_type, crawler).info("开始上传视频...")
  399. our_video_id = Publish.upload_and_publish(log_type=log_type,
  400. crawler=crawler,
  401. strategy=strategy,
  402. our_uid=our_uid,
  403. env=env,
  404. oss_endpoint=oss_endpoint)
  405. if env == 'dev':
  406. our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  407. else:
  408. our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  409. Common.logger(log_type, crawler).info("视频上传完成")
  410. if our_video_id is None:
  411. Common.logger(log_type, crawler).warning(f"our_video_id:{our_video_id} 删除该视频文件夹")
  412. # 删除视频文件夹
  413. shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
  414. return download_finished
  415. # 视频信息保存数据库
  416. insert_sql = f""" insert into crawler_video(video_id,
  417. user_id,
  418. out_user_id,
  419. platform,
  420. strategy,
  421. out_video_id,
  422. video_title,
  423. cover_url,
  424. video_url,
  425. duration,
  426. publish_time,
  427. play_cnt,
  428. crawler_rule,
  429. width,
  430. height)
  431. values({our_video_id},
  432. {our_uid},
  433. "{video_dict['user_id']}",
  434. "{cls.platform}",
  435. "{strategy}",
  436. "{video_dict['video_id']}",
  437. "{video_dict['video_title']}",
  438. "{video_dict['cover_url']}",
  439. "{video_dict['video_url']}",
  440. {int(video_dict['duration'])},
  441. "{video_dict['publish_time_str']}",
  442. {int(video_dict['play_cnt'])},
  443. '{json.dumps(rule_dict)}',
  444. {int(video_dict['video_width'])},
  445. {int(video_dict['video_height'])}) """
  446. Common.logger(log_type, crawler).info(f"insert_sql:{insert_sql}")
  447. MysqlHelper.update_values(log_type, crawler, insert_sql, env, machine)
  448. Common.logger(log_type, crawler).info('视频信息插入数据库成功!\n')
  449. # 视频写入飞书
  450. Feishu.insert_columns(log_type, 'kuaishou', "Aps2BI", "ROWS", 1, 2)
  451. upload_time = int(time.time())
  452. values = [[our_video_id,
  453. time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(upload_time)),
  454. strategy,
  455. str(video_dict['video_id']),
  456. video_dict['video_title'],
  457. our_video_link,
  458. video_dict['play_cnt'],
  459. video_dict['comment_cnt'],
  460. video_dict['like_cnt'],
  461. video_dict['share_cnt'],
  462. video_dict['duration'],
  463. f"{video_dict['video_width']}*{video_dict['video_height']}",
  464. video_dict['publish_time_str'],
  465. video_dict['user_name'],
  466. video_dict['user_id'],
  467. video_dict['avatar_url'],
  468. video_dict['cover_url'],
  469. video_dict['video_url']]]
  470. time.sleep(1)
  471. Feishu.update_values(log_type, 'kuaishou', "Aps2BI", "E2:Z2", values)
  472. Common.logger(log_type, crawler).info(f"视频已保存至云文档\n")
  473. download_finished = True
  474. return download_finished
  475. except Exception as e:
  476. Common.logger(log_type, crawler).error(f"download_publish:{e}\n")
  477. if __name__ == "__main__":
  478. KuaiShouRecommend.get_videoList('recommend', 'kuaishou', '推荐抓取策略', 55440319, 'outer', 'prod', 'aliyun')