大量修改
This commit is contained in:
@@ -1 +0,0 @@
|
||||
528077e4-c137-4dbf-9206-1909e22cda73
|
||||
@@ -1 +0,0 @@
|
||||
4357a39c-dc52-4180-a387-00d44344f293
|
||||
@@ -2,7 +2,7 @@ const { gql } = require("graphql-request");
|
||||
|
||||
module.exports = {
|
||||
url: "https://www.kuaishou.com/graphql",
|
||||
// 获取收藏的视频
|
||||
// 获取用户点赞的视频
|
||||
visionProfileLikePhotoList: gql`
|
||||
fragment photoContent on PhotoEntity {
|
||||
__typename
|
||||
@@ -46,4 +46,40 @@ module.exports = {
|
||||
} hostName pcursor __typename
|
||||
}
|
||||
}`,
|
||||
// 获取主播主页的所有视频
|
||||
visionProfilePhotoList: gql`
|
||||
fragment photoContent on PhotoEntity {
|
||||
__typename id duration caption originCaption
|
||||
likeCount viewCount commentCount realLikeCount coverUrl
|
||||
photoUrl photoH265Url manifest manifestH265 videoResource
|
||||
coverUrls {
|
||||
url __typename
|
||||
}
|
||||
timestamp expTag animatedCoverUrl distance videoRatio liked
|
||||
stereoType profileUserTopPhoto musicBlocked riskTagContent
|
||||
riskTagUrl
|
||||
}
|
||||
fragment recoPhotoFragment on recoPhotoEntity {
|
||||
__typename id duration caption originCaption likeCount viewCount commentCount realLikeCount
|
||||
coverUrl photoUrl photoH265Url manifest manifestH265 videoResource
|
||||
coverUrls { url __typename }
|
||||
timestamp expTag animatedCoverUrl distance videoRatio liked stereoType profileUserTopPhoto
|
||||
musicBlocked riskTagContent riskTagUrl
|
||||
}
|
||||
fragment feedContentWithLiveInfo on Feed {
|
||||
type author {
|
||||
id name headerUrl following livingInfo
|
||||
headerUrls { url __typename } __typename
|
||||
}
|
||||
photo { ...photoContent ...recoPhotoFragment __typename }
|
||||
canAddComment llsid status currentPcursor
|
||||
tags { type name __typename } __typename
|
||||
}
|
||||
query visionProfilePhotoList($pcursor: String, $userId: String, $page: String, $webPageArea: String) {
|
||||
visionProfilePhotoList(pcursor: $pcursor, userId: $userId, page: $page, webPageArea: $webPageArea) {
|
||||
result llsid webPageArea
|
||||
feeds { ...feedContentWithLiveInfo __typename }
|
||||
hostName pcursor __typename }
|
||||
}
|
||||
`
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
9aaa7146-0671-40e8-8c0b-15fb571f35a8
|
||||
@@ -5,14 +5,14 @@ class GraphqlRequest {
|
||||
constructor() {
|
||||
this.client = new GraphQLClient(config.url, {
|
||||
headers: {
|
||||
Cookie: 'context=1|MS43NjQ1ODM2OTgyODY2OTgyLjYxODQzOTUyLjE3MjQ2MTEwOTkyMjkuNDcyNDA=|MS43NjQ1ODM2OTgyODY2OTgyLjE5ODE4Mjk4LjE3MjQ2MTEwOTkyMjkuNDcyNDE=|0|graphql-server|webservice|false|NA; kpf=PC_WEB; clientid=3; did=web_017a1f82461c8b4dc575f8df3fee78ff; userId=58344290; kpn=KUAISHOU_VISION; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABVncUlGSoudMExPNRzEXf8OSAig_Gst7K3MuSob5dchyTwVVPrkPebW5B_ZMl9MFrNPRDjNhSpmGW_PABiZxH3bKuG7Cj-IaMhtEaaQiqs8ajQZfJ5CNjHKAmVizdwjF8qRnULuxZbrDwBE3BdzuUEDB-xE1ybAhhF0zQGz0LqzVDIT4ohfCbbzXfEZWCygEQCArtAgQB8sEooFEfLPXiwBoS5Uf6LooXNTrpm4StA9DDXaoVIiDqFSEmUkB66mi_cuqecbrHKQ5fBC5x74q1-WPiNNwCMSgFMAE;'
|
||||
Cookie: 'kpf=PC_WEB; clientid=3; did=web_4abc14d7790d18335fedc13249834c42; userId=58344290; kuaishou.server.webday7_st=ChprdWFpc2hvdS5zZXJ2ZXIud2ViZGF5Ny5zdBKwARn6brG-fMigWK_p8OkNIz3auEEilOc5O0XadgJ_dkmu41zuO2zSfxcmYBuyqph0KnFS-cVu-YbgPb2HqxwbgaznjeTKtJzieVkfoYClBCJy2Hojx7euihIStw4izkYtP7ztIaIAOK5_kiGFvS2_6V4jAXupKegEjQeM9nd2vxpkSuw63dHwZDzfN1EmTr5__nCExUlhCcxi-vyBl446ReOLlywiTjMe5AGI2_I1uz4dGhLcWLZU0wMn7F5ONAeuFgyQkCwiIFEFfJL9dH1pCQZANFR6CCZP1SaZ_xw7ZpeNre2m31gjKAUwAQ; kuaishou.server.webday7_ph=07c02e409d3bb524d0531c7d3e2d8b539eb6; kpn=KUAISHOU_VISION'
|
||||
},
|
||||
})
|
||||
}
|
||||
async post(document, variables) {
|
||||
try {
|
||||
let res = await this.client.request(document, variables);
|
||||
return res.visionProfileLikePhotoList;
|
||||
return res.visionProfileLikePhotoList || res.visionProfilePhotoList;
|
||||
} catch (error) {
|
||||
console.log("===========================请求出错===========================");
|
||||
console.log(error.message);
|
||||
|
||||
@@ -84,14 +84,14 @@ const savefileToPath = async (fileData, fileName) => {
|
||||
} else {
|
||||
TotalCount += 1;
|
||||
console.log(`第 ${TotalCount} 条视频:${fileName}.mp4 已下载!`);
|
||||
Screenshot(fileName)
|
||||
// Screenshot(fileName)
|
||||
if (TotalCount >= TotalFeeds.length) {
|
||||
console.log("");
|
||||
console.log(`已下载:${TotalFeeds.length} 条视频,20秒后将开始继续下载..`);
|
||||
console.log(`已下载:${TotalFeeds.length} 条视频,5秒后将开始继续下载..`);
|
||||
console.log("结束 ==============================================================");
|
||||
setTimeout(() => {
|
||||
main();
|
||||
}, 10000)
|
||||
}, 5000)
|
||||
}
|
||||
resolve('已下载')
|
||||
}
|
||||
|
||||
95
downKsVideo/src/utils/utils.js
Normal file
95
downKsVideo/src/utils/utils.js
Normal file
@@ -0,0 +1,95 @@
|
||||
const fs = require("fs");
|
||||
const https = require("https");
|
||||
const path = require("path");
|
||||
const request = require("../http/http");
|
||||
const config = require("../config/config");
|
||||
const process = require('child_process');
|
||||
const pr = require('node:process');
|
||||
|
||||
pr.on('uncaughtException', err => {
|
||||
console.log(' pr NOT exit...');
|
||||
console.log(err.stack);
|
||||
});
|
||||
|
||||
|
||||
class Utils {
|
||||
|
||||
TotalFeeds = []
|
||||
TotalCount = 0
|
||||
principalId = ""
|
||||
type = ""
|
||||
userId
|
||||
|
||||
init (type = "visionProfileLikePhotoList", userId) {
|
||||
this.type = type
|
||||
this.userId = userId
|
||||
}
|
||||
|
||||
async start() {
|
||||
let params = { page: "profile", pcursor: this.principalId }
|
||||
|
||||
this.userId ? params.userId = this.userId : null
|
||||
let { pcursor, feeds } = await request.post(config[this.type], params);
|
||||
|
||||
this.principalId = pcursor;
|
||||
|
||||
console.log("");
|
||||
console.log(`1:本单次请求到:${feeds.length} 条视频`);
|
||||
|
||||
// console.log(`下一页页码为:${principalId}`);
|
||||
this.TotalFeeds = [...this.TotalFeeds, ...feeds];
|
||||
console.log("2:当前总视频数为:", this.TotalFeeds.length);
|
||||
console.log("");
|
||||
console.log("-----------视频下载进度-------------");
|
||||
feeds.forEach(async item => {
|
||||
await this.getVideoData(item.photo.photoUrl, 'binary', item.photo.id);
|
||||
});
|
||||
}
|
||||
|
||||
async getVideoData(url, encoding, filename) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let req = https.get(url, res => {
|
||||
let result = ''
|
||||
encoding && res.setEncoding(encoding)
|
||||
res.on('data', d => result += d)
|
||||
res.on('end', () => this.savefileToPath(result, filename))
|
||||
res.on('error', e => {
|
||||
console.log("1 res.on 出错了:", e);
|
||||
console.log("重新请求数据中:", url);
|
||||
this.getVideoData(url, encoding, filename)
|
||||
})
|
||||
})
|
||||
req.end()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
async savefileToPath(fileData, fileName) {
|
||||
let fileFullName = path.join(__dirname, `../../dist/${fileName}.mp4`)
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(fileFullName, fileData, 'binary', err => {
|
||||
if (err) {
|
||||
console.log('savefileToPath error:', err)
|
||||
} else {
|
||||
this.TotalCount += 1;
|
||||
console.log(`第 ${this.TotalCount} 条视频:${fileName}.mp4 已保存到本地!`);
|
||||
// Screenshot(fileName)
|
||||
if (this.TotalCount >= this.TotalFeeds.length) {
|
||||
console.log("-----------视频下载进度-------------");
|
||||
console.log("");
|
||||
console.log(`3:已下载:${this.TotalFeeds.length} 条视频,5秒 后将开始下载 下一页..`);
|
||||
console.log("")
|
||||
console.log("")
|
||||
|
||||
setTimeout(() => this.start(), 5000)
|
||||
}
|
||||
resolve('已下载')
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Utils
|
||||
6
downKsVideo/src/visionProfileLikePhotoList.js
Normal file
6
downKsVideo/src/visionProfileLikePhotoList.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const utils = require("./utils/utils");
|
||||
|
||||
let u = new utils()
|
||||
// u.init("visionProfileLikePhotoList")
|
||||
u.init("visionProfilePhotoList", "3xiem77vya42p4y")
|
||||
u.start()
|
||||
Reference in New Issue
Block a user