快手批量上傳視頻軟件
快手批量上傳視頻軟件安裝教程
快手批量上傳視頻軟件,Python編寫的一個快手批量上傳視頻源碼,生成后即可獲得簡單的批量上傳工具,可以將視頻進行批量壓縮調(diào)整,能大幅節(jié)省上傳者的操作時間,下面給出快手批量上傳視頻軟件詳細的源碼說明,有需求的朋友們可以下載試試。
快手批量上傳視頻軟件介紹
獲取手機號->模擬登錄->獲取kuaishou.web.cp.api_ph->獲取上傳token->申請塊上傳文件->上傳文件->文件上傳完畢->發(fā)布視頻
發(fā)布視頻需要coverKey,fileId,kuaishou.web.cp.api_ph,這三個參數(shù)
coverKey和fileId是上傳文件完畢時獲取到的
kuaishou.web.cp.api_ph是登錄時獲到的
軟件特色
代替人工,無需人工值守,
幫助用戶批量自動上傳視頻
支持各種mp4視頻,可以自動adsl換ip操作
優(yōu)勢亮點
軟件自帶修改視頻(剪切和MD5功能)讓每個視頻都不重復
支持自由設置間隔時間,徹底解放雙手
不用守著電腦,自動批量上傳
源碼一覽
#coding:utf-8
import urllib
import urllib.request
import ssl
import http.cookiejar
import requests,json
import re
import time
import random
import os
from http.cookiejar import MozillaCookieJar
from urllib.request import urlopen
ssl._create_default_https_context=ssl._create_unverified_context
c=http.cookiejar.LWPCookieJar()#生成一個儲存cookie的對象
cookie=urllib.request.HTTPCookieProcessor(c)
opener=urllib.request.build_opener(cookie)#把這儲存器綁定到opener對象中
urllib.request.install_opener(opener)
定時=1#分鐘
header ={
'Referer':'https://cp.kuaishou.com/article/publish/video',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0'
}
def login():
# print("ccccc")
手機號=input('請輸入手機號:')
#獲取驗證碼
req=urllib.request.Request('https://id.kuaishou.com/pass/kuaishou/sms/requestMobileCode')
req.headers=header#模擬瀏覽器
data={
'sid':'kuaishou.web.cp.api',
'type':'53',
'countryCode':'+86',
'phone':手機號,
'ztIdentityVerificationType':"",
'ztIdentityVerificationCheckToken':""
}
data=urllib.parse.urlencode(data).encode('utf-8')
html=opener.open(req,data).read()#html會返回驗證碼成功或不成功
#print(html)
code=input('請輸入驗證碼:')
#驗證 驗證碼區(qū)
req=urllib.request.Request('https://id.kuaishou.com/pass/kuaishou/login/mobileCode')
req.headers=header#模擬瀏覽器
data={
'countryCode':'+86',
'sid':'kuaishou.web.cp.api',
'createId':'true',
'phone':手機號,
'smsCode':code
}
data=urllib.parse.urlencode(data).encode('utf-8')
html=opener.open(req,data).read()#html會返回驗證碼成功或不成功
#print(html)
#獲取kuaishou.web.cp.api.at
提取字符串=html.decode('utf-8')
# print(re.search('kuaishou.web.cp.api.at',提取字符串).span())
元組= re.search('kuaishou.web.cp.api.at',提取字符串).span()
list_str = list(提取字符串)
for num in range(0,元組[0]+25):
list_str.pop(0)
提取字符串 = ''.join(list_str)
元組= re.search('",',提取字符串).span()
list_str = list(提取字符串)
for num in range(元組[0],len(list_str)):
list_str.pop(元組[0])
提取字符串 = ''.join(list_str)
kuaishou_web_cp_api_at=提取字符串
# print(kuaishou_web_cp_api_at)
# print(取第一個數(shù))
# print(type(取第一個數(shù)))
# print(type(num))
隨機數(shù)=random.randint(0,9)
#獲取kuaishou.web.cp.api_ph
data={
'authToken':kuaishou_web_cp_api_at,
'sid':'kuaishou.web.cp.api'
}
data=json.dumps(data).encode()
header2 ={
'Connection':'keep-alive',
'Content-Length':len(data),
'EagleEye-pAppName':'e6zufio2qe@6aa9d0be6640ab'+str(隨機數(shù)),
'EagleEye-SessionID':'stk'+str(隨機數(shù))+'Lke6od75zahpCh3pq8nk99qR',
'Pragma':'no-cache',
'Referer':'https://passport.kuaishou.com/account/login/?sid=kuaishou.web.cp.api&redirectURL=https%3A%2F%2Fcp.kuaishou.com%2Fprofile',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0',
}
req=urllib.request.Request('https://passport.kuaishou.com/account/login/api/verifyToken',data=data,method='POST')
req.headers=header2#模擬瀏覽器
html=opener.open(req,data).read()#html會返回驗證碼成功或不成功
#print(html)
提取字符串=html.decode('utf-8')
元組= re.search('kuaishou.web.cp.api_ph',提取字符串).span()
list_str = list(提取字符串)
for num in range(0,元組[0]+25):
list_str.pop(0)
提取字符串 = ''.join(list_str)
元組= re.search('",',提取字符串).span()
list_str = list(提取字符串)
for num in range(元組[0],len(list_str)):
list_str.pop(元組[0])
提取字符串 = ''.join(list_str)
kuaishou_web_cp_api_ph=提取字符串
#print(kuaishou_web_cp_api_ph)
#html=urlopen(req,data)
# print(c)
# print(len(data))
# print(html.read().decode())
文件個數(shù) = 0
集合=set(())
for root, dirs, files in os.walk(r"."):
# root 表示當前正在訪問的文件夾路徑
# dirs 表示該文件夾下的子目錄名list
# files 表示該文件夾下的文件list
# 遍歷文件
for f in files:
字符串=re.search('.mp4',os.path.join(root, f))
if 字符串!=None:
集合.add(os.path.join(root, f))
文件個數(shù) += 1
# print(集合)
# print(os.path.join(root, f))
列表=list(集合)
print('一共有'+str(文件個數(shù))+'個視頻')
循環(huán)次數(shù)=0
while 循環(huán)次數(shù)<文件個數(shù):
循環(huán)次數(shù)=循環(huán)次數(shù)+1
time.sleep(60*定時)#秒
文件名=列表[0]
真與假=True
while 真與假:
元組= re.search(r'\\',文件名)
if 元組==None:
真與假=False
else:
list_str = list(文件名)
for num in range(0,元組.end()):
list_str.pop(0)
文件名 = ''.join(list_str)
print('正在上傳'+文件名)
#模擬上傳視頻
#1.獲取上傳token
data={
'kuaishou.web.cp.api_ph':kuaishou_web_cp_api_ph,
'uploadType':'1'
}
data=json.dumps(data).encode()
header3 ={
'Connection':'keep-alive',
'Content-Length':len(data),
'Content-Type':'application/json;charset=utf-8',
'Pragma':'no-cache',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0'
}
req=urllib.request.Request('https://cp.kuaishou.com/rest/cp/works/v2/video/pc/upload/pre',data=data,method='POST')
req.headers=header3#模擬瀏覽器
#data=urllib.parse.urlencode(data).encode('utf-8')
html=opener.open(req,data).read()#html會返回驗證碼成功或不成功
# print(html.decode('utf8'))
提取字符串=html.decode('utf-8')
元組= re.search('token',提取字符串).span()
list_str = list(提取字符串)
for num in range(0,元組[0]+8):
list_str.pop(0)
提取字符串 = ''.join(list_str)
元組= re.search('",',提取字符串).span()
list_str = list(提取字符串)
for num in range(元組[0],len(list_str)):
list_str.pop(元組[0])
提取字符串 = ''.join(list_str)
上傳token=提取字符串
# print(上傳token)
#2.https://upload.kuaishouzt.com/api/upload/resume #/api/上傳/恢復
req=urllib.request.Request('https://upload.kuaishouzt.com/api/upload/resume?upload_token='+上傳token)
req.headers=header#模擬瀏覽器
html=opener.open(req).read()#html會返回驗證碼成功或不成功
#print(html.decode('utf8'))
time.sleep(1)
#3.申請塊上傳文件
with open(列表[0],'rb') as f:
視頻數(shù)據(jù)二進制=f.read()
文件大小=len(視頻數(shù)據(jù)二進制)
文件大小2=文件大小
迭代次數(shù) = 0
最后一次文件大小=0
while (迭代次數(shù) < 100):
判斷是否為負=文件大小2-4194304
if 判斷是否為負 < 0:
#print(迭代次數(shù))
最后一次文件大小=文件大小2
# print(最后一次文件大小)
break
迭代次數(shù) = 迭代次數(shù) + 1
文件大小2=判斷是否為負
# print("迭代次數(shù)"+str(迭代次數(shù)))
if 迭代次數(shù)==0:
# print("進入迭代次數(shù)==0")
Content_Range='bytes 0-'+str(文件大小)+'/'+str(文件大小)
header_視頻上傳={
'Accept':'application/json, text/plain, */*',
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Connection':'keep-alive',
'Content-Length':len(視頻數(shù)據(jù)二進制),
'Content-Range':Content_Range,
'Content-Type':'application/octet-stream',
'Host':'upload.kuaishouzt.com',
'Origin':'https://cp.kuaishou.com',
'Referer':'https://cp.kuaishou.com/article/publish/video?origin=www.kuaishou.com',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0'
}
req=urllib.request.Request('https://upload.kuaishouzt.com/api/upload/fragment?upload_token='+上傳token+'&fragment_id=0',data=data,method='POST')
req.headers=header_視頻上傳#模擬瀏覽器
html=opener.open(req,視頻數(shù)據(jù)二進制).read()#html會返回驗證碼成功或不成功
# print(html.decode('utf8'))
else:
for i in range(0,迭代次數(shù)):
# print("i"+str(i))
if i==迭代次數(shù):
# print("進入最后上傳塊")
Content_Range='bytes '+str(迭代次數(shù)*4194304)+'-'+str(文件大小-1)+'/'+str(文件大小)
header_視頻上傳={
'Accept':'application/json, text/plain, */*',
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Connection':'keep-alive',
'Content-Length':最后一次文件大小,
'Content-Range':Content_Range,
'Content-Type':'application/octet-stream',
'Host':'upload.kuaishouzt.com',
'Origin':'https://cp.kuaishou.com',
'Referer':'https://cp.kuaishou.com/article/publish/video?origin=www.kuaishou.com',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0'
}
req=urllib.request.Request('https://upload.kuaishouzt.com/api/upload/fragment?upload_token='+上傳token+'&fragment_id='+str(迭代次數(shù)),data=data,method='POST')
req.headers=header_視頻上傳#模擬瀏覽器
文件切割=視頻數(shù)據(jù)二進制[迭代次數(shù)*4194304:文件大小]
# print("文件大小"+str(文件大小-迭代次數(shù)*4194304))
html=opener.open(req,文件切割).read()#html會返回驗證碼成功或不成功
else:
# print(str(i))
Content_Range='bytes '+str(i*4194304)+'-'+str((i+1)*4194304-1)+'/'+str(文件大小)
# Content_Range='bytes 0-4194303/11765090'
header_視頻上傳={
'Accept':'application/json, text/plain, */*',
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Connection':'keep-alive',
'Content-Length':4194304,
'Content-Range':Content_Range,
'Content-Type':'application/octet-stream',
'Host':'upload.kuaishouzt.com',
'Origin':'https://cp.kuaishou.com',
'Referer':'https://cp.kuaishou.com/article/publish/video?origin=www.kuaishou.com',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0'
}
req=urllib.request.Request('https://upload.kuaishouzt.com/api/upload/fragment?upload_token='+上傳token+'&fragment_id='+str(i),data=data,method='POST')
req.headers=header_視頻上傳#模擬瀏覽器
文件切割=視頻數(shù)據(jù)二進制[i*4194304:(i+1)*4194304]
html=opener.open(req,文件切割).read()#html會返回驗證碼成功或不成功
#print("11111111111"+html.decode('utf8'))
# print(len(data))
header_視頻上傳={
'Accept':'application/json, text/plain, */*',
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Connection':'keep-alive',
'Content-Length':'0',
'Host':'upload.kuaishouzt.com',
'Origin':'https://cp.kuaishou.com',
'Referer':'https://cp.kuaishou.com/article/publish/video?origin=www.kuaishou.com',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0'
}
req=urllib.request.Request('https://upload.kuaishouzt.com/api/upload/complete?fragment_count=1&upload_token='+上傳token,method='POST')
req.headers=header_視頻上傳#模擬瀏覽器
html=opener.open(req).read()#html會返回驗證碼成功或不成功
# print(html.decode('utf8'))
#3.文件上傳完畢
data={
'fileLength':文件大小,#文件大小
'fileName':文件名,#文件名稱
'fileType':'video/mp4',
'kuaishou.web.cp.api_ph':kuaishou_web_cp_api_ph,
'token':上傳token
}
data=json.dumps(data).encode()
header3 ={
'Connection':'keep-alive',
'Content-Length':len(data),
'Content-Type':'application/json;charset=utf-8',
'Pragma':'no-cache',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0'
}
req=urllib.request.Request('https://cp.kuaishou.com/rest/cp/works/v2/video/pc/upload/finish',data=data,method='POST')
req.headers=header3#模擬瀏覽器
html=opener.open(req,data).read()#html會返回驗證碼成功或不成功
# print(html.decode('utf8'))
提取字符串=html.decode('utf-8')
元組= re.search('coverKey',提取字符串).span()
list_str = list(提取字符串)
for num in range(0,元組[0]+8+3):
list_str.pop(0)
提取字符串 = ''.join(list_str)
元組= re.search('",',提取字符串).span()
list_str = list(提取字符串)
for num in range(元組[0],len(list_str)):
list_str.pop(元組[0])
提取字符串 = ''.join(list_str)
coverKey=提取字符串
#print(coverKey)
提取字符串=html.decode('utf-8')
元組= re.search('fileId',提取字符串).span()
list_str = list(提取字符串)
for num in range(0,元組[0]+6+2):
list_str.pop(0)
提取字符串 = ''.join(list_str)
元組= re.search(',"',提取字符串).span()
list_str = list(提取字符串)
for num in range(元組[0],len(list_str)):
list_str.pop(元組[0])
提取字符串 = ''.join(list_str)
fileId=提取字符串
# print(fileId)
#發(fā)布視頻
data={
'caption':"",
'collectionId':"",
'coverCenterX':"",
'coverCenterY':"",
'coverCropped':'false',
'coverKey':coverKey,
'coverTimeStamp':-1,
'coverTitle':"",
'coverTitleStyle':"",
'coverType':1,
'domain':"",
'fileId':fileId,
'kuaishou.web.cp.api_ph':kuaishou_web_cp_api_ph,
'latitude':"",
'longitude':"",
'movieId':"",
'notifyResult':0,
'photoStatus':1,
'photoType':0,
'pkCoverKey':"",
'publishTime':0,
'secondDomain':""
}
data=json.dumps(data).encode()
header_submit ={
'Connection':'keep-alive',
'Content-Length':len(data),
'Content-Type':'application/json;charset=utf-8',
'Pragma':'no-cache',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0'
}
req=urllib.request.Request('https://cp.kuaishou.com/rest/cp/works/v2/video/pc/submit',data=data,method='POST')
req.headers=header_submit#模擬瀏覽器
html=opener.open(req,data).read()#html會返回驗證碼成功或不成功
print(html.decode('utf8'))
os.remove(列表[0])
列表.remove(列表[0])
login()
下載地址
-
- 通用安全下載
-
- 移動安全下載
-
- 聯(lián)通安全下載
-
- 電信安全下載
-
- 移動網(wǎng)絡下載
-
- 聯(lián)通網(wǎng)絡下載
-
- 電信網(wǎng)絡下載
-
- 通用網(wǎng)絡下載