xigua_author_scheduling.py 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/5/26
  4. import base64
  5. import json
  6. import os
  7. import random
  8. import string
  9. import sys
  10. import time
  11. import requests
  12. import urllib3
  13. from requests.adapters import HTTPAdapter
  14. from common.mq import MQ
  15. sys.path.append(os.getcwd())
  16. from common.userAgent import get_random_user_agent
  17. from common.scheduling_db import MysqlHelper
  18. from common.common import Common
  19. from common.public import get_config_from_mysql, download_rule
  20. class XiguaauthorScheduling:
  21. platform = "西瓜视频"
  22. @classmethod
  23. def random_signature(cls):
  24. src_digits = string.digits # string_数字
  25. src_uppercase = string.ascii_uppercase # string_大写字母
  26. src_lowercase = string.ascii_lowercase # string_小写字母
  27. digits_num = random.randint(1, 6)
  28. uppercase_num = random.randint(1, 26 - digits_num - 1)
  29. lowercase_num = 26 - (digits_num + uppercase_num)
  30. password = random.sample(src_digits, digits_num) + random.sample(src_uppercase, uppercase_num) + random.sample(
  31. src_lowercase, lowercase_num)
  32. random.shuffle(password)
  33. new_password = 'AAAAAAAAAA' + ''.join(password)[10:-4] + 'AAAB'
  34. new_password_start = new_password[0:18]
  35. new_password_end = new_password[-7:]
  36. if new_password[18] == '8':
  37. new_password = new_password_start + 'w' + new_password_end
  38. elif new_password[18] == '9':
  39. new_password = new_password_start + 'x' + new_password_end
  40. elif new_password[18] == '-':
  41. new_password = new_password_start + 'y' + new_password_end
  42. elif new_password[18] == '.':
  43. new_password = new_password_start + 'z' + new_password_end
  44. else:
  45. new_password = new_password_start + 'y' + new_password_end
  46. return new_password
  47. @classmethod
  48. def get_video_url(cls, video_info):
  49. video_url_dict = {}
  50. # video_url
  51. if 'videoResource' not in video_info:
  52. video_url_dict["video_url"] = ''
  53. video_url_dict["audio_url"] = ''
  54. video_url_dict["video_width"] = 0
  55. video_url_dict["video_height"] = 0
  56. elif 'dash_120fps' in video_info['videoResource']:
  57. if "video_list" in video_info['videoResource']['dash_120fps'] and 'video_4' in \
  58. video_info['videoResource']['dash_120fps']['video_list']:
  59. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
  60. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
  61. if len(video_url) % 3 == 1:
  62. video_url += '=='
  63. elif len(video_url) % 3 == 2:
  64. video_url += '='
  65. elif len(audio_url) % 3 == 1:
  66. audio_url += '=='
  67. elif len(audio_url) % 3 == 2:
  68. audio_url += '='
  69. video_url = base64.b64decode(video_url).decode('utf8')
  70. audio_url = base64.b64decode(audio_url).decode('utf8')
  71. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_4']['vwidth']
  72. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_4']['vheight']
  73. video_url_dict["video_url"] = video_url
  74. video_url_dict["audio_url"] = audio_url
  75. video_url_dict["video_width"] = video_width
  76. video_url_dict["video_height"] = video_height
  77. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_3' in \
  78. video_info['videoResource']['dash_120fps']['video_list']:
  79. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
  80. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
  81. if len(video_url) % 3 == 1:
  82. video_url += '=='
  83. elif len(video_url) % 3 == 2:
  84. video_url += '='
  85. elif len(audio_url) % 3 == 1:
  86. audio_url += '=='
  87. elif len(audio_url) % 3 == 2:
  88. audio_url += '='
  89. video_url = base64.b64decode(video_url).decode('utf8')
  90. audio_url = base64.b64decode(audio_url).decode('utf8')
  91. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_3']['vwidth']
  92. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_3']['vheight']
  93. video_url_dict["video_url"] = video_url
  94. video_url_dict["audio_url"] = audio_url
  95. video_url_dict["video_width"] = video_width
  96. video_url_dict["video_height"] = video_height
  97. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_2' in \
  98. video_info['videoResource']['dash_120fps']['video_list']:
  99. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
  100. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
  101. if len(video_url) % 3 == 1:
  102. video_url += '=='
  103. elif len(video_url) % 3 == 2:
  104. video_url += '='
  105. elif len(audio_url) % 3 == 1:
  106. audio_url += '=='
  107. elif len(audio_url) % 3 == 2:
  108. audio_url += '='
  109. video_url = base64.b64decode(video_url).decode('utf8')
  110. audio_url = base64.b64decode(audio_url).decode('utf8')
  111. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_2']['vwidth']
  112. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_2']['vheight']
  113. video_url_dict["video_url"] = video_url
  114. video_url_dict["audio_url"] = audio_url
  115. video_url_dict["video_width"] = video_width
  116. video_url_dict["video_height"] = video_height
  117. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_1' in \
  118. video_info['videoResource']['dash_120fps']['video_list']:
  119. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
  120. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
  121. if len(video_url) % 3 == 1:
  122. video_url += '=='
  123. elif len(video_url) % 3 == 2:
  124. video_url += '='
  125. elif len(audio_url) % 3 == 1:
  126. audio_url += '=='
  127. elif len(audio_url) % 3 == 2:
  128. audio_url += '='
  129. video_url = base64.b64decode(video_url).decode('utf8')
  130. audio_url = base64.b64decode(audio_url).decode('utf8')
  131. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_1']['vwidth']
  132. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_1']['vheight']
  133. video_url_dict["video_url"] = video_url
  134. video_url_dict["audio_url"] = audio_url
  135. video_url_dict["video_width"] = video_width
  136. video_url_dict["video_height"] = video_height
  137. elif 'dynamic_video' in video_info['videoResource']['dash_120fps'] \
  138. and 'dynamic_video_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
  139. and 'dynamic_audio_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
  140. and len(
  141. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list']) != 0 \
  142. and len(
  143. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list']) != 0:
  144. video_url = \
  145. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  146. 'backup_url_1']
  147. audio_url = \
  148. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list'][-1][
  149. 'backup_url_1']
  150. if len(video_url) % 3 == 1:
  151. video_url += '=='
  152. elif len(video_url) % 3 == 2:
  153. video_url += '='
  154. elif len(audio_url) % 3 == 1:
  155. audio_url += '=='
  156. elif len(audio_url) % 3 == 2:
  157. audio_url += '='
  158. video_url = base64.b64decode(video_url).decode('utf8')
  159. audio_url = base64.b64decode(audio_url).decode('utf8')
  160. video_width = \
  161. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  162. 'vwidth']
  163. video_height = \
  164. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  165. 'vheight']
  166. video_url_dict["video_url"] = video_url
  167. video_url_dict["audio_url"] = audio_url
  168. video_url_dict["video_width"] = video_width
  169. video_url_dict["video_height"] = video_height
  170. else:
  171. video_url_dict["video_url"] = ''
  172. video_url_dict["audio_url"] = ''
  173. video_url_dict["video_width"] = 0
  174. video_url_dict["video_height"] = 0
  175. elif 'dash' in video_info['videoResource']:
  176. if "video_list" in video_info['videoResource']['dash'] and 'video_4' in \
  177. video_info['videoResource']['dash']['video_list']:
  178. video_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
  179. audio_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
  180. if len(video_url) % 3 == 1:
  181. video_url += '=='
  182. elif len(video_url) % 3 == 2:
  183. video_url += '='
  184. elif len(audio_url) % 3 == 1:
  185. audio_url += '=='
  186. elif len(audio_url) % 3 == 2:
  187. audio_url += '='
  188. video_url = base64.b64decode(video_url).decode('utf8')
  189. audio_url = base64.b64decode(audio_url).decode('utf8')
  190. video_width = video_info['videoResource']['dash']['video_list']['video_4']['vwidth']
  191. video_height = video_info['videoResource']['dash']['video_list']['video_4']['vheight']
  192. video_url_dict["video_url"] = video_url
  193. video_url_dict["audio_url"] = audio_url
  194. video_url_dict["video_width"] = video_width
  195. video_url_dict["video_height"] = video_height
  196. elif "video_list" in video_info['videoResource']['dash'] and 'video_3' in \
  197. video_info['videoResource']['dash']['video_list']:
  198. video_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
  199. audio_url = video_info['videoResource']['dash']['video_list']['video_3']['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 = video_info['videoResource']['dash']['video_list']['video_3']['vwidth']
  211. video_height = video_info['videoResource']['dash']['video_list']['video_3']['vheight']
  212. video_url_dict["video_url"] = video_url
  213. video_url_dict["audio_url"] = audio_url
  214. video_url_dict["video_width"] = video_width
  215. video_url_dict["video_height"] = video_height
  216. elif "video_list" in video_info['videoResource']['dash'] and 'video_2' in \
  217. video_info['videoResource']['dash']['video_list']:
  218. video_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
  219. audio_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
  220. if len(video_url) % 3 == 1:
  221. video_url += '=='
  222. elif len(video_url) % 3 == 2:
  223. video_url += '='
  224. elif len(audio_url) % 3 == 1:
  225. audio_url += '=='
  226. elif len(audio_url) % 3 == 2:
  227. audio_url += '='
  228. video_url = base64.b64decode(video_url).decode('utf8')
  229. audio_url = base64.b64decode(audio_url).decode('utf8')
  230. video_width = video_info['videoResource']['dash']['video_list']['video_2']['vwidth']
  231. video_height = video_info['videoResource']['dash']['video_list']['video_2']['vheight']
  232. video_url_dict["video_url"] = video_url
  233. video_url_dict["audio_url"] = audio_url
  234. video_url_dict["video_width"] = video_width
  235. video_url_dict["video_height"] = video_height
  236. elif "video_list" in video_info['videoResource']['dash'] and 'video_1' in \
  237. video_info['videoResource']['dash']['video_list']:
  238. video_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
  239. audio_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
  240. if len(video_url) % 3 == 1:
  241. video_url += '=='
  242. elif len(video_url) % 3 == 2:
  243. video_url += '='
  244. elif len(audio_url) % 3 == 1:
  245. audio_url += '=='
  246. elif len(audio_url) % 3 == 2:
  247. audio_url += '='
  248. video_url = base64.b64decode(video_url).decode('utf8')
  249. audio_url = base64.b64decode(audio_url).decode('utf8')
  250. video_width = video_info['videoResource']['dash']['video_list']['video_1']['vwidth']
  251. video_height = video_info['videoResource']['dash']['video_list']['video_1']['vheight']
  252. video_url_dict["video_url"] = video_url
  253. video_url_dict["audio_url"] = audio_url
  254. video_url_dict["video_width"] = video_width
  255. video_url_dict["video_height"] = video_height
  256. elif 'dynamic_video' in video_info['videoResource']['dash'] \
  257. and 'dynamic_video_list' in video_info['videoResource']['dash']['dynamic_video'] \
  258. and 'dynamic_audio_list' in video_info['videoResource']['dash']['dynamic_video'] \
  259. and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list']) != 0 \
  260. and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list']) != 0:
  261. video_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  262. 'backup_url_1']
  263. audio_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list'][-1][
  264. 'backup_url_1']
  265. if len(video_url) % 3 == 1:
  266. video_url += '=='
  267. elif len(video_url) % 3 == 2:
  268. video_url += '='
  269. elif len(audio_url) % 3 == 1:
  270. audio_url += '=='
  271. elif len(audio_url) % 3 == 2:
  272. audio_url += '='
  273. video_url = base64.b64decode(video_url).decode('utf8')
  274. audio_url = base64.b64decode(audio_url).decode('utf8')
  275. video_width = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  276. 'vwidth']
  277. video_height = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  278. 'vheight']
  279. video_url_dict["video_url"] = video_url
  280. video_url_dict["audio_url"] = audio_url
  281. video_url_dict["video_width"] = video_width
  282. video_url_dict["video_height"] = video_height
  283. else:
  284. video_url_dict["video_url"] = ''
  285. video_url_dict["audio_url"] = ''
  286. video_url_dict["video_width"] = 0
  287. video_url_dict["video_height"] = 0
  288. elif 'normal' in video_info['videoResource']:
  289. if "video_list" in video_info['videoResource']['normal'] and 'video_4' in \
  290. video_info['videoResource']['normal']['video_list']:
  291. video_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
  292. audio_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
  293. if len(video_url) % 3 == 1:
  294. video_url += '=='
  295. elif len(video_url) % 3 == 2:
  296. video_url += '='
  297. elif len(audio_url) % 3 == 1:
  298. audio_url += '=='
  299. elif len(audio_url) % 3 == 2:
  300. audio_url += '='
  301. video_url = base64.b64decode(video_url).decode('utf8')
  302. audio_url = base64.b64decode(audio_url).decode('utf8')
  303. video_width = video_info['videoResource']['normal']['video_list']['video_4']['vwidth']
  304. video_height = video_info['videoResource']['normal']['video_list']['video_4']['vheight']
  305. video_url_dict["video_url"] = video_url
  306. video_url_dict["audio_url"] = audio_url
  307. video_url_dict["video_width"] = video_width
  308. video_url_dict["video_height"] = video_height
  309. elif "video_list" in video_info['videoResource']['normal'] and 'video_3' in \
  310. video_info['videoResource']['normal']['video_list']:
  311. video_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
  312. audio_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
  313. if len(video_url) % 3 == 1:
  314. video_url += '=='
  315. elif len(video_url) % 3 == 2:
  316. video_url += '='
  317. elif len(audio_url) % 3 == 1:
  318. audio_url += '=='
  319. elif len(audio_url) % 3 == 2:
  320. audio_url += '='
  321. video_url = base64.b64decode(video_url).decode('utf8')
  322. audio_url = base64.b64decode(audio_url).decode('utf8')
  323. video_width = video_info['videoResource']['normal']['video_list']['video_3']['vwidth']
  324. video_height = video_info['videoResource']['normal']['video_list']['video_3']['vheight']
  325. video_url_dict["video_url"] = video_url
  326. video_url_dict["audio_url"] = audio_url
  327. video_url_dict["video_width"] = video_width
  328. video_url_dict["video_height"] = video_height
  329. elif "video_list" in video_info['videoResource']['normal'] and 'video_2' in \
  330. video_info['videoResource']['normal']['video_list']:
  331. video_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
  332. audio_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
  333. if len(video_url) % 3 == 1:
  334. video_url += '=='
  335. elif len(video_url) % 3 == 2:
  336. video_url += '='
  337. elif len(audio_url) % 3 == 1:
  338. audio_url += '=='
  339. elif len(audio_url) % 3 == 2:
  340. audio_url += '='
  341. video_url = base64.b64decode(video_url).decode('utf8')
  342. audio_url = base64.b64decode(audio_url).decode('utf8')
  343. video_width = video_info['videoResource']['normal']['video_list']['video_2']['vwidth']
  344. video_height = video_info['videoResource']['normal']['video_list']['video_2']['vheight']
  345. video_url_dict["video_url"] = video_url
  346. video_url_dict["audio_url"] = audio_url
  347. video_url_dict["video_width"] = video_width
  348. video_url_dict["video_height"] = video_height
  349. elif "video_list" in video_info['videoResource']['normal'] and 'video_1' in \
  350. video_info['videoResource']['normal']['video_list']:
  351. video_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
  352. audio_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
  353. if len(video_url) % 3 == 1:
  354. video_url += '=='
  355. elif len(video_url) % 3 == 2:
  356. video_url += '='
  357. elif len(audio_url) % 3 == 1:
  358. audio_url += '=='
  359. elif len(audio_url) % 3 == 2:
  360. audio_url += '='
  361. video_url = base64.b64decode(video_url).decode('utf8')
  362. audio_url = base64.b64decode(audio_url).decode('utf8')
  363. video_width = video_info['videoResource']['normal']['video_list']['video_1']['vwidth']
  364. video_height = video_info['videoResource']['normal']['video_list']['video_1']['vheight']
  365. video_url_dict["video_url"] = video_url
  366. video_url_dict["audio_url"] = audio_url
  367. video_url_dict["video_width"] = video_width
  368. video_url_dict["video_height"] = video_height
  369. elif 'dynamic_video' in video_info['videoResource']['normal'] \
  370. and 'dynamic_video_list' in video_info['videoResource']['normal']['dynamic_video'] \
  371. and 'dynamic_audio_list' in video_info['videoResource']['normal']['dynamic_video'] \
  372. and len(video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list']) != 0 \
  373. and len(video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list']) != 0:
  374. video_url = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  375. 'backup_url_1']
  376. audio_url = video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list'][-1][
  377. 'backup_url_1']
  378. if len(video_url) % 3 == 1:
  379. video_url += '=='
  380. elif len(video_url) % 3 == 2:
  381. video_url += '='
  382. elif len(audio_url) % 3 == 1:
  383. audio_url += '=='
  384. elif len(audio_url) % 3 == 2:
  385. audio_url += '='
  386. video_url = base64.b64decode(video_url).decode('utf8')
  387. audio_url = base64.b64decode(audio_url).decode('utf8')
  388. video_width = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  389. 'vwidth']
  390. video_height = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  391. 'vheight']
  392. video_url_dict["video_url"] = video_url
  393. video_url_dict["audio_url"] = audio_url
  394. video_url_dict["video_width"] = video_width
  395. video_url_dict["video_height"] = video_height
  396. else:
  397. video_url_dict["video_url"] = ''
  398. video_url_dict["audio_url"] = ''
  399. video_url_dict["video_width"] = 0
  400. video_url_dict["video_height"] = 0
  401. else:
  402. video_url_dict["video_url"] = ''
  403. video_url_dict["audio_url"] = ''
  404. video_url_dict["video_width"] = 0
  405. video_url_dict["video_height"] = 0
  406. return video_url_dict
  407. @classmethod
  408. def get_comment_cnt(cls, item_id):
  409. url = "https://www.ixigua.com/tlb/comment/article/v5/tab_comments/?"
  410. params = {
  411. "tab_index": "0",
  412. "count": "10",
  413. "offset": "10",
  414. "group_id": str(item_id),
  415. "item_id": str(item_id),
  416. "aid": "1768",
  417. "msToken": "50-JJObWB07HfHs-BMJWT1eIDX3G-6lPSF_i-QwxBIXE9VVa-iN0jbEXR5pG2DKjXBmP299n6ZTuXzY-GAy968CCvouSAYIS4GzvGQT3pNlKNejr5G4-1g==",
  418. "X-Bogus": "DFSzswVOyGtANVeWtCLMqR/F6q9U",
  419. "_signature": cls.random_signature(),
  420. }
  421. headers = {
  422. 'authority': 'www.ixigua.com',
  423. 'accept': 'application/json, text/plain, */*',
  424. 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
  425. 'cache-control': 'no-cache',
  426. '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',
  427. 'pragma': 'no-cache',
  428. 'referer': f'https://www.ixigua.com/{item_id}?logTag=3c5aa86a8600b9ab8540',
  429. 'sec-ch-ua': '"Microsoft Edge";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
  430. 'sec-ch-ua-mobile': '?0',
  431. 'sec-ch-ua-platform': '"macOS"',
  432. 'sec-fetch-dest': 'empty',
  433. 'sec-fetch-mode': 'cors',
  434. 'sec-fetch-site': 'same-origin',
  435. 'tt-anti-token': 'cBITBHvmYjEygzv-f9c78c1297722cf1f559c74b084e4525ce4900bdcf9e8588f20cc7c2e3234422',
  436. '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',
  437. 'x-secsdk-csrf-token': '000100000001f8e733cf37f0cd255a51aea9a81ff7bc0c09490cfe41ad827c3c5c18ec809279175e4d9f5553d8a5'
  438. }
  439. urllib3.disable_warnings()
  440. s = requests.session()
  441. # max_retries=3 重试3次
  442. s.mount('http://', HTTPAdapter(max_retries=3))
  443. s.mount('https://', HTTPAdapter(max_retries=3))
  444. response = s.get(url=url, headers=headers, params=params, verify=False, proxies=Common.tunnel_proxies(),
  445. timeout=5)
  446. response.close()
  447. if response.status_code != 200 or 'total_number' not in response.json() or response.json() == {}:
  448. return 0
  449. return response.json().get("total_number", 0)
  450. # 获取视频详情
  451. @classmethod
  452. def get_video_info(cls, log_type, crawler, item_id):
  453. url = 'https://www.ixigua.com/api/mixVideo/information?'
  454. headers = {
  455. "accept-encoding": "gzip, deflate",
  456. "accept-language": "zh-CN,zh-Hans;q=0.9",
  457. "user-agent": get_random_user_agent('pc'),
  458. "referer": "https://www.ixigua.com/7102614741050196520?logTag=0531c88ac04f38ab2c62",
  459. }
  460. params = {
  461. 'mixId': str(item_id),
  462. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfC'
  463. 'NVVIOBNjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  464. 'X-Bogus': 'DFSzswVupYTANCJOSBk0P53WxM-r',
  465. '_signature': '_02B4Z6wo0000119LvEwAAIDCuktNZ0y5wkdfS7jAALThuOR8D9yWNZ.EmWHKV0WSn6Px'
  466. 'fPsH9-BldyxVje0f49ryXgmn7Tzk-swEHNb15TiGqa6YF.cX0jW8Eds1TtJOIZyfc9s5emH7gdWN94',
  467. }
  468. cookies = {
  469. 'ixigua-a-s': '1',
  470. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfCNVVIOB'
  471. 'NjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  472. 'ttwid': '1%7C_yXQeHWwLZgCsgHClOwTCdYSOt_MjdOkgnPIkpi-Sr8%7C1661241238%7Cf57d0c5ef3f1d7'
  473. '6e049fccdca1ac54887c34d1f8731c8e51a49780ff0ceab9f8',
  474. 'tt_scid': 'QZ4l8KXDG0YAEaMCSbADdcybdKbUfG4BC6S4OBv9lpRS5VyqYLX2bIR8CTeZeGHR9ee3',
  475. 'MONITOR_WEB_ID': '0a49204a-7af5-4e96-95f0-f4bafb7450ad',
  476. '__ac_nonce': '06304878000964fdad287',
  477. '__ac_signature': '_02B4Z6wo00f017Rcr3AAAIDCUVxeW1tOKEu0fKvAAI4cvoYzV-wBhq7B6D8k0no7lb'
  478. 'FlvYoinmtK6UXjRIYPXnahUlFTvmWVtb77jsMkKAXzAEsLE56m36RlvL7ky.M3Xn52r9t1IEb7IR3ke8',
  479. 'ttcid': 'e56fabf6e85d4adf9e4d91902496a0e882',
  480. '_tea_utm_cache_1300': 'undefined',
  481. 'support_avif': 'false',
  482. 'support_webp': 'false',
  483. 'xiguavideopcwebid': '7134967546256016900',
  484. 'xiguavideopcwebid.sig': 'xxRww5R1VEMJN_dQepHorEu_eAc',
  485. }
  486. urllib3.disable_warnings()
  487. s = requests.session()
  488. # max_retries=3 重试3次
  489. s.mount('http://', HTTPAdapter(max_retries=3))
  490. s.mount('https://', HTTPAdapter(max_retries=3))
  491. response = s.get(url=url, headers=headers, params=params, cookies=cookies, verify=False,
  492. proxies=Common.tunnel_proxies(), timeout=5)
  493. response.close()
  494. if response.status_code != 200 or 'data' not in response.json() or response.json()['data'] == {}:
  495. Common.logger(log_type, crawler).warning(f"get_video_info:{response.status_code}, {response.text}\n")
  496. return None
  497. else:
  498. video_info = response.json()['data'].get("gidInformation", {}).get("packerData", {}).get("video", {})
  499. if video_info == {}:
  500. return None
  501. video_dict = {
  502. "video_title": video_info.get("title", ""),
  503. "video_id": video_info.get("videoResource", {}).get("vid", ""),
  504. "gid": str(item_id),
  505. "play_cnt": int(video_info.get("video_watch_count", 0)),
  506. "like_cnt": int(video_info.get("video_like_count", 0)),
  507. "comment_cnt": int(cls.get_comment_cnt(item_id)),
  508. "share_cnt": 0,
  509. "favorite_cnt": 0,
  510. "duration": int(video_info.get("video_duration", 0)),
  511. "video_width": int(cls.get_video_url(video_info)["video_width"]),
  512. "video_height": int(cls.get_video_url(video_info)["video_height"]),
  513. "publish_time_stamp": int(video_info.get("video_publish_time", 0)),
  514. "publish_time_str": time.strftime("%Y-%m-%d %H:%M:%S",
  515. time.localtime(int(video_info.get("video_publish_time", 0)))),
  516. "user_name": video_info.get("user_info", {}).get("name", ""),
  517. "user_id": str(video_info.get("user_info", {}).get("user_id", "")),
  518. "avatar_url": str(video_info.get("user_info", {}).get("avatar_url", "")),
  519. "cover_url": video_info.get("poster_url", ""),
  520. "audio_url": cls.get_video_url(video_info)["audio_url"],
  521. "video_url": cls.get_video_url(video_info)["video_url"],
  522. "session": f"xigua-search-{int(time.time())}"
  523. }
  524. return video_dict
  525. @classmethod
  526. def get_videoList(cls, log_type, crawler, user_dict, rule_dict, env):
  527. mq = MQ(topic_name="topic_crawler_etl_" + env)
  528. signature = cls.random_signature()
  529. offset = 0
  530. while True:
  531. url = "https://www.ixigua.com/api/videov2/author/new_video_list?"
  532. params = {
  533. 'to_user_id': str(user_dict["link"].replace("https://www.ixigua.com/home/", "")),
  534. 'offset': str(offset),
  535. 'limit': '30',
  536. 'maxBehotTime': '0',
  537. 'order': 'new',
  538. 'isHome': '0',
  539. # 'msToken': 'G0eRzNkw189a8TLaXjc6nTHVMQwh9XcxVAqTbGKi7iPJdQcLwS3-XRrJ3MZ7QBfqErpxp3EX1WtvWOIcZ3NIgr41hgcd-v64so_RRj3YCRw1UsKW8mIssNLlIMspsg==',
  540. # 'X-Bogus': 'DFSzswVuEkUANjW9ShFTgR/F6qHt',
  541. '_signature': signature,
  542. }
  543. headers = {
  544. 'referer': f'https://www.ixigua.com/home/{user_dict["link"].replace("https://www.ixigua.com/home/", "")}/video/?preActiveKey=hotsoon&list_entrance=userdetail',
  545. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.41',
  546. }
  547. urllib3.disable_warnings()
  548. s = requests.session()
  549. # max_retries=3 重试3次
  550. s.mount('http://', HTTPAdapter(max_retries=3))
  551. s.mount('https://', HTTPAdapter(max_retries=3))
  552. response = s.get(url=url, headers=headers, params=params, proxies=Common.tunnel_proxies(), verify=False, timeout=5)
  553. response.close()
  554. offset += 30
  555. if response.status_code != 200:
  556. Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.text}\n")
  557. Common.logging(log_type, crawler, env, f"get_videolist_response:{response.text}\n")
  558. return
  559. elif 'data' not in response.text:
  560. Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.text}\n")
  561. Common.logging(log_type, crawler, env, f"get_videolist_response:{response.text}\n")
  562. return
  563. elif not response.json()["data"]['videoList']:
  564. Common.logger(log_type, crawler).warning(f"没有更多数据啦~:{response.json()}\n")
  565. Common.logging(log_type, crawler, env, f"没有更多数据啦~:{response.json()}\n")
  566. return
  567. feeds = response.json()['data']['videoList']
  568. for i in range(len(feeds)):
  569. try:
  570. item_id = feeds[i].get("item_id", "")
  571. if item_id == "":
  572. Common.logger(log_type, crawler).info("无效视频\n")
  573. Common.logging(log_type, crawler, env, "无效视频\n")
  574. continue
  575. video_dict = cls.get_video_info(log_type, crawler, item_id)
  576. if video_dict is None:
  577. Common.logger(log_type, crawler).info("无效视频\n")
  578. Common.logging(log_type, crawler, env, "无效视频\n")
  579. continue
  580. for k, v in video_dict.items():
  581. Common.logger(log_type, crawler).info(f"{k}:{v}")
  582. Common.logging(log_type, crawler, env, f"{video_dict}")
  583. if int((int(time.time()) - int(video_dict["publish_time_stamp"])) / (3600 * 24)) > int(rule_dict.get("period", {}).get("max", 1000)):
  584. Common.logger(log_type, crawler).info(f'发布时间超过{int(rule_dict.get("period", {}).get("max", 1000))}天\n')
  585. Common.logging(log_type, crawler, env, f'发布时间超过{int(rule_dict.get("period", {}).get("max", 1000))}天\n')
  586. return
  587. if download_rule(log_type=log_type, crawler=crawler, video_dict=video_dict, rule_dict=rule_dict) is False:
  588. Common.logger(log_type, crawler).info("不满足抓取规则\n")
  589. Common.logging(log_type, crawler, env, "不满足抓取规则\n")
  590. elif any(str(word) if str(word) in video_dict["video_title"] else False
  591. for word in get_config_from_mysql(log_type=log_type,
  592. source=crawler,
  593. env=env,
  594. text="filter",
  595. action="")) is True:
  596. Common.logger(log_type, crawler).info('已中过滤词\n')
  597. Common.logging(log_type, crawler, env, "已中过滤词\n")
  598. elif cls.repeat_video(log_type, crawler, video_dict["video_id"], env) != 0:
  599. Common.logger(log_type, crawler).info('视频已下载\n')
  600. Common.logging(log_type, crawler, env, "视频已下载\n")
  601. else:
  602. video_dict["out_user_id"] = video_dict["user_id"]
  603. video_dict["platform"] = crawler
  604. video_dict["strategy"] = log_type
  605. video_dict["out_video_id"] = video_dict["video_id"]
  606. video_dict["width"] = video_dict["video_width"]
  607. video_dict["height"] = video_dict["video_height"]
  608. video_dict["crawler_rule"] = json.dumps(rule_dict)
  609. video_dict["user_id"] = user_dict["uid"]
  610. video_dict["publish_time"] = video_dict["publish_time_str"]
  611. video_dict["strategy_type"] = log_type
  612. mq.send_msg(video_dict)
  613. except Exception as e:
  614. Common.logger(log_type, crawler).error(f"抓取单条视频异常:{e}\n")
  615. Common.logging(log_type, crawler, env, f"抓取单条视频异常:{e}\n")
  616. @classmethod
  617. def repeat_video(cls, log_type, crawler, video_id, env):
  618. # sql = f""" select * from crawler_video where platform="{cls.platform}" and out_video_id="{video_id}"; """
  619. sql = f""" select * from crawler_video where platform in ("{crawler}","{cls.platform}") and out_video_id="{video_id}"; """
  620. repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env)
  621. return len(repeat_video)
  622. @classmethod
  623. def get_author_videos(cls, log_type, crawler, user_list, rule_dict, env):
  624. for user_dict in user_list:
  625. try:
  626. Common.logger(log_type, crawler).info(f"开始抓取 {user_dict['nick_name']} 用户主页视频\n")
  627. Common.logging(log_type, crawler, env, f"开始抓取 {user_dict['nick_name']} 用户主页视频\n")
  628. cls.get_videoList(log_type=log_type,
  629. crawler=crawler,
  630. user_dict=user_dict,
  631. rule_dict=rule_dict,
  632. env=env)
  633. except Exception as e:
  634. Common.logger(log_type, crawler).error(f"抓取{user_dict['nick_name']}视频时异常:{e}\n")
  635. Common.logging(log_type, crawler, env, f"抓取{user_dict['nick_name']}视频时异常:{e}\n")
  636. if __name__ == '__main__':
  637. print(XiguaauthorScheduling.repeat_video("follow", "xigua", "v0201ag10000ce3jcjbc77u8jsplpgrg", "dev"))
  638. pass