xigua_author_scheduling.py 45 KB

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