Skip to content

Commit

Permalink
修复了从非番剧页打开番剧时产生的错误 (#472)
Browse files Browse the repository at this point in the history
修复了从非番剧页打开番剧时产生的错误
  • Loading branch information
GD-Slime authored Jan 3, 2024
1 parent 69acf4d commit 56056dc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
27 changes: 21 additions & 6 deletions src/BiliLite.UWP/Extensions/BiliExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using BiliLite.Models.Common;
using BiliLite.Models;
using BiliLite.Models.Common;
using BiliLite.Models.Common.Season;
using BiliLite.Models.Exceptions;
using BiliLite.Models.Requests.Api;
using BiliLite.Models.Responses;
using BiliLite.Services;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.UI.Controls;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net.Http;
Expand All @@ -29,12 +31,25 @@ public static async Task<string> BangumiEpidToSid(string epid)
{
try
{
var re = await $"https://bangumi.bilibili.com/view/web_api/season?ep_id={epid}".GetString();
var obj = JObject.Parse(re);
return obj["result"]["season_id"].ToString();
var results = await new SeasonApi().Detail(epid, SeasonIdType.EpId).Request();
if (!results.status)
{
throw new CustomizedErrorException(results.message);
}

//访问番剧详情
var data = await results.GetJson<ApiDataModel<SeasonDetailModel>>();

if (!data.success)
{
throw new CustomizedErrorException(data.message);
}

return data.data.SeasonId.ToString();
}
catch (Exception)
catch (Exception ex)
{
_logger.Error("转换epId到seasonId错误", ex);
return "";
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/BiliLite.UWP/Models/Common/Enumerates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,10 @@ public enum MessageType
/// </summary>
OnlineRankChange,
}

public enum SeasonIdType
{
SeasonId,
EpId,
}
}
23 changes: 20 additions & 3 deletions src/BiliLite.UWP/Models/Requests/Api/SeasonApi.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
using BiliLite.Services;
using System;
using BiliLite.Models.Common;
using Bilibili.App.View.V1;

namespace BiliLite.Models.Requests.Api
{
public class SeasonApi : BaseApi
{

public ApiModel Detail(string season_id, bool proxy = false)
/// <summary>
/// 用season_id / ep_id 取番剧信息
/// </summary>
/// <param name="id"> seasonId / epId</param>
/// <param name="type">id类型</param>
/// <param name="proxy"></param>
/// <returns></returns>
public ApiModel Detail(string id, SeasonIdType type = SeasonIdType.SeasonId, bool proxy = false)
{
var baseUrl = ApiHelper.API_BASE_URL;

var api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"{baseUrl}/pgc/view/v2/app/season",
parameter = ApiHelper.MustParameter(AppKey, true) + $"&season_id={season_id}"
parameter = ApiHelper.MustParameter(AppKey, true),
};
if (type == SeasonIdType.SeasonId)
{
api.parameter += $"&season_id={id}";
}
else
{
api.parameter += $"&ep_id={id}";
}

api.parameter = api.parameter.Replace("build=6235200", "build=75900200");
api.parameter += ApiHelper.GetSign(api.parameter, AppKey);
return api;
Expand Down

0 comments on commit 56056dc

Please sign in to comment.