123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- """
- @author: luojunhui
- """
- from datetime import datetime, timedelta
- import requests
- import json
- import oss2
- from uuid import uuid4
- def generate_daily_strings(start_date, end_date):
- """
- Generate daily date_str
- :param start_date:
- :param end_date:
- :return:
- """
- start = datetime.strptime(start_date, "%Y%m%d")
- end = datetime.strptime(end_date, "%Y%m%d")
- current = start
- date_strings = []
- while current <= end:
- date_strings.append(current.strftime("%Y%m%d"))
- current += timedelta(days=1)
- return date_strings
- def whisper(video_id):
- """
- input video_id, output video_text
- :param video_id:
- :return:
- """
- url = "http://61.48.133.26:5999/video_to_text"
- body = {
- "video_id": video_id
- }
- header = {
- "Content-Type": "application/json",
- }
- response = requests.post(
- url=url,
- json=body,
- headers=header
- )
- return response.json()
- def get_text(video_id):
- """
- input video_id, output video_text
- :param video_id:
- :return:
- """
- url = "http://localhost:8888/get_text"
- body = {
- "vid": video_id
- }
- header = {
- "Content-Type": "application/json",
- }
- response = requests.post(
- url=url,
- json=body,
- headers=header
- )
- return response.json()
- def auto_upload_aigc():
- """
- auto publish
- :return:
- """
- url = "http://aigc-api.cybertogether.net/aigc/crawler/plan/save"
- payload = json.dumps({
- "params": {
- "contentFilters": [],
- "accountFilters": [],
- "filterAccountMatchMode": 1,
- "filterContentMatchMode": 1,
- "selectModeValues": [],
- "imageSearchModeValues": [],
- "contentModal": 3,
- "analyze": {},
- "crawlerComment": 0,
- "inputGroup": [
- [
- {
- "inputValue": [
- {
- "fileName": "pqzf.png",
- "ossKey": "upload/03bf695277827c2387133a1ac9290fd2.png",
- "type": "image/png",
- "size": 2978
- }
- ],
- "fieldName": "cover",
- "fieldType": 1,
- "groupId": "fa9557a13208975a893777188f9e4b28"
- },
- {
- "fieldName": "title",
- "fieldType": 0,
- "groupId": "fa9557a13208975a893777188f9e4b28",
- "inputValue": "412412412"
- },
- {
- "fieldName": "content",
- "fieldType": 0,
- "groupId": "fa9557a13208975a893777188f9e4b28",
- "inputValue": "12312442"
- },
- {
- "fieldName": "image",
- "fieldType": 1,
- "groupId": "fa9557a13208975a893777188f9e4b28",
- "inputValue": [
- {
- "fileName": "lehuo.png",
- "ossKey": "upload/4bf6db57ccd1629909e070833aab8878.png",
- "type": "image/png",
- "size": 5085
- }
- ]
- },
- {
- "fieldName": "video",
- "fieldType": 2,
- "groupId": "fa9557a13208975a893777188f9e4b28"
- },
- {
- "fieldName": "audio",
- "fieldType": 3,
- "groupId": "fa9557a13208975a893777188f9e4b28"
- },
- {
- "fieldName": "tag",
- "fieldType": 0,
- "groupId": "fa9557a13208975a893777188f9e4b28"
- }
- ]
- ],
- "inputSourceGroups": [],
- "modePublishTime": [],
- "name": "junhui测试自动上传_by_python",
- "frequencyType": 3,
- "planType": 2
- },
- "baseInfo": {
- "token": "af54cdc404c3464d896745df389b2dce",
- "appType": 9,
- "platform": "pc",
- "appVersionCode": 1000,
- "clientTimestamp": 1,
- "fid": 1,
- "loginUid": 1,
- "pageSource": 1,
- "requestId": 1,
- "rid": 1,
- "uid": 1
- }
- })
- headers = {
- 'Accept': 'application/json',
- 'Accept-Language': 'en,zh;q=0.9,zh-CN;q=0.8',
- 'Content-Type': 'application/json',
- 'Origin': 'http://aigc-admin.cybertogether.net',
- 'Proxy-Connection': 'keep-alive',
- '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'
- }
- response = requests.request("POST", url, headers=headers, data=payload)
- print(response.text)
- def upload_to_oss(local_path):
- """
- 上传到oss
- :return:
- """
- oss_video_key = str(uuid4())
- access_key_id = "LTAIP6x1l3DXfSxm"
- access_key_secret = "KbTaM9ars4OX3PMS6Xm7rtxGr1FLon"
- endpoint = "oss-cn-hangzhou.aliyuncs.com"
- bucket_name = "art-pubbucket"
- bucket = oss2.Bucket(
- oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name
- )
- bucket.put_object_from_file(key=oss_video_key, filename=local_path)
- return oss_video_key
|