-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using MisakaBiliApi.Models.ApiResponse; | ||
using MisakaBiliCore.Models; | ||
using MisakaBiliCore.Models.BiliApi; | ||
using MisakaBiliCore.Services.BiliApi; | ||
|
||
namespace MisakaBiliApi.Controllers; | ||
|
||
[ApiController] | ||
[Route("live")] | ||
public class BiliLiveController(IBiliLiveApiService biliLiveApiService) : ControllerBase | ||
{ | ||
[HttpGet("url")] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType<MisakaVideoUrlResponse>(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status302Found)] | ||
[Produces("application/json")] | ||
public async Task<IActionResult> GetLiveUrl(string cid, LiveStreamType streamType = LiveStreamType.M3U8, | ||
bool redirect = false) | ||
{ | ||
var liveUrlResponse = | ||
await biliLiveApiService.GetLiveUrlByRoomId(cid, streamType == LiveStreamType.Flv ? "web" : "h5"); | ||
|
||
var liveUrl = liveUrlResponse.Data.Durl.First(); | ||
|
||
if (redirect) | ||
return Redirect(liveUrl.Url.ToString()); | ||
|
||
return Ok(new MisakaVideoUrlResponse( | ||
Url: liveUrl.Url.ToString(), | ||
Format: streamType.ToString(), | ||
TimeLength: liveUrl.Length, | ||
Quality: BiliVideoQuality.R1080P | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace MisakaBiliCore.Models.BiliApi; | ||
|
||
public enum BiliLiveQuality | ||
{ | ||
Smooth = 2, | ||
High = 3, | ||
Original = 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MisakaBiliCore.Models.BiliApi; | ||
|
||
public class BiliLiveUrlResponse | ||
{ | ||
[JsonPropertyName("current_quality")] public long CurrentQuality { get; set; } | ||
|
||
[JsonPropertyName("accept_quality")] public string[] AcceptQuality { get; set; } | ||
|
||
[JsonPropertyName("current_qn")] public long CurrentQn { get; set; } | ||
|
||
[JsonPropertyName("quality_description")] | ||
public QualityDescription[] QualityDescription { get; set; } | ||
|
||
[JsonPropertyName("durl")] public Durl[] Durl { get; set; } | ||
} | ||
|
||
public class Durl | ||
{ | ||
[JsonPropertyName("url")] public Uri Url { get; set; } | ||
|
||
[JsonPropertyName("length")] public long Length { get; set; } | ||
|
||
[JsonPropertyName("order")] public long Order { get; set; } | ||
|
||
[JsonPropertyName("stream_type")] public long StreamType { get; set; } | ||
|
||
[JsonPropertyName("p2p_type")] public long P2PType { get; set; } | ||
} | ||
|
||
public class QualityDescription | ||
{ | ||
[JsonPropertyName("qn")] public long Qn { get; set; } | ||
|
||
[JsonPropertyName("desc")] public string Desc { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace MisakaBiliCore.Models; | ||
|
||
public enum LiveStreamType | ||
{ | ||
M3U8, | ||
Flv | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using MisakaBiliCore.Models.BiliApi; | ||
using Refit; | ||
|
||
namespace MisakaBiliCore.Services.BiliApi; | ||
|
||
public interface IBiliLiveApiService | ||
{ | ||
[Get("/room/v1/Room/playUrl")] | ||
public Task<BiliApiResponse<BiliLiveUrlResponse>> GetLiveUrlByRoomId( | ||
[AliasAs("cid")] string cid, | ||
[AliasAs("platform")] string platform = "web", | ||
[AliasAs("quality")] int quality = (int)BiliLiveQuality.Original); | ||
} |