functions.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. """
  2. @author: luojunhui
  3. """
  4. import time
  5. import json
  6. import random
  7. import hashlib
  8. from datetime import datetime, timedelta
  9. import uuid
  10. import requests
  11. import urllib.parse
  12. def request_for_info(video_id):
  13. """
  14. 请求数据
  15. :param video_id:
  16. :return:
  17. """
  18. url = "https://longvideoapi.piaoquantv.com/longvideoapi/openapi/video/batchSelectVideoInfo"
  19. data = {
  20. "videoIdList": [video_id]
  21. }
  22. header = {
  23. "Content-Type": "application/json",
  24. }
  25. response = requests.post(url, headers=header, data=json.dumps(data))
  26. return response.json()
  27. def generate_daily_strings(start_date, end_date):
  28. """
  29. Generate daily date_str
  30. :param start_date:
  31. :param end_date:
  32. :return:
  33. """
  34. start = datetime.strptime(start_date, "%Y%m%d")
  35. end = datetime.strptime(end_date, "%Y%m%d")
  36. current = start
  37. date_strings = []
  38. while current <= end:
  39. date_strings.append(current.strftime("%Y%m%d"))
  40. current += timedelta(days=1)
  41. return date_strings
  42. def whisper(video_id):
  43. """
  44. input video_id, output video_text
  45. :param video_id:
  46. :return:
  47. """
  48. url = "http://61.48.133.26:5999/video_to_text"
  49. body = {
  50. "video_id": video_id
  51. }
  52. header = {
  53. "Content-Type": "application/json",
  54. }
  55. response = requests.post(
  56. url=url,
  57. json=body,
  58. headers=header
  59. )
  60. return response.json()
  61. def get_text(video_id):
  62. """
  63. input video_id, output video_text
  64. :param video_id:
  65. :return:
  66. """
  67. url = "http://localhost:8888/get_text"
  68. body = {
  69. "vid": video_id
  70. }
  71. header = {
  72. "Content-Type": "application/json",
  73. }
  74. response = requests.post(
  75. url=url,
  76. json=body,
  77. headers=header
  78. )
  79. return response.json()
  80. def hash_title(title):
  81. """
  82. hash map
  83. :param title:
  84. :return:
  85. """
  86. # 创建md5哈希对象
  87. hash_object = hashlib.md5()
  88. # 对标题进行编码
  89. title_bytes = title.encode('utf-8')
  90. # 更新哈希对象
  91. hash_object.update(title_bytes)
  92. # 获取十六进制形式的哈希值
  93. hash_hex = hash_object.hexdigest()
  94. return hash_hex
  95. def create_gzh_path(video_id, shared_uid):
  96. """
  97. :param video_id: 视频 id
  98. :param shared_uid: 分享 id
  99. """
  100. def generate_source_id():
  101. """
  102. generate_source_id
  103. :return:
  104. """
  105. timestamp = str(int(time.time() * 1000))
  106. random_str = str(random.randint(1000, 9999))
  107. hash_input = f"{timestamp}-{random_str}"
  108. return hashlib.md5(hash_input.encode()).hexdigest()
  109. root_share_id = str(uuid.uuid4())
  110. source_id = "video_to_articles" + generate_source_id()
  111. url = f"pages/user-videos?id={video_id}&su={shared_uid}&fromGzh=1&rootShareId={root_share_id}&shareId={root_share_id}&rootSourceId={source_id}"
  112. # 自动把 root_share_id 加入到白名单
  113. # auto_white(root_share_id)
  114. return root_share_id, source_id, f"pages/category?jumpPage={urllib.parse.quote(url, safe='')}"