shipinhao.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import json
  2. import random
  3. import time
  4. import requests
  5. from common import Common, AliyunLogger
  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_id, number, mark, channel_id, name):
  49. account_id = cls.get_account_id(url_id)
  50. if account_id:
  51. url = "http://61.48.133.26:30001/FinderGetUpMasterNextPage"
  52. last_buffer = ""
  53. list = []
  54. for i in range(10):
  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. res_json = response.json()
  65. try:
  66. if len(res_json["DownloadAddress"]) == 0 or res_json["DownloadAddress"] == "" or res_json["DownloadAddress"] == None:
  67. return list
  68. except:
  69. pass
  70. if "objectId" not in response.text or response.status_code != 200:
  71. continue
  72. if len(res_json["UpMasterHomePage"]) == 0:
  73. continue
  74. if not res_json["UpMasterHomePage"]:
  75. continue
  76. else:
  77. last_buffer = res_json.get('last_buffer')
  78. for obj in res_json["UpMasterHomePage"]:
  79. objectId = obj['objectId']
  80. status = sqlCollect.is_used(task_mark, objectId, mark, "视频号")
  81. objectNonceId = obj['objectNonceId']
  82. url1 = "http://61.48.133.26:30001/GetFinderDownloadAddress"
  83. payload = json.dumps({
  84. "objectId": objectId,
  85. "objectNonceId": objectNonceId
  86. })
  87. headers = {
  88. 'Content-Type': 'text/plain'
  89. }
  90. response = requests.request("POST", url1, headers=headers, data=payload)
  91. time.sleep(random.randint(0, 1))
  92. video_obj = response.json()
  93. video_url = video_obj.get('DownloadAddress')
  94. share_cnt = int(obj['forward_count']) # 分享
  95. like_cnt = int(obj['like_count']) # 点赞
  96. old_title = video_obj.get('title').split("\n")[0].split("#")[0]
  97. duration = dataHelp.video_duration(video_url)
  98. log_data = f"user:{url_id},,video_id:{objectId},,video_url:{video_url},,original_title:{old_title},,share_count:{share_cnt},,like_count:{like_cnt},,duration:{duration}"
  99. AliyunLogger.logging(channel_id, name, url_id, objectId, "扫描到一条视频", "2001", log_data)
  100. Common.logger("sph").info(
  101. f"扫描:{task_mark},用户主页id:{url_id},视频id{objectId} ,分享:{share_cnt},点赞:{like_cnt}")
  102. if status:
  103. AliyunLogger.logging(channel_id, name, url_id, objectId, "该视频已改造过", "2001", log_data)
  104. continue
  105. video_percent = '%.2f' % (share_cnt / like_cnt)
  106. special = float(0.25)
  107. if like_cnt >= 30000 or like_cnt >= 50000 or (share_cnt >= 300 and float(video_percent) >= special):
  108. if int(duration) < 30 or int(duration) > 720:
  109. Common.logger("sph").info(
  110. f"任务:{task_mark},用户主页id:{url_id},视频id{objectId} ,分享:{share_cnt},点赞:{like_cnt} ,时长:{duration} ")
  111. AliyunLogger.logging(channel_id, name, url, objectId, "不符合规则:时长不符合规则大于720秒/小于30秒",
  112. "2003", log_data)
  113. continue
  114. cover = video_obj.get('thumb_url')
  115. AliyunLogger.logging(channel_id, name, url_id, objectId, "符合规则等待改造", "2004", log_data)
  116. all_data = {"video_id": objectId, "cover": cover, "video_url": video_url, "rule": video_percent, "old_title": old_title}
  117. list.append(all_data)
  118. if len(list) == int(number):
  119. Common.logger(mark).info(f"获取视频号视频总数:{len(list)}\n")
  120. return list
  121. else:
  122. AliyunLogger.logging(channel_id, name, url_id, objectId, "不符合规则:点赞小于30000/50000 或 分享/点赞小于0.25和分享小于300", "2003", log_data)
  123. Common.logger("sph").info(
  124. f"不符合规则:{task_mark},用户主页id:{url_id},视频id{objectId} ,分享:{share_cnt},点赞:{like_cnt}")
  125. continue
  126. return list
  127. return []
  128. if __name__ == '__main__':
  129. SPH.get_sph_url('1',"霖霖觅影",'10','2',"视频号",'视频号品类账号')