diff --git a/DownKyi.Core/BiliApi/Favorites/FavoritesInfo.cs b/DownKyi.Core/BiliApi/Favorites/FavoritesInfo.cs index 45f5bf1..157c698 100644 --- a/DownKyi.Core/BiliApi/Favorites/FavoritesInfo.cs +++ b/DownKyi.Core/BiliApi/Favorites/FavoritesInfo.cs @@ -3,9 +3,6 @@ using DownKyi.Core.Logging; using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace DownKyi.Core.BiliApi.Favorites { @@ -36,5 +33,110 @@ namespace DownKyi.Core.BiliApi.Favorites } } + /// + /// 查询用户创建的视频收藏夹 + /// + /// 目标用户UID + /// 页码 + /// 每页项数 + /// + public static List GetCreatedFavorites(long mid, int pn, int ps) + { + string url = $"https://api.bilibili.com/x/v3/fav/folder/created/list?up_mid={mid}&pn={pn}&ps={ps}"; + string referer = "https://www.bilibili.com"; + string response = WebClient.RequestWeb(url, referer); + + try + { + var favorites = JsonConvert.DeserializeObject(response); + if (favorites == null || favorites.Data == null || favorites.Data.List == null) + { return null; } + return favorites.Data.List; + } + catch (Exception e) + { + Utils.Debugging.Console.PrintLine("GetCreatedFavorites()发生异常: {0}", e); + LogManager.Error("FavoritesInfo", e); + return null; + } + } + + /// + /// 查询所有的用户创建的视频收藏夹 + /// + /// 目标用户UID + /// + public static List GetAllCreatedFavorites(long mid) + { + List result = new List(); + + int i = 0; + while (true) + { + i++; + int ps = 50; + + var data = GetCreatedFavorites(mid, i, ps); + if (data == null || data.Count == 0) + { break; } + + result.AddRange(data); + } + return result; + } + + /// + /// 查询用户收藏的视频收藏夹 + /// + /// 目标用户UID + /// 页码 + /// 每页项数 + /// + public static List GetCollectedFavorites(long mid, int pn, int ps) + { + string url = $"https://api.bilibili.com/x/v3/fav/folder/collected/list?up_mid={mid}&pn={pn}&ps={ps}"; + string referer = "https://www.bilibili.com"; + string response = WebClient.RequestWeb(url, referer); + + try + { + var favorites = JsonConvert.DeserializeObject(response); + if (favorites == null || favorites.Data == null || favorites.Data.List == null) + { return null; } + return favorites.Data.List; + } + catch (Exception e) + { + Utils.Debugging.Console.PrintLine("GetCollectedFavorites()发生异常: {0}", e); + LogManager.Error("FavoritesInfo", e); + return null; + } + } + + /// + /// 查询所有的用户收藏的视频收藏夹 + /// + /// 目标用户UID + /// + public static List GetAllCollectedFavorites(long mid) + { + List result = new List(); + + int i = 0; + while (true) + { + i++; + int ps = 50; + + var data = GetCollectedFavorites(mid, i, ps); + if (data == null || data.Count == 0) + { break; } + + result.AddRange(data); + } + return result; + } + + } } diff --git a/DownKyi.Core/BiliApi/Favorites/FavoritesResource.cs b/DownKyi.Core/BiliApi/Favorites/FavoritesResource.cs new file mode 100644 index 0000000..36082b8 --- /dev/null +++ b/DownKyi.Core/BiliApi/Favorites/FavoritesResource.cs @@ -0,0 +1,91 @@ +using DownKyi.Core.BiliApi.Favorites.Models; +using DownKyi.Core.Logging; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Favorites +{ + public static class FavoritesResource + { + + /// + /// 获取收藏夹内容明细列表 + /// + /// 收藏夹ID + /// 页码 + /// 每页项数 + /// + public static List GetFavoritesMedia(long mediaId, int pn, int ps) + { + string url = $"https://api.bilibili.com/x/v3/fav/resource/list?media_id={mediaId}&pn={pn}&ps={ps}"; + string referer = "https://www.bilibili.com"; + string response = WebClient.RequestWeb(url, referer); + + try + { + var resource = JsonConvert.DeserializeObject(response); + if (resource == null || resource.Data == null || resource.Data.Medias == null) + { return null; } + return resource.Data.Medias; + } + catch (Exception e) + { + Console.WriteLine("GetFavoritesMedia()发生异常: {0}", e); + LogManager.Error("FavoritesResource", e); + return null; + } + } + + /// + /// 获取收藏夹内容明细列表(全部) + /// + /// 收藏夹ID + /// + public static List GetAllFavoritesMedia(long mediaId) + { + List result = new List(); + + int i = 0; + while (true) + { + i++; + int ps = 20; + + var data = GetFavoritesMedia(mediaId, i, ps); + if (data == null || data.Count == 0) + { break; } + + result.AddRange(data); + } + return result; + } + + /// + /// 获取收藏夹全部内容id + /// + /// + /// + public static List GetFavoritesMediaId(long mediaId) + { + string url = $"https://api.bilibili.com/x/v3/fav/resource/ids?media_id={mediaId}"; + string referer = "https://www.bilibili.com"; + string response = WebClient.RequestWeb(url, referer); + + try + { + var media = JsonConvert.DeserializeObject(response); + if (media == null || media.Data == null) + { return null; } + return media.Data; + } + catch (Exception e) + { + Console.WriteLine("GetFavoritesMediaId()发生异常: {0}", e); + LogManager.Error("FavoritesResource", e); + return null; + } + } + + } +} diff --git a/DownKyi.Core/BiliApi/Favorites/Models/FavStatus.cs b/DownKyi.Core/BiliApi/Favorites/Models/FavStatus.cs new file mode 100644 index 0000000..9c77cbb --- /dev/null +++ b/DownKyi.Core/BiliApi/Favorites/Models/FavStatus.cs @@ -0,0 +1,17 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Favorites.Models +{ + public class FavStatus : BaseModel + { + [JsonProperty("collect")] + public long Collect { get; set; } + [JsonProperty("play")] + public long Play { get; set; } + [JsonProperty("thumb_up")] + public long ThumbUp { get; set; } + [JsonProperty("share")] + public long Share { get; set; } + } +} diff --git a/DownKyi.Core/BiliApi/Favorites/Models/FavUpper.cs b/DownKyi.Core/BiliApi/Favorites/Models/FavUpper.cs new file mode 100644 index 0000000..562277e --- /dev/null +++ b/DownKyi.Core/BiliApi/Favorites/Models/FavUpper.cs @@ -0,0 +1,19 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Favorites.Models +{ + public class FavUpper : BaseModel + { + [JsonProperty("mid")] + public long Mid { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("face")] + public string Face { get; set; } + [JsonProperty("followed")] + public bool Followed { get; set; } + // vip_type + // vip_statue + } +} diff --git a/DownKyi.Core/BiliApi/Favorites/Models/FavoritesList.cs b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesList.cs new file mode 100644 index 0000000..bd412a7 --- /dev/null +++ b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesList.cs @@ -0,0 +1,30 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Favorites.Models +{ + // https://api.bilibili.com/x/v3/fav/folder/collected/list + public class FavoritesListOrigin : 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 FavoritesList Data { get; set; } + } + + public class FavoritesList : BaseModel + { + [JsonProperty("count")] + public int Count { get; set; } + [JsonProperty("list")] + public List List { get; set; } + [JsonProperty("has_more")] + public int HasMore { get; set; } + } + +} diff --git a/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMedia.cs b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMedia.cs new file mode 100644 index 0000000..8464c35 --- /dev/null +++ b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMedia.cs @@ -0,0 +1,43 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Favorites.Models +{ + public class FavoritesMedia : BaseModel + { + [JsonProperty("id")] + public long Id { get; set; } + [JsonProperty("type")] + public int Type { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("cover")] + public string Cover { get; set; } + [JsonProperty("intro")] + public string Intro { get; set; } + [JsonProperty("page")] + public int Page { get; set; } + [JsonProperty("duration")] + public long Duration { get; set; } + [JsonProperty("upper")] + public FavUpper Upper { get; set; } + // attr + [JsonProperty("cnt_info")] + public MediaStatus CntInfo { get; set; } + [JsonProperty("link")] + public string Link { get; set; } + [JsonProperty("ctime")] + public long Ctime { get; set; } + [JsonProperty("pubtime")] + public long Pubtime { get; set; } + [JsonProperty("fav_time")] + public long FavTime { get; set; } + [JsonProperty("bv_id")] + public string BvId { get; set; } + [JsonProperty("bvid")] + public string Bvid { get; set; } + // season + // ogv + // ugc + } +} diff --git a/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMediaId.cs b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMediaId.cs new file mode 100644 index 0000000..173bec8 --- /dev/null +++ b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMediaId.cs @@ -0,0 +1,32 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Favorites.Models +{ + // https://api.bilibili.com/x/v3/fav/resource/ids + public class FavoritesMediaIdOrigin : 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 List Data { get; set; } + } + + public class FavoritesMediaId : BaseModel + { + [JsonProperty("id")] + public long Id { get; set; } + [JsonProperty("type")] + public int Type { get; set; } + [JsonProperty("bv_id")] + public string BvId { get; set; } + [JsonProperty("bvid")] + public string Bvid { get; set; } + } + +} diff --git a/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMediaResource.cs b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMediaResource.cs new file mode 100644 index 0000000..bdd30b5 --- /dev/null +++ b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMediaResource.cs @@ -0,0 +1,30 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Favorites.Models +{ + // https://api.bilibili.com/x/v3/fav/resource/list + public class FavoritesMediaResourceOrigin : 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 FavoritesMediaResource Data { get; set; } + } + + public class FavoritesMediaResource : BaseModel + { + [JsonProperty("info")] + public FavoritesMetaInfo Info { get; set; } + [JsonProperty("medias")] + public List Medias { get; set; } + [JsonProperty("has_more")] + public int HasMore { get; set; } + } + +} diff --git a/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMetaInfo.cs b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMetaInfo.cs index 04ff3ea..d30848f 100644 --- a/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMetaInfo.cs +++ b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMetaInfo.cs @@ -50,30 +50,4 @@ namespace DownKyi.Core.BiliApi.Favorites.Models public int MediaCount { get; set; } } - public class FavUpper : BaseModel - { - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - [JsonProperty("face")] - public string Face { get; set; } - [JsonProperty("followed")] - public bool Followed { get; set; } - // vip_type - // vip_statue - } - - public class FavStatus : BaseModel - { - [JsonProperty("collect")] - public long Collect { get; set; } - [JsonProperty("play")] - public long Play { get; set; } - [JsonProperty("thumb_up")] - public long ThumbUp { get; set; } - [JsonProperty("share")] - public long Share { get; set; } - } - } diff --git a/DownKyi.Core/BiliApi/Favorites/Models/MediaStatus.cs b/DownKyi.Core/BiliApi/Favorites/Models/MediaStatus.cs new file mode 100644 index 0000000..1e56f86 --- /dev/null +++ b/DownKyi.Core/BiliApi/Favorites/Models/MediaStatus.cs @@ -0,0 +1,15 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Favorites.Models +{ + public class MediaStatus : BaseModel + { + [JsonProperty("collect")] + public long Collect { get; set; } + [JsonProperty("play")] + public long Play { get; set; } + [JsonProperty("danmaku")] + public long Danmaku { get; set; } + } +} diff --git a/DownKyi.Core/DownKyi.Core.csproj b/DownKyi.Core/DownKyi.Core.csproj index 8a9a33f..9ca3132 100644 --- a/DownKyi.Core/DownKyi.Core.csproj +++ b/DownKyi.Core/DownKyi.Core.csproj @@ -141,7 +141,15 @@ + + + + + + + +