深夜提醒

现在是深夜,建议您注意休息,不要熬夜哦~

🏮 🏮 🏮

新年快乐

祝君万事如意心想事成!

2024 桐庐半程马拉松
00:00:00
时间
0.00
距离(公里)
--:--
配速
--
步频
--
心率 (bpm)
--
配速
步频
|
share-image
ESC

又拍云异步视频处理demo

开门见山,直接看代码吧!主要是几点,不管用什么语言

  • 第一,签名一定要计算对
  • 第二,参数不要错传,漏传
  • 第三,按照要求拼接
  • 第四,帐号密码不要错了
  • 第五,请求头一定要传时间、认证信息和文件类型

code

#!/usr/bin/python3
# -*-coding:utf-8-*-
import hashlib
import hmac
import base64
import datetime
import requests
import json
import urllib.parse



def b64(s):
return base64.b64encode(s.encode()).decode()


def httpdate_rfc1123(dt=None):
dt = dt or datetime.datetime.utcnow()
return datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')


def sign(username, password, method, uri, date):
signarr = [method, uri, date]
signstr = '&'.join(signarr)
signstr = base64.b64encode(
hmac.new(password.encode(), signstr.encode(), digestmod=hashlib.sha1).digest()
).decode()
return 'UPYUN %s:%s' % (username, signstr)


bucket = "file201503"
operator = "admin"
password = "123456"
password_md5 = hashlib.md5(password.encode()).hexdigest()

headers = {}
headers['Date'] = httpdate_rfc1123()
headers['Authorization'] = sign(operator, password_md5, 'POST', '/pretreatment/', headers['Date'])
headers['Content-Type'] = 'application/x-www-form-urlencoded'


def main():
tasks = {
"type": "video",
"avopts": "/s/240p(4:3)/as/1/r/30",
"return_info": True,
"save_as": "/a/b.mp4"
}
# print(tasks)
# {'type': 'video', 'save_as': '/a/b.mp4', 'return_info': True, 'avopts': '/s/240p(4:3)/as/1/r/30'}
data = {
'source': '/BBB/test.mp4',
'service': bucket,
'notify_url': 'http://lacewing.cc:8090/echo',
'accept': 'json',
'tasks': base64.b64encode(json.dumps([tasks]).encode()).decode()
}
# print(data)
# {'tasks': 'W3sidHlwZSI6ICJ2aWRlbyIsICJhdm9wdHMiOiAiL3MvMjQwcCg0OjMpL2FzLzEvci8zMCIsICJyZXR1cm5faW5mbyI6IHRydWUsICJzYXZlX2FzIjogIi9hL2IubXA0In1d', 'source': '/BBB/test.mp4', 'accept': 'json', 'service': 'file201503', 'notify_url': 'http://lacewing.cc:8090/echo'}
body = urllib.parse.urlencode(data)
# print(body)
# 得到的结果如下accept=json&source=%2FBBB%2Ftest.mp4&notify_url=http%3A%2F%2Flacewing.cc%3A8090%2Fecho&tasks=W3sicmV0dXJuX2luZm8iOiB0cnVlLCAidHlwZSI6ICJ2aWRlbyIsICJzYXZlX2FzIjogIi9hL2IubXA0IiwgImF2b3B0cyI6ICIvcy8yNDBwKDQ6MykvYXMvMS9yLzMwIn1d&service=file201503
response = requests.request("POST", "http://p0.api.upyun.com/pretreatment/", data=body, headers=headers)
print(response.text)


if __name__ == '__main__':
main()
文章作者:阿文
文章链接: https://www.awen.me/post/59441.html
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 阿文的博客
本文于 2017-08-23 20:49 发布,已超过半年(3126天),请注意甄别内容是否已过期。

评论

0 条评论
😀😃😄 😁😅😂 🤣😊😇 🙂🙃😉 😌😍🥰 😘😗😙 😚😋😛 😝😜🤪 🤨🧐🤓 😎🥸🤩 🥳😏😒 😞😔😟 😕🙁☹️ 😣😖😫 😩🥺😢 😭😤😠 😡🤬🤯 😳🥵🥶 😱😨😰 😥😓🤗 🤔🤭🤫 🤥😶😐 😑😬🙄 😯😦😧 😮😲🥱 😴🤤😪 😵🤐🥴 🤢🤮🤧 😷🤒🤕 🤑🤠😈 👿👹👺 🤡💩👻 💀☠️👽 👾🤖🎃 😺😸😹 😻😼😽 🙀😿😾 👍👎👏 🙌👐🤲 🤝🤜🤛 ✌️🤞🤟 🤘👌🤏 👈👉👆 👇☝️ 🤚🖐️🖖 👋🤙💪 🦾🖕✍️ 🙏💅🤳 💯💢💥 💫💦💨 🕳️💣💬 👁️‍🗨️🗨️🗯️ 💭💤❤️ 🧡💛💚 💙💜🖤 🤍🤎💔 ❣️💕💞 💓💗💖 💘💝💟 ☮️✝️☪️ 🕉️☸️✡️ 🔯🕎☯️ ☦️🛐 🆔⚛️🉑 ☢️☣️📴 📳🈶🈚 🈸🈺🈷️ ✴️🆚💮 🉐㊙️㊗️ 🈴🈵🈹 🈲🅰️🅱️ 🆎🆑🅾️ 🆘 🛑📛 🚫💯💢 ♨️🚷🚯 🚳🚱🔞 📵🚭 ‼️⁉️🔅 🔆〽️⚠️ 🚸🔱⚜️ 🔰♻️ 🈯💹❇️ ✳️🌐 💠Ⓜ️🌀 💤🏧🚾 🅿️🈳 🈂🛂🛃 🛄🛅🛗 🚀🛸🚁 🚉🚆🚅 ✈️🛫🛬 🛩️💺🛰️
您的评论由 AI 智能审核,一般1分钟内会展示,若不展示请确认你的评论是否符合社区和法律规范
加载中...

选择联系方式

留言反馈

😀😃😄 😁😅😂 🤣😊😇 🙂🙃😉 😌😍🥰 😘😗😙 😚😋😛 😝😜🤪 🤨🧐🤓 😎🥸🤩 🥳😏😒 😞😔😟 😕🙁☹️ 😣😖😫 😩🥺😢 😭😤😠 😡🤬🤯 😳🥵🥶 😱😨😰 😥😓🤗 🤔🤭🤫 🤥😶😐 😑😬🙄 😯😦😧 😮😲🥱 😴🤤😪 😵🤐🥴 🤢🤮🤧 😷🤒🤕 🤑🤠😈 👿👹👺 🤡💩👻 💀☠️👽 👾🤖🎃 😺😸😹 😻😼😽 🙀😿😾 👍👎👏 🙌👐🤲 🤝🤜🤛 ✌️🤞🤟 🤘👌🤏 👈👉👆 👇☝️ 🤚🖐️🖖 👋🤙💪 🦾🖕✍️ 🙏💅🤳 💯💢💥 💫💦💨 🕳️💣💬 👁️‍🗨️🗨️🗯️ 💭💤❤️ 🧡💛💚 💙💜🖤 🤍🤎💔 ❣️💕💞 💓💗💖 💘💝💟 ☮️✝️☪️ 🕉️☸️✡️ 🔯🕎☯️ ☦️🛐 🆔⚛️🉑 ☢️☣️📴 📳🈶🈚 🈸🈺🈷️ ✴️🆚💮 🉐㊙️㊗️ 🈴🈵🈹 🈲🅰️🅱️ 🆎🆑🅾️ 🆘 🛑📛 🚫💯💢 ♨️🚷🚯 🚳🚱🔞 📵🚭 ‼️⁉️🔅 🔆〽️⚠️ 🚸🔱⚜️ 🔰♻️ 🈯💹❇️ ✳️🌐 💠Ⓜ️🌀 💤🏧🚾 🅿️🈳 🈂🛂🛃 🛄🛅🛗 🚀🛸🚁 🚉🚆🚅 ✈️🛫🛬 🛩️💺🛰️