xigua_recommend_scheduling.py 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/5/25
  4. import base64
  5. import json
  6. import os
  7. import random
  8. import shutil
  9. import string
  10. import sys
  11. import time
  12. from datetime import date, timedelta
  13. from hashlib import md5
  14. import requests
  15. import urllib3
  16. from requests.adapters import HTTPAdapter
  17. from selenium import webdriver
  18. from selenium.webdriver import DesiredCapabilities
  19. from selenium.webdriver.chrome.service import Service
  20. from common.public import download_rule, get_config_from_mysql
  21. sys.path.append(os.getcwd())
  22. from common.userAgent import get_random_user_agent
  23. from common.publish import Publish
  24. from common.common import Common
  25. from common.feishu import Feishu
  26. from common.scheduling_db import MysqlHelper
  27. class XiguarecommendScheduling:
  28. platform = "西瓜视频"
  29. @classmethod
  30. def random_signature(cls):
  31. src_digits = string.digits # string_数字
  32. src_uppercase = string.ascii_uppercase # string_大写字母
  33. src_lowercase = string.ascii_lowercase # string_小写字母
  34. digits_num = random.randint(1, 6)
  35. uppercase_num = random.randint(1, 26 - digits_num - 1)
  36. lowercase_num = 26 - (digits_num + uppercase_num)
  37. password = random.sample(src_digits, digits_num) + random.sample(src_uppercase, uppercase_num) + random.sample(
  38. src_lowercase, lowercase_num)
  39. random.shuffle(password)
  40. new_password = 'AAAAAAAAAA' + ''.join(password)[10:-4] + 'AAAB'
  41. new_password_start = new_password[0:18]
  42. new_password_end = new_password[-7:]
  43. if new_password[18] == '8':
  44. new_password = new_password_start + 'w' + new_password_end
  45. elif new_password[18] == '9':
  46. new_password = new_password_start + 'x' + new_password_end
  47. elif new_password[18] == '-':
  48. new_password = new_password_start + 'y' + new_password_end
  49. elif new_password[18] == '.':
  50. new_password = new_password_start + 'z' + new_password_end
  51. else:
  52. new_password = new_password_start + 'y' + new_password_end
  53. return new_password
  54. @classmethod
  55. def get_signature(cls, env):
  56. # 打印请求配置
  57. ca = DesiredCapabilities.CHROME
  58. ca["goog:loggingPrefs"] = {"performance": "ALL"}
  59. # 不打开浏览器运行
  60. chrome_options = webdriver.ChromeOptions()
  61. chrome_options.add_argument("headless")
  62. chrome_options.add_argument(
  63. f'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36')
  64. chrome_options.add_argument("--no-sandbox")
  65. # driver初始化
  66. if env == "dev":
  67. driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options,
  68. service=Service('/Users/wangkun/Downloads/chromedriver/chromedriver_v113/chromedriver'))
  69. else:
  70. driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options)
  71. driver.implicitly_wait(10)
  72. driver.get('https://www.ixigua.com/')
  73. time.sleep(1)
  74. # 向上滑动 1000 个像素
  75. driver.execute_script('window.scrollBy(0, 2000)')
  76. # Common.logger(log_type, crawler).info('刷新页面')
  77. driver.refresh()
  78. logs = driver.get_log("performance")
  79. # Common.logger(log_type, crawler).info('已获取logs:{}\n', logs)
  80. driver.quit()
  81. for line in logs:
  82. msg = json.loads(line['message'])
  83. if 'params' not in msg['message']:
  84. pass
  85. elif 'documentURL' not in msg['message']['params']:
  86. pass
  87. elif 'www.ixigua.com' not in msg['message']['params']['documentURL']:
  88. pass
  89. elif 'url' not in msg['message']['params']['request']:
  90. pass
  91. elif '_signature' not in msg['message']['params']['request']['url']:
  92. pass
  93. else:
  94. url = msg['message']['params']['request']['url']
  95. signature = url.split('_signature=')[-1].split('&')[0]
  96. return signature
  97. @classmethod
  98. def get_video_url(cls, video_info):
  99. video_url_dict = {}
  100. # video_url
  101. if 'videoResource' not in video_info:
  102. video_url_dict["video_url"] = ''
  103. video_url_dict["audio_url"] = ''
  104. video_url_dict["video_width"] = 0
  105. video_url_dict["video_height"] = 0
  106. elif 'dash_120fps' in video_info['videoResource']:
  107. if "video_list" in video_info['videoResource']['dash_120fps'] and 'video_4' in \
  108. video_info['videoResource']['dash_120fps']['video_list']:
  109. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
  110. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
  111. if len(video_url) % 3 == 1:
  112. video_url += '=='
  113. elif len(video_url) % 3 == 2:
  114. video_url += '='
  115. elif len(audio_url) % 3 == 1:
  116. audio_url += '=='
  117. elif len(audio_url) % 3 == 2:
  118. audio_url += '='
  119. video_url = base64.b64decode(video_url).decode('utf8')
  120. audio_url = base64.b64decode(audio_url).decode('utf8')
  121. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_4']['vwidth']
  122. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_4']['vheight']
  123. video_url_dict["video_url"] = video_url
  124. video_url_dict["audio_url"] = audio_url
  125. video_url_dict["video_width"] = video_width
  126. video_url_dict["video_height"] = video_height
  127. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_3' in \
  128. video_info['videoResource']['dash_120fps']['video_list']:
  129. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
  130. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
  131. if len(video_url) % 3 == 1:
  132. video_url += '=='
  133. elif len(video_url) % 3 == 2:
  134. video_url += '='
  135. elif len(audio_url) % 3 == 1:
  136. audio_url += '=='
  137. elif len(audio_url) % 3 == 2:
  138. audio_url += '='
  139. video_url = base64.b64decode(video_url).decode('utf8')
  140. audio_url = base64.b64decode(audio_url).decode('utf8')
  141. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_3']['vwidth']
  142. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_3']['vheight']
  143. video_url_dict["video_url"] = video_url
  144. video_url_dict["audio_url"] = audio_url
  145. video_url_dict["video_width"] = video_width
  146. video_url_dict["video_height"] = video_height
  147. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_2' in \
  148. video_info['videoResource']['dash_120fps']['video_list']:
  149. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
  150. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
  151. if len(video_url) % 3 == 1:
  152. video_url += '=='
  153. elif len(video_url) % 3 == 2:
  154. video_url += '='
  155. elif len(audio_url) % 3 == 1:
  156. audio_url += '=='
  157. elif len(audio_url) % 3 == 2:
  158. audio_url += '='
  159. video_url = base64.b64decode(video_url).decode('utf8')
  160. audio_url = base64.b64decode(audio_url).decode('utf8')
  161. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_2']['vwidth']
  162. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_2']['vheight']
  163. video_url_dict["video_url"] = video_url
  164. video_url_dict["audio_url"] = audio_url
  165. video_url_dict["video_width"] = video_width
  166. video_url_dict["video_height"] = video_height
  167. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_1' in \
  168. video_info['videoResource']['dash_120fps']['video_list']:
  169. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
  170. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
  171. if len(video_url) % 3 == 1:
  172. video_url += '=='
  173. elif len(video_url) % 3 == 2:
  174. video_url += '='
  175. elif len(audio_url) % 3 == 1:
  176. audio_url += '=='
  177. elif len(audio_url) % 3 == 2:
  178. audio_url += '='
  179. video_url = base64.b64decode(video_url).decode('utf8')
  180. audio_url = base64.b64decode(audio_url).decode('utf8')
  181. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_1']['vwidth']
  182. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_1']['vheight']
  183. video_url_dict["video_url"] = video_url
  184. video_url_dict["audio_url"] = audio_url
  185. video_url_dict["video_width"] = video_width
  186. video_url_dict["video_height"] = video_height
  187. elif 'dynamic_video' in video_info['videoResource']['dash_120fps'] \
  188. and 'dynamic_video_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
  189. and 'dynamic_audio_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
  190. and len(
  191. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list']) != 0 \
  192. and len(
  193. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list']) != 0:
  194. video_url = \
  195. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  196. 'backup_url_1']
  197. audio_url = \
  198. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list'][-1][
  199. 'backup_url_1']
  200. if len(video_url) % 3 == 1:
  201. video_url += '=='
  202. elif len(video_url) % 3 == 2:
  203. video_url += '='
  204. elif len(audio_url) % 3 == 1:
  205. audio_url += '=='
  206. elif len(audio_url) % 3 == 2:
  207. audio_url += '='
  208. video_url = base64.b64decode(video_url).decode('utf8')
  209. audio_url = base64.b64decode(audio_url).decode('utf8')
  210. video_width = \
  211. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  212. 'vwidth']
  213. video_height = \
  214. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  215. 'vheight']
  216. video_url_dict["video_url"] = video_url
  217. video_url_dict["audio_url"] = audio_url
  218. video_url_dict["video_width"] = video_width
  219. video_url_dict["video_height"] = video_height
  220. else:
  221. video_url_dict["video_url"] = ''
  222. video_url_dict["audio_url"] = ''
  223. video_url_dict["video_width"] = 0
  224. video_url_dict["video_height"] = 0
  225. elif 'dash' in video_info['videoResource']:
  226. if "video_list" in video_info['videoResource']['dash'] and 'video_4' in \
  227. video_info['videoResource']['dash']['video_list']:
  228. video_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
  229. audio_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
  230. if len(video_url) % 3 == 1:
  231. video_url += '=='
  232. elif len(video_url) % 3 == 2:
  233. video_url += '='
  234. elif len(audio_url) % 3 == 1:
  235. audio_url += '=='
  236. elif len(audio_url) % 3 == 2:
  237. audio_url += '='
  238. video_url = base64.b64decode(video_url).decode('utf8')
  239. audio_url = base64.b64decode(audio_url).decode('utf8')
  240. video_width = video_info['videoResource']['dash']['video_list']['video_4']['vwidth']
  241. video_height = video_info['videoResource']['dash']['video_list']['video_4']['vheight']
  242. video_url_dict["video_url"] = video_url
  243. video_url_dict["audio_url"] = audio_url
  244. video_url_dict["video_width"] = video_width
  245. video_url_dict["video_height"] = video_height
  246. elif "video_list" in video_info['videoResource']['dash'] and 'video_3' in \
  247. video_info['videoResource']['dash']['video_list']:
  248. video_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
  249. audio_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
  250. if len(video_url) % 3 == 1:
  251. video_url += '=='
  252. elif len(video_url) % 3 == 2:
  253. video_url += '='
  254. elif len(audio_url) % 3 == 1:
  255. audio_url += '=='
  256. elif len(audio_url) % 3 == 2:
  257. audio_url += '='
  258. video_url = base64.b64decode(video_url).decode('utf8')
  259. audio_url = base64.b64decode(audio_url).decode('utf8')
  260. video_width = video_info['videoResource']['dash']['video_list']['video_3']['vwidth']
  261. video_height = video_info['videoResource']['dash']['video_list']['video_3']['vheight']
  262. video_url_dict["video_url"] = video_url
  263. video_url_dict["audio_url"] = audio_url
  264. video_url_dict["video_width"] = video_width
  265. video_url_dict["video_height"] = video_height
  266. elif "video_list" in video_info['videoResource']['dash'] and 'video_2' in \
  267. video_info['videoResource']['dash']['video_list']:
  268. video_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
  269. audio_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
  270. if len(video_url) % 3 == 1:
  271. video_url += '=='
  272. elif len(video_url) % 3 == 2:
  273. video_url += '='
  274. elif len(audio_url) % 3 == 1:
  275. audio_url += '=='
  276. elif len(audio_url) % 3 == 2:
  277. audio_url += '='
  278. video_url = base64.b64decode(video_url).decode('utf8')
  279. audio_url = base64.b64decode(audio_url).decode('utf8')
  280. video_width = video_info['videoResource']['dash']['video_list']['video_2']['vwidth']
  281. video_height = video_info['videoResource']['dash']['video_list']['video_2']['vheight']
  282. video_url_dict["video_url"] = video_url
  283. video_url_dict["audio_url"] = audio_url
  284. video_url_dict["video_width"] = video_width
  285. video_url_dict["video_height"] = video_height
  286. elif "video_list" in video_info['videoResource']['dash'] and 'video_1' in \
  287. video_info['videoResource']['dash']['video_list']:
  288. video_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
  289. audio_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
  290. if len(video_url) % 3 == 1:
  291. video_url += '=='
  292. elif len(video_url) % 3 == 2:
  293. video_url += '='
  294. elif len(audio_url) % 3 == 1:
  295. audio_url += '=='
  296. elif len(audio_url) % 3 == 2:
  297. audio_url += '='
  298. video_url = base64.b64decode(video_url).decode('utf8')
  299. audio_url = base64.b64decode(audio_url).decode('utf8')
  300. video_width = video_info['videoResource']['dash']['video_list']['video_1']['vwidth']
  301. video_height = video_info['videoResource']['dash']['video_list']['video_1']['vheight']
  302. video_url_dict["video_url"] = video_url
  303. video_url_dict["audio_url"] = audio_url
  304. video_url_dict["video_width"] = video_width
  305. video_url_dict["video_height"] = video_height
  306. elif 'dynamic_video' in video_info['videoResource']['dash'] \
  307. and 'dynamic_video_list' in video_info['videoResource']['dash']['dynamic_video'] \
  308. and 'dynamic_audio_list' in video_info['videoResource']['dash']['dynamic_video'] \
  309. and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list']) != 0 \
  310. and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list']) != 0:
  311. video_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  312. 'backup_url_1']
  313. audio_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list'][-1][
  314. 'backup_url_1']
  315. if len(video_url) % 3 == 1:
  316. video_url += '=='
  317. elif len(video_url) % 3 == 2:
  318. video_url += '='
  319. elif len(audio_url) % 3 == 1:
  320. audio_url += '=='
  321. elif len(audio_url) % 3 == 2:
  322. audio_url += '='
  323. video_url = base64.b64decode(video_url).decode('utf8')
  324. audio_url = base64.b64decode(audio_url).decode('utf8')
  325. video_width = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  326. 'vwidth']
  327. video_height = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  328. 'vheight']
  329. video_url_dict["video_url"] = video_url
  330. video_url_dict["audio_url"] = audio_url
  331. video_url_dict["video_width"] = video_width
  332. video_url_dict["video_height"] = video_height
  333. else:
  334. video_url_dict["video_url"] = ''
  335. video_url_dict["audio_url"] = ''
  336. video_url_dict["video_width"] = 0
  337. video_url_dict["video_height"] = 0
  338. elif 'normal' in video_info['videoResource']:
  339. if "video_list" in video_info['videoResource']['normal'] and 'video_4' in \
  340. video_info['videoResource']['normal']['video_list']:
  341. video_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
  342. audio_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
  343. if len(video_url) % 3 == 1:
  344. video_url += '=='
  345. elif len(video_url) % 3 == 2:
  346. video_url += '='
  347. elif len(audio_url) % 3 == 1:
  348. audio_url += '=='
  349. elif len(audio_url) % 3 == 2:
  350. audio_url += '='
  351. video_url = base64.b64decode(video_url).decode('utf8')
  352. audio_url = base64.b64decode(audio_url).decode('utf8')
  353. video_width = video_info['videoResource']['normal']['video_list']['video_4']['vwidth']
  354. video_height = video_info['videoResource']['normal']['video_list']['video_4']['vheight']
  355. video_url_dict["video_url"] = video_url
  356. video_url_dict["audio_url"] = audio_url
  357. video_url_dict["video_width"] = video_width
  358. video_url_dict["video_height"] = video_height
  359. elif "video_list" in video_info['videoResource']['normal'] and 'video_3' in \
  360. video_info['videoResource']['normal']['video_list']:
  361. video_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
  362. audio_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
  363. if len(video_url) % 3 == 1:
  364. video_url += '=='
  365. elif len(video_url) % 3 == 2:
  366. video_url += '='
  367. elif len(audio_url) % 3 == 1:
  368. audio_url += '=='
  369. elif len(audio_url) % 3 == 2:
  370. audio_url += '='
  371. video_url = base64.b64decode(video_url).decode('utf8')
  372. audio_url = base64.b64decode(audio_url).decode('utf8')
  373. video_width = video_info['videoResource']['normal']['video_list']['video_3']['vwidth']
  374. video_height = video_info['videoResource']['normal']['video_list']['video_3']['vheight']
  375. video_url_dict["video_url"] = video_url
  376. video_url_dict["audio_url"] = audio_url
  377. video_url_dict["video_width"] = video_width
  378. video_url_dict["video_height"] = video_height
  379. elif "video_list" in video_info['videoResource']['normal'] and 'video_2' in \
  380. video_info['videoResource']['normal']['video_list']:
  381. video_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
  382. audio_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
  383. if len(video_url) % 3 == 1:
  384. video_url += '=='
  385. elif len(video_url) % 3 == 2:
  386. video_url += '='
  387. elif len(audio_url) % 3 == 1:
  388. audio_url += '=='
  389. elif len(audio_url) % 3 == 2:
  390. audio_url += '='
  391. video_url = base64.b64decode(video_url).decode('utf8')
  392. audio_url = base64.b64decode(audio_url).decode('utf8')
  393. video_width = video_info['videoResource']['normal']['video_list']['video_2']['vwidth']
  394. video_height = video_info['videoResource']['normal']['video_list']['video_2']['vheight']
  395. video_url_dict["video_url"] = video_url
  396. video_url_dict["audio_url"] = audio_url
  397. video_url_dict["video_width"] = video_width
  398. video_url_dict["video_height"] = video_height
  399. elif "video_list" in video_info['videoResource']['normal'] and 'video_1' in \
  400. video_info['videoResource']['normal']['video_list']:
  401. video_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
  402. audio_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
  403. if len(video_url) % 3 == 1:
  404. video_url += '=='
  405. elif len(video_url) % 3 == 2:
  406. video_url += '='
  407. elif len(audio_url) % 3 == 1:
  408. audio_url += '=='
  409. elif len(audio_url) % 3 == 2:
  410. audio_url += '='
  411. video_url = base64.b64decode(video_url).decode('utf8')
  412. audio_url = base64.b64decode(audio_url).decode('utf8')
  413. video_width = video_info['videoResource']['normal']['video_list']['video_1']['vwidth']
  414. video_height = video_info['videoResource']['normal']['video_list']['video_1']['vheight']
  415. video_url_dict["video_url"] = video_url
  416. video_url_dict["audio_url"] = audio_url
  417. video_url_dict["video_width"] = video_width
  418. video_url_dict["video_height"] = video_height
  419. elif 'dynamic_video' in video_info['videoResource']['normal'] \
  420. and 'dynamic_video_list' in video_info['videoResource']['normal']['dynamic_video'] \
  421. and 'dynamic_audio_list' in video_info['videoResource']['normal']['dynamic_video'] \
  422. and len(video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list']) != 0 \
  423. and len(video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list']) != 0:
  424. video_url = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  425. 'backup_url_1']
  426. audio_url = video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list'][-1][
  427. 'backup_url_1']
  428. if len(video_url) % 3 == 1:
  429. video_url += '=='
  430. elif len(video_url) % 3 == 2:
  431. video_url += '='
  432. elif len(audio_url) % 3 == 1:
  433. audio_url += '=='
  434. elif len(audio_url) % 3 == 2:
  435. audio_url += '='
  436. video_url = base64.b64decode(video_url).decode('utf8')
  437. audio_url = base64.b64decode(audio_url).decode('utf8')
  438. video_width = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  439. 'vwidth']
  440. video_height = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  441. 'vheight']
  442. video_url_dict["video_url"] = video_url
  443. video_url_dict["audio_url"] = audio_url
  444. video_url_dict["video_width"] = video_width
  445. video_url_dict["video_height"] = video_height
  446. else:
  447. video_url_dict["video_url"] = ''
  448. video_url_dict["audio_url"] = ''
  449. video_url_dict["video_width"] = 0
  450. video_url_dict["video_height"] = 0
  451. else:
  452. video_url_dict["video_url"] = ''
  453. video_url_dict["audio_url"] = ''
  454. video_url_dict["video_width"] = 0
  455. video_url_dict["video_height"] = 0
  456. return video_url_dict
  457. @classmethod
  458. def get_comment_cnt(cls, item_id):
  459. url = "https://www.ixigua.com/tlb/comment/article/v5/tab_comments/?"
  460. params = {
  461. "tab_index": "0",
  462. "count": "10",
  463. "offset": "10",
  464. "group_id": str(item_id),
  465. "item_id": str(item_id),
  466. "aid": "1768",
  467. "msToken": "50-JJObWB07HfHs-BMJWT1eIDX3G-6lPSF_i-QwxBIXE9VVa-iN0jbEXR5pG2DKjXBmP299n6ZTuXzY-GAy968CCvouSAYIS4GzvGQT3pNlKNejr5G4-1g==",
  468. "X-Bogus": "DFSzswVOyGtANVeWtCLMqR/F6q9U",
  469. "_signature": cls.random_signature(),
  470. }
  471. headers = {
  472. 'authority': 'www.ixigua.com',
  473. 'accept': 'application/json, text/plain, */*',
  474. 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
  475. 'cache-control': 'no-cache',
  476. 'cookie': 'MONITOR_WEB_ID=67cb5099-a022-4ec3-bb8e-c4de6ba51dd0; passport_csrf_token=72b2574f3c99f8ba670e42df430218fd; passport_csrf_token_default=72b2574f3c99f8ba670e42df430218fd; sid_guard=c7472b508ea631823ba765a60cf8757f%7C1680867422%7C3024002%7CFri%2C+12-May-2023+11%3A37%3A04+GMT; uid_tt=c13f47d51767f616befe32fb3e9f485a; uid_tt_ss=c13f47d51767f616befe32fb3e9f485a; sid_tt=c7472b508ea631823ba765a60cf8757f; sessionid=c7472b508ea631823ba765a60cf8757f; sessionid_ss=c7472b508ea631823ba765a60cf8757f; sid_ucp_v1=1.0.0-KGUzNWYxNmRkZGJiZjgxY2MzZWNkMTEzMTkwYjY1Yjg5OTY5NzVlNmMKFQiu3d-eqQIQ3oDAoQYYGCAMOAhACxoCaGwiIGM3NDcyYjUwOGVhNjMxODIzYmE3NjVhNjBjZjg3NTdm; ssid_ucp_v1=1.0.0-KGUzNWYxNmRkZGJiZjgxY2MzZWNkMTEzMTkwYjY1Yjg5OTY5NzVlNmMKFQiu3d-eqQIQ3oDAoQYYGCAMOAhACxoCaGwiIGM3NDcyYjUwOGVhNjMxODIzYmE3NjVhNjBjZjg3NTdm; odin_tt=b893608d4dde2e1e8df8cd5d97a0e2fbeafc4ca762ac72ebef6e6c97e2ed19859bb01d46b4190ddd6dd17d7f9678e1de; SEARCH_CARD_MODE=7168304743566296612_0; support_webp=true; support_avif=false; csrf_session_id=a5355d954d3c63ed1ba35faada452b4d; tt_scid=7Pux7s634-z8DYvCM20y7KigwH5u7Rh6D9C-RROpnT.aGMEcz6Vsxp.oai47wJqa4f86; ttwid=1%7CHHtv2QqpSGuSu8r-zXF1QoWsvjmNi1SJrqOrZzg-UCY%7C1683858689%7Ca5223fe1500578e01e138a0d71d6444692018296c4c24f5885af174a65873c95; ixigua-a-s=3; msToken=50-JJObWB07HfHs-BMJWT1eIDX3G-6lPSF_i-QwxBIXE9VVa-iN0jbEXR5pG2DKjXBmP299n6ZTuXzY-GAy968CCvouSAYIS4GzvGQT3pNlKNejr5G4-1g==; __ac_nonce=0645dcbf0005064517440; __ac_signature=_02B4Z6wo00f01FEGmAwAAIDBKchzCGqn-MBRJpyAAHAjieFC5GEg6gGiwz.I4PRrJl7f0GcixFrExKmgt6QI1i1S-dQyofPEj2ugWTCnmKUdJQv-wYuDofeKNe8VtMtZq2aKewyUGeKU-5Ud21; ixigua-a-s=3',
  477. 'pragma': 'no-cache',
  478. 'referer': f'https://www.ixigua.com/{item_id}?logTag=3c5aa86a8600b9ab8540',
  479. 'sec-ch-ua': '"Microsoft Edge";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
  480. 'sec-ch-ua-mobile': '?0',
  481. 'sec-ch-ua-platform': '"macOS"',
  482. 'sec-fetch-dest': 'empty',
  483. 'sec-fetch-mode': 'cors',
  484. 'sec-fetch-site': 'same-origin',
  485. 'tt-anti-token': 'cBITBHvmYjEygzv-f9c78c1297722cf1f559c74b084e4525ce4900bdcf9e8588f20cc7c2e3234422',
  486. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35',
  487. 'x-secsdk-csrf-token': '000100000001f8e733cf37f0cd255a51aea9a81ff7bc0c09490cfe41ad827c3c5c18ec809279175e4d9f5553d8a5'
  488. }
  489. urllib3.disable_warnings()
  490. s = requests.session()
  491. # max_retries=3 重试3次
  492. s.mount('http://', HTTPAdapter(max_retries=3))
  493. s.mount('https://', HTTPAdapter(max_retries=3))
  494. response = s.get(url=url, headers=headers, params=params, verify=False, proxies=Common.tunnel_proxies(),
  495. timeout=5)
  496. response.close()
  497. if response.status_code != 200 or 'total_number' not in response.json() or response.json() == {}:
  498. return 0
  499. return response.json().get("total_number", 0)
  500. # 获取视频详情
  501. @classmethod
  502. def get_video_info(cls, log_type, crawler, item_id):
  503. url = 'https://www.ixigua.com/api/mixVideo/information?'
  504. headers = {
  505. "accept-encoding": "gzip, deflate",
  506. "accept-language": "zh-CN,zh-Hans;q=0.9",
  507. "user-agent": get_random_user_agent('pc'),
  508. "referer": "https://www.ixigua.com/7102614741050196520?logTag=0531c88ac04f38ab2c62",
  509. }
  510. params = {
  511. 'mixId': str(item_id),
  512. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfC'
  513. 'NVVIOBNjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  514. 'X-Bogus': 'DFSzswVupYTANCJOSBk0P53WxM-r',
  515. '_signature': '_02B4Z6wo0000119LvEwAAIDCuktNZ0y5wkdfS7jAALThuOR8D9yWNZ.EmWHKV0WSn6Px'
  516. 'fPsH9-BldyxVje0f49ryXgmn7Tzk-swEHNb15TiGqa6YF.cX0jW8Eds1TtJOIZyfc9s5emH7gdWN94',
  517. }
  518. cookies = {
  519. 'ixigua-a-s': '1',
  520. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfCNVVIOB'
  521. 'NjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  522. 'ttwid': '1%7C_yXQeHWwLZgCsgHClOwTCdYSOt_MjdOkgnPIkpi-Sr8%7C1661241238%7Cf57d0c5ef3f1d7'
  523. '6e049fccdca1ac54887c34d1f8731c8e51a49780ff0ceab9f8',
  524. 'tt_scid': 'QZ4l8KXDG0YAEaMCSbADdcybdKbUfG4BC6S4OBv9lpRS5VyqYLX2bIR8CTeZeGHR9ee3',
  525. 'MONITOR_WEB_ID': '0a49204a-7af5-4e96-95f0-f4bafb7450ad',
  526. '__ac_nonce': '06304878000964fdad287',
  527. '__ac_signature': '_02B4Z6wo00f017Rcr3AAAIDCUVxeW1tOKEu0fKvAAI4cvoYzV-wBhq7B6D8k0no7lb'
  528. 'FlvYoinmtK6UXjRIYPXnahUlFTvmWVtb77jsMkKAXzAEsLE56m36RlvL7ky.M3Xn52r9t1IEb7IR3ke8',
  529. 'ttcid': 'e56fabf6e85d4adf9e4d91902496a0e882',
  530. '_tea_utm_cache_1300': 'undefined',
  531. 'support_avif': 'false',
  532. 'support_webp': 'false',
  533. 'xiguavideopcwebid': '7134967546256016900',
  534. 'xiguavideopcwebid.sig': 'xxRww5R1VEMJN_dQepHorEu_eAc',
  535. }
  536. urllib3.disable_warnings()
  537. s = requests.session()
  538. # max_retries=3 重试3次
  539. s.mount('http://', HTTPAdapter(max_retries=3))
  540. s.mount('https://', HTTPAdapter(max_retries=3))
  541. response = s.get(url=url, headers=headers, params=params, cookies=cookies, verify=False,
  542. proxies=Common.tunnel_proxies(), timeout=5)
  543. response.close()
  544. if response.status_code != 200 or 'data' not in response.json() or response.json()['data'] == {}:
  545. Common.logger(log_type, crawler).warning(f"get_video_info:{response.status_code}, {response.text}\n")
  546. return None
  547. else:
  548. video_info = response.json()['data'].get("gidInformation", {}).get("packerData", {}).get("video", {})
  549. if video_info == {}:
  550. return None
  551. video_dict = {
  552. "video_title": video_info.get("title", ""),
  553. "video_id": video_info.get("videoResource", {}).get("vid", ""),
  554. "gid": str(item_id),
  555. "play_cnt": int(video_info.get("video_watch_count", 0)),
  556. "like_cnt": int(video_info.get("video_like_count", 0)),
  557. "comment_cnt": int(cls.get_comment_cnt(item_id)),
  558. "share_cnt": 0,
  559. "favorite_cnt": 0,
  560. "duration": int(video_info.get("video_duration", 0)),
  561. "video_width": int(cls.get_video_url(video_info)["video_width"]),
  562. "video_height": int(cls.get_video_url(video_info)["video_height"]),
  563. "publish_time_stamp": int(video_info.get("video_publish_time", 0)),
  564. "publish_time_str": time.strftime("%Y-%m-%d %H:%M:%S",
  565. time.localtime(int(video_info.get("video_publish_time", 0)))),
  566. "user_name": video_info.get("user_info", {}).get("name", ""),
  567. "user_id": str(video_info.get("user_info", {}).get("user_id", "")),
  568. "avatar_url": str(video_info.get("user_info", {}).get("avatar_url", "")),
  569. "cover_url": video_info.get("poster_url", ""),
  570. "audio_url": cls.get_video_url(video_info)["audio_url"],
  571. "video_url": cls.get_video_url(video_info)["video_url"],
  572. "session": f"xigua-search-{int(time.time())}"
  573. }
  574. return video_dict
  575. @classmethod
  576. def repeat_video(cls, log_type, crawler, video_id, env):
  577. sql = f""" select * from crawler_video where platform="西瓜视频" and out_video_id="{video_id}"; """
  578. repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env)
  579. return len(repeat_video)
  580. @classmethod
  581. def get_videoList(cls, log_type, crawler, our_uid, rule_dict, env):
  582. queryCount = 1
  583. while True:
  584. Common.logger(log_type, crawler).info(f"正在抓取第{queryCount}页视频")
  585. signature = cls.get_signature(env)
  586. if signature is None:
  587. Common.logger(log_type, crawler).warning(f"signature:{signature}")
  588. time.sleep(1)
  589. continue
  590. url = "https://www.ixigua.com/api/feedv2/feedById?"
  591. params = {
  592. "channelId": "94349543909",
  593. "count": "9",
  594. "maxTime": str(int(time.time())),
  595. "request_from": "701",
  596. "queryCount": str(queryCount),
  597. "offset": "0",
  598. "aid": "1768",
  599. "msToken": "j0KQp7ejmMFXXXGniwo32qrgVtLD_a7pAhJ4zzoyD_zTXzjdbNH-G0vJi5niZ0FnS98FnahfvUYf7bm5SpHDsdIx0bLc1DnHcdz8ppI0As0P-T5OmE46H7ejeJTyQHE=",
  600. "X-Bogus": "DFSzswVYG40ANtawttFukY/F6qxk",
  601. "_signature": signature,
  602. }
  603. headers = {
  604. 'authority': 'www.ixigua.com',
  605. 'accept': 'application/json, text/plain, */*',
  606. 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
  607. 'cache-control': 'no-cache',
  608. 'cookie': 'MONITOR_WEB_ID=67cb5099-a022-4ec3-bb8e-c4de6ba51dd0; passport_csrf_token=72b2574f3c99f8ba670e42df430218fd; passport_csrf_token_default=72b2574f3c99f8ba670e42df430218fd; sid_guard=c7472b508ea631823ba765a60cf8757f%7C1680867422%7C3024002%7CFri%2C+12-May-2023+11%3A37%3A04+GMT; odin_tt=b893608d4dde2e1e8df8cd5d97a0e2fbeafc4ca762ac72ebef6e6c97e2ed19859bb01d46b4190ddd6dd17d7f9678e1de; SEARCH_CARD_MODE=7168304743566296612_0; support_webp=true; support_avif=false; csrf_session_id=a5355d954d3c63ed1ba35faada452b4d; __ac_signature=_02B4Z6wo00f01G-ByvwAAIDBF08h-UIi.zRvoc5AAH.FLUld9yCjyqpKhLRWUia0dPU0ewdqWjxfXn--vkuavRTCjuIdXseqrNPgbp-ltXUK41RCbVx2UZm8ohx3riithUoZowB5XVCC9bot92; ixigua-a-s=1; s_v_web_id=verify_lhoket5d_0qlKZtzS_YZkf_4Uaj_82mX_j6lRT4PcYJ7A; msToken=j0KQp7ejmMFXXXGniwo32qrgVtLD_a7pAhJ4zzoyD_zTXzjdbNH-G0vJi5niZ0FnS98FnahfvUYf7bm5SpHDsdIx0bLc1DnHcdz8ppI0As0P-T5OmE46H7ejeJTyQHE=; tt_scid=RNxY3L30Tje39GrbDEFHI9xj-6QlojhexB2MwVj.jvAC4gib1X0k5lxTt74CXRcOeba2; ttwid=1%7CHHtv2QqpSGuSu8r-zXF1QoWsvjmNi1SJrqOrZzg-UCY%7C1685006419%7Cadadba21478a3551bc8364ebc49cbb7b6b775479d7c0dad3c65c9812722f4cf7',
  609. 'pragma': 'no-cache',
  610. 'referer': 'https://www.ixigua.com/',
  611. 'sec-ch-ua': '"Microsoft Edge";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
  612. 'sec-ch-ua-mobile': '?0',
  613. 'sec-ch-ua-platform': '"macOS"',
  614. 'sec-fetch-dest': 'empty',
  615. 'sec-fetch-mode': 'cors',
  616. 'sec-fetch-site': 'same-origin',
  617. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35',
  618. 'x-secsdk-csrf-token': '00010000000109233e2aa164da5098d92d53a87b346eb042a041e5a93d29fcb47e03f5d4a0e7176258649d64b4ae',
  619. }
  620. urllib3.disable_warnings()
  621. s = requests.session()
  622. # max_retries=3 重试3次
  623. s.mount('http://', HTTPAdapter(max_retries=3))
  624. s.mount('https://', HTTPAdapter(max_retries=3))
  625. response = requests.get(url=url, headers=headers, params=params, proxies=Common.tunnel_proxies(), verify=False, timeout=5)
  626. response.close()
  627. queryCount += 1
  628. if response.status_code != 200:
  629. Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.text}\n")
  630. return
  631. elif 'data' not in response.text:
  632. Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.text}\n")
  633. return
  634. elif 'channelFeed' not in response.json()['data']:
  635. Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.json()}\n")
  636. return
  637. elif 'Data' not in response.json()['data']['channelFeed']:
  638. Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.json()}\n")
  639. return
  640. elif len(response.json()['data']['channelFeed']['Data']) == 0:
  641. Common.logger(log_type, crawler).warning(f"没有更多数据啦 ~ :{response.json()}\n")
  642. return
  643. else:
  644. feeds = response.json()['data']['channelFeed']['Data']
  645. for i in range(len(feeds)):
  646. item_id = feeds[i].get("data", {}).get("item_id", "")
  647. if item_id == "":
  648. Common.logger(log_type, crawler).info("无效视频\n")
  649. continue
  650. video_dict = cls.get_video_info(log_type, crawler, item_id)
  651. if video_dict is None:
  652. Common.logger(log_type, crawler).info("无效视频\n")
  653. continue
  654. for k, v in video_dict.items():
  655. Common.logger(log_type, crawler).info(f"{k}:{v}")
  656. if download_rule(log_type=log_type, crawler=crawler, video_dict=video_dict, rule_dict=rule_dict) is False:
  657. Common.logger(log_type, crawler).info("不满足抓取规则\n")
  658. elif any(str(word) if str(word) in video_dict["video_title"] else False
  659. for word in get_config_from_mysql(log_type=log_type,
  660. source=crawler,
  661. env=env,
  662. text="filter",
  663. action="")) is True:
  664. Common.logger(log_type, crawler).info('已中过滤词\n')
  665. elif cls.repeat_video(log_type, crawler, video_dict["video_id"], env) != 0:
  666. Common.logger(log_type, crawler).info('视频已下载\n')
  667. else:
  668. cls.download_publish(log_type=log_type,
  669. crawler=crawler,
  670. our_uid=our_uid,
  671. video_dict=video_dict,
  672. rule_dict=rule_dict,
  673. env=env)
  674. @classmethod
  675. def download_publish(cls, log_type, crawler, our_uid, video_dict, rule_dict, env):
  676. # 下载视频
  677. Common.download_method(log_type=log_type, crawler=crawler, text='xigua_video', title=video_dict['video_title'], url=video_dict['video_url'])
  678. # 下载音频
  679. Common.download_method(log_type=log_type, crawler=crawler, text='xigua_audio', title=video_dict['video_title'], url=video_dict['audio_url'])
  680. # 合成音视频
  681. Common.video_compose(log_type=log_type, crawler=crawler, video_dir=f"./{crawler}/videos/{video_dict['video_title']}")
  682. md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
  683. try:
  684. if os.path.getsize(f"./{crawler}/videos/{md_title}/video.mp4") == 0:
  685. # 删除视频文件夹
  686. shutil.rmtree(f"./{crawler}/videos/{md_title}")
  687. Common.logger(log_type, crawler).info("视频size=0,删除成功\n")
  688. return
  689. except FileNotFoundError:
  690. # 删除视频文件夹
  691. shutil.rmtree(f"./{crawler}/videos/{md_title}")
  692. Common.logger(log_type, crawler).info("视频文件不存在,删除文件夹成功\n")
  693. return
  694. # 下载封面
  695. Common.download_method(log_type=log_type, crawler=crawler, text='cover', title=video_dict['video_title'], url=video_dict['cover_url'])
  696. # 保存视频信息至txt
  697. Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
  698. # 上传视频
  699. Common.logger(log_type, crawler).info("开始上传视频...")
  700. if env == "dev":
  701. oss_endpoint = "out"
  702. our_video_id = Publish.upload_and_publish(log_type=log_type,
  703. crawler=crawler,
  704. strategy="推荐抓取策略",
  705. our_uid=our_uid,
  706. env=env,
  707. oss_endpoint=oss_endpoint)
  708. our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  709. else:
  710. oss_endpoint = "inner"
  711. our_video_id = Publish.upload_and_publish(log_type=log_type,
  712. crawler=crawler,
  713. strategy="推荐抓取策略",
  714. our_uid=our_uid,
  715. env=env,
  716. oss_endpoint=oss_endpoint)
  717. our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  718. if our_video_id is None:
  719. try:
  720. # 删除视频文件夹
  721. shutil.rmtree(f"./{crawler}/videos/{md_title}")
  722. return
  723. except FileNotFoundError:
  724. return
  725. # 视频信息保存数据库
  726. insert_sql = f""" insert into crawler_video(video_id,
  727. user_id,
  728. out_user_id,
  729. platform,
  730. strategy,
  731. out_video_id,
  732. video_title,
  733. cover_url,
  734. video_url,
  735. duration,
  736. publish_time,
  737. play_cnt,
  738. crawler_rule,
  739. width,
  740. height)
  741. values({our_video_id},
  742. {our_uid},
  743. "{video_dict['user_id']}",
  744. "{cls.platform}",
  745. "推荐榜爬虫策略",
  746. "{video_dict['video_id']}",
  747. "{video_dict['video_title']}",
  748. "{video_dict['cover_url']}",
  749. "{video_dict['video_url']}",
  750. {int(video_dict['duration'])},
  751. "{video_dict['publish_time_str']}",
  752. {int(video_dict['play_cnt'])},
  753. '{json.dumps(rule_dict)}',
  754. {int(video_dict['video_width'])},
  755. {int(video_dict['video_height'])}) """
  756. Common.logger(log_type, crawler).info(f"insert_sql:{insert_sql}")
  757. MysqlHelper.update_values(log_type, crawler, insert_sql, env, action='')
  758. Common.logger(log_type, crawler).info('视频信息写入数据库成功')
  759. # 视频写入飞书
  760. Feishu.insert_columns(log_type, crawler, "1iKGF1", "ROWS", 1, 2)
  761. upload_time = int(time.time())
  762. values = [[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(upload_time)),
  763. "推荐榜爬虫策略",
  764. video_dict['video_title'],
  765. str(video_dict['video_id']),
  766. our_video_link,
  767. video_dict['gid'],
  768. video_dict['play_cnt'],
  769. video_dict['comment_cnt'],
  770. video_dict['like_cnt'],
  771. video_dict['share_cnt'],
  772. video_dict['duration'],
  773. str(video_dict['video_width']) + '*' + str(video_dict['video_height']),
  774. video_dict['publish_time_str'],
  775. video_dict['user_name'],
  776. video_dict['user_id'],
  777. video_dict['avatar_url'],
  778. video_dict['cover_url'],
  779. video_dict['audio_url'],
  780. video_dict['video_url']]]
  781. time.sleep(1)
  782. Feishu.update_values(log_type, 'xigua', "1iKGF1", "F2:Z2", values)
  783. Common.logger(log_type, crawler).info(f"视频已保存至云文档\n")
  784. if __name__ == "__main__":
  785. # XiguaRecommend.get_signature("recommend", "xigua", "dev")
  786. # XiguaRecommend.get_videolist("recommend", "xigua", "dev")
  787. # print(XiguaRecommend.get_video_url("recommend", "xigua", "7218171653242094139"))
  788. # print(XiguaRecommend.filter_words("recommend", "xigua"))
  789. pass