mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-12-26 12:15:42 +08:00
324c41ab1d
* danmaku: get svr with ck & conn with uid from ck * apply code chagnes for pr * fix bug and add description in advanced settings * fix test --------- Co-authored-by: genteure <genteure@gmail.com>
40 lines
1.9 KiB
C#
40 lines
1.9 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using BililiveRecorder.Core.Api.Model;
|
|
using Polly;
|
|
using Polly.Registry;
|
|
|
|
namespace BililiveRecorder.Core.Api
|
|
{
|
|
internal class PolicyWrappedApiClient<T> : IApiClient, IDanmakuServerApiClient, IDisposable where T : class, IApiClient, IDanmakuServerApiClient, IDisposable
|
|
{
|
|
private readonly T client;
|
|
private readonly IReadOnlyPolicyRegistry<string> policies;
|
|
|
|
public PolicyWrappedApiClient(T client, IReadOnlyPolicyRegistry<string> policies)
|
|
{
|
|
this.client = client ?? throw new ArgumentNullException(nameof(client));
|
|
this.policies = policies ?? throw new ArgumentNullException(nameof(policies));
|
|
}
|
|
|
|
public long GetUid() => this.client.GetUid();
|
|
|
|
public async Task<BilibiliApiResponse<DanmuInfo>> GetDanmakuServerAsync(int roomid) => await this.policies
|
|
.Get<IAsyncPolicy>(PolicyNames.PolicyDanmakuApiRequestAsync)
|
|
.ExecuteAsync(_ => this.client.GetDanmakuServerAsync(roomid), new Context(PolicyNames.CacheKeyDanmaku + ":" + roomid))
|
|
.ConfigureAwait(false);
|
|
|
|
public async Task<BilibiliApiResponse<RoomInfo>> GetRoomInfoAsync(int roomid) => await this.policies
|
|
.Get<IAsyncPolicy>(PolicyNames.PolicyRoomInfoApiRequestAsync)
|
|
.ExecuteAsync(_ => this.client.GetRoomInfoAsync(roomid), new Context(PolicyNames.CacheKeyRoomInfo + ":" + roomid))
|
|
.ConfigureAwait(false);
|
|
|
|
public async Task<BilibiliApiResponse<RoomPlayInfo>> GetStreamUrlAsync(int roomid, int qn) => await this.policies
|
|
.Get<IAsyncPolicy>(PolicyNames.PolicyStreamApiRequestAsync)
|
|
.ExecuteAsync(_ => this.client.GetStreamUrlAsync(roomid, qn), new Context(PolicyNames.CacheKeyStream + ":" + roomid + ":" + qn))
|
|
.ConfigureAwait(false);
|
|
|
|
public void Dispose() => this.client.Dispose();
|
|
}
|
|
}
|