-
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.
Merge pull request #8 from cxfksword/youku
Add youku danmu
- Loading branch information
Showing
48 changed files
with
2,427 additions
and
31 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 @@ | ||
Jellyfin.Plugin.Danmu/Vendor/** linguist-vendored |
41 changes: 18 additions & 23 deletions
41
Jellyfin.Plugin.Danmu.Test/Jellyfin.Plugin.Danmu.Test.csproj
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 |
---|---|---|
@@ -1,23 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="Moq" Version="4.18.2" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Jellyfin.Plugin.Danmu\Jellyfin.Plugin.Danmu.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="Moq" Version="4.18.2" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Jellyfin.Plugin.Danmu\Jellyfin.Plugin.Danmu.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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,107 @@ | ||
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.Youku; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Jellyfin.Plugin.Danmu.Test | ||
{ | ||
|
||
[TestClass] | ||
public class YoukuApiTest | ||
{ | ||
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => | ||
builder.AddSimpleConsole(options => | ||
{ | ||
options.IncludeScopes = true; | ||
options.SingleLine = true; | ||
options.TimestampFormat = "hh:mm:ss "; | ||
})); | ||
|
||
[TestMethod] | ||
public void TestSearch() | ||
{ | ||
var keyword = "夏洛特"; | ||
var api = new YoukuApi(loggerFactory); | ||
|
||
Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
var result = await api.SearchAsync(keyword, CancellationToken.None); | ||
Console.WriteLine(result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
}).GetAwaiter().GetResult(); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public void TestGetVideo() | ||
{ | ||
var api = new YoukuApi(loggerFactory); | ||
|
||
Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
var vid = "0b39c5b6569311e5b2ad"; | ||
var result = await api.GetVideoAsync(vid, CancellationToken.None); | ||
Console.WriteLine(result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
}).GetAwaiter().GetResult(); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public void TestGetDanmuContentByMat() | ||
{ | ||
var api = new YoukuApi(loggerFactory); | ||
|
||
Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
var vid = "XMTM1MTc4MDU3Ng=="; | ||
var result = await api.GetDanmuContentByMatAsync(vid, 0, CancellationToken.None); | ||
Console.WriteLine(result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
}).GetAwaiter().GetResult(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetDanmu() | ||
{ | ||
var api = new YoukuApi(loggerFactory); | ||
|
||
Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
var vid = "XMTM1MTc4MDU3Ng=="; | ||
var result = await api.GetDanmuContentAsync(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,58 @@ | ||
// using AngleSharp.Dom; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Jellyfin.Plugin.Danmu.Core.Extensions | ||
{ | ||
public static class ElementExtension | ||
{ | ||
// public static string? GetText(this IElement el, string css) | ||
// { | ||
// var node = el.QuerySelector(css); | ||
// if (node != null) | ||
// { | ||
// return node.Text().Trim(); | ||
// } | ||
|
||
// return null; | ||
// } | ||
|
||
// public static string GetTextOrDefault(this IElement el, string css, string defaultVal = "") | ||
// { | ||
// var node = el.QuerySelector(css); | ||
// if (node != null) | ||
// { | ||
// return node.Text().Trim(); | ||
// } | ||
|
||
// return defaultVal; | ||
// } | ||
|
||
// public static string? GetAttr(this IElement el, string css, string attr) | ||
// { | ||
// var node = el.QuerySelector(css); | ||
// if (node != null) | ||
// { | ||
// var attrVal = node.GetAttribute(attr); | ||
// return attrVal != null ? attrVal.Trim() : null; | ||
// } | ||
|
||
// return null; | ||
// } | ||
|
||
// public static string? GetAttrOrDefault(this IElement el, string css, string attr, string defaultVal = "") | ||
// { | ||
// var node = el.QuerySelector(css); | ||
// if (node != null) | ||
// { | ||
// var attrVal = node.GetAttribute(attr); | ||
// return attrVal != null ? attrVal.Trim() : defaultVal; | ||
// } | ||
|
||
// return defaultVal; | ||
// } | ||
} | ||
} |
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,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.Eventing.Reader; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace Jellyfin.Plugin.Danmu.Core.Extensions | ||
{ | ||
public static class RegexExtension | ||
{ | ||
public static string FirstMatch(this Regex reg, string text, string defaultVal = "") | ||
{ | ||
var match = reg.Match(text); | ||
if (match.Success) | ||
{ | ||
return match.Value; | ||
} | ||
|
||
return defaultVal; | ||
} | ||
|
||
public static string FirstMatchGroup(this Regex reg, string text, string defaultVal = "") | ||
{ | ||
var match = reg.Match(text); | ||
if (match.Success && match.Groups.Count > 1) | ||
{ | ||
return match.Groups[1].Value.Trim(); | ||
} | ||
|
||
return defaultVal; | ||
} | ||
} | ||
} |
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,84 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
|
||
// ReSharper disable TemplateIsNotCompileTimeConstantProblem | ||
|
||
namespace Jellyfin.Plugin.Danmu.Core.Http | ||
{ | ||
[SuppressMessage("Usage", "CA2254:模板应为静态表达式", Justification = "<挂起>")] | ||
public class HttpLoggingHandler : DelegatingHandler | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public HttpLoggingHandler(HttpMessageHandler innerHandler, ILogger logger) | ||
: base(innerHandler) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
HttpResponseMessage? response = null; | ||
try | ||
{ | ||
response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false); | ||
|
||
await LogRequestAndResponse(request, response, null, cancellationToken).ConfigureAwait(false); | ||
|
||
|
||
return response; | ||
} | ||
catch (Exception exception) | ||
{ | ||
await LogRequestAndResponse(request, response, exception, cancellationToken).ConfigureAwait(false); | ||
throw; | ||
} | ||
} | ||
|
||
private async Task LogRequestAndResponse(HttpRequestMessage? request, HttpResponseMessage? response, Exception? exception, CancellationToken cancellationToken) | ||
{ | ||
var log = new StringBuilder(); | ||
try | ||
{ | ||
if (request != null) | ||
{ | ||
log.Append("Request: ").Append(request).Append('\n'); | ||
} | ||
|
||
if (request?.Content != null) | ||
{ | ||
log.Append("Content: ").Append(await request.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false)).Append('\n'); | ||
} | ||
|
||
if (response != null) | ||
{ | ||
log.Append("Response: ").Append(response).Append('\n'); | ||
} | ||
|
||
if (response?.Content != null) | ||
{ | ||
log.Append("Content: ").Append(await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false)).Append('\n'); | ||
} | ||
} | ||
catch | ||
{ | ||
} | ||
finally | ||
{ | ||
if (exception == null) | ||
{ | ||
_logger.LogWarning(log.ToString()); | ||
} | ||
else | ||
{ | ||
_logger.LogError(exception, log.ToString()); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.