shipinhao.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. class SPH:
  8. @classmethod
  9. def find_target_user(cls, name, user_list):
  10. """
  11. 在搜索到到账号列表中找目标列表
  12. """
  13. for obj in user_list:
  14. if obj['contact']["nickname"] == name:
  15. return obj
  16. else:
  17. continue
  18. return False
  19. @classmethod
  20. def get_account_id(cls, account_name):
  21. channel = 'shipinhao'
  22. history_id = sqlCollect.get_history_id(channel, account_name)
  23. if history_id:
  24. return history_id
  25. else:
  26. url = "http://61.48.133.26:30001/Find_Video_Content"
  27. payload = json.dumps({
  28. "content": account_name,
  29. "type": "19"
  30. })
  31. headers = {
  32. 'Content-Type': 'application/json'
  33. }
  34. response = requests.request("POST", url, headers=headers, data=payload)
  35. info_list = response.json()['info_list']
  36. if len(info_list) == 0:
  37. return False
  38. target_user = cls.find_target_user(name=account_name, user_list=info_list)
  39. # 写入 MySql 数据库
  40. if target_user:
  41. target = target_user['contact']['username']
  42. sqlCollect.insert_history_id(account_name, target, channel)
  43. return target_user['contact']["username"]
  44. else:
  45. return False
  46. @classmethod
  47. def get_sph_url(cls, task_mark, url, number, mark):
  48. account_id = cls.get_account_id(url)
  49. if account_id:
  50. url = "http://61.48.133.26:30001/FinderGetUpMasterNextPage"
  51. last_buffer = ""
  52. list = []
  53. for i in range(5):
  54. headers = {
  55. 'Content-Type': 'application/json'
  56. }
  57. payload = json.dumps({
  58. "username": account_id,
  59. "last_buffer": last_buffer
  60. })
  61. response = requests.request("POST", url, headers=headers, data=payload)
  62. time.sleep(random.randint(1, 5))
  63. if "objectId" not in response.text or response.status_code != 200:
  64. continue
  65. res_json = response.json()
  66. if len(res_json["UpMasterHomePage"]) == 0:
  67. continue
  68. if not res_json["UpMasterHomePage"]:
  69. continue
  70. else:
  71. last_buffer = res_json.get('last_buffer')
  72. for obj in res_json["UpMasterHomePage"]:
  73. objectId = obj['objectId']
  74. status = sqlCollect.is_used(task_mark, objectId, mark, "票圈")
  75. if status:
  76. objectNonceId = obj['objectNonceId']
  77. url = "http://61.48.133.26:30001/GetFinderDownloadAddress"
  78. payload = json.dumps({
  79. "objectId": objectId,
  80. "objectNonceId": objectNonceId
  81. })
  82. headers = {
  83. 'Content-Type': 'text/plain'
  84. }
  85. response = requests.request("POST", url, headers=headers, data=payload)
  86. time.sleep(random.randint(0, 1))
  87. video_obj = response.json()
  88. video_url = video_obj.get('DownloadAddress')
  89. cover = video_obj.get('thumb_url')
  90. all_data = {"video_id": objectId, "cover": cover, "video_url": video_url}
  91. list.append(all_data)
  92. if len(list) == int(number):
  93. Common.logger("log").info(f"获取视频号视频总数:{len(list)}\n")
  94. return list
  95. return list
  96. return []