[C#] 纯文本查看 复制代码 using Flurl.Http;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
string vurl;
string filename;
string path = "D:\\Kuaishou\\";
string logpath = AppDomain.CurrentDomain.BaseDirectory + "log.txt";
string cookie = " ktrace-context=1|MS43NjQ1ODM2OTgyODY2OTgyLjc5MTI3NDE4LjE2MTc4NjYwOTUwNzYuMzE5Nzg=|MS43NjQ1ODM2OTgyODY2OTgyLjkyNDE3ODgyLjE2MTc4NjYwOTUwNzYuMzE5Nzk=|0|graphql-server|webservice|false|NA; clientid=3; did=web_cc45ac9b44e37e17f374f1831d455019; kpf=PC_WEB; kpn=KUAISHOU_VISION; didv=1617866151109";
string url = "https://video.kuaishou.com/graphql";
var data = new { operationName = "brilliantTypeDataQuery", variables = new { hotChannelId = "00", page = "brilliant", pcursor = "1" }, query = "fragment 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 id\n duration\n caption\n likeCount\n realLikeCount\n coverUrl\n photoUrl\n coverUrls {\n url\n __typename\n }\n timestamp\n expTag\n animatedCoverUrl\n distance\n videoRatio\n liked\n stereoType\n __typename\n }\n canAddComment\n llsid\n status\n currentPcursor\n __typename\n}\n\nfragment photoResult on PhotoResult {\n result\n llsid\n expTag\n serverExpTag\n pcursor\n feeds {\n ...feedContent\n __typename\n }\n webPageArea\n __typename\n}\n\nquery brilliantTypeDataQuery($pcursor: String, $hotChannelId: String, $page: String, $webPageArea: String) {\n brilliantTypeData(pcursor: $pcursor, hotChannelId: $hotChannelId, page: $page, webPageArea: $webPageArea) {\n ...photoResult\n __typename\n }\n}\n" };
var result = await url.WithHeaders(new
{
Connection = " keep-alive",
accept = " */*",
User_Agent = " Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36",
content_type = "application/json",
Accept_Language = "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
Cookie = cookie
})
.PostJsonAsync(data).ReceiveJson<JObject>();
var obj = result["data"]["brilliantTypeData"]["feeds"];
foreach (var o in obj)
{
vurl = o["photo"]["photoUrl"].ToString();
filename = o["author"]["name"] + "_" + o["photo"]["caption"] + ".mp4";
filename = filename.Replace("\\", "");
if (File.Exists(path + filename))
{
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}]{filename} 文件已存在");
}
else
{
try
{
await vurl.DownloadFileAsync(path, filename);
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}]{filename} 文件下载完成");
}
catch (Exception ex)
{
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}]{filename} 文件下载失败,请查看日志");
File.AppendAllText(logpath, $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}]{filename},{vurl},{ex.Message}\r\n");
}
}
}
Console.WriteLine();
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] 全部下载完成");
Console.ReadLine();
有个bug没改,留给后人去改吧,看了一位盆友用Python的例子有感而发,地址:https://www.52pojie.cn/thread-1412847-1-1.html
共同进步吧 |