hour_list.py 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584
  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=ba0da4
  347. elif video_id in [j for i in Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4") for j in i]:
  348. Common.logger(log_type).info("该视频已保存过:{}", video_title)
  349. time.sleep(1)
  350. else:
  351. Common.logger(log_type).info("该视频未下载,添加至feeds中:{}".format(video_title))
  352. # feeds工作表,插入空行
  353. time.sleep(1)
  354. Feishu.insert_columns(log_type, "xiaoniangao", "ba0da4", "ROWS", 2, 3)
  355. # 获取当前时间
  356. get_feeds_time = int(time.time())
  357. # 看一看云文档,工作表中写入数据
  358. values = [[profile_id,
  359. profile_mid,
  360. video_id,
  361. video_title,
  362. user_name,
  363. video_duration,
  364. cover_url,
  365. video_url,
  366. time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)),
  367. str(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(get_feeds_time))),
  368. video_play_cnt]]
  369. # 等待 1s,防止操作云文档太频繁,导致报错
  370. time.sleep(1)
  371. Feishu.update_values(log_type, "xiaoniangao", "ba0da4", "A3:K3", values)
  372. # except Exception as e:
  373. # Common.logger(log_type).error("获取小时榜视频列表异常:{}", e)
  374. # 更新小时榜数据
  375. @classmethod
  376. def update_hour_list_data(cls, log_type, today, yesterday, before_yesterday):
  377. """
  378. 更新小时榜数据
  379. """
  380. try:
  381. update_hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")
  382. if len(update_hour_sheet) == 2:
  383. Common.logger(log_type).info("当前工作表无数据")
  384. else:
  385. for i in range(2, len(update_hour_sheet) + 1):
  386. Common.logger(log_type).info("更新第:{}行视频信息", i + 1)
  387. # 略过空行
  388. if update_hour_sheet[i][0] is None \
  389. or update_hour_sheet[i][1] is None or update_hour_sheet[i][2] is None:
  390. Common.logger(log_type).info("空行,略过")
  391. else:
  392. # 视频标题
  393. v_title = update_hour_sheet[i][3]
  394. Common.logger(log_type).info("video_title:{}", v_title)
  395. # 视频 ID
  396. v_id = update_hour_sheet[i][2]
  397. Common.logger(log_type).info("video_id:{}", v_id)
  398. # profile_id,用户 ID
  399. p_id = update_hour_sheet[i][0]
  400. Common.logger(log_type).info("profile_id:{}", p_id)
  401. # profile_mid
  402. p_mid = update_hour_sheet[i][1]
  403. Common.logger(log_type).info("profile_mid:{}", p_mid)
  404. # 抓取时的播放量
  405. v_play_cnt = update_hour_sheet[i][10]
  406. Common.logger(log_type).info("video_play_cnt:{}", v_play_cnt)
  407. # 抓取时间
  408. v_upload_time = update_hour_sheet[i][9]
  409. Common.logger(log_type).info("video_send_time:{}", v_upload_time)
  410. # 抓取时间的时间戳格式(秒为单位)
  411. v_time = int(time.mktime(time.strptime(v_upload_time, "%Y/%m/%d %H:%M:%S")))
  412. # 抓取时间:日期
  413. upload_data = v_upload_time.split(" ")[0]
  414. # 抓取时间:小时
  415. upload_hour = v_upload_time.split(" ")[-1].split(":")[0]
  416. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  417. headers = {
  418. "x-b3-traceid": cls.hour_x_b3_traceid,
  419. "X-Token-Id": cls.hour_x_token_id,
  420. "uid": cls.hour_uid,
  421. "content-type": "application/json",
  422. "Accept-Encoding": "gzip,compress,br,deflate",
  423. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  424. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  425. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  426. "Referer": cls.hour_referer
  427. }
  428. data = {
  429. "play_src": "1",
  430. "profile_id": int(p_id),
  431. "profile_mid": int(p_mid),
  432. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  433. "!400x400r/crop/400x400/interlace/1/format/jpg",
  434. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  435. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  436. "share_width": 625,
  437. "share_height": 500,
  438. "no_comments": True,
  439. "no_follow": True,
  440. "vid": v_id,
  441. "hot_l1_comment": True,
  442. "token": cls.hour_token,
  443. "uid": cls.hour_uid,
  444. "proj": "ma",
  445. "wx_ver": "8.0.20",
  446. "code_ver": "3.62.0",
  447. "log_common_params": {
  448. "e": [{
  449. "data": {
  450. "page": "dynamicSharePage"
  451. }
  452. }],
  453. "ext": {
  454. "brand": "iPhone",
  455. "device": "iPhone 11",
  456. "os": "iOS 14.7.1",
  457. "weixinver": "8.0.20",
  458. "srcver": "2.24.3",
  459. "net": "wifi",
  460. "scene": "1089"
  461. },
  462. "pj": "1",
  463. "pf": "2",
  464. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  465. }
  466. }
  467. try:
  468. urllib3.disable_warnings()
  469. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  470. hour_play_cnt = r.json()["data"]["play_pv"]
  471. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  472. # 固定时间获取符合规则的视频,写入云文档:https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?sheet=ba0da4
  473. update_hour = datetime.datetime.now()
  474. if int(time.time()) - v_time >= 172800:
  475. Common.logger(log_type).info("抓取时间超过 2 天")
  476. return
  477. elif upload_data == today and update_hour.hour == 10 and int(upload_hour) <= 10:
  478. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:10点 and 抓取时间<=10点")
  479. # 当天 10:00 视频播放量
  480. ten_hour_play_cnt = hour_play_cnt
  481. Common.logger(log_type).info("当天 10:00 视频播放量:{}", ten_hour_play_cnt)
  482. # 10:00 的上升榜写入数据
  483. values = int(ten_hour_play_cnt) - int(v_play_cnt)
  484. time.sleep(1)
  485. Feishu.update_values(
  486. log_type, "xiaoniangao", "ba0da4",
  487. "L" + str(i + 1) + ":" + "L" + str(i + 1), [[values]])
  488. Common.logger(log_type).info("10:00数据更新成功:{}", values)
  489. elif upload_data == today and update_hour.hour == 15 and int(upload_hour) <= 10:
  490. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:15点 and 抓取时间<=10点")
  491. # 当天 15:00 视频播放量
  492. fifteen_hour_play_cnt = hour_play_cnt
  493. Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  494. # 当天 10:00 上升的数据
  495. if update_hour_sheet[i][11] is None:
  496. ten_up_cnt = 0
  497. else:
  498. ten_up_cnt = update_hour_sheet[i][11]
  499. # 15:00 的上升榜写入数据
  500. values = int(fifteen_hour_play_cnt) - (int(v_play_cnt) + int(ten_up_cnt))
  501. time.sleep(1)
  502. Feishu.update_values(
  503. log_type, "xiaoniangao", "ba0da4",
  504. "M" + str(i + 1) + ":" + "M" + str(i + 1), [[values]])
  505. Common.logger(log_type).info("15:00数据更新成功:{}", values)
  506. elif upload_data == today and update_hour.hour == 15 and 10 < int(upload_hour) <= 15:
  507. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:15点 and 10<抓取时间<=15点")
  508. # 当天 15:00 视频播放量
  509. fifteen_hour_play_cnt = hour_play_cnt
  510. Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  511. # 15:00 的上升榜写入数据
  512. values = int(fifteen_hour_play_cnt) - int(v_play_cnt)
  513. time.sleep(1)
  514. Feishu.update_values(
  515. log_type, "xiaoniangao", "ba0da4",
  516. "M" + str(i + 1) + ":" + "M" + str(i + 1), [[values]])
  517. Common.logger(log_type).info("15:00数据更新成功:{}", values)
  518. elif upload_data == today and update_hour.hour == 20 and int(upload_hour) <= 10:
  519. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 抓取时间<=10点")
  520. # 当天 20:00 视频播放量
  521. twenty_hour_play_cnt = hour_play_cnt
  522. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  523. # 当天 10:00 上升的数据
  524. if update_hour_sheet[i][11] is None:
  525. ten_up_cnt = 0
  526. else:
  527. ten_up_cnt = update_hour_sheet[i][11]
  528. # 当天 15:00 上升的数据
  529. if update_hour_sheet[i][12] is None:
  530. fifteen_up_cnt = 0
  531. else:
  532. fifteen_up_cnt = update_hour_sheet[i][12]
  533. # 20:00 的上升榜写入数据
  534. values = int(twenty_hour_play_cnt) - (
  535. int(v_play_cnt) + int(ten_up_cnt) + int(fifteen_up_cnt))
  536. time.sleep(1)
  537. Feishu.update_values(
  538. log_type, "xiaoniangao", "ba0da4",
  539. "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
  540. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  541. elif upload_data == today and update_hour.hour == 20 and 10 < int(upload_hour) <= 15:
  542. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 10<抓取时间<=15点")
  543. # 当天 20:00 视频播放量
  544. twenty_hour_play_cnt = hour_play_cnt
  545. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  546. # 当天 15:00 上升的数据
  547. if update_hour_sheet[i][12] is None:
  548. fifteen_up_cnt = 0
  549. else:
  550. fifteen_up_cnt = update_hour_sheet[i][12]
  551. # 20:00 的上升榜写入数据
  552. values = int(twenty_hour_play_cnt) - (int(v_play_cnt) + int(fifteen_up_cnt))
  553. time.sleep(1)
  554. Feishu.update_values(
  555. log_type, "xiaoniangao", "ba0da4",
  556. "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
  557. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  558. elif upload_data == today and update_hour.hour == 20 and 15 < int(upload_hour) <= 20:
  559. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 15<抓取时间<=20点")
  560. # 当天 20:00 视频播放量
  561. twenty_hour_play_cnt = hour_play_cnt
  562. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  563. # 20:00 的上升榜写入数据
  564. values = int(twenty_hour_play_cnt) - int(v_play_cnt)
  565. time.sleep(1)
  566. Feishu.update_values(
  567. log_type, "xiaoniangao", "ba0da4",
  568. "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
  569. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  570. elif (upload_data == yesterday or upload_data == before_yesterday) \
  571. and update_hour.hour == 10:
  572. Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:10点")
  573. # 当天 10:00 视频播放量
  574. ten_hour_play_cnt = hour_play_cnt
  575. Common.logger(log_type).info("当天 10:00 视频播放量:{}", ten_hour_play_cnt)
  576. # 10:00 的上升榜写入数据
  577. values = int(ten_hour_play_cnt) - int(v_play_cnt)
  578. time.sleep(1)
  579. Feishu.update_values(
  580. log_type, "xiaoniangao", "ba0da4",
  581. "L" + str(i + 1) + ":" + "L" + str(i + 1), [[values]])
  582. Common.logger(log_type).info("10:00数据更新成功:{}", values)
  583. elif (upload_data == yesterday or upload_data == before_yesterday) \
  584. and update_hour.hour == 15:
  585. Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:15点")
  586. # 当天 15:00 视频播放量
  587. fifteen_hour_play_cnt = hour_play_cnt
  588. Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  589. # 当天 10:00 上升的数据
  590. if update_hour_sheet[i][11] is None:
  591. ten_up_cnt = 0
  592. else:
  593. ten_up_cnt = update_hour_sheet[i][11]
  594. # 15:00 的上升榜写入数据
  595. values = int(fifteen_hour_play_cnt) - (int(v_play_cnt) + int(ten_up_cnt))
  596. time.sleep(1)
  597. Feishu.update_values(
  598. log_type, "xiaoniangao", "ba0da4",
  599. "M" + str(i + 1) + ":" + "M" + str(i + 1), [[values]])
  600. Common.logger(log_type).info("15:00数据更新成功:{}", values)
  601. elif (upload_data == yesterday or upload_data == before_yesterday) \
  602. and update_hour.hour == 20:
  603. Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:20点")
  604. # 当天 20:00 视频播放量
  605. twenty_hour_play_cnt = hour_play_cnt
  606. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  607. # 当天 10:00 上升的数据
  608. if update_hour_sheet[i][11] is None:
  609. ten_up_cnt = 0
  610. else:
  611. ten_up_cnt = update_hour_sheet[i][11]
  612. # 当天 15:00 上升的数据
  613. if update_hour_sheet[i][12] is None:
  614. fifteen_up_cnt = 0
  615. else:
  616. fifteen_up_cnt = update_hour_sheet[i][12]
  617. # 20:00 的上升榜写入数据
  618. values = int(twenty_hour_play_cnt) - (
  619. int(v_play_cnt) + int(ten_up_cnt) + int(fifteen_up_cnt))
  620. time.sleep(1)
  621. Feishu.update_values(
  622. log_type, "xiaoniangao", "ba0da4",
  623. "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
  624. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  625. except Exception as e:
  626. Common.logger(log_type).error("视频详情:{},异常:{}", v_title, e)
  627. except Exception as e:
  628. Common.logger(log_type).error("获取小时榜数据异常:{}", e)
  629. # 下载/上传
  630. @classmethod
  631. def download_and_publish(cls, log_type):
  632. """
  633. 1.从云文档中去重: https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
  634. 2.从云文档中下载符合规则的视频:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=ba0da4
  635. 2.1 当日 10:00 or 15:00 or 20:00 视频播放量上升 > 5000
  636. 2.2 当日 10:00 and 15:00 视频播放量上升 > 2000
  637. 2.3 当日 15:00 and 20:00 视频播放量上升 > 2000
  638. 2.4 昨日 20:00 and 今日 10:00 视频播放量上升 > 2000
  639. 3.上传
  640. """
  641. try:
  642. time.sleep(1)
  643. download_hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")
  644. if len(download_hour_sheet) == 2:
  645. Common.logger(log_type).info("当前工作表无数据")
  646. else:
  647. for i in range(2, len(download_hour_sheet) + 1):
  648. Common.logger(log_type).info("分析第:{}行视频信息是否符合下载规则", i + 1)
  649. # 略过空行
  650. if download_hour_sheet[i][0] is None \
  651. or download_hour_sheet[i][1] is None or download_hour_sheet[i][2] is None:
  652. Common.logger(log_type).info("空行,略过")
  653. else:
  654. # 今日 10:00 数据上升量
  655. if download_hour_sheet[i][11] is None:
  656. ten_cnt = 0
  657. else:
  658. ten_cnt = download_hour_sheet[i][11]
  659. # 今日 15:00 数据上升量
  660. if download_hour_sheet[i][12] is None:
  661. fifteen_cnt = 0
  662. else:
  663. fifteen_cnt = download_hour_sheet[i][12]
  664. # 今日 20:00 数据上升量
  665. if download_hour_sheet[i][13] is None:
  666. twenty_cnt = 0
  667. else:
  668. twenty_cnt = download_hour_sheet[i][13]
  669. # 昨日 20:00 数据上升量
  670. if download_hour_sheet[i][16] is None:
  671. yesterday_twenty_cnt = 0
  672. else:
  673. yesterday_twenty_cnt = download_hour_sheet[i][16]
  674. # 视频标题
  675. v_title = download_hour_sheet[i][3]
  676. Common.logger(log_type).info("video_title:{}", v_title)
  677. # 视频 ID
  678. v_id = download_hour_sheet[i][2]
  679. Common.logger(log_type).info("video_id:{}", v_id)
  680. # profile_id,用户 ID
  681. p_id = download_hour_sheet[i][0]
  682. # 视频时长
  683. v_duration = download_hour_sheet[i][5]
  684. # profile_mid
  685. p_mid = download_hour_sheet[i][1]
  686. Common.logger(log_type).info("10:00 / 15:00 / 20:00 上升量: {} / {} / {}",
  687. ten_cnt, fifteen_cnt, twenty_cnt)
  688. # 抓取时间
  689. v_upload_time = download_hour_sheet[i][9]
  690. v_send_time = int(time.mktime(time.strptime(v_upload_time, "%Y/%m/%d %H:%M:%S")))
  691. # 播放量
  692. v_play_cnt = download_hour_sheet[i][10]
  693. # # 判断视频 ID 长度,不大于 13 位
  694. # if len(str(v_id)) > 13:
  695. # Common.logger(log_type).info("视频ID长度大于13位:{}", v_id)
  696. #
  697. # el
  698. if int(time.time()) - int(v_send_time) >= 259200:
  699. Common.logger(log_type).info("抓取时间超过 3 天")
  700. return
  701. # 判断视频时长:1-10min
  702. elif int(v_duration) < 40:
  703. Common.logger(log_type).info("视频时长小于 40s")
  704. # # 过滤带字母的视频ID
  705. # elif any(word if word in v_id else False for word in cls.sensitive_videoid_words()) is True:
  706. # Common.logger(log_type).info("视频ID带字母:{}".format(v_id))
  707. # 从云文档中去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
  708. elif v_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "yatRv2") for j in i]:
  709. Common.logger(log_type).info("该视频已下载:{}", v_title)
  710. # 播放量大于 100000,直接下载
  711. elif int(v_play_cnt) >= 100000:
  712. Common.logger(log_type).info("播放量:{} >= 100000,满足下载规则,开始下载视频", v_play_cnt)
  713. try:
  714. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  715. headers = {
  716. "x-b3-traceid": cls.hour_x_b3_traceid,
  717. "X-Token-Id": cls.hour_x_token_id,
  718. "uid": cls.hour_uid,
  719. "content-type": "application/json",
  720. "Accept-Encoding": "gzip,compress,br,deflate",
  721. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  722. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  723. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  724. "Referer": cls.hour_referer
  725. }
  726. data = {
  727. "play_src": "1",
  728. "profile_id": int(p_id),
  729. "profile_mid": int(p_mid),
  730. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  731. "!400x400r/crop/400x400/interlace/1/format/jpg",
  732. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  733. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  734. "share_width": 625,
  735. "share_height": 500,
  736. "no_comments": True,
  737. "no_follow": True,
  738. "vid": v_id,
  739. "hot_l1_comment": True,
  740. "token": cls.hour_token,
  741. "uid": cls.hour_uid,
  742. "proj": "ma",
  743. "wx_ver": "8.0.20",
  744. "code_ver": "3.62.0",
  745. "log_common_params": {
  746. "e": [{
  747. "data": {
  748. "page": "dynamicSharePage"
  749. }
  750. }],
  751. "ext": {
  752. "brand": "iPhone",
  753. "device": "iPhone 11",
  754. "os": "iOS 14.7.1",
  755. "weixinver": "8.0.20",
  756. "srcver": "2.24.3",
  757. "net": "wifi",
  758. "scene": "1089"
  759. },
  760. "pj": "1",
  761. "pf": "2",
  762. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  763. }
  764. }
  765. urllib3.disable_warnings()
  766. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  767. hour_play_cnt = r.json()["data"]["play_pv"]
  768. hour_cover_url = r.json()["data"]["url"]
  769. hour_video_url = r.json()["data"]["v_url"]
  770. hour_video_duration = r.json()["data"]["du"]
  771. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  772. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  773. hour_video_share_cnt = r.json()["data"]["share"]
  774. hour_video_width = r.json()["data"]["w"]
  775. hour_video_height = r.json()["data"]["h"]
  776. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  777. hour_video_send_time = r.json()["data"]["t"]
  778. hour_user_name = r.json()["data"]["user"]["nick"]
  779. hour_head_url = r.json()["data"]["user"]["hurl"]
  780. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  781. # 下载封面
  782. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  783. # 下载视频
  784. Common.download_method(log_type, "video", v_title, hour_video_url)
  785. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  786. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  787. f_a.write(str(v_id) + "\n" +
  788. str(v_title) + "\n" +
  789. str(int(int(hour_video_duration) / 1000)) + "\n" +
  790. str(hour_play_cnt) + "\n" +
  791. str(hour_video_comment_cnt) + "\n" +
  792. str(hour_video_like_cnt) + "\n" +
  793. str(hour_video_share_cnt) + "\n" +
  794. str(hour_video_resolution) + "\n" +
  795. str(hour_video_send_time) + "\n" +
  796. str(hour_user_name) + "\n" +
  797. str(hour_head_url) + "\n" +
  798. str(hour_video_url) + "\n" +
  799. str(hour_cover_url) + "\n" +
  800. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  801. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  802. # 上传视频
  803. Common.logger(log_type).info("开始上传视频")
  804. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  805. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  806. our_video_id) + "/info"
  807. Common.logger(log_type).info("视频上传完成:{}", v_title)
  808. # 上传完成时间
  809. upload_time = int(time.time())
  810. # 保存视频信息到云文档
  811. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  812. # 插入空行
  813. time.sleep(1)
  814. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  815. # 视频信息写入云文档
  816. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  817. "小时级上升榜",
  818. v_id,
  819. v_title,
  820. our_video_link,
  821. hour_play_cnt,
  822. hour_video_comment_cnt,
  823. hour_video_like_cnt,
  824. hour_video_share_cnt,
  825. int(hour_video_duration) / 1000,
  826. hour_video_resolution,
  827. time.strftime("%Y/%m/%d %H:%M:%S",
  828. time.localtime(int(hour_video_send_time) / 1000)),
  829. hour_user_name,
  830. p_id,
  831. p_mid,
  832. hour_head_url,
  833. hour_cover_url,
  834. hour_video_url]]
  835. time.sleep(1)
  836. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  837. # 保存视频信息到监控表
  838. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  839. # 插入空行
  840. time.sleep(1)
  841. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  842. # 视频信息写入监控表
  843. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  844. v_id,
  845. v_title,
  846. our_video_link,
  847. p_id,
  848. p_mid,
  849. hour_user_name,
  850. int(hour_video_duration) / 1000,
  851. time.strftime("%Y/%m/%d %H:%M:%S",
  852. time.localtime(int(hour_video_send_time) / 1000)),
  853. hour_play_cnt]]
  854. time.sleep(1)
  855. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  856. except Exception as e:
  857. Common.logger(log_type).error("下载视频异常:{}", e)
  858. # 上升榜判断逻辑,任意时间段上升量>=5000,连续两个时间段上升量>=2000
  859. elif int(ten_cnt) >= 5000 or int(fifteen_cnt) >= 5000 or int(twenty_cnt) >= 5000:
  860. Common.logger(log_type).info("10:00 or 15:00 or 20:00 数据上升量:{} or {} or {} >= 5000",
  861. ten_cnt, fifteen_cnt, twenty_cnt)
  862. Common.logger(log_type).info("满足下载规则,开始下载视频")
  863. try:
  864. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  865. headers = {
  866. "x-b3-traceid": cls.hour_x_b3_traceid,
  867. "X-Token-Id": cls.hour_x_token_id,
  868. "uid": cls.hour_uid,
  869. "content-type": "application/json",
  870. "Accept-Encoding": "gzip,compress,br,deflate",
  871. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  872. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  873. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  874. "Referer": cls.hour_referer
  875. }
  876. data = {
  877. "play_src": "1",
  878. "profile_id": int(p_id),
  879. "profile_mid": int(p_mid),
  880. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  881. "!400x400r/crop/400x400/interlace/1/format/jpg",
  882. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  883. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  884. "share_width": 625,
  885. "share_height": 500,
  886. "no_comments": True,
  887. "no_follow": True,
  888. "vid": v_id,
  889. "hot_l1_comment": True,
  890. "token": cls.hour_token,
  891. "uid": cls.hour_uid,
  892. "proj": "ma",
  893. "wx_ver": "8.0.20",
  894. "code_ver": "3.62.0",
  895. "log_common_params": {
  896. "e": [{
  897. "data": {
  898. "page": "dynamicSharePage"
  899. }
  900. }],
  901. "ext": {
  902. "brand": "iPhone",
  903. "device": "iPhone 11",
  904. "os": "iOS 14.7.1",
  905. "weixinver": "8.0.20",
  906. "srcver": "2.24.3",
  907. "net": "wifi",
  908. "scene": "1089"
  909. },
  910. "pj": "1",
  911. "pf": "2",
  912. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  913. }
  914. }
  915. urllib3.disable_warnings()
  916. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  917. hour_play_cnt = r.json()["data"]["play_pv"]
  918. hour_cover_url = r.json()["data"]["url"]
  919. hour_video_url = r.json()["data"]["v_url"]
  920. hour_video_duration = r.json()["data"]["du"]
  921. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  922. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  923. hour_video_share_cnt = r.json()["data"]["share"]
  924. hour_video_width = r.json()["data"]["w"]
  925. hour_video_height = r.json()["data"]["h"]
  926. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  927. hour_video_send_time = r.json()["data"]["t"]
  928. hour_user_name = r.json()["data"]["user"]["nick"]
  929. hour_head_url = r.json()["data"]["user"]["hurl"]
  930. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  931. # 下载封面
  932. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  933. # 下载视频
  934. Common.download_method(log_type, "video", v_title, hour_video_url)
  935. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  936. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  937. f_a.write(str(v_id) + "\n" +
  938. str(v_title) + "\n" +
  939. str(int(int(hour_video_duration) / 1000)) + "\n" +
  940. str(hour_play_cnt) + "\n" +
  941. str(hour_video_comment_cnt) + "\n" +
  942. str(hour_video_like_cnt) + "\n" +
  943. str(hour_video_share_cnt) + "\n" +
  944. str(hour_video_resolution) + "\n" +
  945. str(hour_video_send_time) + "\n" +
  946. str(hour_user_name) + "\n" +
  947. str(hour_head_url) + "\n" +
  948. str(hour_video_url) + "\n" +
  949. str(hour_cover_url) + "\n" +
  950. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  951. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  952. # 上传视频
  953. Common.logger(log_type).info("开始上传视频")
  954. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  955. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  956. our_video_id) + "/info"
  957. Common.logger(log_type).info("视频上传完成:{}", v_title)
  958. # 上传完成时间
  959. upload_time = int(time.time())
  960. # 保存视频信息到云文档
  961. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  962. # 插入空行
  963. time.sleep(1)
  964. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  965. # 视频信息写入云文档
  966. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  967. "小时级上升榜",
  968. v_id,
  969. v_title,
  970. our_video_link,
  971. hour_play_cnt,
  972. hour_video_comment_cnt,
  973. hour_video_like_cnt,
  974. hour_video_share_cnt,
  975. int(hour_video_duration) / 1000,
  976. hour_video_resolution,
  977. time.strftime("%Y/%m/%d %H:%M:%S",
  978. time.localtime(int(hour_video_send_time) / 1000)),
  979. hour_user_name,
  980. p_id,
  981. p_mid,
  982. hour_head_url,
  983. hour_cover_url,
  984. hour_video_url]]
  985. time.sleep(1)
  986. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  987. # 保存视频信息到监控表
  988. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  989. # 插入空行
  990. time.sleep(1)
  991. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  992. # 视频信息写入监控表
  993. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  994. v_id,
  995. v_title,
  996. our_video_link,
  997. p_id,
  998. p_mid,
  999. hour_user_name,
  1000. int(hour_video_duration) / 1000,
  1001. time.strftime("%Y/%m/%d %H:%M:%S",
  1002. time.localtime(int(hour_video_send_time) / 1000)),
  1003. hour_play_cnt]]
  1004. time.sleep(1)
  1005. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  1006. except Exception as e:
  1007. Common.logger(log_type).error("下载视频异常:{}", e)
  1008. elif int(ten_cnt) >= 2000 and int(fifteen_cnt) >= 2000:
  1009. Common.logger(log_type).info(
  1010. "10:00 and 15:00 数据上升量:{} and {} >= 2000", ten_cnt, fifteen_cnt)
  1011. Common.logger(log_type).info("满足下载规则,开始下载视频")
  1012. try:
  1013. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  1014. headers = {
  1015. "x-b3-traceid": cls.hour_x_b3_traceid,
  1016. "X-Token-Id": cls.hour_x_token_id,
  1017. "uid": cls.hour_uid,
  1018. "content-type": "application/json",
  1019. "Accept-Encoding": "gzip,compress,br,deflate",
  1020. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  1021. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  1022. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  1023. "Referer": cls.hour_referer
  1024. }
  1025. data = {
  1026. "play_src": "1",
  1027. "profile_id": int(p_id),
  1028. "profile_mid": int(p_mid),
  1029. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  1030. "!400x400r/crop/400x400/interlace/1/format/jpg",
  1031. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  1032. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  1033. "share_width": 625,
  1034. "share_height": 500,
  1035. "no_comments": True,
  1036. "no_follow": True,
  1037. "vid": v_id,
  1038. "hot_l1_comment": True,
  1039. "token": cls.hour_token,
  1040. "uid": cls.hour_uid,
  1041. "proj": "ma",
  1042. "wx_ver": "8.0.20",
  1043. "code_ver": "3.62.0",
  1044. "log_common_params": {
  1045. "e": [{
  1046. "data": {
  1047. "page": "dynamicSharePage"
  1048. }
  1049. }],
  1050. "ext": {
  1051. "brand": "iPhone",
  1052. "device": "iPhone 11",
  1053. "os": "iOS 14.7.1",
  1054. "weixinver": "8.0.20",
  1055. "srcver": "2.24.3",
  1056. "net": "wifi",
  1057. "scene": "1089"
  1058. },
  1059. "pj": "1",
  1060. "pf": "2",
  1061. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  1062. }
  1063. }
  1064. urllib3.disable_warnings()
  1065. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  1066. hour_play_cnt = r.json()["data"]["play_pv"]
  1067. hour_cover_url = r.json()["data"]["url"]
  1068. hour_video_url = r.json()["data"]["v_url"]
  1069. hour_video_duration = r.json()["data"]["du"]
  1070. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  1071. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  1072. hour_video_share_cnt = r.json()["data"]["share"]
  1073. hour_video_width = r.json()["data"]["w"]
  1074. hour_video_height = r.json()["data"]["h"]
  1075. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  1076. hour_video_send_time = r.json()["data"]["t"]
  1077. hour_user_name = r.json()["data"]["user"]["nick"]
  1078. hour_head_url = r.json()["data"]["user"]["hurl"]
  1079. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  1080. # 下载封面
  1081. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  1082. # 下载视频
  1083. Common.download_method(log_type, "video", v_title, hour_video_url)
  1084. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  1085. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  1086. f_a.write(str(v_id) + "\n" +
  1087. str(v_title) + "\n" +
  1088. str(int(int(hour_video_duration) / 1000)) + "\n" +
  1089. str(hour_play_cnt) + "\n" +
  1090. str(hour_video_comment_cnt) + "\n" +
  1091. str(hour_video_like_cnt) + "\n" +
  1092. str(hour_video_share_cnt) + "\n" +
  1093. str(hour_video_resolution) + "\n" +
  1094. str(hour_video_send_time) + "\n" +
  1095. str(hour_user_name) + "\n" +
  1096. str(hour_head_url) + "\n" +
  1097. str(hour_video_url) + "\n" +
  1098. str(hour_cover_url) + "\n" +
  1099. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  1100. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  1101. # 上传
  1102. Common.logger(log_type).info("开始上传视频")
  1103. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  1104. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  1105. our_video_id) + "/info"
  1106. Common.logger(log_type).info("视频上传完成:{}", v_title)
  1107. # 上传完成时间
  1108. upload_time = int(time.time())
  1109. # 保存视频信息到云文档
  1110. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  1111. # 插入空行
  1112. time.sleep(1)
  1113. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  1114. # 视频信息写入云文档
  1115. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1116. "小时级上升榜",
  1117. v_id,
  1118. v_title,
  1119. our_video_link,
  1120. hour_play_cnt,
  1121. hour_video_comment_cnt,
  1122. hour_video_like_cnt,
  1123. hour_video_share_cnt,
  1124. int(hour_video_duration) / 1000,
  1125. hour_video_resolution,
  1126. time.strftime("%Y/%m/%d %H:%M:%S",
  1127. time.localtime(int(hour_video_send_time) / 1000)),
  1128. hour_user_name,
  1129. p_id,
  1130. p_mid,
  1131. hour_head_url,
  1132. hour_cover_url,
  1133. hour_video_url]]
  1134. time.sleep(1)
  1135. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  1136. # 保存视频信息到监控表
  1137. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  1138. # 插入空行
  1139. time.sleep(1)
  1140. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  1141. # 视频信息写入监控表
  1142. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1143. v_id,
  1144. v_title,
  1145. our_video_link,
  1146. p_id,
  1147. p_mid,
  1148. hour_user_name,
  1149. int(hour_video_duration) / 1000,
  1150. time.strftime("%Y/%m/%d %H:%M:%S",
  1151. time.localtime(int(hour_video_send_time) / 1000)),
  1152. hour_play_cnt]]
  1153. time.sleep(1)
  1154. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  1155. except Exception as e:
  1156. Common.logger(log_type).error("下载视频异常:{}", e)
  1157. elif int(fifteen_cnt) >= 2000 and int(twenty_cnt) >= 2000:
  1158. Common.logger(log_type).info(
  1159. "15:00 and 20:00 数据上升量:{} and {} >= 2000", fifteen_cnt, twenty_cnt)
  1160. Common.logger(log_type).info("满足下载规则,开始下载视频")
  1161. try:
  1162. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  1163. headers = {
  1164. "x-b3-traceid": cls.hour_x_b3_traceid,
  1165. "X-Token-Id": cls.hour_x_token_id,
  1166. "uid": cls.hour_uid,
  1167. "content-type": "application/json",
  1168. "Accept-Encoding": "gzip,compress,br,deflate",
  1169. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  1170. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  1171. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  1172. "Referer": cls.hour_referer
  1173. }
  1174. data = {
  1175. "play_src": "1",
  1176. "profile_id": int(p_id),
  1177. "profile_mid": int(p_mid),
  1178. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  1179. "!400x400r/crop/400x400/interlace/1/format/jpg",
  1180. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  1181. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  1182. "share_width": 625,
  1183. "share_height": 500,
  1184. "no_comments": True,
  1185. "no_follow": True,
  1186. "vid": v_id,
  1187. "hot_l1_comment": True,
  1188. "token": cls.hour_token,
  1189. "uid": cls.hour_uid,
  1190. "proj": "ma",
  1191. "wx_ver": "8.0.20",
  1192. "code_ver": "3.62.0",
  1193. "log_common_params": {
  1194. "e": [{
  1195. "data": {
  1196. "page": "dynamicSharePage"
  1197. }
  1198. }],
  1199. "ext": {
  1200. "brand": "iPhone",
  1201. "device": "iPhone 11",
  1202. "os": "iOS 14.7.1",
  1203. "weixinver": "8.0.20",
  1204. "srcver": "2.24.3",
  1205. "net": "wifi",
  1206. "scene": "1089"
  1207. },
  1208. "pj": "1",
  1209. "pf": "2",
  1210. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  1211. }
  1212. }
  1213. urllib3.disable_warnings()
  1214. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  1215. hour_play_cnt = r.json()["data"]["play_pv"]
  1216. hour_cover_url = r.json()["data"]["url"]
  1217. hour_video_url = r.json()["data"]["v_url"]
  1218. hour_video_duration = r.json()["data"]["du"]
  1219. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  1220. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  1221. hour_video_share_cnt = r.json()["data"]["share"]
  1222. hour_video_width = r.json()["data"]["w"]
  1223. hour_video_height = r.json()["data"]["h"]
  1224. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  1225. hour_video_send_time = r.json()["data"]["t"]
  1226. hour_user_name = r.json()["data"]["user"]["nick"]
  1227. hour_head_url = r.json()["data"]["user"]["hurl"]
  1228. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  1229. # 下载封面
  1230. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  1231. # 下载视频
  1232. Common.download_method(log_type, "video", v_title, hour_video_url)
  1233. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  1234. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  1235. f_a.write(str(v_id) + "\n" +
  1236. str(v_title) + "\n" +
  1237. str(int(int(hour_video_duration) / 1000)) + "\n" +
  1238. str(hour_play_cnt) + "\n" +
  1239. str(hour_video_comment_cnt) + "\n" +
  1240. str(hour_video_like_cnt) + "\n" +
  1241. str(hour_video_share_cnt) + "\n" +
  1242. str(hour_video_resolution) + "\n" +
  1243. str(hour_video_send_time) + "\n" +
  1244. str(hour_user_name) + "\n" +
  1245. str(hour_head_url) + "\n" +
  1246. str(hour_video_url) + "\n" +
  1247. str(hour_cover_url) + "\n" +
  1248. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  1249. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  1250. # 上传
  1251. Common.logger(log_type).info("开始上传视频")
  1252. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  1253. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  1254. our_video_id) + "/info"
  1255. Common.logger(log_type).info("视频上传完成:{}", v_title)
  1256. # 上传完成时间
  1257. upload_time = int(time.time())
  1258. # 保存视频信息到云文档
  1259. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  1260. # 插入空行
  1261. time.sleep(1)
  1262. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  1263. # 视频信息写入云文档
  1264. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1265. "小时级上升榜",
  1266. v_id,
  1267. v_title,
  1268. our_video_link,
  1269. hour_play_cnt,
  1270. hour_video_comment_cnt,
  1271. hour_video_like_cnt,
  1272. hour_video_share_cnt,
  1273. int(hour_video_duration) / 1000,
  1274. hour_video_resolution,
  1275. time.strftime("%Y/%m/%d %H:%M:%S",
  1276. time.localtime(int(hour_video_send_time) / 1000)),
  1277. hour_user_name,
  1278. p_id,
  1279. p_mid,
  1280. hour_head_url,
  1281. hour_cover_url,
  1282. hour_video_url]]
  1283. time.sleep(1)
  1284. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  1285. # 保存视频信息到监控表
  1286. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  1287. # 插入空行
  1288. time.sleep(1)
  1289. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  1290. # 视频信息写入监控表
  1291. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1292. v_id,
  1293. v_title,
  1294. our_video_link,
  1295. p_id,
  1296. p_mid,
  1297. hour_user_name,
  1298. int(hour_video_duration) / 1000,
  1299. time.strftime("%Y/%m/%d %H:%M:%S",
  1300. time.localtime(int(hour_video_send_time) / 1000)),
  1301. hour_play_cnt]]
  1302. time.sleep(1)
  1303. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  1304. except Exception as e:
  1305. Common.logger(log_type).error("下载视频异常:{}", e)
  1306. elif int(yesterday_twenty_cnt) >= 2000 and int(ten_cnt) >= 2000:
  1307. Common.logger(log_type).info("昨日20:00 and 今日10:00 数据上升量:{} and {} >= 2000",
  1308. yesterday_twenty_cnt, ten_cnt)
  1309. Common.logger(log_type).info("满足下载规则,开始下载视频")
  1310. try:
  1311. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  1312. headers = {
  1313. "x-b3-traceid": cls.hour_x_b3_traceid,
  1314. "X-Token-Id": cls.hour_x_token_id,
  1315. "uid": cls.hour_uid,
  1316. "content-type": "application/json",
  1317. "Accept-Encoding": "gzip,compress,br,deflate",
  1318. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  1319. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  1320. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  1321. "Referer": cls.hour_referer
  1322. }
  1323. data = {
  1324. "play_src": "1",
  1325. "profile_id": int(p_id),
  1326. "profile_mid": int(p_mid),
  1327. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  1328. "!400x400r/crop/400x400/interlace/1/format/jpg",
  1329. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  1330. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  1331. "share_width": 625,
  1332. "share_height": 500,
  1333. "no_comments": True,
  1334. "no_follow": True,
  1335. "vid": v_id,
  1336. "hot_l1_comment": True,
  1337. "token": cls.hour_token,
  1338. "uid": cls.hour_uid,
  1339. "proj": "ma",
  1340. "wx_ver": "8.0.20",
  1341. "code_ver": "3.62.0",
  1342. "log_common_params": {
  1343. "e": [{
  1344. "data": {
  1345. "page": "dynamicSharePage"
  1346. }
  1347. }],
  1348. "ext": {
  1349. "brand": "iPhone",
  1350. "device": "iPhone 11",
  1351. "os": "iOS 14.7.1",
  1352. "weixinver": "8.0.20",
  1353. "srcver": "2.24.3",
  1354. "net": "wifi",
  1355. "scene": "1089"
  1356. },
  1357. "pj": "1",
  1358. "pf": "2",
  1359. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  1360. }
  1361. }
  1362. urllib3.disable_warnings()
  1363. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  1364. hour_play_cnt = r.json()["data"]["play_pv"]
  1365. hour_cover_url = r.json()["data"]["url"]
  1366. hour_video_url = r.json()["data"]["v_url"]
  1367. hour_video_duration = r.json()["data"]["du"]
  1368. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  1369. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  1370. hour_video_share_cnt = r.json()["data"]["share"]
  1371. hour_video_width = r.json()["data"]["w"]
  1372. hour_video_height = r.json()["data"]["h"]
  1373. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  1374. hour_video_send_time = r.json()["data"]["t"]
  1375. hour_user_name = r.json()["data"]["user"]["nick"]
  1376. hour_head_url = r.json()["data"]["user"]["hurl"]
  1377. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  1378. # 下载封面
  1379. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  1380. # 下载视频
  1381. Common.download_method(log_type, "video", v_title, hour_video_url)
  1382. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  1383. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  1384. f_a.write(str(v_id) + "\n" +
  1385. str(v_title) + "\n" +
  1386. str(int(int(hour_video_duration) / 1000)) + "\n" +
  1387. str(hour_play_cnt) + "\n" +
  1388. str(hour_video_comment_cnt) + "\n" +
  1389. str(hour_video_like_cnt) + "\n" +
  1390. str(hour_video_share_cnt) + "\n" +
  1391. str(hour_video_resolution) + "\n" +
  1392. str(hour_video_send_time) + "\n" +
  1393. str(hour_user_name) + "\n" +
  1394. str(hour_head_url) + "\n" +
  1395. str(hour_video_url) + "\n" +
  1396. str(hour_cover_url) + "\n" +
  1397. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  1398. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  1399. # 上传
  1400. Common.logger(log_type).info("开始上传视频")
  1401. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  1402. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  1403. our_video_id) + "/info"
  1404. Common.logger(log_type).info("视频上传完成:{}", v_title)
  1405. # 上传完成时间
  1406. upload_time = int(time.time())
  1407. # 保存视频信息到云文档
  1408. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  1409. # 插入空行
  1410. time.sleep(1)
  1411. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  1412. # 视频信息写入云文档
  1413. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1414. "小时级上升榜",
  1415. v_id,
  1416. v_title,
  1417. our_video_link,
  1418. hour_play_cnt,
  1419. hour_video_comment_cnt,
  1420. hour_video_like_cnt,
  1421. hour_video_share_cnt,
  1422. int(hour_video_duration) / 1000,
  1423. hour_video_resolution,
  1424. time.strftime("%Y/%m/%d %H:%M:%S",
  1425. time.localtime(int(hour_video_send_time) / 1000)),
  1426. hour_user_name,
  1427. p_id,
  1428. p_mid,
  1429. hour_head_url,
  1430. hour_cover_url,
  1431. hour_video_url]]
  1432. time.sleep(1)
  1433. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  1434. # 保存视频信息到监控表
  1435. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  1436. # 插入空行
  1437. time.sleep(1)
  1438. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  1439. # 视频信息写入监控表
  1440. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1441. v_id,
  1442. v_title,
  1443. our_video_link,
  1444. p_id,
  1445. p_mid,
  1446. hour_user_name,
  1447. int(hour_video_duration) / 1000,
  1448. time.strftime("%Y/%m/%d %H:%M:%S",
  1449. time.localtime(int(hour_video_send_time) / 1000)),
  1450. hour_play_cnt]]
  1451. time.sleep(1)
  1452. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  1453. except Exception as e:
  1454. Common.logger(log_type).error("下载视频异常:{}", e)
  1455. else:
  1456. Common.logger(log_type).info("上升量不满足下载规则")
  1457. except Exception as e:
  1458. Common.logger(log_type).error("下载视频时,获取飞书信息异常:{}", e)
  1459. if __name__ == "__main__":
  1460. HourList.get_hour_list_feeds("hour")
  1461. # HourList.get_expression("hour")