upload.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import oss2
  6. import requests
  7. from uuid import uuid4
  8. def auto_upload_aigc(title, text, img_list):
  9. """
  10. auto publish
  11. :return:
  12. """
  13. group_id = str(uuid4()).replace("-", "")
  14. url = "http://aigc-api.cybertogether.net/aigc/crawler/plan/save"
  15. payload = json.dumps({
  16. "params": {
  17. "contentFilters": [],
  18. "accountFilters": [],
  19. "filterAccountMatchMode": 1,
  20. "filterContentMatchMode": 1,
  21. "selectModeValues": [],
  22. "imageSearchModeValues": [],
  23. "contentModal": 3,
  24. "analyze": {},
  25. "crawlerComment": 0,
  26. "inputGroup": [
  27. [
  28. {
  29. "inputValue": [
  30. {
  31. "fileName": "pqzf.png",
  32. "ossKey": "upload/03bf695277827c2387133a1ac9290fd2.png",
  33. "type": "image/png",
  34. "size": 2978
  35. }
  36. ],
  37. "fieldName": "cover",
  38. "fieldType": 1,
  39. "groupId": group_id
  40. },
  41. {
  42. "fieldName": "title",
  43. "fieldType": 0,
  44. "groupId": group_id,
  45. "inputValue": title
  46. },
  47. {
  48. "fieldName": "content",
  49. "fieldType": 0,
  50. "groupId": group_id,
  51. "inputValue": text
  52. },
  53. {
  54. "fieldName": "image",
  55. "fieldType": 1,
  56. "groupId": group_id,
  57. "inputValue": img_list
  58. },
  59. {
  60. "fieldName": "video",
  61. "fieldType": 2,
  62. "groupId": group_id
  63. },
  64. {
  65. "fieldName": "audio",
  66. "fieldType": 3,
  67. "groupId": group_id
  68. },
  69. {
  70. "fieldName": "tag",
  71. "fieldType": 0,
  72. "groupId": group_id
  73. }
  74. ]
  75. ],
  76. "inputSourceGroups": [],
  77. "modePublishTime": [],
  78. "name": title,
  79. "frequencyType": 3,
  80. "planType": 2
  81. },
  82. "baseInfo": {
  83. "token": "af54cdc404c3464d896745df389b2dce",
  84. "appType": 9,
  85. "platform": "pc",
  86. "appVersionCode": 1000,
  87. "clientTimestamp": 1,
  88. "fid": 1,
  89. "loginUid": 1,
  90. "pageSource": 1,
  91. "requestId": 1,
  92. "rid": 1,
  93. "uid": 1
  94. }
  95. })
  96. headers = {
  97. 'Accept': 'application/json',
  98. 'Accept-Language': 'en,zh;q=0.9,zh-CN;q=0.8',
  99. 'Content-Type': 'application/json',
  100. 'Origin': 'http://aigc-admin.cybertogether.net',
  101. 'Proxy-Connection': 'keep-alive',
  102. 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36'
  103. }
  104. response = requests.request("POST", url, headers=headers, data=payload)
  105. print(response.text)
  106. def upload_to_oss(local_path):
  107. """
  108. 上传到oss
  109. :return:
  110. """
  111. oss_video_key = "upload/" + str(uuid4()) + ".png"
  112. access_key_id = "LTAI5tCHXiNx4sUVPTSrk3zD"
  113. access_key_secret = "BoTrog6kA2dsmp70VrReKC7ZQHjQ0F"
  114. endpoint = "oss-ap-southeast-1.aliyuncs.com"
  115. bucket_name = "aigc-admin"
  116. bucket = oss2.Bucket(
  117. oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name
  118. )
  119. bucket.put_object_from_file(key=oss_video_key, filename=local_path)
  120. return oss_video_key
  121. def download_image(img_path, image_url):
  122. """
  123. 下载视频
  124. :param img_path:
  125. :param image_url:
  126. :return:
  127. """
  128. res = requests.get(image_url)
  129. with open(img_path, "wb") as f:
  130. f.write(res.content)
  131. return img_path