Skip to content

Commit

Permalink
Add mgtv danmu
Browse files Browse the repository at this point in the history
  • Loading branch information
cxfksword committed Feb 19, 2023
1 parent 3c48301 commit 37ce691
Show file tree
Hide file tree
Showing 22 changed files with 1,137 additions and 41 deletions.
78 changes: 78 additions & 0 deletions Jellyfin.Plugin.Danmu.Test/MgtvApiTest.cs
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();
}

}
}
150 changes: 150 additions & 0 deletions Jellyfin.Plugin.Danmu.Test/MgtvTest.cs
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();

}

}
}
8 changes: 0 additions & 8 deletions Jellyfin.Plugin.Danmu/Core/Extensions/StringExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ public static int ToInt(this string s)
return 0;
}

public static Int64 ToInt64(this string s)
{
if (Int64.TryParse(s, out var val))
{
return val;
}

return 0;
}

public static float ToFloat(this string s)
{
Expand Down
8 changes: 0 additions & 8 deletions Jellyfin.Plugin.Danmu/Scrapers/Iqiyi/IqiyiApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,9 @@ namespace Jellyfin.Plugin.Danmu.Scrapers.Iqiyi;

public class IqiyiApi : AbstractApi
{
private static readonly object _lock = new object();
private static readonly Regex yearReg = new Regex(@"[12][890][0-9][0-9]", RegexOptions.Compiled);
private static readonly Regex moviesReg = new Regex(@"<a.*?h5-show-card.*?>([\w\W]+?)</a>", RegexOptions.Compiled);
private static readonly Regex trackInfoReg = new Regex(@"data-trackinfo=""(\{[\w\W]+?\})""", RegexOptions.Compiled);
private static readonly Regex featureReg = new Regex(@"<div.*?show-feature.*?>([\w\W]+?)</div>", RegexOptions.Compiled);
private static readonly Regex unusedReg = new Regex(@"\[.+?\]|\(.+?\)|【.+?】", RegexOptions.Compiled);
private static readonly Regex regTvId = new Regex(@"""tvid"":(\d+?),", RegexOptions.Compiled);


private DateTime lastRequestTime = DateTime.Now.AddDays(-1);

private TimeLimiter _timeConstraint = TimeLimiter.GetFromMaxCountByInterval(1, TimeSpan.FromMilliseconds(1000));
private TimeLimiter _delayExecuteConstraint = TimeLimiter.GetFromMaxCountByInterval(1, TimeSpan.FromMilliseconds(100));

Expand Down
53 changes: 53 additions & 0 deletions Jellyfin.Plugin.Danmu/Scrapers/Mgtv/Entity/MgtvComment.cs
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 Jellyfin.Plugin.Danmu/Scrapers/Mgtv/Entity/MgtvCommentResult.cs
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();
}
}
}
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; }
}
19 changes: 19 additions & 0 deletions Jellyfin.Plugin.Danmu/Scrapers/Mgtv/Entity/MgtvEpisode.cs
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; }
}
Loading

0 comments on commit 37ce691

Please sign in to comment.