xiaoniangao_hour_list.py 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/5/16
  4. import datetime
  5. import os
  6. import random
  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_lib import Feishu
  14. from main.publish import Publish
  15. proxies = {"http": None, "https": None}
  16. class HourList:
  17. # 配置微信
  18. time.sleep(1)
  19. wechat_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "dzcWHw")
  20. hour_x_b3_traceid = wechat_sheet[2][1]
  21. hour_x_token_id = wechat_sheet[3][1]
  22. hour_referer = wechat_sheet[4][1]
  23. hour_uid = wechat_sheet[5][1]
  24. hour_token = wechat_sheet[6][1]
  25. # # 小时级数据表
  26. # hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")
  27. # 生成 uid、token
  28. @classmethod
  29. def get_uid_token(cls):
  30. uid_token = "abcdefghijklmnopqrstuvwxyz0123456789"
  31. uid = ("".join(random.sample(uid_token, 8))) + "-" + ("".join(random.sample(uid_token, 4))) + "-" + (
  32. "".join(random.sample(uid_token, 4))) + "-" + ("".join(random.sample(uid_token, 4))) + "-" + (
  33. "".join(random.sample(uid_token, 12)))
  34. token = ("".join(random.sample(uid_token, 32)))
  35. Feishu.update_values("hour", "xiaoniangao", "dzcWHw", "B6:B6", [[uid]])
  36. time.sleep(1)
  37. Feishu.update_values("hour", "xiaoniangao", "dzcWHw", "B7:B7", [[token]])
  38. Common.logger("hour").info("生成 uid:{}, token:{},写入飞书成功\n", uid, token)
  39. # 过滤敏感词
  40. @classmethod
  41. def sensitive_words(cls, log_type):
  42. # 敏感词库列表
  43. word_list = []
  44. # 从云文档读取所有敏感词,添加到词库列表
  45. time.sleep(1)
  46. lists = Feishu.get_values_batch(log_type, "xiaoniangao", "DRAnZh")
  47. for i in lists:
  48. for j in i:
  49. # 过滤空的单元格内容
  50. if j is None:
  51. pass
  52. else:
  53. word_list.append(j)
  54. return word_list
  55. # 视频ID过滤字母
  56. @classmethod
  57. def sensitive_videoid_words(cls):
  58. # 字母列表
  59. words_list = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
  60. "t", "u", "v", "w", "x", "y", "z",
  61. "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
  62. "T", "U", "V", "W", "X", "Y", "Z"]
  63. return words_list
  64. # 基础门槛规则
  65. @staticmethod
  66. def download_rule(d_duration, d_width, d_height, d_play_cnt, d_like_cnt, d_share_cnt, d_send_time):
  67. """
  68. 下载视频的基本规则
  69. :param d_duration: 时长
  70. :param d_width: 宽
  71. :param d_height: 高
  72. :param d_play_cnt: 播放量
  73. :param d_like_cnt: 点赞量
  74. :param d_share_cnt: 分享量
  75. :param d_send_time: 发布时间
  76. :return: 满足规则,返回 True;反之,返回 False
  77. """
  78. # 视频时长
  79. if int(float(d_duration)) >= 40:
  80. # 宽或高
  81. if int(d_width) >= 0 or int(d_height) >= 0:
  82. # 播放量
  83. if int(d_play_cnt) >= 4000:
  84. # 点赞量
  85. if int(d_like_cnt) >= 0:
  86. # 分享量
  87. if int(d_share_cnt) >= 0:
  88. # 发布时间 <= 10 天
  89. if int(time.time()) - int(d_send_time) / 1000 <= 864000:
  90. return True
  91. else:
  92. return False
  93. else:
  94. return False
  95. else:
  96. return False
  97. else:
  98. return False
  99. return False
  100. return False
  101. # 检查是否有今日的上升榜日期
  102. @classmethod
  103. def check_hour_list_data(cls, log_type, date):
  104. # 判断J1单元格的日期是否为今天
  105. time.sleep(1)
  106. if Feishu.get_range_value(log_type, "xiaoniangao", "ba0da4", "L1:L1")[0] != date:
  107. # 插入3列 L1:N1,并写入日期和时间数据
  108. values = [[date], ["10:00", "15:00", "20:00"]]
  109. time.sleep(1)
  110. Feishu.insert_columns(log_type, "xiaoniangao", "ba0da4", "COLUMNS", 11, 14)
  111. time.sleep(1)
  112. Feishu.update_values(log_type, "xiaoniangao", "ba0da4", "L1:N2", values)
  113. time.sleep(1)
  114. Feishu.merge_cells(log_type, "xiaoniangao", "ba0da4", "L1:N1")
  115. Common.logger(log_type).info("插入今天日期成功")
  116. else:
  117. Common.logger(log_type).info("今日上升榜日期已存在")
  118. # 获取表情及符号
  119. @classmethod
  120. def get_expression(cls):
  121. expression_list = []
  122. char_list = []
  123. char_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "BhlbST")
  124. for i in range(len(char_sheet)):
  125. if char_sheet[i][0] is not None:
  126. expression_list.append(char_sheet[i][0])
  127. if char_sheet[i][1] is not None:
  128. char_list.append(char_sheet[i][1])
  129. # print(f"expression_list:{expression_list}")
  130. # print(f"char_list:{char_list}")
  131. return expression_list, char_list
  132. # 获取列表
  133. @classmethod
  134. def get_hour_list_feeds(cls, log_type):
  135. """
  136. 1.从列表获取视频,7 天内,播放量>=5000
  137. 2.时长 1-10min
  138. 3.每天10:00、15:00、20:00 把符合规则的视频,写入云文档
  139. https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=ba0da4
  140. """
  141. url = "https://kapi.xiaoniangao.cn/trends/get_recommend_trends"
  142. headers = {
  143. "x-b3-traceid": cls.hour_x_b3_traceid,
  144. "X-Token-Id": cls.hour_x_token_id,
  145. "uid": cls.hour_uid,
  146. "content-type": "application/json",
  147. "Accept-Encoding": "gzip,compress,br,deflate",
  148. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  149. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  150. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  151. "Referer": cls.hour_referer
  152. }
  153. data = {
  154. "log_params": {
  155. "page": "discover_rec",
  156. "common": {
  157. "brand": "iPhone",
  158. "device": "iPhone 11",
  159. "os": "iOS 14.7.1",
  160. "weixinver": "8.0.20",
  161. "srcver": "2.24.2",
  162. "net": "wifi",
  163. "scene": 1089
  164. }
  165. },
  166. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!750x500r/crop/750x500/interlace/1/format/jpg",
  167. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!80x80r/crop/80x80/interlace/1/format/jpg",
  168. "share_width": 625,
  169. "share_height": 500,
  170. "ext": {
  171. "fmid": 0,
  172. "items": {}
  173. },
  174. "app": "xng",
  175. "rec_scene": "discover_rec",
  176. "log_common_params": {
  177. "e": [{
  178. "data": {
  179. "page": "discoverIndexPage",
  180. "topic": "recommend"
  181. },
  182. "ab": {}
  183. }],
  184. "ext": {
  185. "brand": "iPhone",
  186. "device": "iPhone 11",
  187. "os": "iOS 14.7.1",
  188. "weixinver": "8.0.20",
  189. "srcver": "2.24.3",
  190. "net": "wifi",
  191. "scene": "1089"
  192. },
  193. "pj": "1",
  194. "pf": "2",
  195. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  196. },
  197. "refresh": False,
  198. "token": cls.hour_token,
  199. "uid": cls.hour_uid,
  200. "proj": "ma",
  201. "wx_ver": "8.0.20",
  202. "code_ver": "3.62.0"
  203. }
  204. try:
  205. urllib3.disable_warnings()
  206. r = requests.post(url=url, headers=headers, json=data, proxies=proxies, verify=False)
  207. if "data" not in r.json():
  208. Common.logger(log_type).warning("获取视频feeds错误:{}", r.text)
  209. elif "list" not in r.json()["data"]:
  210. Common.logger(log_type).warning("获取视频feeds无数据,休眠10s:{}", r.json()["data"])
  211. else:
  212. # 视频列表数据
  213. feeds = r.json()["data"]["list"]
  214. for i in range(len(feeds)):
  215. # 标题,表情随机加在片头、片尾,或替代句子中间的标点符号
  216. if "title" in feeds[i]:
  217. befor_video_title = feeds[i]["title"].strip().replace("\n", "") \
  218. .replace("/", "").replace("\r", "").replace("#", "") \
  219. .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
  220. .replace(":", "").replace("*", "").replace("?", "") \
  221. .replace("?", "").replace('"', "").replace("<", "") \
  222. .replace(">", "").replace("|", "").replace(" ", "").replace("#表情", "").replace("#符号", "")
  223. expression = cls.get_expression()
  224. expression_list = expression[0]
  225. char_list = expression[1]
  226. # print(f"expression_list:{expression_list}")
  227. # print(f"char_list:{char_list}")
  228. # 随机取一个表情
  229. expression = random.choice(expression_list)
  230. # print(f"expression:{expression}")
  231. # 生成标题list[表情+title, title+表情]
  232. expression_title_list = [expression + befor_video_title, befor_video_title + expression]
  233. # print(f"expression_title_list:{expression_title_list}")
  234. # 从标题list中随机取一个标题
  235. title_list1 = random.choice(expression_title_list)
  236. # print(f"title_list1:{title_list1}")
  237. # 生成标题:原标题+符号
  238. title_list2 = befor_video_title + random.choice(char_list)
  239. # print(f"befor_video_title:{befor_video_title}")
  240. # title_list3 = befor_video_title.replace(
  241. # ",", random.choice(expression_list)).replace(",", random.choice(expression_list))
  242. # 表情和标题组合,与标题和符号组合,汇总成待使用的标题列表
  243. title_list4 = [title_list2, title_list1]
  244. # print(f"title_list4:{title_list4}")
  245. # 最终标题
  246. video_title = random.choice(title_list4)
  247. # print(f"video_title:{video_title}\n")
  248. else:
  249. video_title = 0
  250. # 视频 ID
  251. if "vid" in feeds[i]:
  252. video_id = feeds[i]["vid"]
  253. else:
  254. video_id = 0
  255. # 播放量
  256. if "play_pv" in feeds[i]:
  257. video_play_cnt = feeds[i]["play_pv"]
  258. else:
  259. video_play_cnt = 0
  260. # 点赞量
  261. if "favor" in feeds[i]:
  262. video_like_cnt = feeds[i]["favor"]["total"]
  263. else:
  264. video_like_cnt = 0
  265. # 分享量
  266. if "share" in feeds[i]:
  267. video_share_cnt = feeds[i]["share"]
  268. else:
  269. video_share_cnt = 0
  270. # # 评论量
  271. # if "comment_count" in feeds[i]:
  272. # video_comment_cnt = feeds[i]["comment_count"]
  273. # else:
  274. # video_comment_cnt = 0
  275. # 时长
  276. if "du" in feeds[i]:
  277. video_duration = int(feeds[i]["du"] / 1000)
  278. else:
  279. video_duration = 0
  280. # 宽和高
  281. if "w" or "h" in feeds[i]:
  282. video_width = feeds[i]["w"]
  283. video_height = feeds[i]["h"]
  284. else:
  285. video_width = 0
  286. video_height = 0
  287. # 发布时间
  288. if "t" in feeds[i]:
  289. video_send_time = feeds[i]["t"]
  290. else:
  291. video_send_time = 0
  292. # 用户名 / 头像
  293. if "user" in feeds[i]:
  294. user_name = feeds[i]["user"]["nick"].strip().replace("\n", "") \
  295. .replace("/", "").replace("快手", "").replace(" ", "") \
  296. .replace(" ", "").replace("&NBSP", "").replace("\r", "")
  297. head_url = feeds[i]["user"]["hurl"]
  298. else:
  299. user_name = 0
  300. head_url = 0
  301. # 用户 ID
  302. profile_id = feeds[i]["id"]
  303. # 用户 mid
  304. profile_mid = feeds[i]["user"]["mid"]
  305. # 视频封面
  306. if "url" in feeds[i]:
  307. cover_url = feeds[i]["url"]
  308. else:
  309. cover_url = 0
  310. # 视频播放地址
  311. if "v_url" in feeds[i]:
  312. video_url = feeds[i]["v_url"]
  313. else:
  314. video_url = 0
  315. Common.logger(log_type).info("标题:{}", video_title)
  316. Common.logger(log_type).info("视频ID:{}", video_id)
  317. Common.logger(log_type).info("播放量:{}", video_play_cnt)
  318. # Common.logger(log_type).info("点赞量:{}", video_like_cnt)
  319. # Common.logger(log_type).info("分享量:{}", video_share_cnt)
  320. # Common.logger(log_type).info("评论数:{}", video_comment_cnt)
  321. Common.logger(log_type).info("时长:{}秒", video_duration)
  322. # Common.logger(log_type).info("宽高:{}*{}", video_width, video_height)
  323. Common.logger(log_type).info(
  324. "视频发布时间:{}", time.strftime(
  325. "%Y/%m/%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)))
  326. Common.logger(log_type).info("用户名:{}", user_name)
  327. # Common.logger(log_type).info("用户头像:{}", head_url)
  328. # Common.logger(log_type).info("封面:{}", cover_url)
  329. Common.logger(log_type).info("播放地址:{}", video_url)
  330. # 过滤无效视频
  331. if video_title == 0 or video_id == 0 or video_duration == 0 \
  332. or video_send_time == 0 or user_name == 0 or head_url == 0 \
  333. or cover_url == 0 or video_url == 0:
  334. Common.logger(log_type).warning("无效视频")
  335. elif cls.download_rule(video_duration, video_width, video_height, video_play_cnt,
  336. video_like_cnt, video_share_cnt, video_send_time) is False:
  337. Common.logger(log_type).info("不满足基础门槛规则")
  338. # 过滤敏感词
  339. elif any(word if word in video_title else False for word in cls.sensitive_words(log_type)) is True:
  340. Common.logger(log_type).info("视频已中敏感词:{}".format(video_title))
  341. time.sleep(1)
  342. # 从云文档中去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
  343. elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "yatRv2") for j in i]:
  344. Common.logger(log_type).info("该视频已下载:{}", video_title)
  345. time.sleep(1)
  346. # 从云文档中去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=2zD8cv
  347. elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "2zD8cv") for j in i]:
  348. Common.logger(log_type).info("该视频已下载:{}", video_title)
  349. time.sleep(1)
  350. # 从云文档去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=ba0da4
  351. elif video_id in [j for i in Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4") for j in i]:
  352. Common.logger(log_type).info("该视频已保存过:{}", video_title)
  353. time.sleep(1)
  354. else:
  355. Common.logger(log_type).info("该视频未下载,添加至feeds中:{}".format(video_title))
  356. # feeds工作表,插入空行
  357. time.sleep(1)
  358. Feishu.insert_columns(log_type, "xiaoniangao", "ba0da4", "ROWS", 2, 3)
  359. # 获取当前时间
  360. get_feeds_time = int(time.time())
  361. # 看一看云文档,工作表中写入数据
  362. values = [[profile_id,
  363. profile_mid,
  364. video_id,
  365. video_title,
  366. user_name,
  367. video_duration,
  368. cover_url,
  369. video_url,
  370. time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)),
  371. str(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(get_feeds_time))),
  372. video_play_cnt]]
  373. # 等待 1s,防止操作云文档太频繁,导致报错
  374. time.sleep(1)
  375. Feishu.update_values(log_type, "xiaoniangao", "ba0da4", "A3:K3", values)
  376. except Exception as e:
  377. Common.logger(log_type).error("获取小时榜视频列表异常:{}", e)
  378. # 更新小时榜数据
  379. @classmethod
  380. def update_hour_list_data(cls, log_type, today, yesterday, before_yesterday):
  381. """
  382. 更新小时榜数据
  383. """
  384. try:
  385. update_hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")
  386. if len(update_hour_sheet) == 2:
  387. Common.logger(log_type).info("当前工作表无数据")
  388. else:
  389. for i in range(2, len(update_hour_sheet) + 1):
  390. Common.logger(log_type).info("更新第:{}行视频信息", i + 1)
  391. # 略过空行
  392. if update_hour_sheet[i][0] is None \
  393. or update_hour_sheet[i][1] is None or update_hour_sheet[i][2] is None:
  394. Common.logger(log_type).info("空行,略过")
  395. else:
  396. # 视频标题
  397. v_title = update_hour_sheet[i][3]
  398. Common.logger(log_type).info("video_title:{}", v_title)
  399. # 视频 ID
  400. v_id = update_hour_sheet[i][2]
  401. Common.logger(log_type).info("video_id:{}", v_id)
  402. # profile_id,用户 ID
  403. p_id = update_hour_sheet[i][0]
  404. Common.logger(log_type).info("profile_id:{}", p_id)
  405. # profile_mid
  406. p_mid = update_hour_sheet[i][1]
  407. Common.logger(log_type).info("profile_mid:{}", p_mid)
  408. # 抓取时的播放量
  409. v_play_cnt = update_hour_sheet[i][10]
  410. Common.logger(log_type).info("video_play_cnt:{}", v_play_cnt)
  411. # 抓取时间
  412. v_upload_time = update_hour_sheet[i][9]
  413. Common.logger(log_type).info("video_send_time:{}", v_upload_time)
  414. # 抓取时间的时间戳格式(秒为单位)
  415. v_time = int(time.mktime(time.strptime(v_upload_time, "%Y/%m/%d %H:%M:%S")))
  416. # 抓取时间:日期
  417. upload_data = v_upload_time.split(" ")[0]
  418. # 抓取时间:小时
  419. upload_hour = v_upload_time.split(" ")[-1].split(":")[0]
  420. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  421. headers = {
  422. "x-b3-traceid": cls.hour_x_b3_traceid,
  423. "X-Token-Id": cls.hour_x_token_id,
  424. "uid": cls.hour_uid,
  425. "content-type": "application/json",
  426. "Accept-Encoding": "gzip,compress,br,deflate",
  427. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  428. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  429. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  430. "Referer": cls.hour_referer
  431. }
  432. data = {
  433. "play_src": "1",
  434. "profile_id": int(p_id),
  435. "profile_mid": int(p_mid),
  436. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  437. "!400x400r/crop/400x400/interlace/1/format/jpg",
  438. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  439. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  440. "share_width": 625,
  441. "share_height": 500,
  442. "no_comments": True,
  443. "no_follow": True,
  444. "vid": v_id,
  445. "hot_l1_comment": True,
  446. "token": cls.hour_token,
  447. "uid": cls.hour_uid,
  448. "proj": "ma",
  449. "wx_ver": "8.0.20",
  450. "code_ver": "3.62.0",
  451. "log_common_params": {
  452. "e": [{
  453. "data": {
  454. "page": "dynamicSharePage"
  455. }
  456. }],
  457. "ext": {
  458. "brand": "iPhone",
  459. "device": "iPhone 11",
  460. "os": "iOS 14.7.1",
  461. "weixinver": "8.0.20",
  462. "srcver": "2.24.3",
  463. "net": "wifi",
  464. "scene": "1089"
  465. },
  466. "pj": "1",
  467. "pf": "2",
  468. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  469. }
  470. }
  471. try:
  472. urllib3.disable_warnings()
  473. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  474. hour_play_cnt = r.json()["data"]["play_pv"]
  475. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  476. # 固定时间获取符合规则的视频,写入云文档:https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?sheet=ba0da4
  477. update_hour = datetime.datetime.now()
  478. if int(time.time()) - v_time >= 172800:
  479. Common.logger(log_type).info("抓取时间超过 2 天")
  480. return
  481. elif upload_data == today and update_hour.hour == 10 and int(upload_hour) <= 10:
  482. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:10点 and 抓取时间<=10点")
  483. # 当天 10:00 视频播放量
  484. ten_hour_play_cnt = hour_play_cnt
  485. Common.logger(log_type).info("当天 10:00 视频播放量:{}", ten_hour_play_cnt)
  486. # 10:00 的上升榜写入数据
  487. values = int(ten_hour_play_cnt) - int(v_play_cnt)
  488. time.sleep(1)
  489. Feishu.update_values(
  490. log_type, "xiaoniangao", "ba0da4",
  491. "L" + str(i + 1) + ":" + "L" + str(i + 1), [[values]])
  492. Common.logger(log_type).info("10:00数据更新成功:{}", values)
  493. elif upload_data == today and update_hour.hour == 15 and int(upload_hour) <= 10:
  494. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:15点 and 抓取时间<=10点")
  495. # 当天 15:00 视频播放量
  496. fifteen_hour_play_cnt = hour_play_cnt
  497. Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  498. # 当天 10:00 上升的数据
  499. if update_hour_sheet[i][11] is None:
  500. ten_up_cnt = 0
  501. else:
  502. ten_up_cnt = update_hour_sheet[i][11]
  503. # 15:00 的上升榜写入数据
  504. values = int(fifteen_hour_play_cnt) - (int(v_play_cnt) + int(ten_up_cnt))
  505. time.sleep(1)
  506. Feishu.update_values(
  507. log_type, "xiaoniangao", "ba0da4",
  508. "M" + str(i + 1) + ":" + "M" + str(i + 1), [[values]])
  509. Common.logger(log_type).info("15:00数据更新成功:{}", values)
  510. elif upload_data == today and update_hour.hour == 15 and 10 < int(upload_hour) <= 15:
  511. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:15点 and 10<抓取时间<=15点")
  512. # 当天 15:00 视频播放量
  513. fifteen_hour_play_cnt = hour_play_cnt
  514. Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  515. # 15:00 的上升榜写入数据
  516. values = int(fifteen_hour_play_cnt) - int(v_play_cnt)
  517. time.sleep(1)
  518. Feishu.update_values(
  519. log_type, "xiaoniangao", "ba0da4",
  520. "M" + str(i + 1) + ":" + "M" + str(i + 1), [[values]])
  521. Common.logger(log_type).info("15:00数据更新成功:{}", values)
  522. elif upload_data == today and update_hour.hour == 20 and int(upload_hour) <= 10:
  523. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 抓取时间<=10点")
  524. # 当天 20:00 视频播放量
  525. twenty_hour_play_cnt = hour_play_cnt
  526. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  527. # 当天 10:00 上升的数据
  528. if update_hour_sheet[i][11] is None:
  529. ten_up_cnt = 0
  530. else:
  531. ten_up_cnt = update_hour_sheet[i][11]
  532. # 当天 15:00 上升的数据
  533. if update_hour_sheet[i][12] is None:
  534. fifteen_up_cnt = 0
  535. else:
  536. fifteen_up_cnt = update_hour_sheet[i][12]
  537. # 20:00 的上升榜写入数据
  538. values = int(twenty_hour_play_cnt) - (
  539. int(v_play_cnt) + int(ten_up_cnt) + int(fifteen_up_cnt))
  540. time.sleep(1)
  541. Feishu.update_values(
  542. log_type, "xiaoniangao", "ba0da4",
  543. "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
  544. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  545. elif upload_data == today and update_hour.hour == 20 and 10 < int(upload_hour) <= 15:
  546. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 10<抓取时间<=15点")
  547. # 当天 20:00 视频播放量
  548. twenty_hour_play_cnt = hour_play_cnt
  549. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  550. # 当天 15:00 上升的数据
  551. if update_hour_sheet[i][12] is None:
  552. fifteen_up_cnt = 0
  553. else:
  554. fifteen_up_cnt = update_hour_sheet[i][12]
  555. # 20:00 的上升榜写入数据
  556. values = int(twenty_hour_play_cnt) - (int(v_play_cnt) + int(fifteen_up_cnt))
  557. time.sleep(1)
  558. Feishu.update_values(
  559. log_type, "xiaoniangao", "ba0da4",
  560. "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
  561. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  562. elif upload_data == today and update_hour.hour == 20 and 15 < int(upload_hour) <= 20:
  563. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 15<抓取时间<=20点")
  564. # 当天 20:00 视频播放量
  565. twenty_hour_play_cnt = hour_play_cnt
  566. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  567. # 20:00 的上升榜写入数据
  568. values = int(twenty_hour_play_cnt) - int(v_play_cnt)
  569. time.sleep(1)
  570. Feishu.update_values(
  571. log_type, "xiaoniangao", "ba0da4",
  572. "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
  573. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  574. elif (upload_data == yesterday or upload_data == before_yesterday) \
  575. and update_hour.hour == 10:
  576. Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:10点")
  577. # 当天 10:00 视频播放量
  578. ten_hour_play_cnt = hour_play_cnt
  579. Common.logger(log_type).info("当天 10:00 视频播放量:{}", ten_hour_play_cnt)
  580. # 10:00 的上升榜写入数据
  581. values = int(ten_hour_play_cnt) - int(v_play_cnt)
  582. time.sleep(1)
  583. Feishu.update_values(
  584. log_type, "xiaoniangao", "ba0da4",
  585. "L" + str(i + 1) + ":" + "L" + str(i + 1), [[values]])
  586. Common.logger(log_type).info("10:00数据更新成功:{}", values)
  587. elif (upload_data == yesterday or upload_data == before_yesterday) \
  588. and update_hour.hour == 15:
  589. Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:15点")
  590. # 当天 15:00 视频播放量
  591. fifteen_hour_play_cnt = hour_play_cnt
  592. Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  593. # 当天 10:00 上升的数据
  594. if update_hour_sheet[i][11] is None:
  595. ten_up_cnt = 0
  596. else:
  597. ten_up_cnt = update_hour_sheet[i][11]
  598. # 15:00 的上升榜写入数据
  599. values = int(fifteen_hour_play_cnt) - (int(v_play_cnt) + int(ten_up_cnt))
  600. time.sleep(1)
  601. Feishu.update_values(
  602. log_type, "xiaoniangao", "ba0da4",
  603. "M" + str(i + 1) + ":" + "M" + str(i + 1), [[values]])
  604. Common.logger(log_type).info("15:00数据更新成功:{}", values)
  605. elif (upload_data == yesterday or upload_data == before_yesterday) \
  606. and update_hour.hour == 20:
  607. Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:20点")
  608. # 当天 20:00 视频播放量
  609. twenty_hour_play_cnt = hour_play_cnt
  610. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  611. # 当天 10:00 上升的数据
  612. if update_hour_sheet[i][11] is None:
  613. ten_up_cnt = 0
  614. else:
  615. ten_up_cnt = update_hour_sheet[i][11]
  616. # 当天 15:00 上升的数据
  617. if update_hour_sheet[i][12] is None:
  618. fifteen_up_cnt = 0
  619. else:
  620. fifteen_up_cnt = update_hour_sheet[i][12]
  621. # 20:00 的上升榜写入数据
  622. values = int(twenty_hour_play_cnt) - (
  623. int(v_play_cnt) + int(ten_up_cnt) + int(fifteen_up_cnt))
  624. time.sleep(1)
  625. Feishu.update_values(
  626. log_type, "xiaoniangao", "ba0da4",
  627. "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
  628. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  629. except Exception as e:
  630. Common.logger(log_type).error("视频详情:{},异常:{}", v_title, e)
  631. except Exception as e:
  632. Common.logger(log_type).error("获取小时榜数据异常:{}", e)
  633. # 下载/上传
  634. @classmethod
  635. def download_and_publish(cls, log_type):
  636. """
  637. 1.从云文档中去重: https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
  638. 2.从云文档中下载符合规则的视频:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=ba0da4
  639. 2.1 当日 10:00 or 15:00 or 20:00 视频播放量上升 > 5000
  640. 2.2 当日 10:00 and 15:00 视频播放量上升 > 2000
  641. 2.3 当日 15:00 and 20:00 视频播放量上升 > 2000
  642. 2.4 昨日 20:00 and 今日 10:00 视频播放量上升 > 2000
  643. 3.上传
  644. """
  645. try:
  646. time.sleep(1)
  647. download_hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")
  648. if len(download_hour_sheet) == 2:
  649. Common.logger(log_type).info("当前工作表无数据")
  650. else:
  651. for i in range(2, len(download_hour_sheet) + 1):
  652. Common.logger(log_type).info("分析第:{}行视频信息是否符合下载规则", i + 1)
  653. # 略过空行
  654. if download_hour_sheet[i][0] is None \
  655. or download_hour_sheet[i][1] is None or download_hour_sheet[i][2] is None:
  656. Common.logger(log_type).info("空行,略过")
  657. else:
  658. # 今日 10:00 数据上升量
  659. if download_hour_sheet[i][11] is None:
  660. ten_cnt = 0
  661. else:
  662. ten_cnt = download_hour_sheet[i][11]
  663. # 今日 15:00 数据上升量
  664. if download_hour_sheet[i][12] is None:
  665. fifteen_cnt = 0
  666. else:
  667. fifteen_cnt = download_hour_sheet[i][12]
  668. # 今日 20:00 数据上升量
  669. if download_hour_sheet[i][13] is None:
  670. twenty_cnt = 0
  671. else:
  672. twenty_cnt = download_hour_sheet[i][13]
  673. # 昨日 20:00 数据上升量
  674. if download_hour_sheet[i][16] is None:
  675. yesterday_twenty_cnt = 0
  676. else:
  677. yesterday_twenty_cnt = download_hour_sheet[i][16]
  678. # 视频标题
  679. v_title = download_hour_sheet[i][3]
  680. Common.logger(log_type).info("video_title:{}", v_title)
  681. # 视频 ID
  682. v_id = download_hour_sheet[i][2]
  683. Common.logger(log_type).info("video_id:{}", v_id)
  684. # profile_id,用户 ID
  685. p_id = download_hour_sheet[i][0]
  686. # 视频时长
  687. v_duration = download_hour_sheet[i][5]
  688. # profile_mid
  689. p_mid = download_hour_sheet[i][1]
  690. Common.logger(log_type).info("10:00 / 15:00 / 20:00 上升量: {} / {} / {}",
  691. ten_cnt, fifteen_cnt, twenty_cnt)
  692. # 抓取时间
  693. v_upload_time = download_hour_sheet[i][9]
  694. v_send_time = int(time.mktime(time.strptime(v_upload_time, "%Y/%m/%d %H:%M:%S")))
  695. # 播放量
  696. v_play_cnt = download_hour_sheet[i][10]
  697. # # 判断视频 ID 长度,不大于 13 位
  698. # if len(str(v_id)) > 13:
  699. # Common.logger(log_type).info("视频ID长度大于13位:{}", v_id)
  700. #
  701. # el
  702. if int(time.time()) - int(v_send_time) >= 259200:
  703. Common.logger(log_type).info("抓取时间超过 3 天")
  704. return
  705. # 判断视频时长:1-10min
  706. elif int(v_duration) < 40:
  707. Common.logger(log_type).info("视频时长小于 40s")
  708. # # 过滤带字母的视频ID
  709. # elif any(word if word in v_id else False for word in cls.sensitive_videoid_words()) is True:
  710. # Common.logger(log_type).info("视频ID带字母:{}".format(v_id))
  711. # 从云文档中去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
  712. elif v_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "yatRv2") for j in i]:
  713. Common.logger(log_type).info("该视频已下载:{}", v_title)
  714. # 从云文档中去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
  715. elif v_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "2zD8cv") for j in i]:
  716. Common.logger(log_type).info("该视频已下载:{}", v_title)
  717. # 播放量大于 50000,直接下载
  718. elif int(v_play_cnt) >= 50000:
  719. Common.logger(log_type).info("播放量:{} >= 50000,满足下载规则,开始下载视频", v_play_cnt)
  720. try:
  721. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  722. headers = {
  723. "x-b3-traceid": cls.hour_x_b3_traceid,
  724. "X-Token-Id": cls.hour_x_token_id,
  725. "uid": cls.hour_uid,
  726. "content-type": "application/json",
  727. "Accept-Encoding": "gzip,compress,br,deflate",
  728. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  729. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  730. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  731. "Referer": cls.hour_referer
  732. }
  733. data = {
  734. "play_src": "1",
  735. "profile_id": int(p_id),
  736. "profile_mid": int(p_mid),
  737. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  738. "!400x400r/crop/400x400/interlace/1/format/jpg",
  739. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  740. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  741. "share_width": 625,
  742. "share_height": 500,
  743. "no_comments": True,
  744. "no_follow": True,
  745. "vid": v_id,
  746. "hot_l1_comment": True,
  747. "token": cls.hour_token,
  748. "uid": cls.hour_uid,
  749. "proj": "ma",
  750. "wx_ver": "8.0.20",
  751. "code_ver": "3.62.0",
  752. "log_common_params": {
  753. "e": [{
  754. "data": {
  755. "page": "dynamicSharePage"
  756. }
  757. }],
  758. "ext": {
  759. "brand": "iPhone",
  760. "device": "iPhone 11",
  761. "os": "iOS 14.7.1",
  762. "weixinver": "8.0.20",
  763. "srcver": "2.24.3",
  764. "net": "wifi",
  765. "scene": "1089"
  766. },
  767. "pj": "1",
  768. "pf": "2",
  769. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  770. }
  771. }
  772. urllib3.disable_warnings()
  773. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  774. hour_play_cnt = r.json()["data"]["play_pv"]
  775. hour_cover_url = r.json()["data"]["url"]
  776. hour_video_url = r.json()["data"]["v_url"]
  777. hour_video_duration = r.json()["data"]["du"]
  778. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  779. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  780. hour_video_share_cnt = r.json()["data"]["share"]
  781. hour_video_width = r.json()["data"]["w"]
  782. hour_video_height = r.json()["data"]["h"]
  783. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  784. hour_video_send_time = r.json()["data"]["t"]
  785. hour_user_name = r.json()["data"]["user"]["nick"]
  786. hour_head_url = r.json()["data"]["user"]["hurl"]
  787. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  788. # 下载封面
  789. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  790. # 下载视频
  791. Common.download_method(log_type, "video", v_title, hour_video_url)
  792. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  793. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  794. f_a.write(str(v_id) + "\n" +
  795. str(v_title) + "\n" +
  796. str(int(int(hour_video_duration) / 1000)) + "\n" +
  797. str(hour_play_cnt) + "\n" +
  798. str(hour_video_comment_cnt) + "\n" +
  799. str(hour_video_like_cnt) + "\n" +
  800. str(hour_video_share_cnt) + "\n" +
  801. str(hour_video_resolution) + "\n" +
  802. str(hour_video_send_time) + "\n" +
  803. str(hour_user_name) + "\n" +
  804. str(hour_head_url) + "\n" +
  805. str(hour_video_url) + "\n" +
  806. str(hour_cover_url) + "\n" +
  807. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  808. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  809. # 上传视频
  810. Common.logger(log_type).info("开始上传视频")
  811. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  812. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  813. our_video_id) + "/info"
  814. Common.logger(log_type).info("视频上传完成:{}", v_title)
  815. # 上传完成时间
  816. upload_time = int(time.time())
  817. # 保存视频信息到云文档
  818. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  819. # 插入空行
  820. time.sleep(1)
  821. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  822. # 视频信息写入云文档
  823. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  824. "小时级上升榜",
  825. v_id,
  826. v_title,
  827. our_video_link,
  828. hour_play_cnt,
  829. hour_video_comment_cnt,
  830. hour_video_like_cnt,
  831. hour_video_share_cnt,
  832. int(hour_video_duration) / 1000,
  833. hour_video_resolution,
  834. time.strftime("%Y/%m/%d %H:%M:%S",
  835. time.localtime(int(hour_video_send_time) / 1000)),
  836. hour_user_name,
  837. p_id,
  838. p_mid,
  839. hour_head_url,
  840. hour_cover_url,
  841. hour_video_url]]
  842. time.sleep(1)
  843. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  844. # 保存视频信息到监控表
  845. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  846. # 插入空行
  847. time.sleep(1)
  848. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  849. # 视频信息写入监控表
  850. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  851. v_id,
  852. v_title,
  853. our_video_link,
  854. p_id,
  855. p_mid,
  856. hour_user_name,
  857. int(hour_video_duration) / 1000,
  858. time.strftime("%Y/%m/%d %H:%M:%S",
  859. time.localtime(int(hour_video_send_time) / 1000)),
  860. hour_play_cnt]]
  861. time.sleep(1)
  862. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  863. except Exception as e:
  864. Common.logger(log_type).error("下载视频异常:{}", e)
  865. # 上升榜判断逻辑,任意时间段上升量>=5000,连续两个时间段上升量>=2000
  866. elif int(ten_cnt) >= 5000 or int(fifteen_cnt) >= 5000 or int(twenty_cnt) >= 5000:
  867. Common.logger(log_type).info("10:00 or 15:00 or 20:00 数据上升量:{} or {} or {} >= 5000",
  868. ten_cnt, fifteen_cnt, twenty_cnt)
  869. Common.logger(log_type).info("满足下载规则,开始下载视频")
  870. try:
  871. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  872. headers = {
  873. "x-b3-traceid": cls.hour_x_b3_traceid,
  874. "X-Token-Id": cls.hour_x_token_id,
  875. "uid": cls.hour_uid,
  876. "content-type": "application/json",
  877. "Accept-Encoding": "gzip,compress,br,deflate",
  878. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  879. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  880. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  881. "Referer": cls.hour_referer
  882. }
  883. data = {
  884. "play_src": "1",
  885. "profile_id": int(p_id),
  886. "profile_mid": int(p_mid),
  887. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  888. "!400x400r/crop/400x400/interlace/1/format/jpg",
  889. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  890. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  891. "share_width": 625,
  892. "share_height": 500,
  893. "no_comments": True,
  894. "no_follow": True,
  895. "vid": v_id,
  896. "hot_l1_comment": True,
  897. "token": cls.hour_token,
  898. "uid": cls.hour_uid,
  899. "proj": "ma",
  900. "wx_ver": "8.0.20",
  901. "code_ver": "3.62.0",
  902. "log_common_params": {
  903. "e": [{
  904. "data": {
  905. "page": "dynamicSharePage"
  906. }
  907. }],
  908. "ext": {
  909. "brand": "iPhone",
  910. "device": "iPhone 11",
  911. "os": "iOS 14.7.1",
  912. "weixinver": "8.0.20",
  913. "srcver": "2.24.3",
  914. "net": "wifi",
  915. "scene": "1089"
  916. },
  917. "pj": "1",
  918. "pf": "2",
  919. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  920. }
  921. }
  922. urllib3.disable_warnings()
  923. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  924. hour_play_cnt = r.json()["data"]["play_pv"]
  925. hour_cover_url = r.json()["data"]["url"]
  926. hour_video_url = r.json()["data"]["v_url"]
  927. hour_video_duration = r.json()["data"]["du"]
  928. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  929. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  930. hour_video_share_cnt = r.json()["data"]["share"]
  931. hour_video_width = r.json()["data"]["w"]
  932. hour_video_height = r.json()["data"]["h"]
  933. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  934. hour_video_send_time = r.json()["data"]["t"]
  935. hour_user_name = r.json()["data"]["user"]["nick"]
  936. hour_head_url = r.json()["data"]["user"]["hurl"]
  937. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  938. # 下载封面
  939. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  940. # 下载视频
  941. Common.download_method(log_type, "video", v_title, hour_video_url)
  942. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  943. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  944. f_a.write(str(v_id) + "\n" +
  945. str(v_title) + "\n" +
  946. str(int(int(hour_video_duration) / 1000)) + "\n" +
  947. str(hour_play_cnt) + "\n" +
  948. str(hour_video_comment_cnt) + "\n" +
  949. str(hour_video_like_cnt) + "\n" +
  950. str(hour_video_share_cnt) + "\n" +
  951. str(hour_video_resolution) + "\n" +
  952. str(hour_video_send_time) + "\n" +
  953. str(hour_user_name) + "\n" +
  954. str(hour_head_url) + "\n" +
  955. str(hour_video_url) + "\n" +
  956. str(hour_cover_url) + "\n" +
  957. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  958. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  959. # 上传视频
  960. Common.logger(log_type).info("开始上传视频")
  961. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  962. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  963. our_video_id) + "/info"
  964. Common.logger(log_type).info("视频上传完成:{}", v_title)
  965. # 上传完成时间
  966. upload_time = int(time.time())
  967. # 保存视频信息到云文档
  968. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  969. # 插入空行
  970. time.sleep(1)
  971. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  972. # 视频信息写入云文档
  973. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  974. "小时级上升榜",
  975. v_id,
  976. v_title,
  977. our_video_link,
  978. hour_play_cnt,
  979. hour_video_comment_cnt,
  980. hour_video_like_cnt,
  981. hour_video_share_cnt,
  982. int(hour_video_duration) / 1000,
  983. hour_video_resolution,
  984. time.strftime("%Y/%m/%d %H:%M:%S",
  985. time.localtime(int(hour_video_send_time) / 1000)),
  986. hour_user_name,
  987. p_id,
  988. p_mid,
  989. hour_head_url,
  990. hour_cover_url,
  991. hour_video_url]]
  992. time.sleep(1)
  993. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  994. # 保存视频信息到监控表
  995. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  996. # 插入空行
  997. time.sleep(1)
  998. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  999. # 视频信息写入监控表
  1000. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1001. v_id,
  1002. v_title,
  1003. our_video_link,
  1004. p_id,
  1005. p_mid,
  1006. hour_user_name,
  1007. int(hour_video_duration) / 1000,
  1008. time.strftime("%Y/%m/%d %H:%M:%S",
  1009. time.localtime(int(hour_video_send_time) / 1000)),
  1010. hour_play_cnt]]
  1011. time.sleep(1)
  1012. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  1013. except Exception as e:
  1014. Common.logger(log_type).error("下载视频异常:{}", e)
  1015. elif int(ten_cnt) >= 2000 and int(fifteen_cnt) >= 2000:
  1016. Common.logger(log_type).info(
  1017. "10:00 and 15:00 数据上升量:{} and {} >= 2000", ten_cnt, fifteen_cnt)
  1018. Common.logger(log_type).info("满足下载规则,开始下载视频")
  1019. try:
  1020. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  1021. headers = {
  1022. "x-b3-traceid": cls.hour_x_b3_traceid,
  1023. "X-Token-Id": cls.hour_x_token_id,
  1024. "uid": cls.hour_uid,
  1025. "content-type": "application/json",
  1026. "Accept-Encoding": "gzip,compress,br,deflate",
  1027. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  1028. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  1029. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  1030. "Referer": cls.hour_referer
  1031. }
  1032. data = {
  1033. "play_src": "1",
  1034. "profile_id": int(p_id),
  1035. "profile_mid": int(p_mid),
  1036. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  1037. "!400x400r/crop/400x400/interlace/1/format/jpg",
  1038. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  1039. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  1040. "share_width": 625,
  1041. "share_height": 500,
  1042. "no_comments": True,
  1043. "no_follow": True,
  1044. "vid": v_id,
  1045. "hot_l1_comment": True,
  1046. "token": cls.hour_token,
  1047. "uid": cls.hour_uid,
  1048. "proj": "ma",
  1049. "wx_ver": "8.0.20",
  1050. "code_ver": "3.62.0",
  1051. "log_common_params": {
  1052. "e": [{
  1053. "data": {
  1054. "page": "dynamicSharePage"
  1055. }
  1056. }],
  1057. "ext": {
  1058. "brand": "iPhone",
  1059. "device": "iPhone 11",
  1060. "os": "iOS 14.7.1",
  1061. "weixinver": "8.0.20",
  1062. "srcver": "2.24.3",
  1063. "net": "wifi",
  1064. "scene": "1089"
  1065. },
  1066. "pj": "1",
  1067. "pf": "2",
  1068. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  1069. }
  1070. }
  1071. urllib3.disable_warnings()
  1072. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  1073. hour_play_cnt = r.json()["data"]["play_pv"]
  1074. hour_cover_url = r.json()["data"]["url"]
  1075. hour_video_url = r.json()["data"]["v_url"]
  1076. hour_video_duration = r.json()["data"]["du"]
  1077. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  1078. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  1079. hour_video_share_cnt = r.json()["data"]["share"]
  1080. hour_video_width = r.json()["data"]["w"]
  1081. hour_video_height = r.json()["data"]["h"]
  1082. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  1083. hour_video_send_time = r.json()["data"]["t"]
  1084. hour_user_name = r.json()["data"]["user"]["nick"]
  1085. hour_head_url = r.json()["data"]["user"]["hurl"]
  1086. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  1087. # 下载封面
  1088. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  1089. # 下载视频
  1090. Common.download_method(log_type, "video", v_title, hour_video_url)
  1091. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  1092. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  1093. f_a.write(str(v_id) + "\n" +
  1094. str(v_title) + "\n" +
  1095. str(int(int(hour_video_duration) / 1000)) + "\n" +
  1096. str(hour_play_cnt) + "\n" +
  1097. str(hour_video_comment_cnt) + "\n" +
  1098. str(hour_video_like_cnt) + "\n" +
  1099. str(hour_video_share_cnt) + "\n" +
  1100. str(hour_video_resolution) + "\n" +
  1101. str(hour_video_send_time) + "\n" +
  1102. str(hour_user_name) + "\n" +
  1103. str(hour_head_url) + "\n" +
  1104. str(hour_video_url) + "\n" +
  1105. str(hour_cover_url) + "\n" +
  1106. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  1107. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  1108. # 上传
  1109. Common.logger(log_type).info("开始上传视频")
  1110. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  1111. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  1112. our_video_id) + "/info"
  1113. Common.logger(log_type).info("视频上传完成:{}", v_title)
  1114. # 上传完成时间
  1115. upload_time = int(time.time())
  1116. # 保存视频信息到云文档
  1117. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  1118. # 插入空行
  1119. time.sleep(1)
  1120. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  1121. # 视频信息写入云文档
  1122. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1123. "小时级上升榜",
  1124. v_id,
  1125. v_title,
  1126. our_video_link,
  1127. hour_play_cnt,
  1128. hour_video_comment_cnt,
  1129. hour_video_like_cnt,
  1130. hour_video_share_cnt,
  1131. int(hour_video_duration) / 1000,
  1132. hour_video_resolution,
  1133. time.strftime("%Y/%m/%d %H:%M:%S",
  1134. time.localtime(int(hour_video_send_time) / 1000)),
  1135. hour_user_name,
  1136. p_id,
  1137. p_mid,
  1138. hour_head_url,
  1139. hour_cover_url,
  1140. hour_video_url]]
  1141. time.sleep(1)
  1142. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  1143. # 保存视频信息到监控表
  1144. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  1145. # 插入空行
  1146. time.sleep(1)
  1147. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  1148. # 视频信息写入监控表
  1149. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1150. v_id,
  1151. v_title,
  1152. our_video_link,
  1153. p_id,
  1154. p_mid,
  1155. hour_user_name,
  1156. int(hour_video_duration) / 1000,
  1157. time.strftime("%Y/%m/%d %H:%M:%S",
  1158. time.localtime(int(hour_video_send_time) / 1000)),
  1159. hour_play_cnt]]
  1160. time.sleep(1)
  1161. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  1162. except Exception as e:
  1163. Common.logger(log_type).error("下载视频异常:{}", e)
  1164. elif int(fifteen_cnt) >= 2000 and int(twenty_cnt) >= 2000:
  1165. Common.logger(log_type).info(
  1166. "15:00 and 20:00 数据上升量:{} and {} >= 2000", fifteen_cnt, twenty_cnt)
  1167. Common.logger(log_type).info("满足下载规则,开始下载视频")
  1168. try:
  1169. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  1170. headers = {
  1171. "x-b3-traceid": cls.hour_x_b3_traceid,
  1172. "X-Token-Id": cls.hour_x_token_id,
  1173. "uid": cls.hour_uid,
  1174. "content-type": "application/json",
  1175. "Accept-Encoding": "gzip,compress,br,deflate",
  1176. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  1177. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  1178. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  1179. "Referer": cls.hour_referer
  1180. }
  1181. data = {
  1182. "play_src": "1",
  1183. "profile_id": int(p_id),
  1184. "profile_mid": int(p_mid),
  1185. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  1186. "!400x400r/crop/400x400/interlace/1/format/jpg",
  1187. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  1188. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  1189. "share_width": 625,
  1190. "share_height": 500,
  1191. "no_comments": True,
  1192. "no_follow": True,
  1193. "vid": v_id,
  1194. "hot_l1_comment": True,
  1195. "token": cls.hour_token,
  1196. "uid": cls.hour_uid,
  1197. "proj": "ma",
  1198. "wx_ver": "8.0.20",
  1199. "code_ver": "3.62.0",
  1200. "log_common_params": {
  1201. "e": [{
  1202. "data": {
  1203. "page": "dynamicSharePage"
  1204. }
  1205. }],
  1206. "ext": {
  1207. "brand": "iPhone",
  1208. "device": "iPhone 11",
  1209. "os": "iOS 14.7.1",
  1210. "weixinver": "8.0.20",
  1211. "srcver": "2.24.3",
  1212. "net": "wifi",
  1213. "scene": "1089"
  1214. },
  1215. "pj": "1",
  1216. "pf": "2",
  1217. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  1218. }
  1219. }
  1220. urllib3.disable_warnings()
  1221. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  1222. hour_play_cnt = r.json()["data"]["play_pv"]
  1223. hour_cover_url = r.json()["data"]["url"]
  1224. hour_video_url = r.json()["data"]["v_url"]
  1225. hour_video_duration = r.json()["data"]["du"]
  1226. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  1227. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  1228. hour_video_share_cnt = r.json()["data"]["share"]
  1229. hour_video_width = r.json()["data"]["w"]
  1230. hour_video_height = r.json()["data"]["h"]
  1231. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  1232. hour_video_send_time = r.json()["data"]["t"]
  1233. hour_user_name = r.json()["data"]["user"]["nick"]
  1234. hour_head_url = r.json()["data"]["user"]["hurl"]
  1235. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  1236. # 下载封面
  1237. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  1238. # 下载视频
  1239. Common.download_method(log_type, "video", v_title, hour_video_url)
  1240. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  1241. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  1242. f_a.write(str(v_id) + "\n" +
  1243. str(v_title) + "\n" +
  1244. str(int(int(hour_video_duration) / 1000)) + "\n" +
  1245. str(hour_play_cnt) + "\n" +
  1246. str(hour_video_comment_cnt) + "\n" +
  1247. str(hour_video_like_cnt) + "\n" +
  1248. str(hour_video_share_cnt) + "\n" +
  1249. str(hour_video_resolution) + "\n" +
  1250. str(hour_video_send_time) + "\n" +
  1251. str(hour_user_name) + "\n" +
  1252. str(hour_head_url) + "\n" +
  1253. str(hour_video_url) + "\n" +
  1254. str(hour_cover_url) + "\n" +
  1255. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  1256. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  1257. # 上传
  1258. Common.logger(log_type).info("开始上传视频")
  1259. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  1260. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  1261. our_video_id) + "/info"
  1262. Common.logger(log_type).info("视频上传完成:{}", v_title)
  1263. # 上传完成时间
  1264. upload_time = int(time.time())
  1265. # 保存视频信息到云文档
  1266. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  1267. # 插入空行
  1268. time.sleep(1)
  1269. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  1270. # 视频信息写入云文档
  1271. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1272. "小时级上升榜",
  1273. v_id,
  1274. v_title,
  1275. our_video_link,
  1276. hour_play_cnt,
  1277. hour_video_comment_cnt,
  1278. hour_video_like_cnt,
  1279. hour_video_share_cnt,
  1280. int(hour_video_duration) / 1000,
  1281. hour_video_resolution,
  1282. time.strftime("%Y/%m/%d %H:%M:%S",
  1283. time.localtime(int(hour_video_send_time) / 1000)),
  1284. hour_user_name,
  1285. p_id,
  1286. p_mid,
  1287. hour_head_url,
  1288. hour_cover_url,
  1289. hour_video_url]]
  1290. time.sleep(1)
  1291. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  1292. # 保存视频信息到监控表
  1293. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  1294. # 插入空行
  1295. time.sleep(1)
  1296. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  1297. # 视频信息写入监控表
  1298. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1299. v_id,
  1300. v_title,
  1301. our_video_link,
  1302. p_id,
  1303. p_mid,
  1304. hour_user_name,
  1305. int(hour_video_duration) / 1000,
  1306. time.strftime("%Y/%m/%d %H:%M:%S",
  1307. time.localtime(int(hour_video_send_time) / 1000)),
  1308. hour_play_cnt]]
  1309. time.sleep(1)
  1310. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  1311. except Exception as e:
  1312. Common.logger(log_type).error("下载视频异常:{}", e)
  1313. elif int(yesterday_twenty_cnt) >= 2000 and int(ten_cnt) >= 2000:
  1314. Common.logger(log_type).info("昨日20:00 and 今日10:00 数据上升量:{} and {} >= 2000",
  1315. yesterday_twenty_cnt, ten_cnt)
  1316. Common.logger(log_type).info("满足下载规则,开始下载视频")
  1317. try:
  1318. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  1319. headers = {
  1320. "x-b3-traceid": cls.hour_x_b3_traceid,
  1321. "X-Token-Id": cls.hour_x_token_id,
  1322. "uid": cls.hour_uid,
  1323. "content-type": "application/json",
  1324. "Accept-Encoding": "gzip,compress,br,deflate",
  1325. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  1326. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  1327. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  1328. "Referer": cls.hour_referer
  1329. }
  1330. data = {
  1331. "play_src": "1",
  1332. "profile_id": int(p_id),
  1333. "profile_mid": int(p_mid),
  1334. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  1335. "!400x400r/crop/400x400/interlace/1/format/jpg",
  1336. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  1337. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  1338. "share_width": 625,
  1339. "share_height": 500,
  1340. "no_comments": True,
  1341. "no_follow": True,
  1342. "vid": v_id,
  1343. "hot_l1_comment": True,
  1344. "token": cls.hour_token,
  1345. "uid": cls.hour_uid,
  1346. "proj": "ma",
  1347. "wx_ver": "8.0.20",
  1348. "code_ver": "3.62.0",
  1349. "log_common_params": {
  1350. "e": [{
  1351. "data": {
  1352. "page": "dynamicSharePage"
  1353. }
  1354. }],
  1355. "ext": {
  1356. "brand": "iPhone",
  1357. "device": "iPhone 11",
  1358. "os": "iOS 14.7.1",
  1359. "weixinver": "8.0.20",
  1360. "srcver": "2.24.3",
  1361. "net": "wifi",
  1362. "scene": "1089"
  1363. },
  1364. "pj": "1",
  1365. "pf": "2",
  1366. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  1367. }
  1368. }
  1369. urllib3.disable_warnings()
  1370. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  1371. hour_play_cnt = r.json()["data"]["play_pv"]
  1372. hour_cover_url = r.json()["data"]["url"]
  1373. hour_video_url = r.json()["data"]["v_url"]
  1374. hour_video_duration = r.json()["data"]["du"]
  1375. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  1376. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  1377. hour_video_share_cnt = r.json()["data"]["share"]
  1378. hour_video_width = r.json()["data"]["w"]
  1379. hour_video_height = r.json()["data"]["h"]
  1380. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  1381. hour_video_send_time = r.json()["data"]["t"]
  1382. hour_user_name = r.json()["data"]["user"]["nick"]
  1383. hour_head_url = r.json()["data"]["user"]["hurl"]
  1384. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  1385. # 下载封面
  1386. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  1387. # 下载视频
  1388. Common.download_method(log_type, "video", v_title, hour_video_url)
  1389. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  1390. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  1391. f_a.write(str(v_id) + "\n" +
  1392. str(v_title) + "\n" +
  1393. str(int(int(hour_video_duration) / 1000)) + "\n" +
  1394. str(hour_play_cnt) + "\n" +
  1395. str(hour_video_comment_cnt) + "\n" +
  1396. str(hour_video_like_cnt) + "\n" +
  1397. str(hour_video_share_cnt) + "\n" +
  1398. str(hour_video_resolution) + "\n" +
  1399. str(hour_video_send_time) + "\n" +
  1400. str(hour_user_name) + "\n" +
  1401. str(hour_head_url) + "\n" +
  1402. str(hour_video_url) + "\n" +
  1403. str(hour_cover_url) + "\n" +
  1404. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  1405. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  1406. # 上传
  1407. Common.logger(log_type).info("开始上传视频")
  1408. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  1409. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  1410. our_video_id) + "/info"
  1411. Common.logger(log_type).info("视频上传完成:{}", v_title)
  1412. # 上传完成时间
  1413. upload_time = int(time.time())
  1414. # 保存视频信息到云文档
  1415. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  1416. # 插入空行
  1417. time.sleep(1)
  1418. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  1419. # 视频信息写入云文档
  1420. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1421. "小时级上升榜",
  1422. v_id,
  1423. v_title,
  1424. our_video_link,
  1425. hour_play_cnt,
  1426. hour_video_comment_cnt,
  1427. hour_video_like_cnt,
  1428. hour_video_share_cnt,
  1429. int(hour_video_duration) / 1000,
  1430. hour_video_resolution,
  1431. time.strftime("%Y/%m/%d %H:%M:%S",
  1432. time.localtime(int(hour_video_send_time) / 1000)),
  1433. hour_user_name,
  1434. p_id,
  1435. p_mid,
  1436. hour_head_url,
  1437. hour_cover_url,
  1438. hour_video_url]]
  1439. time.sleep(1)
  1440. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  1441. # 保存视频信息到监控表
  1442. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  1443. # 插入空行
  1444. time.sleep(1)
  1445. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  1446. # 视频信息写入监控表
  1447. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1448. v_id,
  1449. v_title,
  1450. our_video_link,
  1451. p_id,
  1452. p_mid,
  1453. hour_user_name,
  1454. int(hour_video_duration) / 1000,
  1455. time.strftime("%Y/%m/%d %H:%M:%S",
  1456. time.localtime(int(hour_video_send_time) / 1000)),
  1457. hour_play_cnt]]
  1458. time.sleep(1)
  1459. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  1460. except Exception as e:
  1461. Common.logger(log_type).error("下载视频异常:{}", e)
  1462. else:
  1463. Common.logger(log_type).info("上升量不满足下载规则")
  1464. except Exception as e:
  1465. Common.logger(log_type).error("下载视频时,获取飞书信息异常:{}", e)
  1466. if __name__ == "__main__":
  1467. HourList.get_hour_list_feeds("hour")
  1468. # HourList.get_expression("hour")