forked from nilaoda/BBDown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BangumiInfoFetcher.cs
83 lines (77 loc) · 3.35 KB
/
BangumiInfoFetcher.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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 BangumiInfoFetcher : IFetcher
{
public async Task<VInfo> FetchAsync(string id)
{
id = id[3..];
string index = "";
string api = $"https://{Config.EPHOST}/pgc/view/web/season?ep_id={id}";
string json = await GetWebSourceAsync(api);
using var infoJson = JsonDocument.Parse(json);
var result = infoJson.RootElement.GetProperty("result");
string cover = result.GetProperty("cover").ToString();
string title = result.GetProperty("title").ToString();
string desc = result.GetProperty("evaluate").ToString();
string pubTimeStr = result.GetProperty("publish").GetProperty("pub_time").ToString();
long pubTime = string.IsNullOrEmpty(pubTimeStr) ? 0 : DateTimeOffset.ParseExact(pubTimeStr, "yyyy-MM-dd HH:mm:ss", null).ToUnixTimeSeconds();
var pages = result.GetProperty("episodes").EnumerateArray();
List<Page> pagesInfo = new();
int i = 1;
//episodes为空; 或者未包含对应epid,番外/花絮什么的
if (!(pages.Any() && result.GetProperty("episodes").ToString().Contains($"/ep{id}")))
{
if (result.TryGetProperty("section", out JsonElement sections))
{
foreach (var section in sections.EnumerateArray())
{
if (section.ToString().Contains($"/ep{id}"))
{
title += "[" + section.GetProperty("title").ToString() + "]";
pages = section.GetProperty("episodes").EnumerateArray();
break;
}
}
}
}
foreach (var page in pages)
{
//跳过预告
if (page.TryGetProperty("badge", out JsonElement badge) && badge.ToString() == "预告") continue;
string res = "";
try
{
res = page.GetProperty("dimension").GetProperty("width").ToString() + "x" + page.GetProperty("dimension").GetProperty("height").ToString();
}
catch (Exception) { }
string _title = page.GetProperty("title").ToString() + " " + page.GetProperty("long_title").ToString();
_title = _title.Trim();
Page p = new(i++,
page.GetProperty("aid").ToString(),
page.GetProperty("cid").ToString(),
page.GetProperty("id").ToString(),
_title,
0, res,
page.GetProperty("pub_time").GetInt64());
if (p.epid == id) index = p.index.ToString();
pagesInfo.Add(p);
}
var info = new VInfo
{
Title = title.Trim(),
Desc = desc.Trim(),
Pic = cover,
PubTime = pubTime,
PagesInfo = pagesInfo,
IsBangumi = true,
IsCheese = true,
Index = index
};
return info;
}
}
}