Skip to content

Commit

Permalink
Support bilibili ugc collection
Browse files Browse the repository at this point in the history
  • Loading branch information
cxfksword committed Feb 6, 2023
1 parent ca09be8 commit 3fab33f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
20 changes: 20 additions & 0 deletions Jellyfin.Plugin.Danmu.Test/BilibiliApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,25 @@ public void TestGetVideoByBvidAsync()
}
}).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();
}
}
}
16 changes: 14 additions & 2 deletions Jellyfin.Plugin.Danmu/Scrapers/Bilibili/Bilibili.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,21 @@ public Bilibili(ILoggerFactory logManager)

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;
Expand Down
3 changes: 3 additions & 0 deletions Jellyfin.Plugin.Danmu/Scrapers/Bilibili/Entity/Video.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ public class Video

[JsonPropertyName("pages")]
public VideoPart[] Pages { get; set; }

[JsonPropertyName("ugc_season")]
public VideoUgcSeason? UgcSeason { get; set; }
}
}
30 changes: 30 additions & 0 deletions Jellyfin.Plugin.Danmu/Scrapers/Bilibili/Entity/VideoUgcSeason.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}

0 comments on commit 3fab33f

Please sign in to comment.