shengshengyingyin.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/1/3
  4. import json
  5. import os
  6. import sys
  7. import time
  8. import requests
  9. import urllib3
  10. sys.path.append(os.getcwd())
  11. from main.common import Common
  12. from main.feishu_lib import Feishu
  13. from main.shengshengyingyin_publish import Publish
  14. proxies = {'http': None, 'https':None}
  15. class Recommend:
  16. current = 1
  17. @classmethod
  18. def get_feeds(cls, log_type, crawler, oss_endpoint, env):
  19. while True:
  20. url = "https://videoflow-prd.zhufutv.vip/api/h5/video/video-main/get-list"
  21. payload = json.dumps({
  22. "current": int(cls.current),
  23. "size": 10,
  24. "data": {
  25. "miniappAppid": "wx67080d80855515b9",
  26. "version": "1"
  27. }
  28. })
  29. headers = {
  30. 'Host': 'videoflow-prd.zhufutv.vip',
  31. 'accept': '*/*',
  32. 'content-type': 'application/json',
  33. 'accept-language': 'zh-CN,zh-Hans;q=0.9',
  34. 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E217 MicroMessenger/6.8.0(0x16080000) NetType/WIFI Language/en Branch/Br_trunk MiniProgramEnv/Mac',
  35. 'referer': 'https://servicewechat.com/wx67080d80855515b9/7/page-frame.html'
  36. }
  37. urllib3.disable_warnings()
  38. response = requests.post(url=url, headers=headers, data=payload, verify=False, proxies=proxies)
  39. cls.current += 1
  40. if response.json()['code'] != 2000000:
  41. Common.logger(log_type).warning(f'response:{response.text}\n')
  42. elif len(response.json()['data']) == 0:
  43. Common.logger(log_type).info('没有更多了~\n')
  44. cls.current = 1
  45. return
  46. else:
  47. feeds = response.json()['data']
  48. for i in range(len(feeds)):
  49. # video_title
  50. if 'title' not in feeds[i]:
  51. video_title = 0
  52. else:
  53. video_title = feeds[i]['title']
  54. # video_id
  55. if 'no' not in feeds[i]:
  56. video_id = 0
  57. else:
  58. video_id = feeds[i]['no']
  59. # cover_url
  60. if 'coverUrl' not in feeds[i]:
  61. cover_url = 0
  62. else:
  63. cover_url = feeds[i]['coverUrl']
  64. # video_url
  65. if 'realUrl' not in feeds[i]:
  66. video_url = 0
  67. else:
  68. video_url = feeds[i]['realUrl']
  69. Common.logger(log_type).info(f'video_title:{video_title}')
  70. Common.logger(log_type).info(f'video_id:{video_id}')
  71. Common.logger(log_type).info(f'cover_url:{cover_url}')
  72. Common.logger(log_type).info(f'video_url:{video_url}')
  73. video_dict = {'video_title': video_title,
  74. 'video_id': video_id,
  75. 'cover_url': cover_url,
  76. 'video_url': video_url}
  77. cls.download_publish(log_type, crawler, video_dict, oss_endpoint, env)
  78. @classmethod
  79. def download_publish(cls, log_type, crawler, video_dict, oss_endpoint, env):
  80. video_id = video_dict['video_id']
  81. video_title = video_dict['video_title']
  82. cover_url = video_dict['cover_url']
  83. video_url = video_dict['video_url']
  84. if video_title == 0 or video_id == 0 or cover_url == 0 or video_url == 0:
  85. Common.logger(log_type).info('无效视频\n')
  86. elif video_id in [x for y in Feishu.get_values_batch(log_type, 'ssyy', '59f11d') for x in y]:
  87. Common.logger(log_type).info('视频已下载\n')
  88. else:
  89. # 下载
  90. Common.download_method(log_type, 'cover', video_title, cover_url)
  91. Common.download_method(log_type, 'video', video_title, video_url)
  92. with open("./videos/" + video_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  93. f_a.write(str(video_id) + "\n" +
  94. str(video_title) + "\n" +
  95. '300' + "\n" +
  96. '100000' + "\n" +
  97. '100000' + "\n" +
  98. '100000' + "\n" +
  99. '100000' + "\n" +
  100. '1920*1080' + "\n" +
  101. str(int(time.time())) + "\n" +
  102. '胜胜影音' + "\n" +
  103. str(cover_url) + "\n" +
  104. str(video_url) + "\n" +
  105. str(cover_url) + "\n" +
  106. "shengshengyingyin" + str(int(time.time())))
  107. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  108. # 上传
  109. our_video_id = Publish.upload_and_publish(log_type, crawler, oss_endpoint, env, 'recommend')
  110. if env == 'dev':
  111. our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
  112. else:
  113. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
  114. Common.logger(log_type).info("视频上传完成")
  115. # 视频信息写入飞书
  116. Feishu.insert_columns(log_type, 'ssyy', "59f11d", "ROWS", 1, 2)
  117. upload_time = int(time.time())
  118. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
  119. "推荐榜",
  120. video_title,
  121. video_id,
  122. our_video_link,
  123. cover_url,
  124. video_url]]
  125. time.sleep(1)
  126. Feishu.update_values(log_type, 'ssyy', "59f11d", "F2:Z2", values)
  127. Common.logger(log_type).info(f"视频已保存至云文档:{video_title}\n")
  128. if __name__ == '__main__':
  129. # 本地测试环境
  130. Recommend.get_feeds('recommend', 'ssyy', 'out', 'dev')
  131. # # 102 服务器正式环境
  132. # Recommend.get_feeds('recommend', 'ssyy', 'inner', 'prod')