Skip to content

Commit

Permalink
添加artplayer弹幕支持
Browse files Browse the repository at this point in the history
  • Loading branch information
MonoLogueChi committed Feb 12, 2020
1 parent 5b55d58 commit 3af4712
Show file tree
Hide file tree
Showing 14 changed files with 422 additions and 375 deletions.
27 changes: 27 additions & 0 deletions Danmaku/Controllers/ArtPlayer/V1/ArtPlayerController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Net.Http;
using System.Threading.Tasks;
using Danmaku.Controllers.Base;
using Danmaku.Model;
using Danmaku.Utils.Dao;
using Microsoft.AspNetCore.Mvc;

namespace Danmaku.Controllers.ArtPlayer.V1
{
[Route("api/artplayer/v1")]
[ApiController]
public class ArtPlayerController : DanmakuDaoBaseApiController
{
private readonly IHttpClientFactory _httpClientFactory;

public ArtPlayerController(IDanmakuDao danmakuDao, IHttpClientFactory httpClientFactory) : base(danmakuDao)
{
_httpClientFactory = httpClientFactory;
}

[HttpGet]
public async Task<string> Get(string id)
{
return string.IsNullOrEmpty(id) ? null : new BilibiliDanmakuData(await Dao.DanmakuQuery(id)).ToXml();
}
}
}
43 changes: 43 additions & 0 deletions Danmaku/Controllers/ArtPlayer/V1/BiliBiliController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Threading.Tasks;
using Danmaku.Model;
using Danmaku.Utils.BiliBili;
using Microsoft.AspNetCore.Mvc;

namespace Danmaku.Controllers.ArtPlayer.V1
{
[Route("api/artplayer/v1")]
[ApiController]
public class BiliBiliController : ControllerBase
{
private readonly IBiliBiliHelp _biliBili;

public BiliBiliController(IBiliBiliHelp biliBiliHelp)
{
_biliBili = biliBiliHelp;
}

// GET: api/dplayer/v3/bilibili
[HttpGet("bilibili")]
public async Task<string> Get()
{
var request = Request.Query;

string[] date = request["date"];
var cid = request["cid"].ToString();
if (string.IsNullOrEmpty(cid))
{
var aid = request["aid"];
if (string.IsNullOrEmpty(aid)) return new DanmakuWebResult(1);
string p = request["p"];
p = string.IsNullOrEmpty(p) ? "1" : p;
if (!int.TryParse(p, out var page)) return new DanmakuWebResult(1);
cid = (await _biliBili.GetCid(aid, page)).ToString();
}

return string.IsNullOrWhiteSpace(cid)
? null
: await _biliBili.GetBiDanmakuRaw(cid);

}
}
}
125 changes: 57 additions & 68 deletions Danmaku/Controllers/Dplayer/DanmakuList/DanmakuListController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,65 @@

namespace Danmaku.Controllers.Dplayer.DanmakuList
{
[Route("dplayer/danmakulist")]
[Authorize]
public class DanmakuListController : DanmakuDaoBaseController
{
public DanmakuListController(IDanmakuDao danmakuDao, ILogger<DanmakuListController> logger) : base(danmakuDao,
logger)
{
}
[Route("dplayer/danmakulist")]
[Authorize]
public class DanmakuListController : DanmakuDaoBaseController
{
public DanmakuListController(IDanmakuDao danmakuDao, ILogger<DanmakuListController> logger) : base(danmakuDao,
logger) { }

public async Task<ActionResult> Index(int page = 1, int size = 20, string vid = null, string author = null,
string date_star = null, string date_end = null, int type = 3,
string ip = null, string text = null,
int order = 0)
{
if (type == 3) return View(await Dao.DanmakuBaseQuery(page, size));
return View(
await Dao.DanmakuBasesQuery(page, size, vid, author, date_star, date_end, type, ip, text, order));
}

public async Task<ActionResult> Index(int page = 1, int size = 20, string vid = null, string author = null,
string date_star = null, string date_end = null, int type = 3, string ip = null, string text = null,
int order = 0)
{
if (type == 3) return View(await Dao.DanmakuBaseQuery(page, size));
return View(await Dao.DanmakuBasesQuery(page, size, vid, author, date_star, date_end, type, ip, text, order));
}
/// <summary>
/// 编辑框
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("editor/{id}")]
public async Task<ActionResult> Editor(string id)
{
var data = await Dao.DanmakuBaseQuery(id);
if (data == null)
return BadRequest();
return View(data);
}

/// <summary>
/// 筛选框
/// </summary>
/// <returns></returns>
[HttpGet("select")]
public ActionResult Select()
{
return View();
}
/// <summary>
/// 修改弹幕
/// </summary>
/// <param name="id"></param>
/// <param name="time"></param>
/// <param name="type"></param>
/// <param name="color"></param>
/// <param name="text"></param>
/// <returns></returns>
[HttpPost("editor/")]
public async Task<ActionResult> Editor([FromForm] string id, [FromForm] float time, [FromForm] int type,
[FromForm] string color, [FromForm] string text)
{
var data = await Dao.DanmakuEdit(id, time, type, color, text);
if (data == null)
return BadRequest();
return View(data);
}

/// <summary>
/// 编辑框
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("editor/{id}")]
public async Task<ActionResult> Editor(string id)
{
var data = await Dao.DanmakuBaseQuery(id);
if (data == null)
return BadRequest();
return View(data);
}

/// <summary>
/// 修改弹幕
/// </summary>
/// <param name="id"></param>
/// <param name="time"></param>
/// <param name="type"></param>
/// <param name="color"></param>
/// <param name="text"></param>
/// <returns></returns>
[HttpPost("editor/")]
public async Task<ActionResult> Editor([FromForm] string id, [FromForm] float time, [FromForm] int type,
[FromForm] string color, [FromForm] string text)
{
var data = await Dao.DanmakuEdit(id, time, type, color, text);
if (data == null)
return BadRequest();
return View(data);
}

/// <summary>
/// 删除弹幕
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("delete/{id}")]
public async Task<bool> Delete(string id)
{
return await Dao.DanmakuDelete(id);
}
}
/// <summary>
/// 删除弹幕
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("delete/{id}")]
public async Task<bool> Delete(string id)
{
return await Dao.DanmakuDelete(id);
}
}
}
64 changes: 32 additions & 32 deletions Danmaku/Controllers/Dplayer/V3/BiliBiliController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@

namespace Danmaku.Controllers.Dplayer.V3
{
[Route("api/dplayer/v3")]
[ApiController]
public class BiliBiliController : ControllerBase
{
private readonly IBiliBiliHelp _biliBili;
[Route("api/dplayer/v3")]
[ApiController]
public class BiliBiliController : ControllerBase
{
private readonly IBiliBiliHelp _biliBili;

public BiliBiliController(IBiliBiliHelp biliBiliHelp)
{
_biliBili = biliBiliHelp;
}
public BiliBiliController(IBiliBiliHelp biliBiliHelp)
{
_biliBili = biliBiliHelp;
}

// GET: api/dplayer/v3/bilibili
[HttpGet("bilibili")]
public async Task<string> Get()
{
var request = Request.Query;
// GET: api/dplayer/v3/bilibili
[HttpGet("bilibili")]
public async Task<string> Get()
{
var request = Request.Query;

string[] date = request["date"];
var cid = request["cid"].ToString();
if (string.IsNullOrEmpty(cid))
{
var aid = request["aid"];
if (string.IsNullOrEmpty(aid)) return new DanmakuWebResult(1);
string p = request["p"];
p = string.IsNullOrEmpty(p) ? "1" : p;
if (!int.TryParse(p, out var page)) return new DanmakuWebResult(1);
cid = (await _biliBili.GetCid(aid, page)).ToString();
}
string[] date = request["date"];
var cid = request["cid"].ToString();
if (string.IsNullOrEmpty(cid))
{
var aid = request["aid"];
if (string.IsNullOrEmpty(aid)) return new DanmakuWebResult(1);
string p = request["p"];
p = string.IsNullOrEmpty(p) ? "1" : p;
if (!int.TryParse(p, out var page)) return new DanmakuWebResult(1);
cid = (await _biliBili.GetCid(aid, page)).ToString();
}

return string.IsNullOrWhiteSpace(cid)
? new DanmakuWebResult(1)
: date.Length == 0
? new DanmakuWebResult(await _biliBili.GetBiDanmaku(cid))
: new DanmakuWebResult(await _biliBili.GetBiDanmaku(cid, date));
}
}
return string.IsNullOrWhiteSpace(cid)
? new DanmakuWebResult(1)
: date.Length == 0
? new DanmakuWebResult(await _biliBili.GetBiDanmaku(cid))
: new DanmakuWebResult(await _biliBili.GetBiDanmaku(cid, date));
}
}
}
55 changes: 27 additions & 28 deletions Danmaku/Controllers/Dplayer/V3/DplayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,34 @@

namespace Danmaku.Controllers.Dplayer.V3
{
[Route("api/dplayer/v3")]
[ApiController]
public class DplayerController : DanmakuDaoBaseApiController
{
public DplayerController(IDanmakuDao danmakuDao) : base(danmakuDao)
{
}
[Route("api/dplayer/v3")]
[ApiController]
public class DplayerController : DanmakuDaoBaseApiController
{
public DplayerController(IDanmakuDao danmakuDao) : base(danmakuDao) { }

// GET: api/dplayer/v3/
[HttpGet]
public async Task<string> Get()
{
string id = Request.Query["id"];
return string.IsNullOrEmpty(id) ? new DanmakuWebResult(1) : new DanmakuWebResult(await Dao.DanmakuQuery(id));
}
// GET: api/dplayer/v3/
[HttpGet]
public async Task<string> Get(string id)
{
return string.IsNullOrEmpty(id)
? new DanmakuWebResult(1)
: new DanmakuWebResult(await Dao.DanmakuQuery(id));
}

// POST: api/dplayer/v3/
[HttpPost]
public async Task<string> Post([FromBody] DanmakuDataInsert data)
{
if (string.IsNullOrWhiteSpace(data.Id) || string.IsNullOrWhiteSpace(data.Text))
return new DanmakuWebResult(1);
data.Ip = IPAddress.TryParse(Request.Headers["X-Real-IP"], out var ip)
? ip
: Request.HttpContext.Connection.RemoteIpAddress;
data.Referer = Request.Headers["Referer"].FirstOrDefault();
// POST: api/dplayer/v3/
[HttpPost]
public async Task<string> Post([FromBody] DanmakuDataInsert data)
{
if (string.IsNullOrWhiteSpace(data.Id) || string.IsNullOrWhiteSpace(data.Text))
return new DanmakuWebResult(1);
data.Ip = IPAddress.TryParse(Request.Headers["X-Real-IP"], out var ip)
? ip
: Request.HttpContext.Connection.RemoteIpAddress;
data.Referer = Request.Headers["Referer"].FirstOrDefault();

var result = await Dao.DanmakuInsert(data);
return result ? new DanmakuWebResult(0) : new DanmakuWebResult(1);
}
}
var result = await Dao.DanmakuInsert(data);
return result ? new DanmakuWebResult(0) : new DanmakuWebResult(1);
}
}
}
1 change: 1 addition & 0 deletions Danmaku/Danmaku.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.0" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 3af4712

Please sign in to comment.