diff --git a/Emby.MeiamSub.Shooter/Emby.MeiamSub.Shooter.csproj b/Emby.MeiamSub.Shooter/Emby.MeiamSub.Shooter.csproj index ccdaffc..3b14774 100644 --- a/Emby.MeiamSub.Shooter/Emby.MeiamSub.Shooter.csproj +++ b/Emby.MeiamSub.Shooter/Emby.MeiamSub.Shooter.csproj @@ -23,8 +23,8 @@ - - + + diff --git a/Emby.MeiamSub.Thunder/Emby.MeiamSub.Thunder.csproj b/Emby.MeiamSub.Thunder/Emby.MeiamSub.Thunder.csproj index 9310b04..e072e4a 100644 --- a/Emby.MeiamSub.Thunder/Emby.MeiamSub.Thunder.csproj +++ b/Emby.MeiamSub.Thunder/Emby.MeiamSub.Thunder.csproj @@ -24,8 +24,8 @@ - - + + diff --git a/Jellyfin.MeiamSub.Shooter/Jellyfin.MeiamSub.Shooter.csproj b/Jellyfin.MeiamSub.Shooter/Jellyfin.MeiamSub.Shooter.csproj index f3bffa0..59dc130 100644 --- a/Jellyfin.MeiamSub.Shooter/Jellyfin.MeiamSub.Shooter.csproj +++ b/Jellyfin.MeiamSub.Shooter/Jellyfin.MeiamSub.Shooter.csproj @@ -12,7 +12,7 @@ - + diff --git a/Jellyfin.MeiamSub.Shooter/Model/SubtitleResponseRoot.cs b/Jellyfin.MeiamSub.Shooter/Model/SubtitleResponseRoot.cs index 6a312b5..5044091 100644 --- a/Jellyfin.MeiamSub.Shooter/Model/SubtitleResponseRoot.cs +++ b/Jellyfin.MeiamSub.Shooter/Model/SubtitleResponseRoot.cs @@ -7,7 +7,7 @@ namespace Jellyfin.MeiamSub.Shooter.Model { public string Desc { get; set; } public int Delay { get; set; } - public SubFileInfo[] Files { get; set; } + public List Files { get; set; } } public class SubFileInfo diff --git a/Jellyfin.MeiamSub.Shooter/ShooterProvider.cs b/Jellyfin.MeiamSub.Shooter/ShooterProvider.cs index 7d10071..e7676c0 100644 --- a/Jellyfin.MeiamSub.Shooter/ShooterProvider.cs +++ b/Jellyfin.MeiamSub.Shooter/ShooterProvider.cs @@ -1,4 +1,7 @@ -using Jellyfin.MeiamSub.Shooter.Model; +using Jellyfin.Data.Entities.Libraries; +using Jellyfin.MeiamSub.Shooter.Model; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Subtitles; using MediaBrowser.Model.Providers; @@ -16,6 +19,7 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; using System.Web; +using static System.Net.WebRequestMethods; namespace Jellyfin.MeiamSub.Shooter { @@ -30,9 +34,13 @@ namespace Jellyfin.MeiamSub.Shooter public const string SRT = "srt"; private readonly ILogger _logger; + private static readonly HttpClient _httpClient = new HttpClient(); - public int Order => 1; + private string apiUrl => "https://www.shooter.cn/api/subapi.php"; + + public int Order => 1000; + public string Name => "MeiamSub.Shooter"; /// @@ -85,7 +93,7 @@ namespace Jellyfin.MeiamSub.Shooter _logger.LogInformation($"{Name} Search | FileHash -> { hash }"); - var content = new Dictionary + var formData = new Dictionary { { "filehash", hash}, { "pathinfo", request.MediaPath}, @@ -93,35 +101,37 @@ namespace Jellyfin.MeiamSub.Shooter { "lang", request.Language == "chi" ? "chn" : "eng"} }; + var content = new FormUrlEncodedContent(formData); - HttpRequestMessage requestMessage = new HttpRequestMessage(); + // 设置请求头 + content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); - requestMessage.Method = HttpMethod.Post; - requestMessage.RequestUri = new Uri($"https://www.shooter.cn/api/subapi.php"); - requestMessage.Content = new FormUrlEncodedContent(content); - requestMessage.Headers.Add("User-Agent", $"{Name}"); - requestMessage.Headers.Add("Accept-Encoding", $"gzip, deflate, br"); - requestMessage.Headers.Add("Accept", $"*/*"); + // 发送 POST 请求 + var response = await _httpClient.PostAsync(apiUrl, content); - var response = await _httpClient.SendAsync(requestMessage); + _logger.LogInformation($"{Name} Search | Response -> {JsonSerializer.Serialize(response)}"); - _logger.LogInformation($"{Name} Search | Response -> { JsonSerializer.Serialize(response) }"); - - if (response.StatusCode == HttpStatusCode.OK && response.Content.Headers.Any(m => m.Value.Contains("application/json; charset=utf-8"))) + // 处理响应 + if (response.IsSuccessStatusCode && response.Content.Headers.Any(m => m.Value.Contains("application/json; charset=utf-8"))) { - var subtitleResponse = JsonSerializer.Deserialize>(await response.Content.ReadAsStringAsync()); + var responseBody = await response.Content.ReadAsStringAsync(); - _logger.LogInformation($"{Name} Search | Response -> { JsonSerializer.Serialize(subtitleResponse) }"); + _logger.LogInformation($"{Name} Search | ResponseBody -> { responseBody } "); - if (subtitleResponse != null) + var subtitles = JsonSerializer.Deserialize>(responseBody); + + _logger.LogInformation($"{Name} Search | Response -> {JsonSerializer.Serialize(subtitles)}"); + + if (subtitles != null) { - var remoteSubtitleInfos = new List(); - foreach (var subFileInfo in subtitleResponse) + var remoteSubtitles = new List(); + + foreach (var subFileInfo in subtitles) { foreach (var subFile in subFileInfo.Files) { - remoteSubtitleInfos.Add(new RemoteSubtitleInfo() + remoteSubtitles.Add(new RemoteSubtitleInfo() { Id = Base64Encode(JsonSerializer.Serialize(new DownloadSubInfo { @@ -130,25 +140,25 @@ namespace Jellyfin.MeiamSub.Shooter Language = request.Language, TwoLetterISOLanguageName = request.TwoLetterISOLanguageName, })), - Name = $"[MEIAMSUB] { Path.GetFileName(request.MediaPath) } | {request.TwoLetterISOLanguageName} | 射手", + Name = $"[MEIAMSUB] {Path.GetFileName(request.MediaPath)} | {request.TwoLetterISOLanguageName} | 射手", Author = "Meiam ", ProviderName = $"{Name}", Format = subFile.Ext, - Comment = $"Format : { ExtractFormat(subFile.Ext)}", - IsHashMatch = true + Comment = $"Format : {ExtractFormat(subFile.Ext)}", + IsHashMatch = true }); } } - _logger.LogInformation($"{Name} Search | Summary -> Get { remoteSubtitleInfos.Count } Subtitles"); + _logger.LogInformation($"{Name} Search | Summary -> Get {remoteSubtitles.Count} Subtitles"); - return remoteSubtitleInfos; + return remoteSubtitles; } + } _logger.LogInformation($"{Name} Search | Summary -> Get 0 Subtitles"); - return Array.Empty(); } #endregion @@ -218,6 +228,7 @@ namespace Jellyfin.MeiamSub.Shooter #region 内部方法 + /// /// Base64 加密 /// @@ -310,6 +321,11 @@ namespace Jellyfin.MeiamSub.Shooter return ret; } + + public Task FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } #endregion } } diff --git a/Jellyfin.MeiamSub.Thunder/Jellyfin.MeiamSub.Thunder.csproj b/Jellyfin.MeiamSub.Thunder/Jellyfin.MeiamSub.Thunder.csproj index 8846528..163660f 100644 --- a/Jellyfin.MeiamSub.Thunder/Jellyfin.MeiamSub.Thunder.csproj +++ b/Jellyfin.MeiamSub.Thunder/Jellyfin.MeiamSub.Thunder.csproj @@ -14,7 +14,7 @@ - + diff --git a/README.md b/README.md index 1d3c3c7..40a72be 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,9 @@ Emby Jellyfin 中文字幕插件 ,支持 迅雷影音、射手网、 精准匹 首先下载已编译好的插件 [LINK](https://github.com/91270/Emby.MeiamSub/releases) +由于 Jellyfin 自身 [BUG](https://github.com/jellyfin/jellyfin/issues/12434) , 会重复下载字幕 。 +建议:媒体库不勾选本插件, 自动扫描缺失字幕时不使用该插件,但不影响手动查找字幕 + ### WINDOWS ```bash 复制插件文件到 Emby-Server\Programdata\Plugins\