xigua_follow.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/8/23
  4. import base64
  5. import os
  6. import subprocess
  7. import sys
  8. import time
  9. import requests
  10. import urllib3
  11. sys.path.append(os.getcwd())
  12. from main.common import Common
  13. from main.feishu import Feishu
  14. from main.xigua_publish import Publish
  15. from main.get_signature import GetSignature
  16. proxies = {"http": None, "https": None}
  17. class Follow:
  18. # 个人主页视频翻页参数
  19. offset = 0
  20. # 获取用户信息(字典格式). 注意:部分 user_id 字符类型是 int / str
  21. @classmethod
  22. def get_user_info_from_feishu(cls, log_type):
  23. try:
  24. user_sheet = Feishu.get_values_batch(log_type, 'xigua', '5tlTYB')
  25. user_dict = {}
  26. for i in range(1, len(user_sheet)):
  27. user_name = user_sheet[i][0]
  28. out_id = user_sheet[i][1]
  29. our_id = user_sheet[i][3]
  30. if user_name is None or out_id is None or our_id is None:
  31. pass
  32. else:
  33. user_dict[user_name] = str(out_id) + ',' + str(our_id)
  34. return user_dict
  35. except Exception as e:
  36. Common.logger(log_type).error('get_user_id_from_feishu异常:{}\n', e)
  37. # 合并音视频
  38. @classmethod
  39. def video_compose(cls, log_type, video_title):
  40. try:
  41. video_path = './videos/' + str(video_title) + '/video1.mp4'
  42. audio_path = './videos/' + str(video_title) + '/audio1.mp4'
  43. out_path = './videos/' + str(video_title) + '/video.mp4'
  44. cmd = 'ffmpeg -i ' + video_path + ' -i ' + audio_path + \
  45. ' -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 ' + out_path
  46. # print(cmd)
  47. subprocess.call(cmd, shell=True)
  48. for file in os.listdir('./videos/' + str(video_title)):
  49. if file.split('.mp4')[0] == 'video1' or file.split('.mp4')[0] == 'audio1':
  50. os.remove('./videos/' + str(video_title) + '/' + file)
  51. Common.logger(log_type).info('合成成功\n')
  52. except Exception as e:
  53. Common.logger(log_type).error(f'video_compose异常:{e}\n')
  54. # 下载规则
  55. @staticmethod
  56. def download_rule(duration, width, height):
  57. if int(duration) >= 60:
  58. if int(width) >= 720 or int(height) >= 720:
  59. return True
  60. else:
  61. return False
  62. else:
  63. return False
  64. # 过滤词库
  65. @classmethod
  66. def filter_words(cls, log_type):
  67. try:
  68. filter_words_sheet = Feishu.get_values_batch(log_type, 'xigua', 'KGB4Hc')
  69. filter_words_list = []
  70. for x in filter_words_sheet:
  71. for y in x:
  72. if y is None:
  73. pass
  74. else:
  75. filter_words_list.append(y)
  76. return filter_words_list
  77. except Exception as e:
  78. Common.logger(log_type).error('filter_words异常:{}\n', e)
  79. # 获取视频详情
  80. @classmethod
  81. def get_video_url(cls, log_type, gid):
  82. # try:
  83. url = 'https://www.ixigua.com/api/mixVideo/information?'
  84. headers = {
  85. "accept-encoding": "gzip, deflate",
  86. "accept-language": "zh-CN,zh-Hans;q=0.9",
  87. "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
  88. "AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Safari/605.1.15",
  89. "referer": "https://www.ixigua.com/7102614741050196520?logTag=0531c88ac04f38ab2c62",
  90. }
  91. params = {
  92. 'mixId': gid,
  93. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfC'
  94. 'NVVIOBNjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  95. 'X-Bogus': 'DFSzswVupYTANCJOSBk0P53WxM-r',
  96. '_signature': '_02B4Z6wo0000119LvEwAAIDCuktNZ0y5wkdfS7jAALThuOR8D9yWNZ.EmWHKV0WSn6Px'
  97. 'fPsH9-BldyxVje0f49ryXgmn7Tzk-swEHNb15TiGqa6YF.cX0jW8Eds1TtJOIZyfc9s5emH7gdWN94',
  98. }
  99. cookies = {
  100. 'ixigua-a-s': '1',
  101. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfCNVVIOB'
  102. 'NjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  103. 'ttwid': '1%7C_yXQeHWwLZgCsgHClOwTCdYSOt_MjdOkgnPIkpi-Sr8%7C1661241238%7Cf57d0c5ef3f1d7'
  104. '6e049fccdca1ac54887c34d1f8731c8e51a49780ff0ceab9f8',
  105. 'tt_scid': 'QZ4l8KXDG0YAEaMCSbADdcybdKbUfG4BC6S4OBv9lpRS5VyqYLX2bIR8CTeZeGHR9ee3',
  106. 'MONITOR_WEB_ID': '0a49204a-7af5-4e96-95f0-f4bafb7450ad',
  107. '__ac_nonce': '06304878000964fdad287',
  108. '__ac_signature': '_02B4Z6wo00f017Rcr3AAAIDCUVxeW1tOKEu0fKvAAI4cvoYzV-wBhq7B6D8k0no7lb'
  109. 'FlvYoinmtK6UXjRIYPXnahUlFTvmWVtb77jsMkKAXzAEsLE56m36RlvL7ky.M3Xn52r9t1IEb7IR3ke8',
  110. 'ttcid': 'e56fabf6e85d4adf9e4d91902496a0e882',
  111. '_tea_utm_cache_1300': 'undefined',
  112. 'support_avif': 'false',
  113. 'support_webp': 'false',
  114. 'xiguavideopcwebid': '7134967546256016900',
  115. 'xiguavideopcwebid.sig': 'xxRww5R1VEMJN_dQepHorEu_eAc',
  116. }
  117. urllib3.disable_warnings()
  118. response = requests.get(url=url, headers=headers, params=params, cookies=cookies, proxies=proxies,
  119. verify=False)
  120. if 'data' not in response.json() or response.json()['data'] == '':
  121. Common.logger(log_type).warning('get_video_info: response: {}', response)
  122. else:
  123. video_info = response.json()['data']['gidInformation']['packerData']['video']
  124. video_url = ''
  125. audio_url = ''
  126. video_width = ''
  127. video_height = ''
  128. # video_url
  129. if 'videoResource' not in video_info:
  130. video_url = 0
  131. audio_url = 0
  132. video_width = 0
  133. video_height = 0
  134. elif 'dash' in video_info['videoResource'] \
  135. and 'dynamic_video' in video_info['videoResource']['dash'] \
  136. and 'dynamic_video_list' in video_info['videoResource']['dash']['dynamic_video']:
  137. video_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  138. 'main_url']
  139. audio_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list'][-1][
  140. 'main_url']
  141. # Common.logger(log_type).info(f'main_video_url:{video_url}')
  142. # Common.logger(log_type).info(f'main_audio_url:{audio_url}\n')
  143. if len(video_url) % 3 == 1:
  144. video_url += '=='
  145. elif len(video_url) % 3 == 2:
  146. video_url += '='
  147. elif len(audio_url) % 3 == 1:
  148. audio_url += '=='
  149. elif len(audio_url) % 3 == 2:
  150. audio_url += '='
  151. # Common.logger(log_type).info(f'%_video_url:{video_url}')
  152. # Common.logger(log_type).info(f'%_audio_url:{audio_url}\n')
  153. video_url = base64.b64decode(video_url).decode('utf8')
  154. audio_url = base64.b64decode(audio_url).decode('utf8')
  155. # Common.logger(log_type).info(f'base64_video_url:{video_url}')
  156. # Common.logger(log_type).info(f'base64_audio_url:{audio_url}\n')
  157. video_width = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  158. 'vwidth']
  159. video_height = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  160. 'vheight']
  161. elif 'dash_120fps' in video_info['videoResource'] \
  162. and 'dynamic_video' in video_info['videoResource']['dash_120fps'] \
  163. and 'dynamic_video_list' in video_info['videoResource']['dash_120fps']['dynamic_video']:
  164. video_url = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  165. 'main_url']
  166. audio_url = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list'][-1][
  167. 'main_url']
  168. if len(video_url) % 3 == 1:
  169. video_url += '=='
  170. elif len(video_url) % 3 == 2:
  171. video_url += '='
  172. elif len(audio_url) % 3 == 1:
  173. audio_url += '=='
  174. elif len(audio_url) % 3 == 2:
  175. audio_url += '='
  176. video_url = base64.b64decode(video_url).decode('utf8')
  177. audio_url = base64.b64decode(audio_url).decode('utf8')
  178. video_width = video_info['videoResource']['dash_120fps']['dynamic_video'][
  179. 'dynamic_video_list'][-1]['vwidth']
  180. video_height = video_info['videoResource']['dash_120fps']['dynamic_video'][
  181. 'dynamic_video_list'][-1]['vheight']
  182. elif 'normal' in video_info['videoResource']:
  183. video_list = video_info['videoResource']['normal']['video_list']
  184. if 'video_4' in video_list.keys():
  185. # Common.logger(log_type).info('{}', video_list['video_4'])
  186. video_url = video_list['video_4']['main_url']
  187. audio_url = video_list['video_4']['main_url']
  188. if len(video_url) % 3 == 1:
  189. video_url += '=='
  190. elif len(video_url) % 3 == 2:
  191. video_url += '='
  192. elif len(audio_url) % 3 == 1:
  193. audio_url += '=='
  194. elif len(audio_url) % 3 == 2:
  195. audio_url += '='
  196. video_url = base64.b64decode(video_url).decode('utf8')
  197. audio_url = base64.b64decode(audio_url).decode('utf8')
  198. video_width = video_list['video_4']['vwidth']
  199. video_height = video_list['video_4']['vheight']
  200. elif 'video_3' in video_list.keys():
  201. # Common.logger(log_type).info('{}', video_list['video_3'])
  202. video_url = video_list['video_3']['main_url']
  203. audio_url = video_list['video_3']['main_url']
  204. if len(video_url) % 3 == 1:
  205. video_url += '=='
  206. elif len(video_url) % 3 == 2:
  207. video_url += '='
  208. elif len(audio_url) % 3 == 1:
  209. audio_url += '=='
  210. elif len(audio_url) % 3 == 2:
  211. audio_url += '='
  212. video_url = base64.b64decode(video_url).decode('utf8')
  213. audio_url = base64.b64decode(audio_url).decode('utf8')
  214. video_width = video_list['video_3']['vwidth']
  215. video_height = video_list['video_3']['vheight']
  216. elif 'video_2' in video_list.keys():
  217. # Common.logger(log_type).info('{}', video_list['video_2'])
  218. video_url = video_list['video_2']['main_url']
  219. audio_url = video_list['video_2']['main_url']
  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_list['video_2']['vwidth']
  231. video_height = video_list['video_2']['vheight']
  232. elif 'video_1' in video_list.keys():
  233. # Common.logger(log_type).info('{}', video_list['video_1'])
  234. video_url = video_list['video_1']['main_url']
  235. audio_url = video_list['video_1']['main_url']
  236. if len(video_url) % 3 == 1:
  237. video_url += '=='
  238. elif len(video_url) % 3 == 2:
  239. video_url += '='
  240. elif len(audio_url) % 3 == 1:
  241. audio_url += '=='
  242. elif len(audio_url) % 3 == 2:
  243. audio_url += '='
  244. video_url = base64.b64decode(video_url).decode('utf8')
  245. audio_url = base64.b64decode(audio_url).decode('utf8')
  246. video_width = video_list['video_1']['vwidth']
  247. video_height = video_list['video_1']['vheight']
  248. else:
  249. video_url = 0
  250. audio_url = 0
  251. video_width = 0
  252. video_height = 0
  253. return video_url, audio_url, video_width, video_height
  254. # except Exception as e:
  255. # Common.logger(log_type).error(f'get_video_info异常:{e}\n')
  256. @classmethod
  257. def get_feeds(cls, log_type, outid):
  258. # try:
  259. url = "https://www.ixigua.com/api/videov2/author/new_video_list?"
  260. headers = {
  261. 'sec-ch-ua': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
  262. 'accept': 'application/json, text/plain, */*',
  263. 'sec-ch-ua-mobile': '?0',
  264. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko)'
  265. ' Chrome/103.0.0.0 Safari/537.36',
  266. 'sec-ch-ua-platform': '"macOS"',
  267. 'sec-fetch-site': 'same-origin',
  268. 'sec-fetch-mode': 'cors',
  269. 'sec-fetch-dest': 'document',
  270. 'referer': 'https://www.ixigua.com/home/' + str(outid),
  271. 'accept-encoding': 'gzip, deflate',
  272. 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
  273. }
  274. params = {
  275. 'to_user_id': str(outid),
  276. 'offset': str(cls.offset),
  277. 'limit': '30',
  278. 'maxBehotTime': '0',
  279. 'order': 'new',
  280. 'isHome': '0',
  281. 'msToken': '2ZHINOMBPK-qlCKApv37xVCBKkXyPli8mTYNlTSXvr17eZ0Ea8B__Otimkx6q_'
  282. 'enDc9m8Kgzi3Re7wpLIMSSE9dofTYdqQgvB7mHQbx_AMnVnf5lsByU',
  283. 'X-Bogus': 'DFSzswVuVvTANe2BSBBMCR/F6qyc',
  284. '_signature': Feishu.get_values_batch(log_type, 'xigua', '6tZHhs')[1][1],
  285. }
  286. cookies = {
  287. '__ac_signature': '_02B4Z6wo00f017vzS8QAAIDCwz2gwwDpX9-7009AAI4Bc4',
  288. 'MONITOR_WEB_ID': 'fd4244aa-2003-4e19-a2a4-715c19310a56',
  289. 'ixigua-a-s': '1',
  290. 'support_webp': 'true',
  291. 'support_avif': 'true',
  292. '_tea_utm_cache_1300': 'undefined',
  293. 'ttcid': '16a3b6b9b80b4a87ae258f5f3f101e6310',
  294. 'msToken': 'G8pL2oH-9Zl1hrLZPyOMSceMaII3ejKda2o-tgO1heYrj7b_fgm9vGlvwyLOA2H8oUShZgAYfxEvIuktT'
  295. '7OuxBuy85N-ousFfqxuAIrfruMEFZUTYp2z',
  296. 'tt_scid': 'a0zhISPImN-dVMMdbeb1Kzhl1x4oJS5Yr81FzH6qYk3jDtj1d2E5gsywN4rwna8ib398',
  297. 'ttwid': '1%7CvorN1HQjbSgBViRkEoZYEbqP_sQVoQqaUqGcFA-bzpA%7C1661324763%7Ce040213e1107973ebb0d'
  298. 'b64f0e77cfb027375f1fb5854bb40588d692d025af1f',
  299. }
  300. urllib3.disable_warnings()
  301. response = requests.get(url=url, headers=headers, params=params,
  302. cookies=cookies, proxies=proxies, verify=False)
  303. cls.offset += 30
  304. if 'data' not in response.text or response.json()['data'] == '' or response.json()['code'] != 200:
  305. Common.logger(log_type).info('get_follow_feeds: response:{}', response.text)
  306. else:
  307. feeds = response.json()['data']['videoList']
  308. return feeds
  309. # except Exception as e:
  310. # Common.logger(log_type).error(f'get_feeds异常:{e}\n')
  311. # 下载 / 上传
  312. @classmethod
  313. def download_publish(cls, log_type, video_dict, our_id, env):
  314. # try:
  315. if video_dict['gid'] == 0 or video_dict['video_id'] == 0 or video_dict['video_url'] == 0:
  316. Common.logger(log_type).info('无效视频\n')
  317. elif video_dict['is_top'] is True and int(time.time()) - int(video_dict['send_time']) > 3600 * 24 * 10:
  318. Common.logger(log_type).info(
  319. f'置顶视频,'
  320. f'且发布时间超过10天:{time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(video_dict["send_time"]))}\n')
  321. elif int(time.time()) - int(video_dict['send_time']) > 3600 * 24 * 10:
  322. Common.logger(log_type).info(
  323. f'发布时间超过10天:{time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(video_dict["send_time"]))}\n')
  324. cls.offset = 0
  325. return
  326. elif cls.download_rule(video_dict['video_duration'], video_dict['video_width'], video_dict['video_height']) is False:
  327. Common.logger(log_type).info('不满足抓取规则\n')
  328. elif any(word if word in video_dict['video_title'] else False for word in cls.filter_words(log_type)) is True:
  329. Common.logger(log_type).info('标题已中过滤词:{}\n', video_dict['video_title'])
  330. elif str(video_dict['video_id']) in [x for y in Feishu.get_values_batch(log_type, 'xigua', 'e075e9') for x in y]:
  331. Common.logger(log_type).info('视频已下载\n')
  332. elif str(video_dict['video_id']) in [x for y in Feishu.get_values_batch(log_type, 'xigua', '3Ul6wZ') for x in y]:
  333. Common.logger(log_type).info('视频已下载\n')
  334. elif str(video_dict['video_id']) in [x for y in Feishu.get_values_batch(log_type, 'xigua', 'QOWqMo') for x in y]:
  335. Common.logger(log_type).info('视频已下载\n')
  336. elif str(video_dict['video_id']) in [x for y in Feishu.get_values_batch(log_type, 'xigua', 'wjhpDs') for x in y]:
  337. Common.logger(log_type).info('视频已存在\n')
  338. else:
  339. # 下载封面
  340. Common.download_method(log_type=log_type, text='cover', d_name=video_dict['video_title'],
  341. d_url=video_dict['cover_url'])
  342. # 下载视频
  343. Common.download_method(log_type=log_type, text='video', d_name=video_dict['video_title'],
  344. d_url=video_dict['video_url'])
  345. # 下载音频
  346. Common.download_method(log_type=log_type, text='audio', d_name=video_dict['video_title'],
  347. d_url=video_dict['audio_url'])
  348. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  349. with open("./videos/" + video_dict['video_title'] + "/" + "info.txt",
  350. "a", encoding="UTF-8") as f_a:
  351. f_a.write(str(video_dict['video_id']) + "\n" +
  352. str(video_dict['video_title']) + "\n" +
  353. str(video_dict['video_duration']) + "\n" +
  354. str(video_dict['play_cnt']) + "\n" +
  355. str(video_dict['comment_cnt']) + "\n" +
  356. str(video_dict['like_cnt']) + "\n" +
  357. str(video_dict['share_cnt']) + "\n" +
  358. str(video_dict['video_width'])+'*'+str(video_dict['video_height']) + "\n" +
  359. str(video_dict['send_time']) + "\n" +
  360. str(video_dict['user_name']) + "\n" +
  361. str(video_dict['head_url']) + "\n" +
  362. str(video_dict['video_url']) + "\n" +
  363. str(video_dict['cover_url']) + "\n" +
  364. "xigua" + str(int(time.time())))
  365. Common.logger("follow").info("==========视频信息已保存至info.txt==========")
  366. # 合成音视频
  367. cls.video_compose(log_type, video_dict['video_title'])
  368. # 上传视频
  369. Common.logger(log_type).info("开始上传视频:{}".format(video_dict['video_title']))
  370. our_video_id = Publish.upload_and_publish(log_type, env, our_id)
  371. if env == 'dev':
  372. our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
  373. else:
  374. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
  375. Common.logger(log_type).info("视频上传完成:{}\n", video_dict['video_title'])
  376. # 视频ID工作表,插入首行
  377. Feishu.insert_columns(log_type, 'xigua', "e075e9", "ROWS", 1, 2)
  378. # 视频ID工作表,首行写入数据
  379. upload_time = int(time.time())
  380. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
  381. "关注榜",
  382. video_dict['video_title'],
  383. str(video_dict['video_id']),
  384. our_video_link,
  385. video_dict['gid'],
  386. video_dict['play_cnt'],
  387. video_dict['comment_cnt'],
  388. video_dict['like_cnt'],
  389. video_dict['share_cnt'],
  390. video_dict['video_duration'],
  391. str(video_dict['video_width'])+'*'+str(video_dict['video_height']),
  392. time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(video_dict['send_time'])),
  393. video_dict['user_name'],
  394. video_dict['user_id'],
  395. video_dict['head_url'],
  396. video_dict['cover_url'],
  397. video_dict['video_url'],
  398. video_dict['audio_url']]]
  399. time.sleep(1)
  400. Feishu.update_values(log_type, 'xigua', "e075e9", "F2:Z2", values)
  401. Common.logger(log_type).info(f"视频已保存至云文档:{video_dict['video_title']}\n")
  402. # except Exception as e:
  403. # Common.logger(log_type).error(f'download_publish异常:{e}\n')
  404. @classmethod
  405. def get_videos(cls, log_type, out_id, our_id, env):
  406. feeds = cls.get_feeds(log_type, out_id)
  407. for i in range(len(feeds)):
  408. # video_title
  409. if 'title' not in feeds[i]:
  410. video_title = 0
  411. else:
  412. video_title = feeds[i]['title'].strip().replace('手游', '') \
  413. .replace('/', '').replace('\/', '').replace('\n', '')
  414. # video_id
  415. if 'video_id' not in feeds[i]:
  416. video_id = 0
  417. else:
  418. video_id = feeds[i]['video_id']
  419. # gid
  420. if 'gid' not in feeds[i]:
  421. gid = 0
  422. else:
  423. gid = feeds[i]['gid']
  424. # play_cnt
  425. if 'video_detail_info' not in feeds[i]:
  426. play_cnt = 0
  427. elif 'video_watch_count' not in feeds[i]['video_detail_info']:
  428. play_cnt = 0
  429. else:
  430. play_cnt = feeds[i]['video_detail_info']['video_watch_count']
  431. # comment_cnt
  432. if 'comment_count' not in feeds[i]:
  433. comment_cnt = 0
  434. else:
  435. comment_cnt = feeds[i]['comment_count']
  436. # like_cnt
  437. if 'digg_count' not in feeds[i]:
  438. like_cnt = 0
  439. else:
  440. like_cnt = feeds[i]['digg_count']
  441. # share_cnt
  442. share_cnt = 0
  443. # video_duration
  444. if 'video_duration' not in feeds[i]:
  445. video_duration = 0
  446. else:
  447. video_duration = feeds[i]['video_duration']
  448. # send_time
  449. if 'publish_time' not in feeds[i]:
  450. send_time = 0
  451. else:
  452. send_time = feeds[i]['publish_time']
  453. # is_top
  454. if 'is_top' not in feeds[i]:
  455. is_top = 0
  456. else:
  457. is_top = feeds[i]['is_top']
  458. # user_name
  459. if 'user_info' not in feeds[i]:
  460. user_name = 0
  461. elif 'name' not in feeds[i]['user_info']:
  462. user_name = 0
  463. else:
  464. user_name = feeds[i]['user_info']['name']
  465. # user_id
  466. if 'user_info' not in feeds[i]:
  467. user_id = 0
  468. elif 'user_id' not in feeds[i]['user_info']:
  469. user_id = 0
  470. else:
  471. user_id = feeds[i]['user_info']['user_id']
  472. # head_url
  473. if 'user_info' not in feeds[i]:
  474. head_url = 0
  475. elif 'avatar_url' not in feeds[i]['user_info']:
  476. head_url = 0
  477. else:
  478. head_url = feeds[i]['user_info']['avatar_url']
  479. # cover_url
  480. if 'video_detail_info' not in feeds[i]:
  481. cover_url = 0
  482. elif 'detail_video_large_image' not in feeds[i]['video_detail_info']:
  483. cover_url = 0
  484. elif 'url' in feeds[i]['video_detail_info']['detail_video_large_image']:
  485. cover_url = feeds[i]['video_detail_info']['detail_video_large_image']['url']
  486. else:
  487. cover_url = feeds[i]['video_detail_info']['detail_video_large_image']['url_list'][0]['url']
  488. Common.logger(log_type).info(f'video_title:{video_title}')
  489. Common.logger(log_type).info(f'video_id:{video_id}')
  490. Common.logger(log_type).info(f'play_cnt:{play_cnt}')
  491. Common.logger(log_type).info(f'send_time:{time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(send_time))}')
  492. video_url_info = cls.get_video_url(log_type, gid)
  493. video_url = video_url_info[0]
  494. audio_url = video_url_info[1]
  495. video_width = video_url_info[2]
  496. video_height = video_url_info[-1]
  497. Common.logger(log_type).info(f'audio_url:{audio_url}')
  498. Common.logger(log_type).info(f'video_url:{video_url}')
  499. video_dict = {'video_title': video_title,
  500. 'video_id': video_id,
  501. 'gid': gid,
  502. 'play_cnt': play_cnt,
  503. 'comment_cnt': comment_cnt,
  504. 'like_cnt': like_cnt,
  505. 'share_cnt': share_cnt,
  506. 'video_width': video_width,
  507. 'video_height': video_height,
  508. 'video_duration': video_duration,
  509. 'send_time': send_time,
  510. 'is_top': is_top,
  511. 'user_name': user_name,
  512. 'user_id': user_id,
  513. 'head_url': head_url,
  514. 'cover_url': cover_url,
  515. 'audio_url': audio_url,
  516. 'video_url': video_url}
  517. cls.download_publish(log_type, video_dict, our_id, env)
  518. # 获取所有用户主页视频
  519. @classmethod
  520. def get_all_person_videos(cls, log_type, env):
  521. try:
  522. user_list = cls.get_user_info_from_feishu(log_type)
  523. if len(user_list) == 0:
  524. Common.logger(log_type).warning('用户ID列表为空\n')
  525. else:
  526. for k, v in user_list.items():
  527. Common.logger(log_type).info('正在获取 {} 主页视频\n', k)
  528. GetSignature.get_signature('follow')
  529. cls.get_videos(log_type, v.split(',')[0], v.split(',')[1], env)
  530. time.sleep(10)
  531. cls.offset = 0
  532. except Exception as e:
  533. Common.logger(log_type).error('get_all_person_videos异常:{}\n', e)
  534. if __name__ == '__main__':
  535. Follow.get_videos('follow', '805266955183463', '6267140', 'dev')
  536. pass