shipinhao.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import json
  2. import random
  3. import time
  4. import requests
  5. from common import Common
  6. from common.sql_help import sqlCollect
  7. from data_channel.data_help import dataHelp
  8. class SPH:
  9. @classmethod
  10. def find_target_user(cls, name, user_list):
  11. """
  12. 在搜索到到账号列表中找目标列表
  13. """
  14. for obj in user_list:
  15. if obj['contact']["nickname"] == name:
  16. return obj
  17. else:
  18. continue
  19. return False
  20. @classmethod
  21. def get_account_id(cls, account_name):
  22. channel = 'shipinhao'
  23. history_id = sqlCollect.get_history_id(channel, account_name)
  24. if history_id:
  25. return history_id
  26. else:
  27. url = "http://61.48.133.26:30001/Find_Video_Content"
  28. payload = json.dumps({
  29. "content": account_name,
  30. "type": "19"
  31. })
  32. headers = {
  33. 'Content-Type': 'application/json'
  34. }
  35. response = requests.request("POST", url, headers=headers, data=payload)
  36. info_list = response.json()['info_list']
  37. if len(info_list) == 0:
  38. return False
  39. target_user = cls.find_target_user(name=account_name, user_list=info_list)
  40. # 写入 MySql 数据库
  41. if target_user:
  42. target = target_user['contact']['username']
  43. sqlCollect.insert_history_id(account_name, target, channel)
  44. return target_user['contact']["username"]
  45. else:
  46. return False
  47. @classmethod
  48. def get_sph_url(cls, task_mark, url, number, mark):
  49. account_id = cls.get_account_id(url)
  50. if account_id:
  51. url = "http://61.48.133.26:30001/FinderGetUpMasterNextPage"
  52. last_buffer = ""
  53. list = []
  54. for i in range(5):
  55. headers = {
  56. 'Content-Type': 'application/json'
  57. }
  58. payload = json.dumps({
  59. "username": account_id,
  60. "last_buffer": last_buffer
  61. })
  62. response = requests.request("POST", url, headers=headers, data=payload)
  63. time.sleep(random.randint(1, 5))
  64. if "objectId" not in response.text or response.status_code != 200:
  65. continue
  66. res_json = response.json()
  67. if len(res_json["UpMasterHomePage"]) == 0:
  68. continue
  69. if not res_json["UpMasterHomePage"]:
  70. continue
  71. else:
  72. last_buffer = res_json.get('last_buffer')
  73. for obj in res_json["UpMasterHomePage"]:
  74. objectId = obj['objectId']
  75. status = sqlCollect.is_used(task_mark, objectId, mark, "视频号")
  76. if status:
  77. objectNonceId = obj['objectNonceId']
  78. url = "http://61.48.133.26:30001/GetFinderDownloadAddress"
  79. payload = json.dumps({
  80. "objectId": objectId,
  81. "objectNonceId": objectNonceId
  82. })
  83. headers = {
  84. 'Content-Type': 'text/plain'
  85. }
  86. response = requests.request("POST", url, headers=headers, data=payload)
  87. time.sleep(random.randint(0, 1))
  88. video_obj = response.json()
  89. video_url = video_obj.get('DownloadAddress')
  90. share_cnt = int(obj['forward_count']) # 分享
  91. like_cnt = int(obj['like_count']) # 点赞
  92. old_title = video_obj.get('title').split("\n")[0].split("#")[0]
  93. if share_cnt < 500:
  94. Common.logger("sph").info(
  95. f"任务:{task_mark},用户主页id:{url},视频id{objectId} ,分享:{share_cnt},点赞:{like_cnt}")
  96. continue
  97. video_percent = '%.2f' % (share_cnt / like_cnt)
  98. special = float(0.25)
  99. if float(video_percent) < special:
  100. Common.logger("sph").info(
  101. f"任务:{task_mark},用户主页id:{url},视频id{objectId} ,分享:{share_cnt},点赞:{like_cnt}")
  102. continue
  103. duration = dataHelp.video_duration(video_url)
  104. if int(duration) >= 45:
  105. cover = video_obj.get('thumb_url')
  106. all_data = {"video_id": objectId, "cover": cover, "video_url": video_url, "rule": video_percent, "old_title": old_title}
  107. list.append(all_data)
  108. if len(list) == int(number):
  109. Common.logger("log").info(f"获取视频号视频总数:{len(list)}\n")
  110. return list
  111. else:
  112. Common.logger("sph").info(
  113. f"任务:{task_mark},用户主页id:{url},视频id{objectId} ,分享:{share_cnt},点赞:{like_cnt} ,时长:{duration} ")
  114. return list
  115. return []
  116. if __name__ == '__main__':
  117. SPH.get_sph_url('1',"霖霖觅影",'10','2')