demo.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/5/16
  4. import datetime
  5. import time
  6. from datetime import timedelta
  7. import requests
  8. import urllib3
  9. proxies = {"http": None, "https": None}
  10. class Demo:
  11. # 查询视频详情的各项数据
  12. @classmethod
  13. def video_detail_info(cls, user_id, user_mid, video_id):
  14. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  15. headers = {
  16. "x-b3-traceid": "bd267349bf41b",
  17. "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
  18. "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
  19. "content-type": "application/json",
  20. "Accept-Encoding": "gzip,compress,br,deflate",
  21. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  22. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  23. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  24. "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
  25. }
  26. data = {
  27. "play_src": "1",
  28. "profile_id": int(user_id),
  29. "profile_mid": int(user_mid),
  30. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  31. "!400x400r/crop/400x400/interlace/1/format/jpg",
  32. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  33. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  34. "share_width": 625,
  35. "share_height": 500,
  36. "no_comments": True,
  37. "no_follow": True,
  38. "vid": video_id,
  39. "hot_l1_comment": True,
  40. "token": "90747742180aeb22c0fe3a3c6a38f3d9",
  41. "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
  42. "proj": "ma",
  43. "wx_ver": "8.0.20",
  44. "code_ver": "3.62.0",
  45. "log_common_params": {
  46. "e": [{
  47. "data": {
  48. "page": "dynamicSharePage"
  49. }
  50. }],
  51. "ext": {
  52. "brand": "iPhone",
  53. "device": "iPhone 11",
  54. "os": "iOS 14.7.1",
  55. "weixinver": "8.0.20",
  56. "srcver": "2.24.3",
  57. "net": "wifi",
  58. "scene": "1089"
  59. },
  60. "pj": "1",
  61. "pf": "2",
  62. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  63. }
  64. }
  65. try:
  66. urllib3.disable_warnings()
  67. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  68. video_title = r.json()["data"]["title"]
  69. video_id = r.json()["data"]["vid"]
  70. video_play_cnt = r.json()["data"]["play_pv"]
  71. video_duration = int(r.json()["data"]["du"])/1000
  72. video_url = r.json()["data"]["v_url"]
  73. video_send_time = r.json()["data"]["t"]
  74. print(f"video_title:{video_title}")
  75. print(f"video_id:{video_id}")
  76. print(f"video_play_cnt:{video_play_cnt}")
  77. print(f"video_duration:{video_duration}")
  78. print(f'video_send_time:{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time)/1000))}')
  79. print(f"video_url:{video_url}")
  80. except Exception as e:
  81. print(e)
  82. # 时间
  83. @classmethod
  84. def times(cls):
  85. before_yesterday = (datetime.date.today() + timedelta(days=-2)).strftime("%Y/%m/%d %H:%M:%S")
  86. before_yesterday = time.strptime(before_yesterday, "%Y/%m/%d %H:%M:%S")
  87. before_yesterday = int(time.mktime(before_yesterday))
  88. print(before_yesterday)
  89. print(type(before_yesterday))
  90. if __name__ == "__main__":
  91. demo = Demo()
  92. # demo.video_detail_info("44373353", "1161593420", "4572205769")
  93. # demo.times()
  94. print(1654744346-1654605576)