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; } } } }