快手视频批量采集
// ==UserScript==
// @name 快手视频批量采集
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author 李恒道
// @match https://live.kuaishou.com/profile/*
// @icon https://www.google.com/s2/favicons?domain=kuaishou.com
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
// @run-at document-start
// ==/UserScript==
let oldfetch=unsafeWindow.fetch
function newobj(){}
let savelistid=[]
let downloadurl=[]
let url=window.location.href
function fuckkuaishouvideo(id,index){
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url:"https://www.kuaishou.com/graphql",
method :"POST",
data:'{"operationName":"visionVideoDetail","variables":{"photoId":"'+id+'","page":"detail"},"query":"query visionVideoDetail($photoId: String, $type: String, $page: String, $webPageArea: String) {\\n visionVideoDetail(photoId: $photoId, type: $type, page: $page, webPageArea: $webPageArea) {\\n status\\n type\\n author {\\n id\\n name\\n following\\n headerUrl\\n __typename\\n }\\n photo {\\n id\\n duration\\n caption\\n likeCount\\n realLikeCount\\n coverUrl\\n photoUrl\\n liked\\n timestamp\\n expTag\\n llsid\\n viewCount\\n videoRatio\\n stereoType\\n croppedPhotoUrl\\n manifest {\\n mediaType\\n businessType\\n version\\n adaptationSet {\\n id\\n duration\\n representation {\\n id\\n defaultSelect\\n backupUrl\\n codecs\\n url\\n height\\n width\\n avgBitrate\\n maxBitrate\\n m3u8Slice\\n qualityType\\n qualityLabel\\n frameRate\\n featureP2sp\\n hidden\\n disableAdaptive\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n tags {\\n type\\n name\\n __typename\\n }\\n commentLimit {\\n canAddComment\\n __typename\\n }\\n llsid\\n danmakuSwitch\\n __typename\\n }\\n}\\n"}'
,headers: {
"Content-type": "application/json"
},
onload:function(xhr){
let obj=JSON.parse(xhr.responseText)
let res=obj.data.visionVideoDetail.photo
if(res===null){
console.log('失败的id"',id,index)
resolve('success')
}
downloadurl.push(res.photoUrl)
resolve('success')
}
});
})
}
function fuckfetch(...bianliang){
return new Promise(function(resolve, reject){
oldfetch(...bianliang).then(function(response) {
let handler = {
get: function(target, prop, receiver) {
if(typeof Reflect.get(target,prop)==='function')
{
if(Reflect.get(target,prop+'proxy')===undefined)
{
target[prop+'proxy']=(...funcargs)=> {
let result=target[prop].call(target,...funcargs)
if(prop==='text'){
if(bianliang.length>=2&&bianliang[1].body!==undefined)
{
if(bianliang[1].body.indexOf('\"operationName\":\"privateFeedsQuery\"')!==-1||bianliang[1].body.indexOf('\"operationName\":\"publicFeedsQuery\"')!==-1){
if(url!==window.location.href){
url=window.location.href
createbtn()
}
return new Promise(function(resolve, reject){
result.then(
function(data){
let list=JSON.parse(data)
console.log('获取了list',list)
let target=null
if(list.data.privateFeeds!==undefined){
target=list.data.privateFeeds
}
if(list.data.publicFeeds!==undefined){
target=list.data.publicFeeds
}
if(target!==null){
for(let index=0;index<target.list.length;index++){
savelistid.push(target.list[index].id)
}
}
let enddownload=document.querySelector('.enddownload')
if(enddownload!==null){
enddownload.innerHTML=''+savelistid.length
}
resolve(data)
}
)
})
}
}
}
return result
}
}
return Reflect.get(target,prop+'proxy')
}
return Reflect.get(target, prop);
},
set(target, prop, value) {
return Reflect.set(target, prop, value);
},
};
let proxy=new Proxy(response, handler)
resolve(proxy)
})
});
}
async function StatToGetVideo(){
alert('已开始,不要重复点击!')
for(let index=0;index<savelistid.length;index++){
let id=savelistid[index]
let result= await fuckkuaishouvideo(id,index)
if(result==='success'){
let startdownload=document.querySelector('.startdownload')
if(startdownload!==null){
startdownload.innerHTML=''+index
}
}
}
GM_setClipboard(downloadurl.join('\n'))
alert(savelistid.length+'个成功:'+downloadurl.length+'可能存在图片')
downloadurl=[]
}
unsafeWindow.fetch=fuckfetch
function createbtn(){
if(document.querySelector('.startdownload')!=null){
return;
}
savelistid=[]
downloadurl=[]
let div=document.createElement("div");
div.innerHTML=`<div style="display: flex;align-items: center;margin-top: 10px;"><button type="button" class="followed pl-btn pl-btn-default pl-btn-medium pl-btn-radius" data-v-13e05b4e="" data-v-2bb7639b="" style="margin-right: 15px;">
下载视频
</button><div><span class="startdownload">0</span>-><span class="enddownload">${savelistid.length}</span></div></div>`
div.onclick=function(event){
if(event.target.innerText==='下载视频'){
StatToGetVideo()
}
};
unsafeWindow.document.querySelector('.tab').append(div);
}
unsafeWindow.onload=createbtn