xigua_author.py 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. import json
  2. import os
  3. import re
  4. import random
  5. import sys
  6. import string
  7. import time
  8. import uuid
  9. import base64
  10. import requests
  11. from fake_useragent import FakeUserAgent
  12. from common.mq import MQ
  13. sys.path.append(os.getcwd())
  14. from common import AliyunLogger, PiaoQuanPipeline, tunnel_proxies
  15. from common.limit import AuthorLimit
  16. def extract_info_by_re(text):
  17. """
  18. 通过正则表达式获取文本中的信息
  19. :param text:
  20. :return:
  21. """
  22. # 标题
  23. title_match = re.search(r'<title[^>]*>(.*?)</title>', text)
  24. if title_match:
  25. title_content = title_match.group(1)
  26. title_content = title_content.split(" - ")[0]
  27. title_content = bytes(title_content, "latin1").decode()
  28. else:
  29. title_content = ""
  30. # video_url
  31. main_url = re.search(r'("main_url":")(.*?)"', text)[0]
  32. main_url = main_url.split(":")[1]
  33. decoded_data = base64.b64decode(main_url)
  34. try:
  35. # 尝试使用utf-8解码
  36. video_url = decoded_data.decode()
  37. except UnicodeDecodeError:
  38. # 如果utf-8解码失败,尝试使用其他编码方式
  39. video_url = decoded_data.decode('latin-1')
  40. # video_id
  41. video_id = re.search(r'"vid":"(.*?)"', text).group(1)
  42. # like_count
  43. like_count = re.search(r'"video_like_count":(.*?),', text).group(1)
  44. # cover_url
  45. cover_url = re.search(r'"avatar_url":"(.*?)"', text).group(1)
  46. # video_play
  47. video_watch_count = re.search(r'"video_watch_count":(.*?),', text).group(1)
  48. # "video_publish_time"
  49. publish_time = re.search(r'"video_publish_time":"(.*?)"', text).group(1)
  50. # video_duration
  51. duration = re.search(r'("video_duration":)(.*?)"', text).group(2).replace(",", "")
  52. return {
  53. "title": title_content,
  54. "url": video_url,
  55. "video_id": video_id,
  56. "like_count": like_count,
  57. "cover_url": cover_url,
  58. "play_count": video_watch_count,
  59. "publish_time": publish_time,
  60. "duration": duration
  61. }
  62. def random_signature():
  63. """
  64. 随机生成签名
  65. """
  66. src_digits = string.digits # string_数字
  67. src_uppercase = string.ascii_uppercase # string_大写字母
  68. src_lowercase = string.ascii_lowercase # string_小写字母
  69. digits_num = random.randint(1, 6)
  70. uppercase_num = random.randint(1, 26 - digits_num - 1)
  71. lowercase_num = 26 - (digits_num + uppercase_num)
  72. password = (
  73. random.sample(src_digits, digits_num)
  74. + random.sample(src_uppercase, uppercase_num)
  75. + random.sample(src_lowercase, lowercase_num)
  76. )
  77. random.shuffle(password)
  78. new_password = "AAAAAAAAAA" + "".join(password)[10:-4] + "AAAB"
  79. new_password_start = new_password[0:18]
  80. new_password_end = new_password[-7:]
  81. if new_password[18] == "8":
  82. new_password = new_password_start + "w" + new_password_end
  83. elif new_password[18] == "9":
  84. new_password = new_password_start + "x" + new_password_end
  85. elif new_password[18] == "-":
  86. new_password = new_password_start + "y" + new_password_end
  87. elif new_password[18] == ".":
  88. new_password = new_password_start + "z" + new_password_end
  89. else:
  90. new_password = new_password_start + "y" + new_password_end
  91. return new_password
  92. def byte_dance_cookie(item_id):
  93. """
  94. 获取西瓜视频的 cookie
  95. :param item_id:
  96. """
  97. sess = requests.Session()
  98. sess.headers.update({
  99. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
  100. 'referer': 'https://www.ixigua.com/home/{}/'.format(item_id),
  101. })
  102. # 获取 cookies
  103. sess.get('https://i.snssdk.com/slardar/sdk.js?bid=xigua_video_web_pc')
  104. data = '{"region":"cn","aid":1768,"needFid":false,"service":"www.ixigua.com","migrate_info":{"ticket":"","source":"node"},"cbUrlProtocol":"https","union":true}'
  105. r = sess.post('https://ttwid.bytedance.com/ttwid/union/register/', data=data)
  106. # print(r.text)
  107. return r.cookies.values()[0]
  108. def get_video_url(video_info):
  109. """
  110. 获取视频的链接
  111. """
  112. video_url_dict = {}
  113. # video_url
  114. if "videoResource" not in video_info:
  115. video_url_dict["video_url"] = ""
  116. video_url_dict["audio_url"] = ""
  117. video_url_dict["video_width"] = 0
  118. video_url_dict["video_height"] = 0
  119. elif "dash_120fps" in video_info["videoResource"]:
  120. if (
  121. "video_list" in video_info["videoResource"]["dash_120fps"]
  122. and "video_4" in video_info["videoResource"]["dash_120fps"]["video_list"]
  123. ):
  124. video_url = video_info["videoResource"]["dash_120fps"]["video_list"][
  125. "video_4"
  126. ]["backup_url_1"]
  127. audio_url = video_info["videoResource"]["dash_120fps"]["video_list"][
  128. "video_4"
  129. ]["backup_url_1"]
  130. if len(video_url) % 3 == 1:
  131. video_url += "=="
  132. elif len(video_url) % 3 == 2:
  133. video_url += "="
  134. elif len(audio_url) % 3 == 1:
  135. audio_url += "=="
  136. elif len(audio_url) % 3 == 2:
  137. audio_url += "="
  138. video_url = base64.b64decode(video_url).decode("utf8")
  139. audio_url = base64.b64decode(audio_url).decode("utf8")
  140. video_width = video_info["videoResource"]["dash_120fps"]["video_list"][
  141. "video_4"
  142. ]["vwidth"]
  143. video_height = video_info["videoResource"]["dash_120fps"]["video_list"][
  144. "video_4"
  145. ]["vheight"]
  146. video_url_dict["video_url"] = video_url
  147. video_url_dict["audio_url"] = audio_url
  148. video_url_dict["video_width"] = video_width
  149. video_url_dict["video_height"] = video_height
  150. elif (
  151. "video_list" in video_info["videoResource"]["dash_120fps"]
  152. and "video_3" in video_info["videoResource"]["dash_120fps"]["video_list"]
  153. ):
  154. video_url = video_info["videoResource"]["dash_120fps"]["video_list"][
  155. "video_3"
  156. ]["backup_url_1"]
  157. audio_url = video_info["videoResource"]["dash_120fps"]["video_list"][
  158. "video_3"
  159. ]["backup_url_1"]
  160. if len(video_url) % 3 == 1:
  161. video_url += "=="
  162. elif len(video_url) % 3 == 2:
  163. video_url += "="
  164. elif len(audio_url) % 3 == 1:
  165. audio_url += "=="
  166. elif len(audio_url) % 3 == 2:
  167. audio_url += "="
  168. video_url = base64.b64decode(video_url).decode("utf8")
  169. audio_url = base64.b64decode(audio_url).decode("utf8")
  170. video_width = video_info["videoResource"]["dash_120fps"]["video_list"][
  171. "video_3"
  172. ]["vwidth"]
  173. video_height = video_info["videoResource"]["dash_120fps"]["video_list"][
  174. "video_3"
  175. ]["vheight"]
  176. video_url_dict["video_url"] = video_url
  177. video_url_dict["audio_url"] = audio_url
  178. video_url_dict["video_width"] = video_width
  179. video_url_dict["video_height"] = video_height
  180. elif (
  181. "video_list" in video_info["videoResource"]["dash_120fps"]
  182. and "video_2" in video_info["videoResource"]["dash_120fps"]["video_list"]
  183. ):
  184. video_url = video_info["videoResource"]["dash_120fps"]["video_list"][
  185. "video_2"
  186. ]["backup_url_1"]
  187. audio_url = video_info["videoResource"]["dash_120fps"]["video_list"][
  188. "video_2"
  189. ]["backup_url_1"]
  190. if len(video_url) % 3 == 1:
  191. video_url += "=="
  192. elif len(video_url) % 3 == 2:
  193. video_url += "="
  194. elif len(audio_url) % 3 == 1:
  195. audio_url += "=="
  196. elif len(audio_url) % 3 == 2:
  197. audio_url += "="
  198. video_url = base64.b64decode(video_url).decode("utf8")
  199. audio_url = base64.b64decode(audio_url).decode("utf8")
  200. video_width = video_info["videoResource"]["dash_120fps"]["video_list"][
  201. "video_2"
  202. ]["vwidth"]
  203. video_height = video_info["videoResource"]["dash_120fps"]["video_list"][
  204. "video_2"
  205. ]["vheight"]
  206. video_url_dict["video_url"] = video_url
  207. video_url_dict["audio_url"] = audio_url
  208. video_url_dict["video_width"] = video_width
  209. video_url_dict["video_height"] = video_height
  210. elif (
  211. "video_list" in video_info["videoResource"]["dash_120fps"]
  212. and "video_1" in video_info["videoResource"]["dash_120fps"]["video_list"]
  213. ):
  214. video_url = video_info["videoResource"]["dash_120fps"]["video_list"][
  215. "video_1"
  216. ]["backup_url_1"]
  217. audio_url = video_info["videoResource"]["dash_120fps"]["video_list"][
  218. "video_1"
  219. ]["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_120fps"]["video_list"][
  231. "video_1"
  232. ]["vwidth"]
  233. video_height = video_info["videoResource"]["dash_120fps"]["video_list"][
  234. "video_1"
  235. ]["vheight"]
  236. video_url_dict["video_url"] = video_url
  237. video_url_dict["audio_url"] = audio_url
  238. video_url_dict["video_width"] = video_width
  239. video_url_dict["video_height"] = video_height
  240. elif (
  241. "dynamic_video" in video_info["videoResource"]["dash_120fps"]
  242. and "dynamic_video_list"
  243. in video_info["videoResource"]["dash_120fps"]["dynamic_video"]
  244. and "dynamic_audio_list"
  245. in video_info["videoResource"]["dash_120fps"]["dynamic_video"]
  246. and len(
  247. video_info["videoResource"]["dash_120fps"]["dynamic_video"][
  248. "dynamic_video_list"
  249. ]
  250. )
  251. != 0
  252. and len(
  253. video_info["videoResource"]["dash_120fps"]["dynamic_video"][
  254. "dynamic_audio_list"
  255. ]
  256. )
  257. != 0
  258. ):
  259. video_url = video_info["videoResource"]["dash_120fps"]["dynamic_video"][
  260. "dynamic_video_list"
  261. ][-1]["backup_url_1"]
  262. audio_url = video_info["videoResource"]["dash_120fps"]["dynamic_video"][
  263. "dynamic_audio_list"
  264. ][-1]["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_120fps"]["dynamic_video"][
  276. "dynamic_video_list"
  277. ][-1]["vwidth"]
  278. video_height = video_info["videoResource"]["dash_120fps"]["dynamic_video"][
  279. "dynamic_video_list"
  280. ][-1]["vheight"]
  281. video_url_dict["video_url"] = video_url
  282. video_url_dict["audio_url"] = audio_url
  283. video_url_dict["video_width"] = video_width
  284. video_url_dict["video_height"] = video_height
  285. else:
  286. video_url_dict["video_url"] = ""
  287. video_url_dict["audio_url"] = ""
  288. video_url_dict["video_width"] = 0
  289. video_url_dict["video_height"] = 0
  290. elif "dash" in video_info["videoResource"]:
  291. if (
  292. "video_list" in video_info["videoResource"]["dash"]
  293. and "video_4" in video_info["videoResource"]["dash"]["video_list"]
  294. ):
  295. video_url = video_info["videoResource"]["dash"]["video_list"]["video_4"][
  296. "backup_url_1"
  297. ]
  298. audio_url = video_info["videoResource"]["dash"]["video_list"]["video_4"][
  299. "backup_url_1"
  300. ]
  301. if len(video_url) % 3 == 1:
  302. video_url += "=="
  303. elif len(video_url) % 3 == 2:
  304. video_url += "="
  305. elif len(audio_url) % 3 == 1:
  306. audio_url += "=="
  307. elif len(audio_url) % 3 == 2:
  308. audio_url += "="
  309. video_url = base64.b64decode(video_url).decode("utf8")
  310. audio_url = base64.b64decode(audio_url).decode("utf8")
  311. video_width = video_info["videoResource"]["dash"]["video_list"]["video_4"][
  312. "vwidth"
  313. ]
  314. video_height = video_info["videoResource"]["dash"]["video_list"]["video_4"][
  315. "vheight"
  316. ]
  317. video_url_dict["video_url"] = video_url
  318. video_url_dict["audio_url"] = audio_url
  319. video_url_dict["video_width"] = video_width
  320. video_url_dict["video_height"] = video_height
  321. elif (
  322. "video_list" in video_info["videoResource"]["dash"]
  323. and "video_3" in video_info["videoResource"]["dash"]["video_list"]
  324. ):
  325. video_url = video_info["videoResource"]["dash"]["video_list"]["video_3"][
  326. "backup_url_1"
  327. ]
  328. audio_url = video_info["videoResource"]["dash"]["video_list"]["video_3"][
  329. "backup_url_1"
  330. ]
  331. if len(video_url) % 3 == 1:
  332. video_url += "=="
  333. elif len(video_url) % 3 == 2:
  334. video_url += "="
  335. elif len(audio_url) % 3 == 1:
  336. audio_url += "=="
  337. elif len(audio_url) % 3 == 2:
  338. audio_url += "="
  339. video_url = base64.b64decode(video_url).decode("utf8")
  340. audio_url = base64.b64decode(audio_url).decode("utf8")
  341. video_width = video_info["videoResource"]["dash"]["video_list"]["video_3"][
  342. "vwidth"
  343. ]
  344. video_height = video_info["videoResource"]["dash"]["video_list"]["video_3"][
  345. "vheight"
  346. ]
  347. video_url_dict["video_url"] = video_url
  348. video_url_dict["audio_url"] = audio_url
  349. video_url_dict["video_width"] = video_width
  350. video_url_dict["video_height"] = video_height
  351. elif (
  352. "video_list" in video_info["videoResource"]["dash"]
  353. and "video_2" in video_info["videoResource"]["dash"]["video_list"]
  354. ):
  355. video_url = video_info["videoResource"]["dash"]["video_list"]["video_2"][
  356. "backup_url_1"
  357. ]
  358. audio_url = video_info["videoResource"]["dash"]["video_list"]["video_2"][
  359. "backup_url_1"
  360. ]
  361. if len(video_url) % 3 == 1:
  362. video_url += "=="
  363. elif len(video_url) % 3 == 2:
  364. video_url += "="
  365. elif len(audio_url) % 3 == 1:
  366. audio_url += "=="
  367. elif len(audio_url) % 3 == 2:
  368. audio_url += "="
  369. video_url = base64.b64decode(video_url).decode("utf8")
  370. audio_url = base64.b64decode(audio_url).decode("utf8")
  371. video_width = video_info["videoResource"]["dash"]["video_list"]["video_2"][
  372. "vwidth"
  373. ]
  374. video_height = video_info["videoResource"]["dash"]["video_list"]["video_2"][
  375. "vheight"
  376. ]
  377. video_url_dict["video_url"] = video_url
  378. video_url_dict["audio_url"] = audio_url
  379. video_url_dict["video_width"] = video_width
  380. video_url_dict["video_height"] = video_height
  381. elif (
  382. "video_list" in video_info["videoResource"]["dash"]
  383. and "video_1" in video_info["videoResource"]["dash"]["video_list"]
  384. ):
  385. video_url = video_info["videoResource"]["dash"]["video_list"]["video_1"][
  386. "backup_url_1"
  387. ]
  388. audio_url = video_info["videoResource"]["dash"]["video_list"]["video_1"][
  389. "backup_url_1"
  390. ]
  391. if len(video_url) % 3 == 1:
  392. video_url += "=="
  393. elif len(video_url) % 3 == 2:
  394. video_url += "="
  395. elif len(audio_url) % 3 == 1:
  396. audio_url += "=="
  397. elif len(audio_url) % 3 == 2:
  398. audio_url += "="
  399. video_url = base64.b64decode(video_url).decode("utf8")
  400. audio_url = base64.b64decode(audio_url).decode("utf8")
  401. video_width = video_info["videoResource"]["dash"]["video_list"]["video_1"][
  402. "vwidth"
  403. ]
  404. video_height = video_info["videoResource"]["dash"]["video_list"]["video_1"][
  405. "vheight"
  406. ]
  407. video_url_dict["video_url"] = video_url
  408. video_url_dict["audio_url"] = audio_url
  409. video_url_dict["video_width"] = video_width
  410. video_url_dict["video_height"] = video_height
  411. elif (
  412. "dynamic_video" in video_info["videoResource"]["dash"]
  413. and "dynamic_video_list"
  414. in video_info["videoResource"]["dash"]["dynamic_video"]
  415. and "dynamic_audio_list"
  416. in video_info["videoResource"]["dash"]["dynamic_video"]
  417. and len(
  418. video_info["videoResource"]["dash"]["dynamic_video"][
  419. "dynamic_video_list"
  420. ]
  421. )
  422. != 0
  423. and len(
  424. video_info["videoResource"]["dash"]["dynamic_video"][
  425. "dynamic_audio_list"
  426. ]
  427. )
  428. != 0
  429. ):
  430. video_url = video_info["videoResource"]["dash"]["dynamic_video"][
  431. "dynamic_video_list"
  432. ][-1]["backup_url_1"]
  433. audio_url = video_info["videoResource"]["dash"]["dynamic_video"][
  434. "dynamic_audio_list"
  435. ][-1]["backup_url_1"]
  436. if len(video_url) % 3 == 1:
  437. video_url += "=="
  438. elif len(video_url) % 3 == 2:
  439. video_url += "="
  440. elif len(audio_url) % 3 == 1:
  441. audio_url += "=="
  442. elif len(audio_url) % 3 == 2:
  443. audio_url += "="
  444. video_url = base64.b64decode(video_url).decode("utf8")
  445. audio_url = base64.b64decode(audio_url).decode("utf8")
  446. video_width = video_info["videoResource"]["dash"]["dynamic_video"][
  447. "dynamic_video_list"
  448. ][-1]["vwidth"]
  449. video_height = video_info["videoResource"]["dash"]["dynamic_video"][
  450. "dynamic_video_list"
  451. ][-1]["vheight"]
  452. video_url_dict["video_url"] = video_url
  453. video_url_dict["audio_url"] = audio_url
  454. video_url_dict["video_width"] = video_width
  455. video_url_dict["video_height"] = video_height
  456. else:
  457. video_url_dict["video_url"] = ""
  458. video_url_dict["audio_url"] = ""
  459. video_url_dict["video_width"] = 0
  460. video_url_dict["video_height"] = 0
  461. elif "normal" in video_info["videoResource"]:
  462. if (
  463. "video_list" in video_info["videoResource"]["normal"]
  464. and "video_4" in video_info["videoResource"]["normal"]["video_list"]
  465. ):
  466. video_url = video_info["videoResource"]["normal"]["video_list"]["video_4"][
  467. "backup_url_1"
  468. ]
  469. audio_url = video_info["videoResource"]["normal"]["video_list"]["video_4"][
  470. "backup_url_1"
  471. ]
  472. if len(video_url) % 3 == 1:
  473. video_url += "=="
  474. elif len(video_url) % 3 == 2:
  475. video_url += "="
  476. elif len(audio_url) % 3 == 1:
  477. audio_url += "=="
  478. elif len(audio_url) % 3 == 2:
  479. audio_url += "="
  480. video_url = base64.b64decode(video_url).decode("utf8")
  481. audio_url = base64.b64decode(audio_url).decode("utf8")
  482. video_width = video_info["videoResource"]["normal"]["video_list"][
  483. "video_4"
  484. ]["vwidth"]
  485. video_height = video_info["videoResource"]["normal"]["video_list"][
  486. "video_4"
  487. ]["vheight"]
  488. video_url_dict["video_url"] = video_url
  489. video_url_dict["audio_url"] = audio_url
  490. video_url_dict["video_width"] = video_width
  491. video_url_dict["video_height"] = video_height
  492. elif (
  493. "video_list" in video_info["videoResource"]["normal"]
  494. and "video_3" in video_info["videoResource"]["normal"]["video_list"]
  495. ):
  496. video_url = video_info["videoResource"]["normal"]["video_list"]["video_3"][
  497. "backup_url_1"
  498. ]
  499. audio_url = video_info["videoResource"]["normal"]["video_list"]["video_3"][
  500. "backup_url_1"
  501. ]
  502. if len(video_url) % 3 == 1:
  503. video_url += "=="
  504. elif len(video_url) % 3 == 2:
  505. video_url += "="
  506. elif len(audio_url) % 3 == 1:
  507. audio_url += "=="
  508. elif len(audio_url) % 3 == 2:
  509. audio_url += "="
  510. video_url = base64.b64decode(video_url).decode("utf8")
  511. audio_url = base64.b64decode(audio_url).decode("utf8")
  512. video_width = video_info["videoResource"]["normal"]["video_list"][
  513. "video_3"
  514. ]["vwidth"]
  515. video_height = video_info["videoResource"]["normal"]["video_list"][
  516. "video_3"
  517. ]["vheight"]
  518. video_url_dict["video_url"] = video_url
  519. video_url_dict["audio_url"] = audio_url
  520. video_url_dict["video_width"] = video_width
  521. video_url_dict["video_height"] = video_height
  522. elif (
  523. "video_list" in video_info["videoResource"]["normal"]
  524. and "video_2" in video_info["videoResource"]["normal"]["video_list"]
  525. ):
  526. video_url = video_info["videoResource"]["normal"]["video_list"]["video_2"][
  527. "backup_url_1"
  528. ]
  529. audio_url = video_info["videoResource"]["normal"]["video_list"]["video_2"][
  530. "backup_url_1"
  531. ]
  532. if len(video_url) % 3 == 1:
  533. video_url += "=="
  534. elif len(video_url) % 3 == 2:
  535. video_url += "="
  536. elif len(audio_url) % 3 == 1:
  537. audio_url += "=="
  538. elif len(audio_url) % 3 == 2:
  539. audio_url += "="
  540. video_url = base64.b64decode(video_url).decode("utf8")
  541. audio_url = base64.b64decode(audio_url).decode("utf8")
  542. video_width = video_info["videoResource"]["normal"]["video_list"][
  543. "video_2"
  544. ]["vwidth"]
  545. video_height = video_info["videoResource"]["normal"]["video_list"][
  546. "video_2"
  547. ]["vheight"]
  548. video_url_dict["video_url"] = video_url
  549. video_url_dict["audio_url"] = audio_url
  550. video_url_dict["video_width"] = video_width
  551. video_url_dict["video_height"] = video_height
  552. elif (
  553. "video_list" in video_info["videoResource"]["normal"]
  554. and "video_1" in video_info["videoResource"]["normal"]["video_list"]
  555. ):
  556. video_url = video_info["videoResource"]["normal"]["video_list"]["video_1"][
  557. "backup_url_1"
  558. ]
  559. audio_url = video_info["videoResource"]["normal"]["video_list"]["video_1"][
  560. "backup_url_1"
  561. ]
  562. if len(video_url) % 3 == 1:
  563. video_url += "=="
  564. elif len(video_url) % 3 == 2:
  565. video_url += "="
  566. elif len(audio_url) % 3 == 1:
  567. audio_url += "=="
  568. elif len(audio_url) % 3 == 2:
  569. audio_url += "="
  570. video_url = base64.b64decode(video_url).decode("utf8")
  571. audio_url = base64.b64decode(audio_url).decode("utf8")
  572. video_width = video_info["videoResource"]["normal"]["video_list"][
  573. "video_1"
  574. ]["vwidth"]
  575. video_height = video_info["videoResource"]["normal"]["video_list"][
  576. "video_1"
  577. ]["vheight"]
  578. video_url_dict["video_url"] = video_url
  579. video_url_dict["audio_url"] = audio_url
  580. video_url_dict["video_width"] = video_width
  581. video_url_dict["video_height"] = video_height
  582. elif (
  583. "dynamic_video" in video_info["videoResource"]["normal"]
  584. and "dynamic_video_list"
  585. in video_info["videoResource"]["normal"]["dynamic_video"]
  586. and "dynamic_audio_list"
  587. in video_info["videoResource"]["normal"]["dynamic_video"]
  588. and len(
  589. video_info["videoResource"]["normal"]["dynamic_video"][
  590. "dynamic_video_list"
  591. ]
  592. )
  593. != 0
  594. and len(
  595. video_info["videoResource"]["normal"]["dynamic_video"][
  596. "dynamic_audio_list"
  597. ]
  598. )
  599. != 0
  600. ):
  601. video_url = video_info["videoResource"]["normal"]["dynamic_video"][
  602. "dynamic_video_list"
  603. ][-1]["backup_url_1"]
  604. audio_url = video_info["videoResource"]["normal"]["dynamic_video"][
  605. "dynamic_audio_list"
  606. ][-1]["backup_url_1"]
  607. if len(video_url) % 3 == 1:
  608. video_url += "=="
  609. elif len(video_url) % 3 == 2:
  610. video_url += "="
  611. elif len(audio_url) % 3 == 1:
  612. audio_url += "=="
  613. elif len(audio_url) % 3 == 2:
  614. audio_url += "="
  615. video_url = base64.b64decode(video_url).decode("utf8")
  616. audio_url = base64.b64decode(audio_url).decode("utf8")
  617. video_width = video_info["videoResource"]["normal"]["dynamic_video"][
  618. "dynamic_video_list"
  619. ][-1]["vwidth"]
  620. video_height = video_info["videoResource"]["normal"]["dynamic_video"][
  621. "dynamic_video_list"
  622. ][-1]["vheight"]
  623. video_url_dict["video_url"] = video_url
  624. video_url_dict["audio_url"] = audio_url
  625. video_url_dict["video_width"] = video_width
  626. video_url_dict["video_height"] = video_height
  627. else:
  628. video_url_dict["video_url"] = ""
  629. video_url_dict["audio_url"] = ""
  630. video_url_dict["video_width"] = 0
  631. video_url_dict["video_height"] = 0
  632. else:
  633. video_url_dict["video_url"] = ""
  634. video_url_dict["audio_url"] = ""
  635. video_url_dict["video_width"] = 0
  636. video_url_dict["video_height"] = 0
  637. return video_url_dict
  638. def get_comment_cnt(item_id):
  639. """
  640. 获取视频的评论数量
  641. """
  642. url = "https://www.ixigua.com/tlb/comment/article/v5/tab_comments/?"
  643. params = {
  644. "tab_index": "0",
  645. "count": "10",
  646. "offset": "10",
  647. "group_id": str(item_id),
  648. "item_id": str(item_id),
  649. "aid": "1768",
  650. "msToken": "50-JJObWB07HfHs-BMJWT1eIDX3G-6lPSF_i-QwxBIXE9VVa-iN0jbEXR5pG2DKjXBmP299n6ZTuXzY-GAy968CCvouSAYIS4GzvGQT3pNlKNejr5G4-1g==",
  651. "X-Bogus": "DFSzswVOyGtANVeWtCLMqR/F6q9U",
  652. "_signature": random_signature(),
  653. }
  654. headers = {
  655. "authority": "www.ixigua.com",
  656. "accept": "application/json, text/plain, */*",
  657. "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  658. "cache-control": "no-cache",
  659. "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",
  660. "pragma": "no-cache",
  661. "referer": f"https://www.ixigua.com/{item_id}?logTag=3c5aa86a8600b9ab8540",
  662. "sec-ch-ua": '"Microsoft Edge";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
  663. "sec-ch-ua-mobile": "?0",
  664. "sec-ch-ua-platform": '"macOS"',
  665. "sec-fetch-dest": "empty",
  666. "sec-fetch-mode": "cors",
  667. "sec-fetch-site": "same-origin",
  668. "tt-anti-token": "cBITBHvmYjEygzv-f9c78c1297722cf1f559c74b084e4525ce4900bdcf9e8588f20cc7c2e3234422",
  669. "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",
  670. "x-secsdk-csrf-token": "000100000001f8e733cf37f0cd255a51aea9a81ff7bc0c09490cfe41ad827c3c5c18ec809279175e4d9f5553d8a5",
  671. }
  672. response = requests.get(
  673. url=url, headers=headers, params=params, proxies=tunnel_proxies(), timeout=5
  674. )
  675. response.close()
  676. if (
  677. response.status_code != 200
  678. or "total_number" not in response.json()
  679. or response.json() == {}
  680. ):
  681. return 0
  682. return response.json().get("total_number", 0)
  683. class XiGuaAuthor:
  684. """
  685. 西瓜账号爬虫
  686. """
  687. def __init__(self, platform, mode, rule_dict, env, user_list):
  688. self.platform = platform
  689. self.mode = mode
  690. self.rule_dict = rule_dict
  691. self.env = env
  692. self.user_list = user_list
  693. self.mq = MQ(topic_name="topic_crawler_etl_" + self.env)
  694. self.download_count = 0
  695. self.limiter = AuthorLimit(platform=self.platform, mode=self.mode)
  696. def rule_maker(self, account):
  697. """
  698. 通过不同的账号生成不同的规则
  699. :param account: 输入的账号信息
  700. {'play_cnt': {'min': 100000, 'max': 0}, 'period': {'min': 5, 'max': 5}}
  701. """
  702. temp = account['link'].split("_")
  703. if len(temp) == 1:
  704. return self.rule_dict
  705. else:
  706. flag = temp[-2]
  707. match flag:
  708. case "V1":
  709. rule_dict = {
  710. "play_cnt": {"min": 100000, "max": 0},
  711. 'period': {"min": 90, "max": 90},
  712. 'special': 0.02
  713. }
  714. return rule_dict
  715. case "V2":
  716. rule_dict = {
  717. "play_cnt": {"min": 10000, "max": 0},
  718. 'period': {"min": 90, "max": 90},
  719. 'special': 0.01
  720. }
  721. return rule_dict
  722. case "V3":
  723. rule_dict = {
  724. "play_cnt": {"min": 5000, "max": 0},
  725. 'period': {"min": 90, "max": 90},
  726. 'special': 0.01
  727. }
  728. return rule_dict
  729. def get_author_list(self):
  730. """
  731. 每轮只抓取定量的数据,到达数量后自己退出
  732. 获取账号列表以及账号信息
  733. """
  734. # max_count = int(self.rule_dict.get("videos_cnt", {}).get("min", 300))
  735. for user_dict in self.user_list:
  736. # if self.download_count <= max_count:
  737. try:
  738. flag = user_dict["link"][0]
  739. match flag:
  740. case "V":
  741. self.get_video_list(user_dict)
  742. case "X":
  743. self.get_tiny_video_list(user_dict)
  744. case "h":
  745. self.get_video_list(user_dict)
  746. case "D":
  747. self.get_video_list(user_dict)
  748. case "B":
  749. self.get_video_list(user_dict)
  750. self.get_tiny_video_list(user_dict)
  751. except Exception as e:
  752. AliyunLogger.logging(
  753. code="3001",
  754. account=user_dict["uid"],
  755. platform=self.platform,
  756. mode=self.mode,
  757. env=self.env,
  758. message="扫描账号时出现bug, 报错是 {}".format(e)
  759. )
  760. # time.sleep(random.randint(1, 15))
  761. # else:
  762. # AliyunLogger.logging(
  763. # code="2000",
  764. # platform=self.platform,
  765. # mode=self.mode,
  766. # env=self.env,
  767. # message="本轮已经抓取足够数量的视频,已经自动退出",
  768. # )
  769. # return
  770. def get_video_list(self, user_dict):
  771. """
  772. 获取某个账号的视频列表
  773. 账号分为 3 类
  774. """
  775. offset = 0
  776. signature = random_signature()
  777. link = user_dict['link'].split("_")[-1]
  778. url = "https://www.ixigua.com/api/videov2/author/new_video_list?"
  779. while True:
  780. to_user_id = str(link.replace("https://www.ixigua.com/home/", ""))
  781. params = {
  782. "to_user_id": to_user_id,
  783. "offset": str(offset),
  784. "limit": "30",
  785. "maxBehotTime": "0",
  786. "order": "new",
  787. "isHome": "0",
  788. "_signature": signature,
  789. }
  790. headers = {
  791. "referer": f'https://www.ixigua.com/home/{link.replace("https://www.ixigua.com/home/", "")}/video/?preActiveKey=hotsoon&list_entrance=userdetail',
  792. "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",
  793. }
  794. response = requests.get(
  795. url=url,
  796. headers=headers,
  797. params=params,
  798. proxies=tunnel_proxies(),
  799. timeout=5,
  800. )
  801. offset += 30
  802. if "data" not in response.text or response.status_code != 200:
  803. AliyunLogger.logging(
  804. code="3000",
  805. platform=self.platform,
  806. mode=self.mode,
  807. env=self.env,
  808. message=f"get_videoList:{response.text}\n",
  809. )
  810. return
  811. elif not response.json()["data"]["videoList"]:
  812. AliyunLogger.logging(
  813. code="3000",
  814. platform=self.platform,
  815. mode=self.mode,
  816. env=self.env,
  817. message=f"没有更多数据啦~\n",
  818. )
  819. return
  820. else:
  821. feeds = response.json()["data"]["videoList"]
  822. for video_obj in feeds:
  823. try:
  824. AliyunLogger.logging(
  825. code="1001",
  826. account=user_dict['uid'],
  827. platform=self.platform,
  828. mode=self.mode,
  829. env=self.env,
  830. data=video_obj,
  831. message="扫描到一条视频",
  832. )
  833. date_flag = self.process_video_obj(video_obj, user_dict, "l")
  834. if not date_flag:
  835. return
  836. except Exception as e:
  837. AliyunLogger.logging(
  838. code="3000",
  839. platform=self.platform,
  840. mode=self.mode,
  841. env=self.env,
  842. data=video_obj,
  843. message="抓取单条视频异常, 报错原因是: {}".format(e),
  844. )
  845. def get_tiny_video_list(self, user_dict):
  846. """
  847. 获取小视频
  848. """
  849. url = "https://www.ixigua.com/api/videov2/hotsoon/video"
  850. max_behot_time = "0"
  851. link = user_dict['link'].split("_")[-1]
  852. to_user_id = str(link.replace("https://www.ixigua.com/home/", ""))
  853. while True:
  854. params = {
  855. "to_user_id": to_user_id,
  856. "max_behot_time": max_behot_time,
  857. "_signature": random_signature()
  858. }
  859. headers = {
  860. "referer": "https://www.ixigua.com/{}?&".format(to_user_id),
  861. "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",
  862. }
  863. response = requests.get(
  864. url=url,
  865. headers=headers,
  866. params=params,
  867. proxies=tunnel_proxies(),
  868. timeout=5,
  869. )
  870. if "data" not in response.text or response.status_code != 200:
  871. AliyunLogger.logging(
  872. code="2000",
  873. platform=self.platform,
  874. mode=self.mode,
  875. env=self.env,
  876. message=f"get_videoList:{response.text}\n",
  877. )
  878. return
  879. elif not response.json()["data"]["data"]:
  880. AliyunLogger.logging(
  881. code="2000",
  882. platform=self.platform,
  883. mode=self.mode,
  884. env=self.env,
  885. message=f"没有更多数据啦~\n",
  886. )
  887. return
  888. else:
  889. video_list = response.json()['data']['data']
  890. max_behot_time = video_list[-1]["max_behot_time"]
  891. for video_obj in video_list:
  892. try:
  893. AliyunLogger.logging(
  894. code="1001",
  895. account=user_dict['uid'],
  896. platform=self.platform,
  897. mode=self.mode,
  898. env=self.env,
  899. data=video_obj,
  900. message="扫描到一条小视频",
  901. )
  902. date_flag = self.process_video_obj(video_obj, user_dict, "s")
  903. if not date_flag:
  904. return
  905. except Exception as e:
  906. AliyunLogger.logging(
  907. code="3000",
  908. platform=self.platform,
  909. mode=self.mode,
  910. env=self.env,
  911. data=video_obj,
  912. message="抓取单条视频异常, 报错原因是: {}".format(e),
  913. )
  914. def process_video_obj(self, video_obj, user_dict, f):
  915. """
  916. process video_obj and extract video_url
  917. """
  918. new_rule = self.rule_maker(user_dict)
  919. trace_id = self.platform + str(uuid.uuid1())
  920. if f == "s":
  921. item_id = video_obj.get("id_str", "")
  922. else:
  923. item_id = video_obj.get("item_id", "")
  924. if not item_id:
  925. AliyunLogger.logging(
  926. code="2005",
  927. account=user_dict['uid'],
  928. platform=self.platform,
  929. mode=self.mode,
  930. env=self.env,
  931. message="无效视频",
  932. data=video_obj,
  933. trace_id=trace_id,
  934. )
  935. return
  936. # 获取视频信息
  937. video_dict = self.get_video_info(item_id=item_id)
  938. video_dict["platform"] = self.platform
  939. video_dict["strategy"] = self.mode
  940. video_dict["out_video_id"] = video_dict["video_id"]
  941. video_dict["width"] = video_dict["video_width"]
  942. video_dict["height"] = video_dict["video_height"]
  943. video_dict["crawler_rule"] = json.dumps(new_rule)
  944. video_dict["user_id"] = user_dict["uid"]
  945. video_dict["publish_time"] = video_dict["publish_time_str"]
  946. video_dict["strategy_type"] = self.mode
  947. video_dict["update_time_stamp"] = int(time.time())
  948. if int(time.time()) - video_dict['publish_time_stamp'] > 3600 * 24 * int(
  949. new_rule.get("period", {}).get("max", 1000)):
  950. if not video_obj['is_top']:
  951. """
  952. 非置顶数据发布时间超过才退出
  953. """
  954. AliyunLogger.logging(
  955. code="2004",
  956. account=user_dict['uid'],
  957. platform=self.platform,
  958. mode=self.mode,
  959. env=self.env,
  960. data=video_dict,
  961. message="发布时间超过{}天".format(
  962. int(new_rule.get("period", {}).get("max", 1000))
  963. ),
  964. )
  965. return False
  966. pipeline = PiaoQuanPipeline(
  967. platform=self.platform,
  968. mode=self.mode,
  969. rule_dict=new_rule,
  970. env=self.env,
  971. item=video_dict,
  972. trace_id=trace_id,
  973. )
  974. limit_flag = self.limiter.author_limitation(user_id=video_dict['user_id'])
  975. if limit_flag:
  976. title_flag = pipeline.title_flag()
  977. repeat_flag = pipeline.repeat_video()
  978. if title_flag and repeat_flag:
  979. if new_rule.get("special"):
  980. if int(video_dict['play_cnt']) >= int(new_rule.get("play_cnt", {}).get("min", 100000)):
  981. if float(video_dict['like_cnt']) / float(video_dict['play_cnt']) >= new_rule['special']:
  982. self.mq.send_msg(video_dict)
  983. self.download_count += 1
  984. AliyunLogger.logging(
  985. code="1002",
  986. account=user_dict['uid'],
  987. platform=self.platform,
  988. mode=self.mode,
  989. env=self.env,
  990. data=video_dict,
  991. trace_id=trace_id,
  992. message="成功发送 MQ 至 ETL",
  993. )
  994. return True
  995. else:
  996. AliyunLogger.logging(
  997. code="2008",
  998. account=user_dict['uid'],
  999. platform=self.platform,
  1000. mode=self.mode,
  1001. env=self.env,
  1002. message="不满足特殊规则, 点赞量/播放量",
  1003. data=video_dict
  1004. )
  1005. else:
  1006. if int(video_dict['play_cnt']) >= int(new_rule.get("play_cnt", {}).get("min", 100000)):
  1007. self.mq.send_msg(video_dict)
  1008. self.download_count += 1
  1009. AliyunLogger.logging(
  1010. code="1002",
  1011. account=user_dict['uid'],
  1012. platform=self.platform,
  1013. mode=self.mode,
  1014. env=self.env,
  1015. data=video_dict,
  1016. trace_id=trace_id,
  1017. message="成功发送 MQ 至 ETL",
  1018. )
  1019. return True
  1020. else:
  1021. AliyunLogger.logging(
  1022. code="2008",
  1023. account=user_dict['uid'],
  1024. platform=self.platform,
  1025. mode=self.mode,
  1026. env=self.env,
  1027. message="不满足特殊规则, 播放量",
  1028. data=video_dict
  1029. )
  1030. return True
  1031. def get_video_info(self, item_id):
  1032. """
  1033. 获取视频信息
  1034. """
  1035. url = "https://www.ixigua.com/{}".format(item_id)
  1036. headers = {
  1037. "accept-encoding": "gzip, deflate",
  1038. "accept-language": "zh-CN,zh-Hans;q=0.9",
  1039. "cookie": "ttwid={}".format(byte_dance_cookie(item_id)),
  1040. "user-agent": FakeUserAgent().random,
  1041. "referer": "https://www.ixigua.com/{}/".format(item_id),
  1042. }
  1043. response = requests.get(
  1044. url=url,
  1045. headers=headers,
  1046. proxies=tunnel_proxies(),
  1047. timeout=5,
  1048. )
  1049. video_info = extract_info_by_re(response.text)
  1050. video_dict = {
  1051. "video_title": video_info.get("title", ""),
  1052. "video_id": video_info.get("video_id"),
  1053. "gid": str(item_id),
  1054. "play_cnt": int(video_info.get("play_count", 0)),
  1055. "like_cnt": int(video_info.get("like_count", 0)),
  1056. "comment_cnt": 0,
  1057. "share_cnt": 0,
  1058. "favorite_cnt": 0,
  1059. "duration": int(video_info.get("duration", 0)),
  1060. "video_width": 0,
  1061. "video_height": 0,
  1062. "publish_time_stamp": int(video_info.get("publish_time", 0)),
  1063. "publish_time_str": time.strftime(
  1064. "%Y-%m-%d %H:%M:%S",
  1065. time.localtime(int(video_info.get("publish_time", 0))),
  1066. ),
  1067. "avatar_url": str(
  1068. video_info.get("user_info", {}).get("avatar_url", "")
  1069. ),
  1070. "cover_url": video_info.get("cover_url", ""),
  1071. "video_url": video_info.get("url"),
  1072. "session": f"xigua-search-{int(time.time())}",
  1073. }
  1074. return video_dict
  1075. if __name__ == "__main__":
  1076. user_list = [
  1077. {
  1078. "uid": 6267140,
  1079. "source": "xigua",
  1080. "link": "https://www.ixigua.com/home/2779177225827568",
  1081. "nick_name": "秋晴爱音乐",
  1082. "avatar_url": "",
  1083. "mode": "author",
  1084. },
  1085. {
  1086. "uid": 6267140,
  1087. "source": "xigua",
  1088. "link": "https://www.ixigua.com/home/2885546124776780",
  1089. "nick_name": "朗诵放歌的老山羊",
  1090. "avatar_url": "",
  1091. "mode": "author",
  1092. },
  1093. {
  1094. "uid": 6267140,
  1095. "source": "xigua",
  1096. "link": "https://www.ixigua.com/home/5880938217",
  1097. "nick_name": "天原声疗",
  1098. "avatar_url": "",
  1099. "mode": "author",
  1100. },
  1101. ]
  1102. rule = {'period': {'min': 30, 'max': 30}, 'duration': {'min': 20, 'max': 0}, 'play_cnt': {'min': 100000, 'max': 0}}
  1103. XGA = XiGuaAuthor(
  1104. platform="xigua",
  1105. mode="author",
  1106. rule_dict=rule,
  1107. env="prod",
  1108. user_list=user_list
  1109. )
  1110. XGA.get_author_list()