forked from nilaoda/BBDown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheeseInfoFetcher.cs
59 lines (56 loc) · 2.22 KB
/
CheeseInfoFetcher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using BBDown.Core.Entity;
using System.Text.Json;
using static BBDown.Core.Entity.Entity;
using static BBDown.Core.Util.HTTPUtil;
namespace BBDown.Core.Fetcher
{
public class CheeseInfoFetcher : IFetcher
{
public async Task<VInfo> FetchAsync(string id)
{
id = id[7..];
string index = "";
string api = $"https://api.bilibili.com/pugv/view/web/season?ep_id={id}";
string json = await GetWebSourceAsync(api);
using var infoJson = JsonDocument.Parse(json);
var data = infoJson.RootElement.GetProperty("data");
string cover = data.GetProperty("cover").ToString();
string title = data.GetProperty("title").ToString();
string desc = data.GetProperty("subtitle").ToString();
string ownerName = data.GetProperty("up_info").GetProperty("uname").ToString();
string ownerMid = data.GetProperty("up_info").GetProperty("mid").ToString();
var pages = data.GetProperty("episodes").EnumerateArray();
List<Page> pagesInfo = new();
foreach (var page in pages)
{
Page p = new(page.GetProperty("index").GetInt32(),
page.GetProperty("aid").ToString(),
page.GetProperty("cid").ToString(),
page.GetProperty("id").ToString(),
page.GetProperty("title").ToString().Trim(),
page.GetProperty("duration").GetInt32(),
"",
page.GetProperty("release_date").GetInt64(),
"",
"",
ownerName,
ownerMid);
if (p.epid == id) index = p.index.ToString();
pagesInfo.Add(p);
}
long pubTime = pagesInfo.Any() ? pagesInfo[0].pubTime : 0;
var info = new VInfo
{
Title = title.Trim(),
Desc = desc.Trim(),
Pic = cover,
PubTime = pubTime,
PagesInfo = pagesInfo,
IsBangumi = true,
IsCheese = true,
Index = index
};
return info;
}
}
}