You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
downkyi/DownKyi.Core/BiliApi/Bangumi/BangumiInfo.cs

69 lines
2.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using DownKyi.Core.BiliApi.Bangumi.Models;
using DownKyi.Core.Logging;
using Newtonsoft.Json;
using System;
namespace DownKyi.Core.BiliApi.Bangumi
{
public static class BangumiInfo
{
/// <summary>
/// 剧集基本信息mediaId方式
/// </summary>
/// <param name="mediaId"></param>
/// <returns></returns>
public static BangumiMedia BangumiMediaInfo(long mediaId)
{
string url = $"https://api.bilibili.com/pgc/review/user?media_id={mediaId}";
string referer = "https://www.bilibili.com";
string response = WebClient.RequestWeb(url, referer);
try
{
var media = JsonConvert.DeserializeObject<BangumiMediaOrigin>(response);
if (media != null && media.Result != null) { return media.Result.Media; }
else { return null; }
}
catch (Exception e)
{
Utils.Debugging.Console.PrintLine("BangumiMediaInfo()发生异常: {0}", e);
LogManager.Error("BangumiInfo", e);
return null;
}
}
/// <summary>
/// 获取剧集明细web端seasonId/episodeId方式
/// </summary>
/// <param name="seasonId"></param>
/// <param name="episodeId"></param>
/// <returns></returns>
public static BangumiSeason BangumiSeasonInfo(long seasonId = -1, long episodeId = -1)
{
string baseUrl = "https://api.bilibili.com/pgc/view/web/season";
string referer = "https://www.bilibili.com";
string url;
if (seasonId > -1) { url = $"{baseUrl}?season_id={seasonId}"; }
else if (episodeId > -1) { url = $"{baseUrl}?ep_id={episodeId}"; }
else { return null; }
string response = WebClient.RequestWeb(url, referer);
try
{
var bangumiSeason = JsonConvert.DeserializeObject<BangumiSeasonOrigin>(response);
if (bangumiSeason != null) { return bangumiSeason.Result; }
else { return null; }
}
catch (Exception e)
{
Utils.Debugging.Console.PrintLine("BangumiSeasonInfo()发生异常: {0}", e);
LogManager.Error("BangumiInfo", e);
return null;
}
}
}
}