xigua_follow.py 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/2/17
  4. import json
  5. from lxml import etree
  6. import base64
  7. import os
  8. import random
  9. import shutil
  10. import string
  11. import sys
  12. import time
  13. import requests
  14. import urllib3
  15. from selenium.webdriver import DesiredCapabilities
  16. from selenium.webdriver.chrome.service import Service
  17. from selenium.webdriver.common.by import By
  18. from seleniumwire import webdriver
  19. sys.path.append(os.getcwd())
  20. from common.db import MysqlHelper
  21. from common.users import Users
  22. from common.common import Common
  23. from common.feishu import Feishu
  24. from common.publish import Publish
  25. proxies = {"http": None, "https": None}
  26. class Follow:
  27. # 个人主页视频翻页参数
  28. offset = 0
  29. platform = "西瓜视频"
  30. tag = "西瓜视频爬虫,定向爬虫策略"
  31. # 下载规则
  32. @staticmethod
  33. def download_rule(duration, width, height):
  34. if int(duration) >= 60:
  35. if int(width) >= 720 or int(height) >= 720:
  36. return True
  37. else:
  38. return False
  39. else:
  40. return False
  41. # 过滤词库
  42. @classmethod
  43. def filter_words(cls, log_type, crawler):
  44. try:
  45. filter_words_sheet = Feishu.get_values_batch(log_type, crawler, 'KGB4Hc')
  46. filter_words_list = []
  47. for x in filter_words_sheet:
  48. for y in x:
  49. if y is None:
  50. pass
  51. else:
  52. filter_words_list.append(y)
  53. return filter_words_list
  54. except Exception as e:
  55. Common.logger(log_type, crawler).error(f'filter_words异常:{e}\n')
  56. @classmethod
  57. def get_out_user_info(cls, log_type, crawler, out_uid):
  58. try:
  59. headers = {'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',
  60. 'referer': f'https://www.ixigua.com/home/{out_uid}',
  61. 'Cookie': f'ixigua-a-s=1; support_webp=true; support_avif=false; csrf_session_id=a5355d954d3c63ed1ba35faada452b4d; __ac_signature={cls.random_signature()}; MONITOR_WEB_ID=67cb5099-a022-4ec3-bb8e-c4de6ba51dd0; s_v_web_id=verify_lef4i99x_32SosrdH_Qrtk_4LJn_8S7q_fhu16xe3s8ZV; tt_scid=QLJjPuHf6wxVqu6IIq6gHiJXQpVrCwrdhjH2zpm7-E3ZniE1RXBcP6M8b41FJOdo41e1; ttwid=1%7CHHtv2QqpSGuSu8r-zXF1QoWsvjmNi1SJrqOrZzg-UCY%7C1677047013%7C5866a444e5ae10a9df8c11551db75010fb77b657f214ccf84e503fae8d313d09; msToken=PerXJcDdIsZ6zXkGITsftXX4mDaVaW21GuqtzSVdctH46oXXT2GcELIs9f0XW2hunRzP6KVHLZaYElRvNYflLKUXih7lC27XKxs3HjdZiXPK9NQaoKbLfA==; ixigua-a-s=1',}
  62. url = f"https://www.ixigua.com/home/{out_uid}"
  63. response = requests.get(url=url, headers=headers, proxies=proxies).text
  64. html = etree.HTML(response)
  65. out_follow_str = html.xpath('//div[@class="userDetailV3__header__detail2"]/*[1]/span')[0].text.encode('raw_unicode_escape').decode()
  66. out_fans_str = html.xpath('//div[@class="userDetailV3__header__detail2"]/*[2]/span')[0].text.encode('raw_unicode_escape').decode()
  67. out_like_str = html.xpath('//div[@class="userDetailV3__header__detail2"]/*[3]/span')[0].text.encode('raw_unicode_escape').decode()
  68. out_avatar_url = f"""https:{html.xpath('//span[@class="component-avatar__inner"]//img/@src')[0]}"""
  69. if "万" in out_follow_str:
  70. out_follow = int(float(out_follow_str.split("万")[0])*10000)
  71. else:
  72. out_follow = int(out_follow_str.replace(",", ""))
  73. if "万" in out_fans_str:
  74. out_fans = int(float(out_fans_str.split("万")[0])*10000)
  75. else:
  76. out_fans = int(out_fans_str.replace(",", ""))
  77. if "万" in out_like_str:
  78. out_like = int(float(out_like_str.split("万")[0])*10000)
  79. else:
  80. out_like = int(out_like_str.replace(",", ""))
  81. out_user_dict = {
  82. "out_follow": out_follow,
  83. "out_fans": out_fans,
  84. "out_like": out_like,
  85. "out_avatar_url": out_avatar_url,
  86. }
  87. # for k, v in out_user_dict.items():
  88. # print(f"{k}:{v}")
  89. return out_user_dict
  90. except Exception as e:
  91. Common.logger(log_type, crawler).error(f"get_out_user_info:{e}\n")
  92. # 获取用户信息(字典格式). 注意:部分 user_id 字符类型是 int / str
  93. @classmethod
  94. def get_user_list(cls, log_type, crawler, sheetid, env, machine):
  95. try:
  96. user_sheet = Feishu.get_values_batch(log_type, crawler, sheetid)
  97. our_user_list = []
  98. for i in range(1, len(user_sheet)):
  99. out_uid = user_sheet[i][2]
  100. user_name = user_sheet[i][3]
  101. our_uid = user_sheet[i][6]
  102. our_user_link = user_sheet[i][7]
  103. if out_uid is None or user_name is None:
  104. Common.logger(log_type, crawler).info("空行\n")
  105. else:
  106. Common.logger(log_type, crawler).info(f"正在更新 {user_name} 用户信息\n")
  107. if our_uid is None:
  108. out_user_info = cls.get_out_user_info(log_type, crawler, out_uid)
  109. out_user_dict = {
  110. "out_uid": out_uid,
  111. "user_name": user_name,
  112. "out_avatar_url": out_user_info["out_avatar_url"],
  113. "out_create_time": '',
  114. "out_tag": '',
  115. "out_play_cnt": 0,
  116. "out_fans": out_user_info["out_fans"],
  117. "out_follow": out_user_info["out_follow"],
  118. "out_friend": 0,
  119. "out_like": out_user_info["out_like"],
  120. "platform": cls.platform,
  121. "tag": cls.tag,
  122. }
  123. our_user_dict = Users.create_user(log_type=log_type, crawler=crawler, out_user_dict=out_user_dict, env=env, machine=machine)
  124. our_uid = our_user_dict['our_uid']
  125. our_user_link = our_user_dict['our_user_link']
  126. Feishu.update_values(log_type, crawler, sheetid, f'G{i + 1}:H{i + 1}', [[our_uid, our_user_link]])
  127. Common.logger(log_type, crawler).info(f'站内用户信息写入飞书成功!\n')
  128. our_user_list.append(our_user_dict)
  129. else:
  130. our_user_dict = {
  131. 'out_uid': out_uid,
  132. 'user_name': user_name,
  133. 'our_uid': our_uid,
  134. 'our_user_link': our_user_link,
  135. }
  136. our_user_list.append(our_user_dict)
  137. return our_user_list
  138. except Exception as e:
  139. Common.logger(log_type, crawler).error(f'get_user_id_from_feishu异常:{e}\n')
  140. @classmethod
  141. def random_signature(cls):
  142. src_digits = string.digits # string_数字
  143. src_uppercase = string.ascii_uppercase # string_大写字母
  144. src_lowercase = string.ascii_lowercase # string_小写字母
  145. digits_num = random.randint(1, 6)
  146. uppercase_num = random.randint(1, 26 - digits_num - 1)
  147. lowercase_num = 26 - (digits_num + uppercase_num)
  148. password = random.sample(src_digits, digits_num) + random.sample(src_uppercase, uppercase_num) + random.sample(
  149. src_lowercase, lowercase_num)
  150. random.shuffle(password)
  151. new_password = 'AAAAAAAAAA' + ''.join(password)[10:-4] + 'AAAB'
  152. new_password_start = new_password[0:18]
  153. new_password_end = new_password[-7:]
  154. if new_password[18] == '8':
  155. new_password = new_password_start + 'w' + new_password_end
  156. elif new_password[18] == '9':
  157. new_password = new_password_start + 'x' + new_password_end
  158. elif new_password[18] == '-':
  159. new_password = new_password_start + 'y' + new_password_end
  160. elif new_password[18] == '.':
  161. new_password = new_password_start + 'z' + new_password_end
  162. else:
  163. new_password = new_password_start + 'y' + new_password_end
  164. return new_password
  165. @classmethod
  166. def get_signature(cls, log_type, crawler, out_uid, machine):
  167. try:
  168. # 打印请求配置
  169. ca = DesiredCapabilities.CHROME
  170. ca["goog:loggingPrefs"] = {"performance": "ALL"}
  171. # 不打开浏览器运行
  172. chrome_options = webdriver.ChromeOptions()
  173. chrome_options.add_argument("--headless")
  174. chrome_options.add_argument('--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36')
  175. chrome_options.add_argument("--no-sandbox")
  176. # driver初始化
  177. if machine == 'aliyun' or machine == 'aliyun_hk':
  178. driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options)
  179. elif machine == 'macpro':
  180. driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options,
  181. service=Service('/Users/lieyunye/Downloads/chromedriver_v86/chromedriver'))
  182. elif machine == 'macair':
  183. driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options,
  184. service=Service('/Users/piaoquan/Downloads/chromedriver'))
  185. else:
  186. driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options, service=Service('/Users/wangkun/Downloads/chromedriver/chromedriver_v110/chromedriver'))
  187. driver.implicitly_wait(10)
  188. driver.get(f'https://www.ixigua.com/home/{out_uid}/')
  189. time.sleep(3)
  190. data_src = driver.find_elements(By.XPATH, '//img[@class="tt-img BU-MagicImage tt-img-loaded"]')[1].get_attribute("data-src")
  191. signature = data_src.split("x-signature=")[-1]
  192. return signature
  193. except Exception as e:
  194. Common.logger(log_type, crawler).error(f'get_signature异常:{e}\n')
  195. # 获取视频详情
  196. @classmethod
  197. def get_video_url(cls, log_type, crawler, gid):
  198. try:
  199. url = 'https://www.ixigua.com/api/mixVideo/information?'
  200. headers = {
  201. "accept-encoding": "gzip, deflate",
  202. "accept-language": "zh-CN,zh-Hans;q=0.9",
  203. "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
  204. "AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Safari/605.1.15",
  205. "referer": "https://www.ixigua.com/7102614741050196520?logTag=0531c88ac04f38ab2c62",
  206. }
  207. params = {
  208. 'mixId': gid,
  209. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfC'
  210. 'NVVIOBNjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  211. 'X-Bogus': 'DFSzswVupYTANCJOSBk0P53WxM-r',
  212. '_signature': '_02B4Z6wo0000119LvEwAAIDCuktNZ0y5wkdfS7jAALThuOR8D9yWNZ.EmWHKV0WSn6Px'
  213. 'fPsH9-BldyxVje0f49ryXgmn7Tzk-swEHNb15TiGqa6YF.cX0jW8Eds1TtJOIZyfc9s5emH7gdWN94',
  214. }
  215. cookies = {
  216. 'ixigua-a-s': '1',
  217. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfCNVVIOB'
  218. 'NjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  219. 'ttwid': '1%7C_yXQeHWwLZgCsgHClOwTCdYSOt_MjdOkgnPIkpi-Sr8%7C1661241238%7Cf57d0c5ef3f1d7'
  220. '6e049fccdca1ac54887c34d1f8731c8e51a49780ff0ceab9f8',
  221. 'tt_scid': 'QZ4l8KXDG0YAEaMCSbADdcybdKbUfG4BC6S4OBv9lpRS5VyqYLX2bIR8CTeZeGHR9ee3',
  222. 'MONITOR_WEB_ID': '0a49204a-7af5-4e96-95f0-f4bafb7450ad',
  223. '__ac_nonce': '06304878000964fdad287',
  224. '__ac_signature': '_02B4Z6wo00f017Rcr3AAAIDCUVxeW1tOKEu0fKvAAI4cvoYzV-wBhq7B6D8k0no7lb'
  225. 'FlvYoinmtK6UXjRIYPXnahUlFTvmWVtb77jsMkKAXzAEsLE56m36RlvL7ky.M3Xn52r9t1IEb7IR3ke8',
  226. 'ttcid': 'e56fabf6e85d4adf9e4d91902496a0e882',
  227. '_tea_utm_cache_1300': 'undefined',
  228. 'support_avif': 'false',
  229. 'support_webp': 'false',
  230. 'xiguavideopcwebid': '7134967546256016900',
  231. 'xiguavideopcwebid.sig': 'xxRww5R1VEMJN_dQepHorEu_eAc',
  232. }
  233. urllib3.disable_warnings()
  234. response = requests.get(url=url, headers=headers, params=params, cookies=cookies, verify=False)
  235. if 'data' not in response.json() or response.json()['data'] == '':
  236. Common.logger(log_type, crawler).warning('get_video_info: response: {}', response)
  237. else:
  238. video_info = response.json()['data']['gidInformation']['packerData']['video']
  239. video_url_dict = {}
  240. # video_url
  241. if 'videoResource' not in video_info:
  242. video_url_dict["video_url"] = ''
  243. video_url_dict["audio_url"] = ''
  244. video_url_dict["video_width"] = 0
  245. video_url_dict["video_height"] = 0
  246. elif 'dash_120fps' in video_info['videoResource']:
  247. if "video_list" in video_info['videoResource']['dash_120fps'] and 'video_4' in video_info['videoResource']['dash_120fps']['video_list']:
  248. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
  249. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
  250. if len(video_url) % 3 == 1:
  251. video_url += '=='
  252. elif len(video_url) % 3 == 2:
  253. video_url += '='
  254. elif len(audio_url) % 3 == 1:
  255. audio_url += '=='
  256. elif len(audio_url) % 3 == 2:
  257. audio_url += '='
  258. video_url = base64.b64decode(video_url).decode('utf8')
  259. audio_url = base64.b64decode(audio_url).decode('utf8')
  260. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_4']['vwidth']
  261. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_4']['vheight']
  262. video_url_dict["video_url"] = video_url
  263. video_url_dict["audio_url"] = audio_url
  264. video_url_dict["video_width"] = video_width
  265. video_url_dict["video_height"] = video_height
  266. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_3' in video_info['videoResource']['dash_120fps']['video_list']:
  267. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
  268. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
  269. if len(video_url) % 3 == 1:
  270. video_url += '=='
  271. elif len(video_url) % 3 == 2:
  272. video_url += '='
  273. elif len(audio_url) % 3 == 1:
  274. audio_url += '=='
  275. elif len(audio_url) % 3 == 2:
  276. audio_url += '='
  277. video_url = base64.b64decode(video_url).decode('utf8')
  278. audio_url = base64.b64decode(audio_url).decode('utf8')
  279. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_3']['vwidth']
  280. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_3']['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. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_2' in video_info['videoResource']['dash_120fps']['video_list']:
  286. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
  287. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
  288. if len(video_url) % 3 == 1:
  289. video_url += '=='
  290. elif len(video_url) % 3 == 2:
  291. video_url += '='
  292. elif len(audio_url) % 3 == 1:
  293. audio_url += '=='
  294. elif len(audio_url) % 3 == 2:
  295. audio_url += '='
  296. video_url = base64.b64decode(video_url).decode('utf8')
  297. audio_url = base64.b64decode(audio_url).decode('utf8')
  298. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_2']['vwidth']
  299. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_2']['vheight']
  300. video_url_dict["video_url"] = video_url
  301. video_url_dict["audio_url"] = audio_url
  302. video_url_dict["video_width"] = video_width
  303. video_url_dict["video_height"] = video_height
  304. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_1' in video_info['videoResource']['dash_120fps']['video_list']:
  305. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
  306. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
  307. if len(video_url) % 3 == 1:
  308. video_url += '=='
  309. elif len(video_url) % 3 == 2:
  310. video_url += '='
  311. elif len(audio_url) % 3 == 1:
  312. audio_url += '=='
  313. elif len(audio_url) % 3 == 2:
  314. audio_url += '='
  315. video_url = base64.b64decode(video_url).decode('utf8')
  316. audio_url = base64.b64decode(audio_url).decode('utf8')
  317. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_1']['vwidth']
  318. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_1']['vheight']
  319. video_url_dict["video_url"] = video_url
  320. video_url_dict["audio_url"] = audio_url
  321. video_url_dict["video_width"] = video_width
  322. video_url_dict["video_height"] = video_height
  323. elif 'dynamic_video' in video_info['videoResource']['dash_120fps'] \
  324. and 'dynamic_video_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
  325. and 'dynamic_audio_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
  326. and len(video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list']) != 0 \
  327. and len(video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list']) != 0:
  328. video_url = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1]['backup_url_1']
  329. audio_url = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list'][-1]['backup_url_1']
  330. if len(video_url) % 3 == 1:
  331. video_url += '=='
  332. elif len(video_url) % 3 == 2:
  333. video_url += '='
  334. elif len(audio_url) % 3 == 1:
  335. audio_url += '=='
  336. elif len(audio_url) % 3 == 2:
  337. audio_url += '='
  338. video_url = base64.b64decode(video_url).decode('utf8')
  339. audio_url = base64.b64decode(audio_url).decode('utf8')
  340. video_width = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1]['vwidth']
  341. video_height = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1]['vheight']
  342. video_url_dict["video_url"] = video_url
  343. video_url_dict["audio_url"] = audio_url
  344. video_url_dict["video_width"] = video_width
  345. video_url_dict["video_height"] = video_height
  346. else:
  347. video_url_dict["video_url"] = ''
  348. video_url_dict["audio_url"] = ''
  349. video_url_dict["video_width"] = 0
  350. video_url_dict["video_height"] = 0
  351. elif 'dash' in video_info['videoResource']:
  352. if "video_list" in video_info['videoResource']['dash'] and 'video_4' in video_info['videoResource']['dash']['video_list']:
  353. video_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
  354. audio_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
  355. if len(video_url) % 3 == 1:
  356. video_url += '=='
  357. elif len(video_url) % 3 == 2:
  358. video_url += '='
  359. elif len(audio_url) % 3 == 1:
  360. audio_url += '=='
  361. elif len(audio_url) % 3 == 2:
  362. audio_url += '='
  363. video_url = base64.b64decode(video_url).decode('utf8')
  364. audio_url = base64.b64decode(audio_url).decode('utf8')
  365. video_width = video_info['videoResource']['dash']['video_list']['video_4']['vwidth']
  366. video_height = video_info['videoResource']['dash']['video_list']['video_4']['vheight']
  367. video_url_dict["video_url"] = video_url
  368. video_url_dict["audio_url"] = audio_url
  369. video_url_dict["video_width"] = video_width
  370. video_url_dict["video_height"] = video_height
  371. elif "video_list" in video_info['videoResource']['dash'] and 'video_3' in video_info['videoResource']['dash']['video_list']:
  372. video_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
  373. audio_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
  374. if len(video_url) % 3 == 1:
  375. video_url += '=='
  376. elif len(video_url) % 3 == 2:
  377. video_url += '='
  378. elif len(audio_url) % 3 == 1:
  379. audio_url += '=='
  380. elif len(audio_url) % 3 == 2:
  381. audio_url += '='
  382. video_url = base64.b64decode(video_url).decode('utf8')
  383. audio_url = base64.b64decode(audio_url).decode('utf8')
  384. video_width = video_info['videoResource']['dash']['video_list']['video_3']['vwidth']
  385. video_height = video_info['videoResource']['dash']['video_list']['video_3']['vheight']
  386. video_url_dict["video_url"] = video_url
  387. video_url_dict["audio_url"] = audio_url
  388. video_url_dict["video_width"] = video_width
  389. video_url_dict["video_height"] = video_height
  390. elif "video_list" in video_info['videoResource']['dash'] and 'video_2' in video_info['videoResource']['dash']['video_list']:
  391. video_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
  392. audio_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
  393. if len(video_url) % 3 == 1:
  394. video_url += '=='
  395. elif len(video_url) % 3 == 2:
  396. video_url += '='
  397. elif len(audio_url) % 3 == 1:
  398. audio_url += '=='
  399. elif len(audio_url) % 3 == 2:
  400. audio_url += '='
  401. video_url = base64.b64decode(video_url).decode('utf8')
  402. audio_url = base64.b64decode(audio_url).decode('utf8')
  403. video_width = video_info['videoResource']['dash']['video_list']['video_2']['vwidth']
  404. video_height = video_info['videoResource']['dash']['video_list']['video_2']['vheight']
  405. video_url_dict["video_url"] = video_url
  406. video_url_dict["audio_url"] = audio_url
  407. video_url_dict["video_width"] = video_width
  408. video_url_dict["video_height"] = video_height
  409. elif "video_list" in video_info['videoResource']['dash'] and 'video_1' in video_info['videoResource']['dash']['video_list']:
  410. video_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
  411. audio_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
  412. if len(video_url) % 3 == 1:
  413. video_url += '=='
  414. elif len(video_url) % 3 == 2:
  415. video_url += '='
  416. elif len(audio_url) % 3 == 1:
  417. audio_url += '=='
  418. elif len(audio_url) % 3 == 2:
  419. audio_url += '='
  420. video_url = base64.b64decode(video_url).decode('utf8')
  421. audio_url = base64.b64decode(audio_url).decode('utf8')
  422. video_width = video_info['videoResource']['dash']['video_list']['video_1']['vwidth']
  423. video_height = video_info['videoResource']['dash']['video_list']['video_1']['vheight']
  424. video_url_dict["video_url"] = video_url
  425. video_url_dict["audio_url"] = audio_url
  426. video_url_dict["video_width"] = video_width
  427. video_url_dict["video_height"] = video_height
  428. elif 'dynamic_video' in video_info['videoResource']['dash'] \
  429. and 'dynamic_video_list' in video_info['videoResource']['dash']['dynamic_video'] \
  430. and 'dynamic_audio_list' in video_info['videoResource']['dash']['dynamic_video'] \
  431. and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list']) != 0 \
  432. and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list']) != 0:
  433. video_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1]['backup_url_1']
  434. audio_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list'][-1]['backup_url_1']
  435. if len(video_url) % 3 == 1:
  436. video_url += '=='
  437. elif len(video_url) % 3 == 2:
  438. video_url += '='
  439. elif len(audio_url) % 3 == 1:
  440. audio_url += '=='
  441. elif len(audio_url) % 3 == 2:
  442. audio_url += '='
  443. video_url = base64.b64decode(video_url).decode('utf8')
  444. audio_url = base64.b64decode(audio_url).decode('utf8')
  445. video_width = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1]['vwidth']
  446. video_height = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1]['vheight']
  447. video_url_dict["video_url"] = video_url
  448. video_url_dict["audio_url"] = audio_url
  449. video_url_dict["video_width"] = video_width
  450. video_url_dict["video_height"] = video_height
  451. else:
  452. video_url_dict["video_url"] = ''
  453. video_url_dict["audio_url"] = ''
  454. video_url_dict["video_width"] = 0
  455. video_url_dict["video_height"] = 0
  456. elif 'normal' in video_info['videoResource']:
  457. if "video_list" in video_info['videoResource']['normal'] and 'video_4' in \
  458. video_info['videoResource']['normal']['video_list']:
  459. video_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
  460. audio_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
  461. if len(video_url) % 3 == 1:
  462. video_url += '=='
  463. elif len(video_url) % 3 == 2:
  464. video_url += '='
  465. elif len(audio_url) % 3 == 1:
  466. audio_url += '=='
  467. elif len(audio_url) % 3 == 2:
  468. audio_url += '='
  469. video_url = base64.b64decode(video_url).decode('utf8')
  470. audio_url = base64.b64decode(audio_url).decode('utf8')
  471. video_width = video_info['videoResource']['normal']['video_list']['video_4']['vwidth']
  472. video_height = video_info['videoResource']['normal']['video_list']['video_4']['vheight']
  473. video_url_dict["video_url"] = video_url
  474. video_url_dict["audio_url"] = audio_url
  475. video_url_dict["video_width"] = video_width
  476. video_url_dict["video_height"] = video_height
  477. elif "video_list" in video_info['videoResource']['normal'] and 'video_3' in \
  478. video_info['videoResource']['normal']['video_list']:
  479. video_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
  480. audio_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
  481. if len(video_url) % 3 == 1:
  482. video_url += '=='
  483. elif len(video_url) % 3 == 2:
  484. video_url += '='
  485. elif len(audio_url) % 3 == 1:
  486. audio_url += '=='
  487. elif len(audio_url) % 3 == 2:
  488. audio_url += '='
  489. video_url = base64.b64decode(video_url).decode('utf8')
  490. audio_url = base64.b64decode(audio_url).decode('utf8')
  491. video_width = video_info['videoResource']['normal']['video_list']['video_3']['vwidth']
  492. video_height = video_info['videoResource']['normal']['video_list']['video_3']['vheight']
  493. video_url_dict["video_url"] = video_url
  494. video_url_dict["audio_url"] = audio_url
  495. video_url_dict["video_width"] = video_width
  496. video_url_dict["video_height"] = video_height
  497. elif "video_list" in video_info['videoResource']['normal'] and 'video_2' in \
  498. video_info['videoResource']['normal']['video_list']:
  499. video_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
  500. audio_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
  501. if len(video_url) % 3 == 1:
  502. video_url += '=='
  503. elif len(video_url) % 3 == 2:
  504. video_url += '='
  505. elif len(audio_url) % 3 == 1:
  506. audio_url += '=='
  507. elif len(audio_url) % 3 == 2:
  508. audio_url += '='
  509. video_url = base64.b64decode(video_url).decode('utf8')
  510. audio_url = base64.b64decode(audio_url).decode('utf8')
  511. video_width = video_info['videoResource']['normal']['video_list']['video_2']['vwidth']
  512. video_height = video_info['videoResource']['normal']['video_list']['video_2']['vheight']
  513. video_url_dict["video_url"] = video_url
  514. video_url_dict["audio_url"] = audio_url
  515. video_url_dict["video_width"] = video_width
  516. video_url_dict["video_height"] = video_height
  517. elif "video_list" in video_info['videoResource']['normal'] and 'video_1' in \
  518. video_info['videoResource']['normal']['video_list']:
  519. video_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
  520. audio_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
  521. if len(video_url) % 3 == 1:
  522. video_url += '=='
  523. elif len(video_url) % 3 == 2:
  524. video_url += '='
  525. elif len(audio_url) % 3 == 1:
  526. audio_url += '=='
  527. elif len(audio_url) % 3 == 2:
  528. audio_url += '='
  529. video_url = base64.b64decode(video_url).decode('utf8')
  530. audio_url = base64.b64decode(audio_url).decode('utf8')
  531. video_width = video_info['videoResource']['normal']['video_list']['video_1']['vwidth']
  532. video_height = video_info['videoResource']['normal']['video_list']['video_1']['vheight']
  533. video_url_dict["video_url"] = video_url
  534. video_url_dict["audio_url"] = audio_url
  535. video_url_dict["video_width"] = video_width
  536. video_url_dict["video_height"] = video_height
  537. elif 'dynamic_video' in video_info['videoResource']['normal'] \
  538. and 'dynamic_video_list' in video_info['videoResource']['normal']['dynamic_video'] \
  539. and 'dynamic_audio_list' in video_info['videoResource']['normal']['dynamic_video'] \
  540. and len(video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list']) != 0 \
  541. and len(video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list']) != 0:
  542. video_url = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  543. 'backup_url_1']
  544. audio_url = video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list'][-1][
  545. 'backup_url_1']
  546. if len(video_url) % 3 == 1:
  547. video_url += '=='
  548. elif len(video_url) % 3 == 2:
  549. video_url += '='
  550. elif len(audio_url) % 3 == 1:
  551. audio_url += '=='
  552. elif len(audio_url) % 3 == 2:
  553. audio_url += '='
  554. video_url = base64.b64decode(video_url).decode('utf8')
  555. audio_url = base64.b64decode(audio_url).decode('utf8')
  556. video_width = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  557. 'vwidth']
  558. video_height = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  559. 'vheight']
  560. video_url_dict["video_url"] = video_url
  561. video_url_dict["audio_url"] = audio_url
  562. video_url_dict["video_width"] = video_width
  563. video_url_dict["video_height"] = video_height
  564. else:
  565. video_url_dict["video_url"] = ''
  566. video_url_dict["audio_url"] = ''
  567. video_url_dict["video_width"] = 0
  568. video_url_dict["video_height"] = 0
  569. else:
  570. video_url_dict["video_url"] = ''
  571. video_url_dict["audio_url"] = ''
  572. video_url_dict["video_width"] = 0
  573. video_url_dict["video_height"] = 0
  574. return video_url_dict
  575. except Exception as e:
  576. Common.logger(log_type, crawler).error(f'get_video_url:{e}\n')
  577. @classmethod
  578. def get_videolist(cls, log_type, crawler, strategy, our_uid, out_uid, oss_endpoint, env, machine):
  579. signature = cls.random_signature()
  580. while True:
  581. url = "https://www.ixigua.com/api/videov2/author/new_video_list?"
  582. params = {
  583. 'to_user_id': str(out_uid),
  584. 'offset': str(cls.offset),
  585. 'limit': '30',
  586. 'maxBehotTime': '0',
  587. 'order': 'new',
  588. 'isHome': '0',
  589. 'msToken': 'G0eRzNkw189a8TLaXjc6nTHVMQwh9XcxVAqTbGKi7iPJdQcLwS3-XRrJ3MZ7QBfqErpxp3EX1WtvWOIcZ3NIgr41hgcd-v64so_RRj3YCRw1UsKW8mIssNLlIMspsg==',
  590. 'X-Bogus': 'DFSzswVuEkUANjW9ShFTgR/F6qHt',
  591. '_signature': signature,
  592. }
  593. headers = {
  594. 'authority': 'www.ixigua.com',
  595. 'accept': 'application/json, text/plain, */*',
  596. 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
  597. 'cache-control': 'no-cache',
  598. 'cookie': f'MONITOR_WEB_ID=7168304743566296612; __ac_signature={signature}; ixigua-a-s=1; support_webp=true; support_avif=false; csrf_session_id=a5355d954d3c63ed1ba35faada452b4d; msToken=G0eRzNkw189a8TLaXjc6nTHVMQwh9XcxVAqTbGKi7iPJdQcLwS3-XRrJ3MZ7QBfqErpxp3EX1WtvWOIcZ3NIgr41hgcd-v64so_RRj3YCRw1UsKW8mIssNLlIMspsg==; tt_scid=o4agqz7u9SKPwfBoPt6S82Cw0q.9KDtqmNe0JHxMqmpxNHQWq1BmrQdgVU6jEoX7ed99; ttwid=1%7CHHtv2QqpSGuSu8r-zXF1QoWsvjmNi1SJrqOrZzg-UCY%7C1676618894%7Cee5ad95378275f282f230a7ffa9947ae7eff40d0829c5a2568672a6dc90a1c96; ixigua-a-s=1',
  599. 'pragma': 'no-cache',
  600. 'referer': f'https://www.ixigua.com/home/{out_uid}/video/?preActiveKey=hotsoon&list_entrance=userdetail',
  601. 'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Microsoft Edge";v="110"',
  602. 'sec-ch-ua-mobile': '?0',
  603. 'sec-ch-ua-platform': '"macOS"',
  604. 'sec-fetch-dest': 'empty',
  605. 'sec-fetch-mode': 'cors',
  606. 'sec-fetch-site': 'same-origin',
  607. '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',
  608. 'x-secsdk-csrf-token': '00010000000119e3f9454d1dcbb288704cda1960f241e2d19bd21f2fd283520c3615a990ac5a17448bfbb902a249'
  609. }
  610. urllib3.disable_warnings()
  611. response = requests.get(url=url, headers=headers, params=params, proxies=proxies, verify=False)
  612. cls.offset += 30
  613. if response.status_code != 200:
  614. Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.text}\n")
  615. elif 'data' not in response.text:
  616. Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.text}\n")
  617. elif 'videoList' not in response.json()["data"]:
  618. Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.json()}\n")
  619. else:
  620. videoList = response.json()['data']['videoList']
  621. for i in range(len(videoList)):
  622. # video_title
  623. if 'title' not in videoList[i]:
  624. video_title = 0
  625. else:
  626. video_title = videoList[i]['title'].strip().replace('手游', '') \
  627. .replace('/', '').replace('\/', '').replace('\n', '')
  628. # video_id
  629. if 'video_id' not in videoList[i]:
  630. video_id = 0
  631. else:
  632. video_id = videoList[i]['video_id']
  633. # gid
  634. if 'gid' not in videoList[i]:
  635. gid = 0
  636. else:
  637. gid = videoList[i]['gid']
  638. # play_cnt
  639. if 'video_detail_info' not in videoList[i]:
  640. play_cnt = 0
  641. elif 'video_watch_count' not in videoList[i]['video_detail_info']:
  642. play_cnt = 0
  643. else:
  644. play_cnt = videoList[i]['video_detail_info']['video_watch_count']
  645. # comment_cnt
  646. if 'comment_count' not in videoList[i]:
  647. comment_cnt = 0
  648. else:
  649. comment_cnt = videoList[i]['comment_count']
  650. # like_cnt
  651. if 'digg_count' not in videoList[i]:
  652. like_cnt = 0
  653. else:
  654. like_cnt = videoList[i]['digg_count']
  655. # share_cnt
  656. share_cnt = 0
  657. # video_duration
  658. if 'video_duration' not in videoList[i]:
  659. video_duration = 0
  660. else:
  661. video_duration = videoList[i]['video_duration']
  662. # send_time
  663. if 'publish_time' not in videoList[i]:
  664. publish_time = 0
  665. else:
  666. publish_time = videoList[i]['publish_time']
  667. publish_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(publish_time))
  668. # is_top
  669. if 'is_top' not in videoList[i]:
  670. is_top = 0
  671. else:
  672. is_top = videoList[i]['is_top']
  673. # user_name
  674. if 'user_info' not in videoList[i]:
  675. user_name = 0
  676. elif 'name' not in videoList[i]['user_info']:
  677. user_name = 0
  678. else:
  679. user_name = videoList[i]['user_info']['name']
  680. # user_id
  681. if 'user_info' not in videoList[i]:
  682. user_id = 0
  683. elif 'user_id' not in videoList[i]['user_info']:
  684. user_id = 0
  685. else:
  686. user_id = videoList[i]['user_info']['user_id']
  687. # avatar_url
  688. if 'user_info' not in videoList[i]:
  689. avatar_url = 0
  690. elif 'avatar_url' not in videoList[i]['user_info']:
  691. avatar_url = 0
  692. else:
  693. avatar_url = videoList[i]['user_info']['avatar_url']
  694. # cover_url
  695. if 'video_detail_info' not in videoList[i]:
  696. cover_url = 0
  697. elif 'detail_video_large_image' not in videoList[i]['video_detail_info']:
  698. cover_url = 0
  699. elif 'url' in videoList[i]['video_detail_info']['detail_video_large_image']:
  700. cover_url = videoList[i]['video_detail_info']['detail_video_large_image']['url']
  701. else:
  702. cover_url = videoList[i]['video_detail_info']['detail_video_large_image']['url_list'][0]['url']
  703. if gid == 0 or video_id == 0 or cover_url == 0:
  704. Common.logger(log_type, crawler).info('无效视频\n')
  705. elif is_top is True and int(time.time()) - int(publish_time) > 3600 * 24 * 10:
  706. Common.logger(log_type, crawler).info(f'置顶视频,且发布时间超过10天:{publish_time_str}\n')
  707. elif int(time.time()) - int(publish_time) > 3600 * 24 * 10:
  708. Common.logger(log_type, crawler).info(f'发布时间超过10天:{publish_time_str}\n')
  709. cls.offset = 0
  710. return
  711. else:
  712. video_url_dict = cls.get_video_url(log_type, crawler, gid)
  713. video_url = video_url_dict["video_url"]
  714. audio_url = video_url_dict["audio_url"]
  715. video_width = video_url_dict["video_width"]
  716. video_height = video_url_dict["video_height"]
  717. video_dict = {'video_title': video_title,
  718. 'video_id': video_id,
  719. 'gid': gid,
  720. 'play_cnt': play_cnt,
  721. 'comment_cnt': comment_cnt,
  722. 'like_cnt': like_cnt,
  723. 'share_cnt': share_cnt,
  724. 'video_width': video_width,
  725. 'video_height': video_height,
  726. 'duration': video_duration,
  727. 'publish_time_stamp': publish_time,
  728. 'publish_time_str': publish_time_str,
  729. 'is_top': is_top,
  730. 'user_name': user_name,
  731. 'user_id': user_id,
  732. 'avatar_url': avatar_url,
  733. 'cover_url': cover_url,
  734. 'audio_url': audio_url,
  735. 'video_url': video_url,
  736. 'session': signature}
  737. for k, v in video_dict.items():
  738. Common.logger(log_type, crawler).info(f"{k}:{v}")
  739. # cls.download_publish(log_type=log_type,
  740. # crawler=crawler,
  741. # video_dict=video_dict,
  742. # strategy=strategy,
  743. # our_uid=our_uid,
  744. # oss_endpoint=oss_endpoint,
  745. # env=env,
  746. # machine=machine)
  747. # 下载 / 上传
  748. @classmethod
  749. def download_publish(cls, log_type, crawler, strategy, video_dict, our_uid, oss_endpoint, env, machine):
  750. # try:
  751. if cls.download_rule(video_dict['duration'], video_dict['video_width'], video_dict['video_height']) is False:
  752. Common.logger(log_type, crawler).info('不满足抓取规则\n')
  753. elif any(word if word in video_dict['video_title'] else False for word in cls.filter_words(log_type, crawler)) is True:
  754. Common.logger(log_type, crawler).info('标题已中过滤词:{}\n', video_dict['video_title'])
  755. elif str(video_dict['video_id']) in [x for y in Feishu.get_values_batch(log_type, 'xigua', 'e075e9') for x in y]:
  756. Common.logger(log_type, crawler).info('视频已下载\n')
  757. elif str(video_dict['video_id']) in [x for y in Feishu.get_values_batch(log_type, 'xigua', '3Ul6wZ') for x in y]:
  758. Common.logger(log_type, crawler).info('视频已下载\n')
  759. elif str(video_dict['video_id']) in [x for y in Feishu.get_values_batch(log_type, 'xigua', 'QOWqMo') for x in y]:
  760. Common.logger(log_type, crawler).info('视频已下载\n')
  761. elif str(video_dict['video_id']) in [x for y in Feishu.get_values_batch(log_type, 'xigua', 'wjhpDs') for x in y]:
  762. Common.logger(log_type, crawler).info('视频已存在\n')
  763. else:
  764. # 下载封面
  765. Common.download_method(log_type=log_type, crawler=crawler, text='cover', title=video_dict['video_title'], url=video_dict['cover_url'])
  766. # 下载视频
  767. Common.download_method(log_type=log_type, crawler=crawler, text='xigua_video', title=video_dict['video_title'], url=video_dict['video_url'])
  768. # 下载音频
  769. Common.download_method(log_type=log_type, crawler=crawler, text='xigua_audio', title=video_dict['video_title'], url=video_dict['audio_url'])
  770. # 保存视频信息至txt
  771. Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
  772. # 合成音视频
  773. Common.video_compose(log_type=log_type, crawler=crawler, video_dir=f"./{crawler}/videos/{video_dict['video_title']}")
  774. # 上传视频
  775. Common.logger(log_type, crawler).info("开始上传视频...")
  776. our_video_id = Publish.upload_and_publish(log_type=log_type,
  777. crawler=crawler,
  778. strategy=strategy,
  779. our_uid=our_uid,
  780. env=env,
  781. oss_endpoint=oss_endpoint)
  782. if env == 'dev':
  783. our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  784. else:
  785. our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  786. Common.logger(log_type, crawler).info("视频上传完成")
  787. if our_video_id is None:
  788. # 删除视频文件夹
  789. shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}/")
  790. return
  791. # 视频写入飞书
  792. Feishu.insert_columns(log_type, 'xigua', "e075e9", "ROWS", 1, 2)
  793. upload_time = int(time.time())
  794. values = [[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(upload_time)),
  795. "定向榜",
  796. video_dict['video_title'],
  797. str(video_dict['video_id']),
  798. our_video_link,
  799. video_dict['gid'],
  800. video_dict['play_cnt'],
  801. video_dict['comment_cnt'],
  802. video_dict['like_cnt'],
  803. video_dict['share_cnt'],
  804. video_dict['duration'],
  805. str(video_dict['video_width']) + '*' + str(video_dict['video_height']),
  806. video_dict['publish_time_str'],
  807. video_dict['user_name'],
  808. video_dict['user_id'],
  809. video_dict['avatar_url'],
  810. video_dict['cover_url'],
  811. video_dict['video_url'],
  812. video_dict['audio_url']]]
  813. time.sleep(1)
  814. Feishu.update_values(log_type, 'xigua', "e075e9", "F2:Z2", values)
  815. Common.logger(log_type, crawler).info(f"视频已保存至云文档\n")
  816. # 视频信息保存数据库
  817. sql = f""" insert into crawler_video(video_id,
  818. user_id,
  819. out_user_id,
  820. platform,
  821. strategy,
  822. out_video_id,
  823. video_title,
  824. cover_url,
  825. video_url,
  826. duration,
  827. publish_time,
  828. play_cnt,
  829. crawler_rule,
  830. width,
  831. height)
  832. values({our_video_id},
  833. "{our_uid}",
  834. "{video_dict['user_id']}",
  835. "{cls.platform}",
  836. "定向爬虫策略",
  837. "{video_dict['video_id']}",
  838. "{video_dict['video_title']}",
  839. "{video_dict['cover_url']}",
  840. "{video_dict['video_url']}",
  841. {int(video_dict['duration'])},
  842. "{video_dict['publish_time_str']}",
  843. {int(video_dict['play_cnt'])},
  844. "4,5,6",
  845. {int(video_dict['video_width'])},
  846. {int(video_dict['video_height'])}) """
  847. MysqlHelper.update_values(log_type, crawler, sql, env, machine)
  848. Common.logger(log_type, crawler).info('视频信息插入数据库成功!\n')
  849. # except Exception as e:
  850. # Common.logger(log_type, crawler).error(f'download_publish异常:{e}\n')
  851. if __name__ == '__main__':
  852. # print(Follow.get_signature("follow", "xigua", "95420624045", "local"))
  853. # Follow.get_videolist(log_type="follow",
  854. # crawler="xigua",
  855. # strategy="定向爬虫策略",
  856. # our_uid="6267141",
  857. # out_uid="95420624045",
  858. # oss_endpoint="out",
  859. # env="dev",
  860. # machine="local")
  861. # print(Follow.random_signature())
  862. user_list = Follow.get_user_list(log_type="follow", crawler="xigua", sheetid="5tlTYB", env="dev", machine="local")
  863. print(len(user_list))
  864. for user in user_list:
  865. print(user)
  866. pass