Support bilibili ugc collection

This commit is contained in:
cxfksword
2023-02-06 15:30:35 +08:00
parent ca09be8425
commit 3fab33f241
4 changed files with 67 additions and 2 deletions

View File

@@ -83,5 +83,25 @@ namespace Jellyfin.Plugin.Danmu.Test
}
}).GetAwaiter().GetResult();
}
[TestMethod]
public void TestGetVideoByBvidForCollectionAsync()
{
var bvid = "BV1z34y1h7yQ";
var _bilibiliApi = new BilibiliApi(loggerFactory);
Task.Run(async () =>
{
try
{
var result = await _bilibiliApi.GetVideoByBvidAsync(bvid, CancellationToken.None);
Console.WriteLine(result);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}).GetAwaiter().GetResult();
}
}
}

View File

@@ -64,9 +64,21 @@ public class Bilibili : AbstractScraper
media.Id = id;
media.Name = video.Title;
foreach (var (page, idx) in video.Pages.WithIndex())
if (video.UgcSeason != null && video.UgcSeason.Sections != null && video.UgcSeason.Sections.Count > 0)
{
media.Episodes.Add(new ScraperEpisode() { Id = "", CommentId = $"{page.Cid}" });
// 合集
foreach (var (page, idx) in video.UgcSeason.Sections[0].Episodes.WithIndex())
{
media.Episodes.Add(new ScraperEpisode() { Id = "", CommentId = $"{page.CId}" });
}
}
else
{
// 分P
foreach (var (page, idx) in video.Pages.WithIndex())
{
media.Episodes.Add(new ScraperEpisode() { Id = "", CommentId = $"{page.Cid}" });
}
}
return media;

View File

@@ -24,5 +24,8 @@ namespace Jellyfin.Plugin.Danmu.Scrapers.Bilibili.Entity
[JsonPropertyName("pages")]
public VideoPart[] Pages { get; set; }
[JsonPropertyName("ugc_season")]
public VideoUgcSeason? UgcSeason { get; set; }
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace Jellyfin.Plugin.Danmu.Scrapers.Bilibili.Entity
{
public class VideoUgcSeason
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("title")]
public string Title { get; set; }
[JsonPropertyName("sections")]
public List<VideoUgcSection> Sections { get; set; }
}
public class VideoUgcSection
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("episodes")]
public List<VideoEpisode> Episodes { get; set; }
}
}