-
Notifications
You must be signed in to change notification settings - Fork 6
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
22 changed files
with
1,137 additions
and
41 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,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Jellyfin.Plugin.Danmu.Model; | ||
using Jellyfin.Plugin.Danmu.Scrapers.Mgtv; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Jellyfin.Plugin.Danmu.Test | ||
{ | ||
|
||
[TestClass] | ||
public class MgtvApiTest : BaseTest | ||
{ | ||
[TestMethod] | ||
public void TestSearch() | ||
{ | ||
Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
var keyword = "大侦探"; | ||
var api = new MgtvApi(loggerFactory); | ||
var result = await api.SearchAsync(keyword, CancellationToken.None); | ||
Console.WriteLine(result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
}).GetAwaiter().GetResult(); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public void TestGetVideo() | ||
{ | ||
Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
var id = "310102"; | ||
var api = new MgtvApi(loggerFactory); | ||
var result = await api.GetVideoAsync(id, CancellationToken.None); | ||
Console.WriteLine(result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
}).GetAwaiter().GetResult(); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public void TestGetDanmu() | ||
{ | ||
|
||
Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
var cid = "514446"; | ||
var vid = "18053294"; | ||
var api = new MgtvApi(loggerFactory); | ||
var result = await api.GetDanmuContentAsync(cid, vid, CancellationToken.None); | ||
Console.WriteLine(result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
}).GetAwaiter().GetResult(); | ||
} | ||
|
||
} | ||
} |
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,150 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Jellyfin.Plugin.Danmu.Model; | ||
using Jellyfin.Plugin.Danmu.Scrapers; | ||
using Jellyfin.Plugin.Danmu.Scrapers.Mgtv; | ||
using MediaBrowser.Controller.Entities.Movies; | ||
using MediaBrowser.Controller.Entities.TV; | ||
using MediaBrowser.Controller.Library; | ||
using MediaBrowser.Controller.Providers; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
|
||
namespace Jellyfin.Plugin.Danmu.Test | ||
{ | ||
|
||
[TestClass] | ||
public class MgtvTest : BaseTest | ||
{ | ||
[TestMethod] | ||
public void TestAddMovie() | ||
{ | ||
var libraryManagerStub = new Mock<ILibraryManager>(); | ||
var scraperManager = new ScraperManager(loggerFactory); | ||
scraperManager.register(new Jellyfin.Plugin.Danmu.Scrapers.Mgtv.Mgtv(loggerFactory, libraryManagerStub.Object)); | ||
|
||
var fileSystemStub = new Mock<Jellyfin.Plugin.Danmu.Core.IFileSystem>(); | ||
var directoryServiceStub = new Mock<IDirectoryService>(); | ||
|
||
var libraryManagerEventsHelper = new LibraryManagerEventsHelper(libraryManagerStub.Object, loggerFactory, fileSystemStub.Object, scraperManager); | ||
|
||
var item = new Movie | ||
{ | ||
Name = "虚颜" | ||
}; | ||
|
||
var list = new List<LibraryEvent>(); | ||
list.Add(new LibraryEvent { Item = item, EventType = EventType.Add }); | ||
|
||
Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
await libraryManagerEventsHelper.ProcessQueuedMovieEvents(list, EventType.Add); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
}).GetAwaiter().GetResult(); | ||
|
||
} | ||
|
||
|
||
[TestMethod] | ||
public void TestUpdateMovie() | ||
{ | ||
var libraryManagerStub = new Mock<ILibraryManager>(); | ||
var scraperManager = new ScraperManager(loggerFactory); | ||
scraperManager.register(new Jellyfin.Plugin.Danmu.Scrapers.Mgtv.Mgtv(loggerFactory, libraryManagerStub.Object)); | ||
|
||
var fileSystemStub = new Mock<Jellyfin.Plugin.Danmu.Core.IFileSystem>(); | ||
var directoryServiceStub = new Mock<IDirectoryService>(); | ||
var libraryManagerEventsHelper = new LibraryManagerEventsHelper(libraryManagerStub.Object, loggerFactory, fileSystemStub.Object, scraperManager); | ||
|
||
var item = new Movie | ||
{ | ||
Name = "虚颜", | ||
ProviderIds = new Dictionary<string, string>() { { Mgtv.ScraperProviderId, "519236" } }, | ||
}; | ||
|
||
var list = new List<LibraryEvent>(); | ||
list.Add(new LibraryEvent { Item = item, EventType = EventType.Update }); | ||
|
||
Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
await libraryManagerEventsHelper.ProcessQueuedMovieEvents(list, EventType.Update); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
}).GetAwaiter().GetResult(); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
[TestMethod] | ||
public void TestAddSeason() | ||
{ | ||
var libraryManagerStub = new Mock<ILibraryManager>(); | ||
var scraperManager = new ScraperManager(loggerFactory); | ||
scraperManager.register(new Jellyfin.Plugin.Danmu.Scrapers.Mgtv.Mgtv(loggerFactory, libraryManagerStub.Object)); | ||
|
||
var fileSystemStub = new Mock<Jellyfin.Plugin.Danmu.Core.IFileSystem>(); | ||
var directoryServiceStub = new Mock<IDirectoryService>(); | ||
var libraryManagerEventsHelper = new LibraryManagerEventsHelper(libraryManagerStub.Object, loggerFactory, fileSystemStub.Object, scraperManager); | ||
|
||
var item = new Season | ||
{ | ||
Name = "大侦探 第八季", | ||
ProductionYear = 2023, | ||
}; | ||
|
||
var list = new List<LibraryEvent>(); | ||
list.Add(new LibraryEvent { Item = item, EventType = EventType.Add }); | ||
|
||
Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
await libraryManagerEventsHelper.ProcessQueuedSeasonEvents(list, EventType.Add); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
}).GetAwaiter().GetResult(); | ||
|
||
} | ||
|
||
[TestMethod] | ||
public void TestGetMedia() | ||
{ | ||
|
||
Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
var libraryManagerStub = new Mock<ILibraryManager>(); | ||
var api = new Mgtv(loggerFactory, libraryManagerStub.Object); | ||
var media = await api.GetMedia(new Season(), "514446"); | ||
Console.WriteLine(media); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
}).GetAwaiter().GetResult(); | ||
|
||
} | ||
|
||
} | ||
} |
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
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,53 @@ | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Jellyfin.Plugin.Danmu.Scrapers.Mgtv.Entity; | ||
|
||
public class MgtvComment | ||
{ | ||
[JsonPropertyName("id")] | ||
public long Id { get; set; } | ||
[JsonPropertyName("ids")] | ||
public string Ids { get; set; } | ||
[JsonPropertyName("type")] | ||
public int Type { get; set; } | ||
[JsonPropertyName("uid")] | ||
public long Uid { get; set; } | ||
[JsonPropertyName("uuid")] | ||
public string Uuid { get; set; } | ||
[JsonPropertyName("content")] | ||
public string Content { get; set; } | ||
[JsonPropertyName("time")] | ||
public int Time { get; set; } | ||
[JsonPropertyName("v2_color")] | ||
public MgtvCommentColor Color { get; set; } | ||
|
||
} | ||
|
||
public class MgtvCommentColor | ||
{ | ||
[JsonPropertyName("color_left")] | ||
public MgtvCommentColorRGB ColorLeft { get; set; } | ||
[JsonPropertyName("color_right")] | ||
public MgtvCommentColorRGB ColorRight { get; set; } | ||
} | ||
|
||
|
||
public class MgtvCommentColorRGB | ||
{ | ||
[JsonPropertyName("r")] | ||
public int R { get; set; } | ||
[JsonPropertyName("g")] | ||
public int G { get; set; } | ||
[JsonPropertyName("b")] | ||
public int B { get; set; } | ||
|
||
public uint HexNumber | ||
{ | ||
get | ||
{ | ||
return (uint)((R << 16) | (G << 8) | (B)); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Jellyfin.Plugin.Danmu/Scrapers/Mgtv/Entity/MgtvCommentResult.cs
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,32 @@ | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Jellyfin.Plugin.Danmu.Scrapers.Mgtv.Entity; | ||
|
||
public class MgtvCommentResult | ||
{ | ||
[JsonPropertyName("data")] | ||
public MgtvCommentData Data { get; set; } | ||
} | ||
|
||
public class MgtvCommentData | ||
{ | ||
[JsonPropertyName("cdn_list")] | ||
public string CdnList { get; set; } | ||
[JsonPropertyName("cdn_version")] | ||
public string CdnVersion { get; set; } | ||
|
||
public string CdnHost | ||
{ | ||
get | ||
{ | ||
if (string.IsNullOrEmpty(CdnList)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
return CdnList.Split(",").First(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Jellyfin.Plugin.Danmu/Scrapers/Mgtv/Entity/MgtvCommentSegemntResult.cs
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,20 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Jellyfin.Plugin.Danmu.Scrapers.Mgtv.Entity; | ||
|
||
public class MgtvCommentSegmentResult | ||
{ | ||
[JsonPropertyName("data")] | ||
public MgtvCommentSegmentData Data { get; set; } | ||
} | ||
|
||
|
||
public class MgtvCommentSegmentData | ||
{ | ||
[JsonPropertyName("total")] | ||
public int Total { get; set; } | ||
|
||
[JsonPropertyName("items")] | ||
public List<MgtvComment> Items { 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,19 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Jellyfin.Plugin.Danmu.Scrapers.Mgtv.Entity; | ||
|
||
public class MgtvEpisode | ||
{ | ||
[JsonPropertyName("src_clip_id")] | ||
public string SourceClipId { get; set; } | ||
[JsonPropertyName("clip_id")] | ||
public string ClipId { get; set; } | ||
[JsonPropertyName("t1")] | ||
public string Title { get; set; } | ||
[JsonPropertyName("time")] | ||
public string Time { get; set; } | ||
[JsonPropertyName("video_id")] | ||
public string VideoId { get; set; } | ||
[JsonPropertyName("contentType")] | ||
public string ContentType { get; set; } | ||
} |
Oops, something went wrong.