Skip to content

Commit

Permalink
domandのAccessRight取得時に音声Idのみを渡すケースに対応。
Browse files Browse the repository at this point in the history
  • Loading branch information
tor4kichi committed Nov 11, 2023
1 parent c4a75a3 commit 32be55e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
35 changes: 16 additions & 19 deletions NiconicoToolkit.Shared/Video/Watch/VideoWatchSubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,24 @@ public async Task<WatchJsonResponse> GetDmcWatchJsonAsync(VideoId videoId, bool
public async Task<DomandHlsAccessRightResponse> GetDomandHlsAccessRightAsync(
VideoId videoId,
MediaDomand domand,
string videoQualityId,
string audioQualityId,
string? videoQualityId,
string? audioQualityId,
string? watchTrackId = null,
CancellationToken ct = default)
{
{
List<string> qualities = new ();
if (videoQualityId != null)
{
qualities.Add(videoQualityId);
}
if (audioQualityId != null)
{
qualities.Add(audioQualityId);
}
return await _context.SendJsonAsAsync<DomandHlsAccessRightResponse>(
HttpMethod.Post,
$"{NiconicoUrls.NvApiV1Url}watch/{videoId}/access-rights/hls{(watchTrackId != null ? $"?actionTrackId={watchTrackId}" : "")}",
$"{{\"outputs\":[[\"{videoQualityId}\",\"{audioQualityId}\"]]}}",
$"{{\"outputs\":[[{string.Join(',', qualities.Select(x => $"\"{x}\""))}]]}}",
null,
(header) =>
{
Expand All @@ -174,25 +183,13 @@ public async Task<DomandHlsAccessRightResponse> GetDomandHlsAccessRightAsync(
public async Task<DomandHlsAccessRightResponse> GetDomandHlsAccessRightAsync(
VideoId videoId,
MediaDomand domand,
DomandVideo videoQuality,
DomandAudio audioQuality,
DomandVideo? videoQuality,
DomandAudio? audioQuality,
string? watchTrackId = null,
CancellationToken ct = default
)
{
return await _context.SendJsonAsAsync<DomandHlsAccessRightResponse>(
HttpMethod.Post,
$"{NiconicoUrls.NvApiV1Url}watch/{videoId}/access-rights/hls{(watchTrackId != null ? $"?actionTrackId={watchTrackId}" : "")}",
$"{{\"outputs\":[[\"{videoQuality.Id}\",\"{audioQuality.Id}\"]]}}",
null,
(header) =>
{
header.Add("X-Access-Right-Key", domand.AccessRightKey);
header.Add("X-Frontend-Version", "0");
header.Add("X-Frontend-Id", "6");
header.Add("X-Request-With", "https://www.nicovideo.jp");
},
ct);
return await GetDomandHlsAccessRightAsync(videoId, domand, videoQuality?.Id, audioQuality?.Id, watchTrackId, ct);
}

#endregion
Expand Down
18 changes: 18 additions & 0 deletions Test/NiconicoToolkit.Shared.Test/VideoWatchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ public async Task Domand_PlayVideoAsync(string videoId)
Assert.IsTrue(!string.IsNullOrEmpty(accessRight.Data.ContentUrl));
}

[TestMethod]
[DataRow("so42997483")]
public async Task Domand_PlayVideoOnlyAudioAsync(string videoId)
{
var res = await _context.Video.VideoWatch.GetInitialWatchDataAsync(videoId, false, false);
Assert.IsNotNull(res.WatchApiResponse.WatchApiData.Media.Domand);

var accessRight = await _context.Video.VideoWatch.GetDomandHlsAccessRightAsync(
videoId,
res.WatchApiResponse.WatchApiData.Media.Domand,
null,
res.WatchApiResponse.WatchApiData.Media.Domand.Audios.First(x => x.IsAvailable ?? false).Id,
res.WatchApiResponse.WatchApiData.VideoAds.AdditionalParams.WatchTrackId
);
Assert.IsTrue(accessRight.IsSuccess);
Assert.IsTrue(!string.IsNullOrEmpty(accessRight.Data.ContentUrl));
}

#endregion

#region Watch Video
Expand Down

0 comments on commit 32be55e

Please sign in to comment.