好友
阅读权限20
听众
最后登录1970-1-1
|
本帖最后由 huguo002 于 2023-3-24 18:21 编辑
做自媒体短视频,一些平台的视频无疑是需要下载的,那么今天这篇就带来快手短视频下载工具,总结了一下短视频下载工具,供大家参考和学习,当然仅仅是本渣渣的一些使用分享而已!
方式一:浏览器插件下载这一方法无疑是比较简单的,而且有很多视频解析插件可以使用,不过部分较长视频无法解析下载,仅供参考!
本渣渣这里用的是:Flash Video Downloader
例如:https://www.kuaishou.com/f/X9yqpxiPsYhy1Kn
方式二:在线网页解析工具这一方法也是比较简单的,直接用网上大佬分享的在线网页解析工具即可下载短视频!
例如:1.多平台短视频下载(快手接口失效)https://watermark.iculture.cc/2.抖音短视频下载https://ouotool.com/dy
Python源码参考
以第一个平台为例,简单的用Python写一个模拟访问获取视频的源码:
[Python] 纯文本查看 复制代码 # -*-coding:utf-8-*-
import requests
import time
from contextlib import closing
def get_video_url(url):
"""
在线解析短视频地址
:param url: 短视频分享地址
:return:
"""
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
}
jkurl=f"https://api.iculture.cc/api/video/?url={url}"
response=requests.get(url=jkurl,headers=headers,timeout=6)
print(response.status_code)
time.sleep(2)
# print(response.json())
response_json=response.json()
print(response_json['msg'])
video_title=response_json['title']
print(video_title)
video_url=response_json['url']
print(video_url)
video=video_title,video_url
return video
def get_video(video_title,video_url):
"""
下载视频
:param video_title: 视频标题
:param video_url: 视频地址
:return:
"""
url = video_url
headers = {
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.42'
}
response = requests.get(url=url, headers=headers, timeout=10, stream=True)
with open(f'{video_title}.mp4','wb') as f:
f.write(response.content)
print(f'{video_title}下载完成')
def down_video(video_title,video_url):
"""
带进度条显示下载视频
:param video_title: 视频标题
:param video_url: 视频地址
:return:
"""
url =video_url
headers = {
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.42'
}
with closing(requests.get(url=url,headers=headers, stream=True)) as response:
chunk_size = 1024 # 单次请求最大值
# response.headers['content-length']得到的数据类型是str而不是int
content_size = int(response.headers['content-length']) # 文件总大小
data_count = 0 # 当前已传输的大小
with open(f'{video_title}.mp4', "wb") as file:
for data in response.iter_content(chunk_size=chunk_size):
file.write(data)
done_block = int((data_count / content_size) * 50)
# 已经下载的文件大小
data_count = data_count + len(data)
# 实时进度条进度
now_jd = (data_count / content_size) * 100
# %% 表示%
print("\r [%s%s] %d%% " % (done_block * '█', ' ' * (50 - 1 - done_block), now_jd), end=" ")
print(f'{video_title}.mp4 下载完成!')
if __name__=="__main__":
url="http://v.douyin.com/uycNy6/"
#url="https://www.kuaishou.com/f/X-1JB88iJi3UY13A"
video=get_video_url(url)
video_title=video[0]
video_url=video[1]
# get_video(video_title, video_url)
down_video(video_title, video_url)
方式三:Python批量下载工具
例如:https://www.kuaishou.com/profile/3xk2asbe3pqa2ds
浏览器关键抓包信息内容:
本渣渣参考写的代码:
[Python] 纯文本查看 复制代码 -*-coding:utf-8-*-
import requests
import time
from contextlib import closing
import re
def get_vedio_list(id,did):
"""
解析用户主页视频
:param id: 用户id
:param did: Cookies
:return:
"""
url="https://www.kuaishou.com/graphql"
headers={
'content-type': 'application/json',
'Host': 'www.kuaishou.com',
'Origin': 'https://www.kuaishou.com',
'Referer': f'https://www.kuaishou.com/profile/{id}',
"Cookie": f"kpf=PC_WEB; clientid=3; did={did}",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
}
data={
"operationName": "visionProfilePhotoList",
"query": "fragment photoContent on PhotoEntity {\n id\n duration\n caption\n originCaption\n likeCount\n viewCount\n realLikeCount\n coverUrl\n photoUrl\n photoH265Url\n manifest\n manifestH265\n videoResource\n coverUrls {\n url\n __typename\n }\n timestamp\n expTag\n animatedCoverUrl\n distance\n videoRatio\n liked\n stereoType\n profileUserTopPhoto\n musicBlocked\n __typename\n}\n\nfragment feedContent on Feed {\n type\n author {\n id\n name\n headerUrl\n following\n headerUrls {\n url\n __typename\n }\n __typename\n }\n photo {\n ...photoContent\n __typename\n }\n canAddComment\n llsid\n status\n currentPcursor\n tags {\n type\n name\n __typename\n }\n __typename\n}\n\nquery visionProfilePhotoList($pcursor: String, $userId: String, $page: String, $webPageArea: String) {\n visionProfilePhotoList(pcursor: $pcursor, userId: $userId, page: $page, webPageArea: $webPageArea) {\n result\n llsid\n webPageArea\n feeds {\n ...feedContent\n __typename\n }\n hostName\n pcursor\n __typename\n }\n}\n",
"variables": {"userId": f'{id}', "pcursor": "", "page": "profile"},
}
response=requests.post(url=url,json=data,headers=headers,timeout=6)
print(response.json())
response_json=response.json()
data_json=response_json['data']['visionProfilePhotoList']
print(data_json['pcursor']) # 下一页地址参数
video_lists=data_json['feeds']
for video_list in video_lists:
# print(video_list)
video_title=video_list['photo']['originCaption']
video_title=filter_title(video_title) #标题特殊字符过滤
print(video_title)
video_url=video_list['photo']['photoUrl']
print(video_url)
down_video(video_title, video_url) #下载视频
time.sleep(3)
def filter_title(title):
"""
标题特殊字符过滤处理
:param title: 视频标题
:return:
"""
title = title.strip()
rstr = r"[\/\\\:\*\?\"\<\>\|\.\,|\r\n]+"
new_title = re.sub(rstr,'_',title)
return new_title
def get_video(video_title,video_url):
"""
下载视频
:param video_title: 视频标题
:param video_url: 视频地址
:return:
"""
url = video_url
headers = {
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.42'
}
response = requests.get(url=url, headers=headers, timeout=10, stream=True)
with open(f'{video_title}.mp4','wb') as f:
f.write(response.content)
print(f'{video_title}下载完成')
def down_video(video_title,video_url):
"""
带进度条显示下载视频
:param video_title: 视频标题
:param video_url: 视频地址
:return:
"""
url =video_url
headers = {
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.42'
}
with closing(requests.get(url=url,headers=headers, stream=True)) as response:
chunk_size = 1024 # 单次请求最大值
# response.headers['content-length']得到的数据类型是str而不是int
content_size = int(response.headers['content-length']) # 文件总大小
data_count = 0 # 当前已传输的大小
with open(f'{video_title}.mp4', "wb") as file:
for data in response.iter_content(chunk_size=chunk_size):
file.write(data)
done_block = int((data_count / content_size) * 50)
# 已经下载的文件大小
data_count = data_count + len(data)
# 实时进度条进度
now_jd = (data_count / content_size) * 100
# %% 表示%
print("\r [%s%s] %d%% " % (done_block * '█', ' ' * (50 - 1 - done_block), now_jd), end=" ")
print(f'{video_title}.mp4 下载完成!')
if __name__=='__main__':
id="3xk2asbe3pqa2ds"
did=did
get_vedio_list(id,did)
几个关键点:
1.requests.post json 请求数据方式
2.头部 headers 和 请求的json 请求数据 须正确
3.Cookie 须正常账号登陆获取
4.pcursor 下一页地址参数获取
实现效果:
exe工具
异步大佬的https://www.52pojie.cn/thread-1668148-1-1.html
我就不献丑了.......
参考来源:
1.快手短视频下载V1.91
https://www.52pojie.cn/thread-1631965-1-1.html
2.快手视频下载,指定作者批量下载无水印
https://www.52pojie.cn/thread-1668148-1-1.html
3.python中Requests发送json格式的post请求方法
https://www.jb51.net/article/262153.htm
仅供参考,学习,有用可以点个赞,支持一下! |
免费评分
-
查看全部评分
|