mirror of
https://github.com/cxfksword/jellyfin-plugin-danmu.git
synced 2026-06-28 00:27:06 +08:00
fix: fix update movie bvid danmu
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,4 +6,5 @@ obj/
|
||||
artifacts
|
||||
**/.DS_Store
|
||||
*.json
|
||||
**/.env
|
||||
**/.env
|
||||
build.sh
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using Jellyfin.Plugin.Danmu.Model;
|
||||
using Jellyfin.Plugin.Danmu.Scrapers.Bilibili;
|
||||
using Jellyfin.Plugin.Danmu.Scrapers.Bilibili.Entity;
|
||||
@@ -153,9 +154,12 @@ namespace Jellyfin.Plugin.Danmu.Test
|
||||
{
|
||||
try
|
||||
{
|
||||
var cid = 37578346061;
|
||||
var result = await _bilibiliApi.GetDanmuContentByCidAsync(cid, CancellationToken.None);
|
||||
Console.WriteLine(result);
|
||||
var cid = 541370210;
|
||||
var bytes = await _bilibiliApi.GetDanmuContentByCidAsync(cid, CancellationToken.None);
|
||||
var doc = new XmlDocument();
|
||||
doc.LoadXml(System.Text.Encoding.UTF8.GetString(bytes));
|
||||
var nodes = doc.GetElementsByTagName("d");
|
||||
Console.WriteLine(nodes.Count);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -173,8 +177,8 @@ namespace Jellyfin.Plugin.Danmu.Test
|
||||
{
|
||||
try
|
||||
{
|
||||
var aid = 5048623;
|
||||
var cid = 9708007;
|
||||
var aid = 381941309;
|
||||
var cid = 541370210;
|
||||
var result = await _bilibiliApi.GetDanmuContentByProtoAsync(aid, cid, CancellationToken.None);
|
||||
Console.WriteLine(result);
|
||||
}
|
||||
|
||||
@@ -204,6 +204,41 @@ public class Bilibili : AbstractScraper
|
||||
return new ScraperEpisode() { Id = id, CommentId = id };
|
||||
}
|
||||
|
||||
var isMovieItemType = item is MediaBrowser.Controller.Entities.Movies.Movie;
|
||||
|
||||
if (id.StartsWith("BV", StringComparison.CurrentCultureIgnoreCase) && isMovieItemType)
|
||||
{
|
||||
var video = await _api.GetVideoByBvidAsync(id, CancellationToken.None).ConfigureAwait(false);
|
||||
if (video == null)
|
||||
{
|
||||
log.LogInformation("获取不到b站视频信息:bvid={0}", id);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (video.UgcSeason != null && video.UgcSeason.Sections != null && video.UgcSeason.Sections.Count > 0)
|
||||
{
|
||||
var page = video.UgcSeason.Sections[0].Episodes[0];
|
||||
return new ScraperEpisode() { Id = id, CommentId = $"{page.CId}" };
|
||||
}
|
||||
|
||||
var firstPage = video.Pages[0];
|
||||
return new ScraperEpisode() { Id = id, CommentId = $"{firstPage.Cid}" };
|
||||
}
|
||||
|
||||
if (id.StartsWith("av", StringComparison.CurrentCultureIgnoreCase) && isMovieItemType)
|
||||
{
|
||||
var biliplusVideo = await _api.GetVideoByAvidAsync(id, CancellationToken.None).ConfigureAwait(false);
|
||||
if (biliplusVideo == null)
|
||||
{
|
||||
log.LogInformation("获取不到b站视频信息:avid={0}", id);
|
||||
return null;
|
||||
}
|
||||
|
||||
var aid = id.Substring(2);
|
||||
var firstPage = biliplusVideo.List[0];
|
||||
return new ScraperEpisode() { Id = id, CommentId = $"{aid},{firstPage.Cid}" };
|
||||
}
|
||||
|
||||
var epId = id.ToLong();
|
||||
if (epId <= 0)
|
||||
{
|
||||
@@ -231,13 +266,21 @@ public class Bilibili : AbstractScraper
|
||||
var cmid = arr[1].ToLong();
|
||||
if (aid > 0 && cmid > 0)
|
||||
{
|
||||
// GetDanmuContentByCidAsync 获取的弹幕比较多,优先使用
|
||||
var bytes = await _api.GetDanmuContentByCidAsync(cmid, CancellationToken.None).ConfigureAwait(false);
|
||||
var danmaku = ParseXml(System.Text.Encoding.UTF8.GetString(bytes));
|
||||
if (danmaku != null && danmaku.Items.Count > 0)
|
||||
{
|
||||
danmaku.ChatId = cmid;
|
||||
return danmaku;
|
||||
}
|
||||
|
||||
return await _api.GetDanmuContentByProtoAsync(aid, cmid, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
var cid = commentId.ToLong();
|
||||
if (cid > 0)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ public class ExternalUrlProvider : IExternalUrlProvider
|
||||
{
|
||||
if (externalId.StartsWith("bv", StringComparison.OrdinalIgnoreCase) || externalId.StartsWith("av", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
yield return $"https://www.bilibili.com/{externalId}";
|
||||
yield return $"https://www.bilibili.com/video/{externalId}";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -59,7 +59,7 @@ public class ExternalUrlProvider : IExternalUrlProvider
|
||||
{
|
||||
if (externalId.StartsWith("bv", StringComparison.OrdinalIgnoreCase) || externalId.StartsWith("av", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
yield return $"https://www.bilibili.com/{externalId}";
|
||||
yield return $"https://www.bilibili.com/video/{externalId}";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user