新增历史记录和稍后再看api

croire 3 years ago
parent fea42637b2
commit 1a7c9cd6fc

@ -0,0 +1,63 @@
using DownKyi.Core.BiliApi.History.Models;
using DownKyi.Core.Logging;
using Newtonsoft.Json;
using System;
namespace DownKyi.Core.BiliApi.History
{
/// <summary>
/// 历史记录
/// </summary>
public static class History
{
/// <summary>
/// 获取历史记录列表(视频、直播、专栏)
/// startId和startTime必须同时使用才有效分别对应结果中的max和view_at默认为0
/// </summary>
/// <param name="startId">历史记录开始目标ID</param>
/// <param name="startTime">历史记录开始时间</param>
/// <param name="ps">每页项数</param>
/// <param name="business">历史记录ID类型</param>
/// <returns></returns>
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<HistoryOrigin>(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;
}
}
}
}

@ -0,0 +1,11 @@
namespace DownKyi.Core.BiliApi.History.Models
{
public enum HistoryBusiness
{
ARCHIVE = 1, // 稿件
PGC, // 番剧(影视)
LIVE, // 直播
ARTICLE_LIST, // 文集
ARTICLE, // 文章
}
}

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

@ -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<HistoryDataTab> tab { get; set; }
[JsonProperty("list")]
public List<HistoryList> List { get; set; }
}
}

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

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

@ -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<ToViewList> List { get; set; }
}
}

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

@ -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
{
/// <summary>
/// 稍后再看
/// </summary>
public static class ToView
{
/// <summary>
/// 获取稍后再看视频列表
/// </summary>
/// <returns></returns>
public static List<ToViewList> 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<ToViewOrigin>(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;
}
}
}
}

@ -151,6 +151,15 @@
<Compile Include="BiliApi\Favorites\Models\FavStatus.cs" />
<Compile Include="BiliApi\Favorites\Models\FavUpper.cs" />
<Compile Include="BiliApi\Favorites\Models\MediaStatus.cs" />
<Compile Include="BiliApi\History\History.cs" />
<Compile Include="BiliApi\History\Models\HistoryBusiness.cs" />
<Compile Include="BiliApi\History\Models\HistoryCursor.cs" />
<Compile Include="BiliApi\History\Models\HistoryData.cs" />
<Compile Include="BiliApi\History\Models\HistoryList.cs" />
<Compile Include="BiliApi\History\Models\HistoryListHistory.cs" />
<Compile Include="BiliApi\History\Models\ToViewData.cs" />
<Compile Include="BiliApi\History\Models\ToViewList.cs" />
<Compile Include="BiliApi\History\ToView.cs" />
<Compile Include="BiliApi\Login\LoginHelper.cs" />
<Compile Include="BiliApi\Models\BaseModel.cs" />
<Compile Include="BiliApi\BiliUtils\BvId.cs" />

Loading…
Cancel
Save