diff --git a/DownKyi.Core/BiliApi/History/History.cs b/DownKyi.Core/BiliApi/History/History.cs new file mode 100644 index 0000000..1bfd2bd --- /dev/null +++ b/DownKyi.Core/BiliApi/History/History.cs @@ -0,0 +1,63 @@ +using DownKyi.Core.BiliApi.History.Models; +using DownKyi.Core.Logging; +using Newtonsoft.Json; +using System; + +namespace DownKyi.Core.BiliApi.History +{ + /// + /// 历史记录 + /// + public static class History + { + /// + /// 获取历史记录列表(视频、直播、专栏) + /// startId和startTime必须同时使用才有效,分别对应结果中的max和view_at,默认为0 + /// + /// 历史记录开始目标ID + /// 历史记录开始时间 + /// 每页项数 + /// 历史记录ID类型 + /// + public static HistoryData GetHistory(long startId, long startTime, int ps = 30, HistoryBusiness business = HistoryBusiness.ARCHIVE) + { + string businessStr = string.Empty; + switch (business) + { + case HistoryBusiness.ARCHIVE: + businessStr = "archive"; + break; + case HistoryBusiness.PGC: + businessStr = "pgc"; + break; + case HistoryBusiness.LIVE: + businessStr = "live"; + break; + case HistoryBusiness.ARTICLE_LIST: + businessStr = "article-list"; + break; + case HistoryBusiness.ARTICLE: + businessStr = "article"; + break; + } + + string url = $"https://api.bilibili.com/x/web-interface/history/cursor?max={startId}&view_at={startTime}&ps={ps}&business={businessStr}"; + string referer = "https://www.bilibili.com"; + string response = WebClient.RequestWeb(url, referer); + + try + { + var history = JsonConvert.DeserializeObject(response); + if (history == null || history.Data == null) { return null; } + return history.Data; + } + catch (Exception e) + { + Utils.Debugging.Console.PrintLine("GetHistory()发生异常: {0}", e); + LogManager.Error("History", e); + return null; + } + } + + } +} diff --git a/DownKyi.Core/BiliApi/History/Models/HistoryBusiness.cs b/DownKyi.Core/BiliApi/History/Models/HistoryBusiness.cs new file mode 100644 index 0000000..0b40257 --- /dev/null +++ b/DownKyi.Core/BiliApi/History/Models/HistoryBusiness.cs @@ -0,0 +1,11 @@ +namespace DownKyi.Core.BiliApi.History.Models +{ + public enum HistoryBusiness + { + ARCHIVE = 1, // 稿件 + PGC, // 番剧(影视) + LIVE, // 直播 + ARTICLE_LIST, // 文集 + ARTICLE, // 文章 + } +} diff --git a/DownKyi.Core/BiliApi/History/Models/HistoryCursor.cs b/DownKyi.Core/BiliApi/History/Models/HistoryCursor.cs new file mode 100644 index 0000000..c6641e7 --- /dev/null +++ b/DownKyi.Core/BiliApi/History/Models/HistoryCursor.cs @@ -0,0 +1,17 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.History.Models +{ + public class HistoryCursor : BaseModel + { + [JsonProperty("max")] + public long Max { get; set; } + [JsonProperty("view_at")] + public long ViewAt { get; set; } + [JsonProperty("business")] + public string Business { get; set; } + [JsonProperty("ps")] + public int Ps { get; set; } + } +} diff --git a/DownKyi.Core/BiliApi/History/Models/HistoryData.cs b/DownKyi.Core/BiliApi/History/Models/HistoryData.cs new file mode 100644 index 0000000..ca58a5b --- /dev/null +++ b/DownKyi.Core/BiliApi/History/Models/HistoryData.cs @@ -0,0 +1,28 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.History.Models +{ + // https://api.bilibili.com/x/web-interface/history/cursor?max={startId}&view_at={startTime}&ps={ps}&business={businessStr} + public class HistoryOrigin : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + //[JsonProperty("ttl")] + //public int Ttl { get; set; } + [JsonProperty("data")] + public HistoryData Data { get; set; } + } + + public class HistoryData : BaseModel + { + [JsonProperty("cursor")] + public HistoryCursor Cursor { get; set; } + //public List tab { get; set; } + [JsonProperty("list")] + public List List { get; set; } + } +} diff --git a/DownKyi.Core/BiliApi/History/Models/HistoryList.cs b/DownKyi.Core/BiliApi/History/Models/HistoryList.cs new file mode 100644 index 0000000..5ac7372 --- /dev/null +++ b/DownKyi.Core/BiliApi/History/Models/HistoryList.cs @@ -0,0 +1,46 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.History.Models +{ + public class HistoryList : BaseModel + { + [JsonProperty("title")] + public string Title { get; set; } + // long_title + [JsonProperty("cover")] + public string Cover { get; set; } + // covers + [JsonProperty("uri")] + public string Uri { get; set; } + [JsonProperty("history")] + public HistoryListHistory History { get; set; } + [JsonProperty("videos")] + public int Videos { get; set; } + [JsonProperty("author_name")] + public string AuthorName { get; set; } + [JsonProperty("author_face")] + public string AuthorFace { get; set; } + [JsonProperty("author_mid")] + public long AuthorMid { get; set; } + [JsonProperty("view_at")] + public long ViewAt { get; set; } + [JsonProperty("progress")] + public long Progress { get; set; } + // badge + [JsonProperty("show_title")] + public string ShowTitle { get; set; } + [JsonProperty("duration")] + public long Duration { get; set; } + // current + // total + [JsonProperty("new_desc")] + public string NewDesc { get; set; } + // is_finish + // is_fav + // kid + [JsonProperty("tag_name")] + public string TagName { get; set; } + // live_status + } +} diff --git a/DownKyi.Core/BiliApi/History/Models/HistoryListHistory.cs b/DownKyi.Core/BiliApi/History/Models/HistoryListHistory.cs new file mode 100644 index 0000000..8ea33f0 --- /dev/null +++ b/DownKyi.Core/BiliApi/History/Models/HistoryListHistory.cs @@ -0,0 +1,25 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.History.Models +{ + public class HistoryListHistory : BaseModel + { + [JsonProperty("oid")] + public long Oid { get; set; } + [JsonProperty("epid")] + public long Epid { get; set; } + [JsonProperty("bvid")] + public string Bvid { get; set; } + [JsonProperty("page")] + public int Page { get; set; } + [JsonProperty("cid")] + public long Cid { get; set; } + [JsonProperty("part")] + public string Part { get; set; } + [JsonProperty("business")] + public string Business { get; set; } + [JsonProperty("dt")] + public int Dt { get; set; } + } +} diff --git a/DownKyi.Core/BiliApi/History/Models/ToViewData.cs b/DownKyi.Core/BiliApi/History/Models/ToViewData.cs new file mode 100644 index 0000000..5c1a7ac --- /dev/null +++ b/DownKyi.Core/BiliApi/History/Models/ToViewData.cs @@ -0,0 +1,27 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.History.Models +{ + // https://api.bilibili.com/x/v2/history/toview + public class ToViewOrigin : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + //[JsonProperty("ttl")] + //public int Ttl { get; set; } + [JsonProperty("data")] + public ToViewData Data { get; set; } + } + + public class ToViewData : BaseModel + { + [JsonProperty("count")] + public int Count { get; set; } + [JsonProperty("list")] + public List List { get; set; } + } +} diff --git a/DownKyi.Core/BiliApi/History/Models/ToViewList.cs b/DownKyi.Core/BiliApi/History/Models/ToViewList.cs new file mode 100644 index 0000000..cf22bdb --- /dev/null +++ b/DownKyi.Core/BiliApi/History/Models/ToViewList.cs @@ -0,0 +1,48 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DownKyi.Core.BiliApi.History.Models +{ + public class ToViewList : BaseModel + { + [JsonProperty("aid")] + public long Aid { get; set; } + // videos + // tid + // tname + // copyright + [JsonProperty("pic")] + public string Pic { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + // pubdate + // ctime + // desc + // state + // duration + // rights + [JsonProperty("owner")] + public VideoOwner Owner { get; set; } + // stat + // dynamic + // dimension + // short_link_v2 + // first_frame + // page + // count + [JsonProperty("cid")] + public long Cid { get; set; } + // progress + [JsonProperty("add_at")] + public long AddAt { get; set; } + [JsonProperty("bvid")] + public string Bvid { get; set; } + // uri + // viewed + } +} diff --git a/DownKyi.Core/BiliApi/History/ToView.cs b/DownKyi.Core/BiliApi/History/ToView.cs new file mode 100644 index 0000000..354569b --- /dev/null +++ b/DownKyi.Core/BiliApi/History/ToView.cs @@ -0,0 +1,38 @@ +using DownKyi.Core.BiliApi.History.Models; +using DownKyi.Core.Logging; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.History +{ + /// + /// 稍后再看 + /// + public static class ToView + { + /// + /// 获取稍后再看视频列表 + /// + /// + public static List GetToView() + { + string url = "https://api.bilibili.com/x/v2/history/toview"; + string referer = "https://www.bilibili.com"; + string response = WebClient.RequestWeb(url, referer); + + try + { + var toView = JsonConvert.DeserializeObject(response); + if (toView == null || toView.Data == null) { return null; } + return toView.Data.List; + } + catch (Exception e) + { + Utils.Debugging.Console.PrintLine("GetToView()发生异常: {0}", e); + LogManager.Error("ToView", e); + return null; + } + } + } +} diff --git a/DownKyi.Core/DownKyi.Core.csproj b/DownKyi.Core/DownKyi.Core.csproj index fc516b6..fb65dfc 100644 --- a/DownKyi.Core/DownKyi.Core.csproj +++ b/DownKyi.Core/DownKyi.Core.csproj @@ -151,6 +151,15 @@ + + + + + + + + +