xigua_search.py 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/2/17
  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 urllib.parse import quote
  16. from requests.adapters import HTTPAdapter
  17. sys.path.append(os.getcwd())
  18. from common.db import MysqlHelper
  19. from common.getuser import getUser
  20. from common.common import Common
  21. from common.feishu import Feishu
  22. from common.publish import Publish
  23. from common.userAgent import get_random_user_agent, get_random_header
  24. class XiguaSearch:
  25. platform = "西瓜视频"
  26. tag = "西瓜视频爬虫,搜索爬虫策略"
  27. @classmethod
  28. def get_rule(cls, log_type, crawler):
  29. try:
  30. while True:
  31. rule_sheet = Feishu.get_values_batch(log_type, crawler, "shxOl7")
  32. if rule_sheet is None:
  33. Common.logger(log_type, crawler).warning("rule_sheet is None! 10秒后重新获取")
  34. time.sleep(10)
  35. continue
  36. rule_dict = {
  37. "play_cnt": int(rule_sheet[1][2]),
  38. "min_duration": int(rule_sheet[2][2]),
  39. "max_duration": int(rule_sheet[3][2]),
  40. "publish_time": int(rule_sheet[4][2]),
  41. }
  42. return rule_dict
  43. except Exception as e:
  44. Common.logger(log_type, crawler).error(f"get_rule:{e}\n")
  45. # 下载规则
  46. @classmethod
  47. def download_rule(cls, video_info_dict, rule_dict):
  48. if video_info_dict['play_cnt'] >= rule_dict['play_cnt']:
  49. if video_info_dict['comment_cnt'] >= rule_dict['comment_cnt']:
  50. if video_info_dict['like_cnt'] >= rule_dict['like_cnt']:
  51. if video_info_dict['duration'] >= rule_dict['duration']:
  52. if video_info_dict['video_width'] >= rule_dict['video_width'] \
  53. or video_info_dict['video_height'] >= rule_dict['video_height']:
  54. return True
  55. else:
  56. return False
  57. else:
  58. return False
  59. else:
  60. return False
  61. else:
  62. return False
  63. else:
  64. return False
  65. # 过滤词库
  66. @classmethod
  67. def filter_words(cls, log_type, crawler):
  68. try:
  69. while True:
  70. filter_words_sheet = Feishu.get_values_batch(log_type, crawler, 'KGB4Hc')
  71. if filter_words_sheet is None:
  72. Common.logger(log_type, crawler).warning(f"filter_words_sheet:{filter_words_sheet} 10秒钟后重试")
  73. continue
  74. filter_words_list = []
  75. for x in filter_words_sheet:
  76. for y in x:
  77. if y is None:
  78. pass
  79. else:
  80. filter_words_list.append(y)
  81. return filter_words_list
  82. except Exception as e:
  83. Common.logger(log_type, crawler).error(f'filter_words异常:{e}\n')
  84. # 获取用户信息(字典格式). 注意:部分 user_id 字符类型是 int / str
  85. @classmethod
  86. def get_user_list(cls, log_type, crawler, sheetid, env, machine):
  87. try:
  88. while True:
  89. user_sheet = Feishu.get_values_batch(log_type, crawler, sheetid)
  90. if user_sheet is None:
  91. Common.logger(log_type, crawler).warning(f"user_sheet:{user_sheet} 10秒钟后重试")
  92. continue
  93. our_user_list = []
  94. for i in range(1, len(user_sheet)):
  95. our_uid = user_sheet[i][6]
  96. search_word = user_sheet[i][4]
  97. tag1 = user_sheet[i][8]
  98. tag2 = user_sheet[i][9]
  99. tag3 = user_sheet[i][10]
  100. tag4 = user_sheet[i][11]
  101. tag5 = user_sheet[i][12]
  102. tag6 = user_sheet[i][13]
  103. tag7 = user_sheet[i][14]
  104. Common.logger(log_type, crawler).info(f"正在更新 {search_word} 关键词信息\n")
  105. if our_uid is None:
  106. default_user = getUser.get_default_user()
  107. # 用来创建our_id的信息
  108. user_dict = {
  109. 'recommendStatus': -6,
  110. 'appRecommendStatus': -6,
  111. 'nickName': default_user['nickName'],
  112. 'avatarUrl': default_user['avatarUrl'],
  113. 'tagName': f'{tag1},{tag2},{tag3},{tag4},{tag5},{tag6},{tag7}',
  114. }
  115. Common.logger(log_type, crawler).info(f'新创建的站内UID:{our_uid}')
  116. our_uid = getUser.create_uid(log_type, crawler, user_dict, env)
  117. if env == 'prod':
  118. our_user_link = f'https://admin.piaoquantv.com/ums/user/{our_uid}/post'
  119. else:
  120. our_user_link = f'https://testadmin.piaoquantv.com/ums/user/{our_uid}/post'
  121. Feishu.update_values(log_type, crawler, sheetid, f'G{i + 1}:H{i + 1}',
  122. [[our_uid, our_user_link]])
  123. Common.logger(log_type, crawler).info(f'站内用户信息写入飞书成功!\n')
  124. our_user_dict = {
  125. 'out_uid': '',
  126. 'search_word': search_word,
  127. 'our_uid': our_uid,
  128. 'our_user_link': f'https://admin.piaoquantv.com/ums/user/{our_uid}/post',
  129. }
  130. our_user_list.append(our_user_dict)
  131. return our_user_list
  132. except Exception as e:
  133. Common.logger(log_type, crawler).error(f'get_user_id_from_feishu异常:{e}\n')
  134. @classmethod
  135. def random_signature(cls):
  136. src_digits = string.digits # string_数字
  137. src_uppercase = string.ascii_uppercase # string_大写字母
  138. src_lowercase = string.ascii_lowercase # string_小写字母
  139. digits_num = random.randint(1, 6)
  140. uppercase_num = random.randint(1, 26 - digits_num - 1)
  141. lowercase_num = 26 - (digits_num + uppercase_num)
  142. password = random.sample(src_digits, digits_num) + random.sample(src_uppercase, uppercase_num) + random.sample(
  143. src_lowercase, lowercase_num)
  144. random.shuffle(password)
  145. new_password = 'AAAAAAAAAA' + ''.join(password)[10:-4] + 'AAAB'
  146. new_password_start = new_password[0:18]
  147. new_password_end = new_password[-7:]
  148. if new_password[18] == '8':
  149. new_password = new_password_start + 'w' + new_password_end
  150. elif new_password[18] == '9':
  151. new_password = new_password_start + 'x' + new_password_end
  152. elif new_password[18] == '-':
  153. new_password = new_password_start + 'y' + new_password_end
  154. elif new_password[18] == '.':
  155. new_password = new_password_start + 'z' + new_password_end
  156. else:
  157. new_password = new_password_start + 'y' + new_password_end
  158. return new_password
  159. # 获取视频详情
  160. @classmethod
  161. def get_video_url(cls, log_type, crawler, gid):
  162. try:
  163. url = 'https://www.ixigua.com/api/mixVideo/information?'
  164. headers = {
  165. "accept-encoding": "gzip, deflate",
  166. "accept-language": "zh-CN,zh-Hans;q=0.9",
  167. "user-agent": get_random_user_agent('pc'),
  168. "referer": "https://www.ixigua.com/7102614741050196520?logTag=0531c88ac04f38ab2c62",
  169. }
  170. params = {
  171. 'mixId': gid,
  172. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfC'
  173. 'NVVIOBNjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  174. 'X-Bogus': 'DFSzswVupYTANCJOSBk0P53WxM-r',
  175. '_signature': '_02B4Z6wo0000119LvEwAAIDCuktNZ0y5wkdfS7jAALThuOR8D9yWNZ.EmWHKV0WSn6Px'
  176. 'fPsH9-BldyxVje0f49ryXgmn7Tzk-swEHNb15TiGqa6YF.cX0jW8Eds1TtJOIZyfc9s5emH7gdWN94',
  177. }
  178. cookies = {
  179. 'ixigua-a-s': '1',
  180. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfCNVVIOB'
  181. 'NjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  182. 'ttwid': '1%7C_yXQeHWwLZgCsgHClOwTCdYSOt_MjdOkgnPIkpi-Sr8%7C1661241238%7Cf57d0c5ef3f1d7'
  183. '6e049fccdca1ac54887c34d1f8731c8e51a49780ff0ceab9f8',
  184. 'tt_scid': 'QZ4l8KXDG0YAEaMCSbADdcybdKbUfG4BC6S4OBv9lpRS5VyqYLX2bIR8CTeZeGHR9ee3',
  185. 'MONITOR_WEB_ID': '0a49204a-7af5-4e96-95f0-f4bafb7450ad',
  186. '__ac_nonce': '06304878000964fdad287',
  187. '__ac_signature': '_02B4Z6wo00f017Rcr3AAAIDCUVxeW1tOKEu0fKvAAI4cvoYzV-wBhq7B6D8k0no7lb'
  188. 'FlvYoinmtK6UXjRIYPXnahUlFTvmWVtb77jsMkKAXzAEsLE56m36RlvL7ky.M3Xn52r9t1IEb7IR3ke8',
  189. 'ttcid': 'e56fabf6e85d4adf9e4d91902496a0e882',
  190. '_tea_utm_cache_1300': 'undefined',
  191. 'support_avif': 'false',
  192. 'support_webp': 'false',
  193. 'xiguavideopcwebid': '7134967546256016900',
  194. 'xiguavideopcwebid.sig': 'xxRww5R1VEMJN_dQepHorEu_eAc',
  195. }
  196. urllib3.disable_warnings()
  197. s = requests.session()
  198. # max_retries=3 重试3次
  199. s.mount('http://', HTTPAdapter(max_retries=3))
  200. s.mount('https://', HTTPAdapter(max_retries=3))
  201. response = s.get(url=url, headers=headers, params=params, cookies=cookies, verify=False,
  202. proxies=Common.tunnel_proxies(), timeout=5)
  203. response.close()
  204. if 'data' not in response.json() or response.json()['data'] == '':
  205. Common.logger(log_type, crawler).warning('get_video_info: response: {}', response)
  206. else:
  207. video_info = response.json()['data']['gidInformation']['packerData']['video']
  208. video_url_dict = {}
  209. # video_url
  210. if 'videoResource' not in video_info:
  211. video_url_dict["video_url"] = ''
  212. video_url_dict["audio_url"] = ''
  213. video_url_dict["video_width"] = 0
  214. video_url_dict["video_height"] = 0
  215. elif 'dash_120fps' in video_info['videoResource']:
  216. if "video_list" in video_info['videoResource']['dash_120fps'] and 'video_4' in \
  217. video_info['videoResource']['dash_120fps']['video_list']:
  218. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
  219. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['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']['video_4']['vwidth']
  231. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_4']['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_120fps'] and 'video_3' in \
  237. video_info['videoResource']['dash_120fps']['video_list']:
  238. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
  239. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['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_120fps']['video_list']['video_3']['vwidth']
  251. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_3']['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 "video_list" in video_info['videoResource']['dash_120fps'] and 'video_2' in \
  257. video_info['videoResource']['dash_120fps']['video_list']:
  258. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
  259. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
  260. if len(video_url) % 3 == 1:
  261. video_url += '=='
  262. elif len(video_url) % 3 == 2:
  263. video_url += '='
  264. elif len(audio_url) % 3 == 1:
  265. audio_url += '=='
  266. elif len(audio_url) % 3 == 2:
  267. audio_url += '='
  268. video_url = base64.b64decode(video_url).decode('utf8')
  269. audio_url = base64.b64decode(audio_url).decode('utf8')
  270. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_2']['vwidth']
  271. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_2']['vheight']
  272. video_url_dict["video_url"] = video_url
  273. video_url_dict["audio_url"] = audio_url
  274. video_url_dict["video_width"] = video_width
  275. video_url_dict["video_height"] = video_height
  276. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_1' in \
  277. video_info['videoResource']['dash_120fps']['video_list']:
  278. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
  279. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
  280. if len(video_url) % 3 == 1:
  281. video_url += '=='
  282. elif len(video_url) % 3 == 2:
  283. video_url += '='
  284. elif len(audio_url) % 3 == 1:
  285. audio_url += '=='
  286. elif len(audio_url) % 3 == 2:
  287. audio_url += '='
  288. video_url = base64.b64decode(video_url).decode('utf8')
  289. audio_url = base64.b64decode(audio_url).decode('utf8')
  290. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_1']['vwidth']
  291. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_1']['vheight']
  292. video_url_dict["video_url"] = video_url
  293. video_url_dict["audio_url"] = audio_url
  294. video_url_dict["video_width"] = video_width
  295. video_url_dict["video_height"] = video_height
  296. elif 'dynamic_video' in video_info['videoResource']['dash_120fps'] \
  297. and 'dynamic_video_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
  298. and 'dynamic_audio_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
  299. and len(
  300. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list']) != 0 \
  301. and len(
  302. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list']) != 0:
  303. video_url = \
  304. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  305. 'backup_url_1']
  306. audio_url = \
  307. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list'][-1][
  308. 'backup_url_1']
  309. if len(video_url) % 3 == 1:
  310. video_url += '=='
  311. elif len(video_url) % 3 == 2:
  312. video_url += '='
  313. elif len(audio_url) % 3 == 1:
  314. audio_url += '=='
  315. elif len(audio_url) % 3 == 2:
  316. audio_url += '='
  317. video_url = base64.b64decode(video_url).decode('utf8')
  318. audio_url = base64.b64decode(audio_url).decode('utf8')
  319. video_width = \
  320. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  321. 'vwidth']
  322. video_height = \
  323. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  324. '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. else:
  330. video_url_dict["video_url"] = ''
  331. video_url_dict["audio_url"] = ''
  332. video_url_dict["video_width"] = 0
  333. video_url_dict["video_height"] = 0
  334. elif 'dash' in video_info['videoResource']:
  335. if "video_list" in video_info['videoResource']['dash'] and 'video_4' in \
  336. video_info['videoResource']['dash']['video_list']:
  337. video_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
  338. audio_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
  339. if len(video_url) % 3 == 1:
  340. video_url += '=='
  341. elif len(video_url) % 3 == 2:
  342. video_url += '='
  343. elif len(audio_url) % 3 == 1:
  344. audio_url += '=='
  345. elif len(audio_url) % 3 == 2:
  346. audio_url += '='
  347. video_url = base64.b64decode(video_url).decode('utf8')
  348. audio_url = base64.b64decode(audio_url).decode('utf8')
  349. video_width = video_info['videoResource']['dash']['video_list']['video_4']['vwidth']
  350. video_height = video_info['videoResource']['dash']['video_list']['video_4']['vheight']
  351. video_url_dict["video_url"] = video_url
  352. video_url_dict["audio_url"] = audio_url
  353. video_url_dict["video_width"] = video_width
  354. video_url_dict["video_height"] = video_height
  355. elif "video_list" in video_info['videoResource']['dash'] and 'video_3' in \
  356. video_info['videoResource']['dash']['video_list']:
  357. video_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
  358. audio_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
  359. if len(video_url) % 3 == 1:
  360. video_url += '=='
  361. elif len(video_url) % 3 == 2:
  362. video_url += '='
  363. elif len(audio_url) % 3 == 1:
  364. audio_url += '=='
  365. elif len(audio_url) % 3 == 2:
  366. audio_url += '='
  367. video_url = base64.b64decode(video_url).decode('utf8')
  368. audio_url = base64.b64decode(audio_url).decode('utf8')
  369. video_width = video_info['videoResource']['dash']['video_list']['video_3']['vwidth']
  370. video_height = video_info['videoResource']['dash']['video_list']['video_3']['vheight']
  371. video_url_dict["video_url"] = video_url
  372. video_url_dict["audio_url"] = audio_url
  373. video_url_dict["video_width"] = video_width
  374. video_url_dict["video_height"] = video_height
  375. elif "video_list" in video_info['videoResource']['dash'] and 'video_2' in \
  376. video_info['videoResource']['dash']['video_list']:
  377. video_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
  378. audio_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
  379. if len(video_url) % 3 == 1:
  380. video_url += '=='
  381. elif len(video_url) % 3 == 2:
  382. video_url += '='
  383. elif len(audio_url) % 3 == 1:
  384. audio_url += '=='
  385. elif len(audio_url) % 3 == 2:
  386. audio_url += '='
  387. video_url = base64.b64decode(video_url).decode('utf8')
  388. audio_url = base64.b64decode(audio_url).decode('utf8')
  389. video_width = video_info['videoResource']['dash']['video_list']['video_2']['vwidth']
  390. video_height = video_info['videoResource']['dash']['video_list']['video_2']['vheight']
  391. video_url_dict["video_url"] = video_url
  392. video_url_dict["audio_url"] = audio_url
  393. video_url_dict["video_width"] = video_width
  394. video_url_dict["video_height"] = video_height
  395. elif "video_list" in video_info['videoResource']['dash'] and 'video_1' in \
  396. video_info['videoResource']['dash']['video_list']:
  397. video_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
  398. audio_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
  399. if len(video_url) % 3 == 1:
  400. video_url += '=='
  401. elif len(video_url) % 3 == 2:
  402. video_url += '='
  403. elif len(audio_url) % 3 == 1:
  404. audio_url += '=='
  405. elif len(audio_url) % 3 == 2:
  406. audio_url += '='
  407. video_url = base64.b64decode(video_url).decode('utf8')
  408. audio_url = base64.b64decode(audio_url).decode('utf8')
  409. video_width = video_info['videoResource']['dash']['video_list']['video_1']['vwidth']
  410. video_height = video_info['videoResource']['dash']['video_list']['video_1']['vheight']
  411. video_url_dict["video_url"] = video_url
  412. video_url_dict["audio_url"] = audio_url
  413. video_url_dict["video_width"] = video_width
  414. video_url_dict["video_height"] = video_height
  415. elif 'dynamic_video' in video_info['videoResource']['dash'] \
  416. and 'dynamic_video_list' in video_info['videoResource']['dash']['dynamic_video'] \
  417. and 'dynamic_audio_list' in video_info['videoResource']['dash']['dynamic_video'] \
  418. and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list']) != 0 \
  419. and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list']) != 0:
  420. video_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  421. 'backup_url_1']
  422. audio_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list'][-1][
  423. 'backup_url_1']
  424. if len(video_url) % 3 == 1:
  425. video_url += '=='
  426. elif len(video_url) % 3 == 2:
  427. video_url += '='
  428. elif len(audio_url) % 3 == 1:
  429. audio_url += '=='
  430. elif len(audio_url) % 3 == 2:
  431. audio_url += '='
  432. video_url = base64.b64decode(video_url).decode('utf8')
  433. audio_url = base64.b64decode(audio_url).decode('utf8')
  434. video_width = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  435. 'vwidth']
  436. video_height = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  437. 'vheight']
  438. video_url_dict["video_url"] = video_url
  439. video_url_dict["audio_url"] = audio_url
  440. video_url_dict["video_width"] = video_width
  441. video_url_dict["video_height"] = video_height
  442. else:
  443. video_url_dict["video_url"] = ''
  444. video_url_dict["audio_url"] = ''
  445. video_url_dict["video_width"] = 0
  446. video_url_dict["video_height"] = 0
  447. elif 'normal' in video_info['videoResource']:
  448. if "video_list" in video_info['videoResource']['normal'] and 'video_4' in \
  449. video_info['videoResource']['normal']['video_list']:
  450. video_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
  451. audio_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
  452. if len(video_url) % 3 == 1:
  453. video_url += '=='
  454. elif len(video_url) % 3 == 2:
  455. video_url += '='
  456. elif len(audio_url) % 3 == 1:
  457. audio_url += '=='
  458. elif len(audio_url) % 3 == 2:
  459. audio_url += '='
  460. video_url = base64.b64decode(video_url).decode('utf8')
  461. audio_url = base64.b64decode(audio_url).decode('utf8')
  462. video_width = video_info['videoResource']['normal']['video_list']['video_4']['vwidth']
  463. video_height = video_info['videoResource']['normal']['video_list']['video_4']['vheight']
  464. video_url_dict["video_url"] = video_url
  465. video_url_dict["audio_url"] = audio_url
  466. video_url_dict["video_width"] = video_width
  467. video_url_dict["video_height"] = video_height
  468. elif "video_list" in video_info['videoResource']['normal'] and 'video_3' in \
  469. video_info['videoResource']['normal']['video_list']:
  470. video_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
  471. audio_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
  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']['video_3']['vwidth']
  483. video_height = video_info['videoResource']['normal']['video_list']['video_3']['vheight']
  484. video_url_dict["video_url"] = video_url
  485. video_url_dict["audio_url"] = audio_url
  486. video_url_dict["video_width"] = video_width
  487. video_url_dict["video_height"] = video_height
  488. elif "video_list" in video_info['videoResource']['normal'] and 'video_2' in \
  489. video_info['videoResource']['normal']['video_list']:
  490. video_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
  491. audio_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
  492. if len(video_url) % 3 == 1:
  493. video_url += '=='
  494. elif len(video_url) % 3 == 2:
  495. video_url += '='
  496. elif len(audio_url) % 3 == 1:
  497. audio_url += '=='
  498. elif len(audio_url) % 3 == 2:
  499. audio_url += '='
  500. video_url = base64.b64decode(video_url).decode('utf8')
  501. audio_url = base64.b64decode(audio_url).decode('utf8')
  502. video_width = video_info['videoResource']['normal']['video_list']['video_2']['vwidth']
  503. video_height = video_info['videoResource']['normal']['video_list']['video_2']['vheight']
  504. video_url_dict["video_url"] = video_url
  505. video_url_dict["audio_url"] = audio_url
  506. video_url_dict["video_width"] = video_width
  507. video_url_dict["video_height"] = video_height
  508. elif "video_list" in video_info['videoResource']['normal'] and 'video_1' in \
  509. video_info['videoResource']['normal']['video_list']:
  510. video_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
  511. audio_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
  512. if len(video_url) % 3 == 1:
  513. video_url += '=='
  514. elif len(video_url) % 3 == 2:
  515. video_url += '='
  516. elif len(audio_url) % 3 == 1:
  517. audio_url += '=='
  518. elif len(audio_url) % 3 == 2:
  519. audio_url += '='
  520. video_url = base64.b64decode(video_url).decode('utf8')
  521. audio_url = base64.b64decode(audio_url).decode('utf8')
  522. video_width = video_info['videoResource']['normal']['video_list']['video_1']['vwidth']
  523. video_height = video_info['videoResource']['normal']['video_list']['video_1']['vheight']
  524. video_url_dict["video_url"] = video_url
  525. video_url_dict["audio_url"] = audio_url
  526. video_url_dict["video_width"] = video_width
  527. video_url_dict["video_height"] = video_height
  528. elif 'dynamic_video' in video_info['videoResource']['normal'] \
  529. and 'dynamic_video_list' in video_info['videoResource']['normal']['dynamic_video'] \
  530. and 'dynamic_audio_list' in video_info['videoResource']['normal']['dynamic_video'] \
  531. and len(video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list']) != 0 \
  532. and len(video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list']) != 0:
  533. video_url = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  534. 'backup_url_1']
  535. audio_url = video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list'][-1][
  536. 'backup_url_1']
  537. if len(video_url) % 3 == 1:
  538. video_url += '=='
  539. elif len(video_url) % 3 == 2:
  540. video_url += '='
  541. elif len(audio_url) % 3 == 1:
  542. audio_url += '=='
  543. elif len(audio_url) % 3 == 2:
  544. audio_url += '='
  545. video_url = base64.b64decode(video_url).decode('utf8')
  546. audio_url = base64.b64decode(audio_url).decode('utf8')
  547. video_width = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  548. 'vwidth']
  549. video_height = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  550. 'vheight']
  551. video_url_dict["video_url"] = video_url
  552. video_url_dict["audio_url"] = audio_url
  553. video_url_dict["video_width"] = video_width
  554. video_url_dict["video_height"] = video_height
  555. else:
  556. video_url_dict["video_url"] = ''
  557. video_url_dict["audio_url"] = ''
  558. video_url_dict["video_width"] = 0
  559. video_url_dict["video_height"] = 0
  560. else:
  561. video_url_dict["video_url"] = ''
  562. video_url_dict["audio_url"] = ''
  563. video_url_dict["video_width"] = 0
  564. video_url_dict["video_height"] = 0
  565. return video_url_dict
  566. except Exception as e:
  567. Common.logger(log_type, crawler).error(f'get_video_url:{e}\n')
  568. @classmethod
  569. def get_video_info(cls, log_type, crawler, item_id):
  570. d_url = "http://a6.pstatp.com/article/full/11/1/{video_id}/{video_id}/1/0/?iid=3636030325&device_id=5787057242" \
  571. "&ac=wifi&channel=wandoujia&aid=13&app_name=news_article&version_code=532&version_name=5.3.2&device_platform" \
  572. "=android&ab_client=a1%2Cc2%2Ce1%2Cf2%2Cg2%2Cb3%2Cf4&abflag=3&ssmix=a&device_type=SM705" \
  573. "&device_brand=smartisan&os_api=19&os_version=4.4.2&uuid=864593021012562&openudid=e23a5ff037ef2d1a" \
  574. "&manifest_version_code=532&resolution=1080*1920&dpi=480&update_version_code=5320".format(
  575. video_id=item_id)
  576. res = requests.get(url=d_url, headers=get_random_header('pc'), proxies=Common.tunnel_proxies())
  577. data = json.loads(res.text)['data']
  578. item_counter = data['h5_extra']['itemCell']['itemCounter']
  579. user_info = data['user_info']
  580. detail_info = data['video_detail_info']
  581. video_dict = {'video_title': data['title'].replace('"' ,'').replace("'", ''),
  582. 'video_id': detail_info['video_id'],
  583. 'gid': data['group_id'],
  584. 'play_cnt': item_counter['videoWatchCount'],
  585. 'comment_cnt': item_counter['commentCount'],
  586. 'like_cnt': item_counter['diggCount'],
  587. 'share_cnt': item_counter['shareCount'],
  588. 'duration': data['video_duration'],
  589. 'publish_time_stamp': data['publish_time'],
  590. 'publish_time_str': time.strftime("%Y-%m-%d %H:%M:%S",
  591. time.localtime(data['publish_time'])),
  592. 'user_name': user_info['name'],
  593. 'user_id': user_info['user_id'],
  594. 'avatar_url': user_info['avatar_url'],
  595. 'cover_url': data['large_image']['url'].replace('\u0026', '&'),
  596. }
  597. return video_dict
  598. @classmethod
  599. def is_ruled(cls, log_type, crawler, video_dict, rule_dict):
  600. old_time = int(time.time()) - (3600 * 24 * rule_dict['publish_time'])
  601. if video_dict['publish_time_stamp'] <= old_time:
  602. return False
  603. elif video_dict['play_cnt'] <= rule_dict['play_cnt']:
  604. return False
  605. elif video_dict['duration'] < rule_dict['min_duration'] or video_dict['duration'] > rule_dict['max_duration']:
  606. return False
  607. else:
  608. return True
  609. @classmethod
  610. def get_videolist(cls, log_type, crawler, strategy, our_uid, search_word, oss_endpoint, env, machine):
  611. total_count = 1
  612. offset = 0
  613. while True:
  614. signature = cls.random_signature()
  615. url = "https://www.ixigua.com/api/searchv2/complex/{}/{}?order_type=publish_time&click_position=new".format(
  616. quote(search_word), offset, signature)
  617. headers = {
  618. 'referer': 'https://www.ixigua.com/search/{}/?logTag=594535e3690f17a88cdb&tab_name=search'.format(
  619. quote(search_word)),
  620. 'cookie': 'ttwid=1%7Cx_4RDmVTqp6BQ5Xy5AnuCZCQdDyDxv-fnMVWzj19VU0%7C1679382377%7C4e25692dc4b9d5dca56d690001d168b21ed028a9ac075808ab9262238cb405ee;',
  621. 'user-agent': get_random_user_agent('pc'),
  622. }
  623. try:
  624. res = requests.request("GET", url, headers=headers, proxies=Common.tunnel_proxies())
  625. search_list = res.json()['data']['data']
  626. except Exception as e:
  627. continue
  628. if not search_list:
  629. Common.logger(log_type, crawler).error(f'关键词:{search_word},没有获取到视频列表:offset{offset}')
  630. return
  631. for video_info in search_list:
  632. v_type = video_info['type']
  633. rule_dict = cls.get_rule(log_type, crawler)
  634. publish_time = video_info['data']['publish_time']
  635. old_time = int(time.time()) - (3600 * 24 * rule_dict['publish_time'])
  636. if publish_time <= old_time:
  637. Common.logger(log_type, crawler).error(f'关键词:{search_word},抓取完毕,退出抓取\n')
  638. return
  639. if v_type == 'video':
  640. item_id = video_info['data']['group_id']
  641. if video_info['data']['publish_time'] <= old_time:
  642. Common.logger(log_type, crawler).error(f'关键词:{search_word},视频:{item_id},不符合抓取规则\n')
  643. continue
  644. elif video_info['data']['video_watch_count'] <= rule_dict['play_cnt']:
  645. Common.logger(log_type, crawler).error(f'关键词:{search_word},视频:{item_id},不符合抓取规则\n')
  646. continue
  647. elif video_info['data']['video_time'] < rule_dict['min_duration'] or video_info['data'][
  648. 'video_time'] > rule_dict['max_duration']:
  649. Common.logger(log_type, crawler).error(f'关键词:{search_word},视频:{item_id},不符合抓取规则\n')
  650. continue
  651. try:
  652. video_dict = cls.get_video_info(log_type, crawler, item_id)
  653. video_url_dict = cls.get_video_url(log_type, crawler, video_dict['gid'])
  654. video_dict['video_width'] = video_url_dict["video_width"]
  655. video_dict['video_height'] = video_url_dict["video_height"]
  656. video_dict['audio_url'] = video_url_dict["audio_url"]
  657. video_dict['video_url'] = video_url_dict["video_url"]
  658. video_dict['session'] = signature
  659. except Exception as e:
  660. Common.logger(log_type, crawler).error(f'关键词:{search_word},视频:{item_id},获取详情失败,原因:{e}')
  661. continue
  662. if cls.repeat_video(log_type, crawler, video_dict['video_id'], env, machine) != 0:
  663. Common.logger(log_type, crawler).info(f'关键词:{search_word},gid:{video_dict["gid"]},视频已下载,无需重复下载\n')
  664. continue
  665. for k, v in video_dict.items():
  666. Common.logger(log_type, crawler).info(f"{k}:{v}")
  667. try:
  668. # print(
  669. # f'search_word:{search_word},title:{video_dict["video_title"]},gid:{video_dict["gid"]},offset:{offset}, total:{total_count}')
  670. cls.download_publish(
  671. search_word=search_word,
  672. log_type=log_type,
  673. crawler=crawler,
  674. video_dict=video_dict,
  675. rule_dict=rule_dict,
  676. strategy=strategy,
  677. our_uid=our_uid,
  678. oss_endpoint=oss_endpoint,
  679. env=env,
  680. machine=machine
  681. )
  682. except Exception as e:
  683. Common.logger(log_type, crawler).error(f'关键词:{search_word},视频:{item_id},下载失败,原因:{e}')
  684. continue
  685. total_count += 1
  686. Common.logger(log_type, crawler).info(f'search_word:{search_word},title:{video_dict["video_title"]},gid:{video_dict["gid"]},offset:{offset}, total:{total_count}')
  687. if total_count >= 30:
  688. return
  689. # elif v_type == 'pseries':
  690. # try:
  691. # item_id = video_info['data']['group_id']
  692. # p_url = "https://www.ixigua.com/api/videov2/pseries_more_v2?pSeriesId={}&rank=0&tailCount=30&aid=1768&msToken=wHEafKFLx0k3hihOPbhXYNsfMBxWiq2AB0K5R-34kEFixyq3ATi_DuXbL4Q47J9C2uK2zgWItMa1g2yc4FyDxM4dMijmSdwF4c4T8sSmOkoOI0wGzeEcPw==&X-Bogus=DFSzswVOzdUANG3ItaVHYr7TlqCv&_signature=_02B4Z6wo00001vB6l3QAAIDBZKzMeTihTmbwepPAANgh1Ai3JgFFo4e6anoezmBEpHfEMEYlWISGhXI-QKfev4N-2bwgXsHOuNGLnOsGqMbANIjFPh7Yj6OakQWrkbACenlv0P-arswtB6Zn45".format(
  693. # item_id)
  694. # p_headers = {
  695. # 'referer': 'https://www.ixigua.com/{}?series_flow=1&logTag=cfec9d927da968feff89'.format(
  696. # item_id),
  697. # 'user-agent': get_random_user_agent('pc'),
  698. # }
  699. # p_res = requests.request("GET", p_url, headers=p_headers,
  700. # proxies=Common.tunnel_proxies()).json()
  701. # except Exception as e:
  702. # Common.logger(log_type, crawler).error(f'合集:{item_id},没有获取到合集详情,原因:{e}')
  703. # continue
  704. # for video in p_res['data']:
  705. # item_id = video['item_id']
  706. # try:
  707. # video_dict = cls.get_video_info(log_type, crawler, item_id)
  708. # video_url_dict = cls.get_video_url(log_type, crawler, video_dict['gid'])
  709. # video_dict['video_width'] = video_url_dict["video_width"]
  710. # video_dict['video_height'] = video_url_dict["video_height"]
  711. # video_dict['audio_url'] = video_url_dict["audio_url"]
  712. # video_dict['video_url'] = video_url_dict["video_url"]
  713. # video_dict['session'] = signature
  714. # except Exception as e:
  715. # Common.logger(log_type, crawler).error(f'视频:{item_id},没有获取到视频详情,原因:{e}')
  716. # continue
  717. # if cls.repeat_video(log_type, crawler, video_dict['video_id'], env, machine) != 0:
  718. # Common.logger(log_type, crawler).info(
  719. # f'gid:{video_dict["gid"]},视频已下载,无需重复下载\n')
  720. # continue
  721. # if not cls.is_ruled(log_type, crawler, video_dict, rule_dict):
  722. # Common.logger(log_type, crawler).error(f'视频:{item_id},不符合抓取规则\n')
  723. # continue
  724. # for k, v in video_dict.items():
  725. # Common.logger(log_type, crawler).info(f"{k}:{v}")
  726. # try:
  727. # # print(
  728. # # f'search_word:{search_word},title:{video_dict["video_title"]},gid:{video_dict["gid"]},offset:{offset}, total:{total_count}')
  729. # cls.download_publish(
  730. # search_word=search_word,
  731. # log_type=log_type,
  732. # crawler=crawler,
  733. # video_dict=video_dict,
  734. # rule_dict=rule_dict,
  735. # strategy=strategy,
  736. # our_uid=our_uid,
  737. # oss_endpoint=oss_endpoint,
  738. # env=env,
  739. # machine=machine
  740. # )
  741. # total_count += 1
  742. # if total_count >= 30:
  743. # return
  744. # else:
  745. # break
  746. # except Exception as e:
  747. # Common.logger(log_type, crawler).error(f'视频:{item_id},download_publish异常:{e}\n')
  748. offset += 10
  749. @classmethod
  750. def repeat_video(cls, log_type, crawler, video_id, env, machine):
  751. sql = f""" select * from crawler_video where platform="{cls.platform}" and out_video_id="{video_id}"; """
  752. repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env, machine)
  753. return len(repeat_video)
  754. # 下载 / 上传
  755. @classmethod
  756. def download_publish(cls, log_type, crawler, search_word, strategy, video_dict, rule_dict, our_uid, oss_endpoint,
  757. env, machine):
  758. Common.download_method(log_type=log_type, crawler=crawler, text='xigua_video',
  759. title=video_dict['video_title'], url=video_dict['video_url'])
  760. # 下载音频
  761. Common.download_method(log_type=log_type, crawler=crawler, text='xigua_audio',
  762. title=video_dict['video_title'], url=video_dict['audio_url'])
  763. # 合成音视频
  764. Common.video_compose(log_type=log_type, crawler=crawler,
  765. video_dir=f"./{crawler}/videos/{video_dict['video_title']}")
  766. md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
  767. if os.path.getsize(f"./{crawler}/videos/{md_title}/video.mp4") == 0:
  768. # 删除视频文件夹
  769. shutil.rmtree(f"./{crawler}/videos/{md_title}")
  770. Common.logger(log_type, crawler).info("视频size=0,删除成功\n")
  771. return
  772. # ffmpeg_dict = Common.ffmpeg(log_type, crawler,
  773. # f"./{crawler}/videos/{video_dict['video_title']}/video.mp4")
  774. # if ffmpeg_dict is None or ffmpeg_dict['size'] == 0:
  775. # Common.logger(log_type, crawler).warning(f"下载的视频无效,已删除\n")
  776. # # 删除视频文件夹
  777. # shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
  778. # return
  779. # 下载封面
  780. Common.download_method(log_type=log_type, crawler=crawler, text='cover',
  781. title=video_dict['video_title'], url=video_dict['cover_url'])
  782. # 保存视频信息至txt
  783. Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
  784. # 上传视频
  785. Common.logger(log_type, crawler).info("开始上传视频...")
  786. our_video_id = Publish.upload_and_publish(log_type=log_type,
  787. crawler=crawler,
  788. strategy=strategy,
  789. our_uid=our_uid,
  790. env=env,
  791. oss_endpoint=oss_endpoint)
  792. if env == 'dev':
  793. our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  794. else:
  795. our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  796. Common.logger(log_type, crawler).info("视频上传完成")
  797. if our_video_id is None:
  798. # 删除视频文件夹
  799. shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
  800. return
  801. # 视频写入飞书
  802. Feishu.insert_columns(log_type, 'xigua', "BUNvGC", "ROWS", 1, 2)
  803. upload_time = int(time.time())
  804. values = [[
  805. search_word,
  806. time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(upload_time)),
  807. "关键词搜索",
  808. video_dict['video_title'],
  809. str(video_dict['video_id']),
  810. our_video_link,
  811. video_dict['gid'],
  812. video_dict['play_cnt'],
  813. video_dict['comment_cnt'],
  814. video_dict['like_cnt'],
  815. video_dict['share_cnt'],
  816. video_dict['duration'],
  817. str(video_dict['video_width']) + '*' + str(video_dict['video_height']),
  818. video_dict['publish_time_str'],
  819. video_dict['user_name'],
  820. video_dict['user_id'],
  821. video_dict['avatar_url'],
  822. video_dict['cover_url'],
  823. video_dict['video_url'],
  824. video_dict['audio_url']]]
  825. time.sleep(1)
  826. Feishu.update_values(log_type, 'xigua', "BUNvGC", "E2:Z2", values)
  827. Common.logger(log_type, crawler).info(f"视频已保存至云文档\n")
  828. # 视频信息保存数据库
  829. insert_sql = f""" insert into crawler_video(video_id,
  830. user_id,
  831. out_user_id,
  832. platform,
  833. strategy,
  834. out_video_id,
  835. video_title,
  836. cover_url,
  837. video_url,
  838. duration,
  839. publish_time,
  840. play_cnt,
  841. crawler_rule,
  842. width,
  843. height)
  844. values({our_video_id},
  845. {our_uid},
  846. "{video_dict['user_id']}",
  847. "{cls.platform}",
  848. "定向爬虫策略",
  849. "{video_dict['video_id']}",
  850. "{video_dict['video_title']}",
  851. "{video_dict['cover_url']}",
  852. "{video_dict['video_url']}",
  853. {int(video_dict['duration'])},
  854. "{video_dict['publish_time_str']}",
  855. {int(video_dict['play_cnt'])},
  856. '{json.dumps(rule_dict)}',
  857. {int(video_dict['video_width'])},
  858. {int(video_dict['video_height'])}) """
  859. Common.logger(log_type, crawler).info(f"insert_sql:{insert_sql}")
  860. MysqlHelper.update_values(log_type, crawler, insert_sql, env, machine)
  861. Common.logger(log_type, crawler).info('视频信息插入数据库成功!\n')
  862. @classmethod
  863. def get_search_videos(cls, log_type, crawler, strategy, oss_endpoint, env, machine):
  864. try:
  865. user_list = cls.get_user_list(log_type=log_type, crawler=crawler, sheetid="SSPNPW", env=env,
  866. machine=machine)
  867. for user in user_list:
  868. search_word = user["search_word"]
  869. our_uid = user["our_uid"]
  870. Common.logger(log_type, crawler).info(f"开始抓取 {search_word} 用户主页视频\n")
  871. cls.get_videolist(log_type=log_type,
  872. crawler=crawler,
  873. strategy=strategy,
  874. our_uid=our_uid,
  875. search_word=search_word,
  876. oss_endpoint=oss_endpoint,
  877. env=env,
  878. machine=machine)
  879. except Exception as e:
  880. Common.logger(log_type, crawler).error(f"get_search_videos:{e}\n")
  881. if __name__ == '__main__':
  882. # print(Follow.get_signature("follow", "xigua", "95420624045", "local"))
  883. # XiguaSearch.get_search_videos('search', 'xigua', 'xigua_search', 'inner', 'prod', 'aliyun')
  884. # Follow.get_videolist(log_type="follow",
  885. # crawler="xigua",
  886. # strategy="定向爬虫策略",
  887. # our_uid="6267141",
  888. # out_uid="95420624045",
  889. # oss_endpoint="out",
  890. # env="dev",
  891. # machine="local")
  892. # print(Follow.random_signature())
  893. # rule = Follow.get_rule("follow", "xigua")
  894. # print(type(rule))
  895. # print(type(json.dumps(rule)))
  896. # print(json.dumps(rule))
  897. pass