├── Manifest.exe ├── bin.Emby ├── AngleSharp.dll └── Jellyfin-Plugin-AdultsSubtitle.dll ├── Jellyfin-Plugin-AdultsSubtitle ├── logo.png ├── Properties │ └── launchSettings.json ├── Configuration │ └── PluginConfiguration.cs ├── PluginRegistrator.cs ├── AdultsSubtitlePlugin.cs ├── Api.cs ├── Jellyfin-Plugin-AdultsSubtitle.csproj ├── ScheduledTasks │ ├── UpdatePluginTask.cs │ └── ScanSubtitlesTask.cs └── AdultsSubtitleProvider.cs ├── LICENSE.txt ├── README.md ├── .github └── workflows │ └── dotnet.yml ├── Jellyfin-Plugin-AdultsSubtitle.sln ├── .gitattributes ├── manifest.json └── .gitignore /Manifest.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/HEAD/Manifest.exe -------------------------------------------------------------------------------- /bin.Emby/AngleSharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/HEAD/bin.Emby/AngleSharp.dll -------------------------------------------------------------------------------- /Jellyfin-Plugin-AdultsSubtitle/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/HEAD/Jellyfin-Plugin-AdultsSubtitle/logo.png -------------------------------------------------------------------------------- /bin.Emby/Jellyfin-Plugin-AdultsSubtitle.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/HEAD/bin.Emby/Jellyfin-Plugin-AdultsSubtitle.dll -------------------------------------------------------------------------------- /Jellyfin-Plugin-AdultsSubtitle/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Jellyfin-Plugin-AdultsSubtitle": { 4 | "commandName": "Project", 5 | "workingDirectory": "E:\\EDGE DownLoad\\jellyfin_10.8.13\\jellyfin_10.8.13", 6 | "remoteDebugEnabled": false 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Jellyfin-Plugin-AdultsSubtitle/Configuration/PluginConfiguration.cs: -------------------------------------------------------------------------------- 1 | #if __EMBY__ 2 | using Emby.Web.GenericEdit; 3 | #else 4 | using MediaBrowser.Model.Plugins; 5 | #endif 6 | 7 | 8 | namespace Jellyfin_Plugin_AdultsSubtitle.Configuration 9 | { 10 | #if __EMBY__ 11 | public class PluginConfiguration : EditableOptionsBase 12 | { 13 | public override string EditorTitle => AdultsSubtitlePlugin.Instance.Name; 14 | #else 15 | public class PluginConfiguration : BasePluginConfiguration 16 | { 17 | #endif 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Jellyfin-Plugin-AdultsSubtitle/PluginRegistrator.cs: -------------------------------------------------------------------------------- 1 | #if !__EMBY__ 2 | using MediaBrowser.Controller; 3 | using MediaBrowser.Controller.Plugins; 4 | using MediaBrowser.Controller.Subtitles; 5 | using Microsoft.Extensions.DependencyInjection; 6 | 7 | namespace Jellyfin_Plugin_AdultsSubtitle 8 | { 9 | public class PluginRegistrator : IPluginServiceRegistrator 10 | { 11 | public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost) 12 | { 13 | serviceCollection.AddSingleton(); 14 | } 15 | } 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 - 2024 AngleSharp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Jellyfin-Plugin-AdultsSubtitle/AdultsSubtitlePlugin.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin_Plugin_AdultsSubtitle.Configuration; 2 | 3 | 4 | #if __EMBY__ 5 | using MediaBrowser.Common; 6 | using MediaBrowser.Common.Configuration; 7 | using MediaBrowser.Controller.Plugins; 8 | using MediaBrowser.Model.Logging; 9 | using System.Reflection; 10 | #else 11 | using MediaBrowser.Common.Configuration; 12 | using MediaBrowser.Common.Plugins; 13 | using MediaBrowser.Model.Serialization; 14 | #endif 15 | 16 | namespace Jellyfin_Plugin_AdultsSubtitle 17 | { 18 | #if __EMBY__ 19 | public class AdultsSubtitlePlugin : BasePluginSimpleUI 20 | { 21 | private readonly IApplicationPaths _applicationPaths; 22 | private readonly ILogger _logger; 23 | public AdultsSubtitlePlugin(IApplicationHost applicationHost, IApplicationPaths applicationPaths, ILogger logger) : base(applicationHost) 24 | { 25 | _applicationPaths = applicationPaths; 26 | _logger = logger; 27 | var path = Path.Combine(_applicationPaths.ProgramDataPath, "plugins", "AngleSharp.dll"); 28 | _logger.Info($"Assembly Load {path}"); 29 | try 30 | { 31 | Assembly.LoadFrom(path); 32 | } 33 | catch(Exception e) 34 | { 35 | _logger.Error(e.ToString()); 36 | } 37 | 38 | Instance = this; 39 | } 40 | #else 41 | 42 | public class AdultsSubtitlePlugin : BasePlugin 43 | { 44 | public AdultsSubtitlePlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) : base(applicationPaths, xmlSerializer) 45 | { 46 | Instance = this; 47 | } 48 | #endif 49 | public static AdultsSubtitlePlugin? Instance { get; private set; } 50 | public override string Name => "Adults Subtitle"; 51 | public override Guid Id 52 | => Guid.Parse("898269F2-F951-C3FF-B714-9E8F785BE3B2"); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Jellyfin-Plugin-AdultsSubtitle/Api.cs: -------------------------------------------------------------------------------- 1 | using AngleSharp.Html.Dom; 2 | using AngleSharp.Html.Parser; 3 | using System.Collections.Concurrent; 4 | 5 | namespace Jellyfin_Plugin_AdultsSubtitle 6 | { 7 | public class Api 8 | { 9 | public static readonly ConcurrentDictionary DownloadUrls = new(); 10 | public static readonly Dictionary LanguagesMaps = new() 11 | { 12 | {"chi","zh-CN"}, 13 | {"eng","en"}, 14 | {"zh-CN","zh-CN"}, 15 | }; 16 | private static readonly HtmlParser _parser = new(); 17 | public static async Task SearchDownloadUrlAsync(HttpClient client, string language, string url, CancellationToken cancellationToken) 18 | { 19 | var response = await client.GetAsync($"https://www.subtitlecat.com{url}", cancellationToken); 20 | var content = await response.Content.ReadAsStringAsync(cancellationToken); 21 | var document = _parser.ParseDocument(content); 22 | var element = document.All.FirstOrDefault(p => p.Id == $"download_{language}"); 23 | if (element is IHtmlAnchorElement anchorElement) 24 | { 25 | return $"https://www.subtitlecat.com{anchorElement.Href.Replace("about://", "")}"; 26 | } 27 | return null; 28 | } 29 | 30 | public static async Task SearchAsync(HttpClient client, string name, CancellationToken cancellationToken) 31 | { 32 | var response = await client.GetAsync($"https://www.subtitlecat.com/index.php?search={name}", cancellationToken); 33 | var content = await response.Content.ReadAsStringAsync(cancellationToken); 34 | using var document = _parser.ParseDocument(content); 35 | var element = document.All.FirstOrDefault(p => p is IHtmlAnchorElement anchorElement && anchorElement.Href.ToLower().Contains(name.ToLower())); 36 | if (element is IHtmlAnchorElement anchorElement) 37 | { 38 | return anchorElement.Href.Replace("about://", ""); 39 | } 40 | return null; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Jellyfin-Plugin-AdultsSubtitle 4 | 5 | 6 | Stars 7 | 8 | 9 | Contributors 10 | 11 | 12 | Forks 13 | 14 | 15 | Issues 16 | 17 | 18 | MIT License 19 | 20 | 21 | Downloads 22 | 23 | 24 | Releases 25 | 26 | 27 |

28 | 29 | Logo 30 | 31 | 32 | ### 关于 33 | 34 | 为jellyfin中的小姐姐添加个字幕吧~~ 35 | 36 | ### 使用 37 | 38 | - jellyfin 10.8.13 39 | - jellyfin 插件存储库添加源 40 | 41 | ``` 42 | https://raw.githubusercontent.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/master/manifest.json 43 | ``` 44 | 45 | - jellyfin 插件目录中安装最新版本 46 | - 重启 jellyfin 47 | 48 | ### 框架 49 | 50 | - [AngleSharp](https://github.com/AngleSharp/AngleSharp) 51 | 52 | -------------------------------------------------------------------------------- /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a .NET project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net 3 | 4 | name: .NET 5 | 6 | on: 7 | push: 8 | tags: 9 | - "v*" 10 | 11 | jobs: 12 | build: 13 | name: build 14 | runs-on: windows-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: Setup .NET 19 | uses: actions/setup-dotnet@v4 20 | with: 21 | dotnet-version: 8.0.x 22 | 23 | - name: Publish 24 | run: dotnet publish --configuration Release --output bin 25 | 26 | - name: Publish Emby 27 | run: dotnet publish --configuration Release.Emby --output bin.Emby 28 | 29 | - name: Package 30 | id: create_package 31 | shell: bash 32 | run: | 33 | tag=$(git describe --tags --always) 34 | release_name="AdultsSubtitle_${tag}" 35 | emby_release_name="AdultsSubtitle_Emby_${tag}" 36 | 37 | # Pack files 38 | 7z a -tzip "${release_name}.zip" "./bin/*" 39 | echo "::set-output name=release_name::${release_name}" 40 | echo "::set-output name=release_tag::${tag}" 41 | echo "::set-output name=filename::${release_name}.zip" 42 | 43 | 7z a -tzip "${emby_release_name}.zip" "./bin.Emby/*" 44 | echo "::set-output name=emby_release_name::${emby_release_name}" 45 | echo "::set-output name=emby_release_name::${tag}" 46 | echo "::set-output name=filename::${emby_release_name}.zip" 47 | 48 | - uses: "marvinpinto/action-automatic-releases@latest" 49 | with: 50 | repo_token: "${{ secrets.GITHUB_TOKEN }}" 51 | name: "${{ steps.create_package.outputs.release_tag }}" 52 | automatic_release_tag: "${{ steps.create_package.outputs.release_tag }}" 53 | prerelease: false 54 | # "${{ steps.create_package.outputs.filename }}" 55 | files: | 56 | *.zip 57 | - name: Update Manifest 58 | shell: cmd 59 | run: Manifest.exe ${{ steps.create_package.outputs.release_tag }} 60 | 61 | - name: Commit & Push changes 62 | uses: stefanzweifel/git-auto-commit-action@v5 63 | with: 64 | branch: master 65 | commit_message: update manifest.json 66 | 67 | -------------------------------------------------------------------------------- /Jellyfin-Plugin-AdultsSubtitle/Jellyfin-Plugin-AdultsSubtitle.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | Jellyfin_Plugin_AdultsSubtitle 6 | enable 7 | enable 8 | 1.1.1.2 9 | false 10 | Debug;Release;Debug.Emby;Release.Emby 11 | 12 | 13 | 14 | __EMBY__ 15 | 16 | 17 | 18 | true 19 | false 20 | false 21 | C:\ProgramData\Jellyfin\Server\plugins\AdultsSubtitle_v$(Version) 22 | 23 | 24 | 25 | true 26 | false 27 | false 28 | E:\EDGE DownLoad\embyserver-win-x64-4.8.5.0\system\plugins 29 | 30 | 31 | 32 | 33 | false 34 | None 35 | 36 | 37 | 38 | 39 | 40 | all 41 | 42 | 43 | 44 | 45 | 46 | all 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Jellyfin-Plugin-AdultsSubtitle.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.9.34321.82 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jellyfin-Plugin-AdultsSubtitle", "Jellyfin-Plugin-AdultsSubtitle\Jellyfin-Plugin-AdultsSubtitle.csproj", "{0D3F3273-1186-4EB6-892C-780F86479546}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug.Emby|Any CPU = Debug.Emby|Any CPU 11 | Debug.Emby|x64 = Debug.Emby|x64 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Release.Emby|Any CPU = Release.Emby|Any CPU 15 | Release.Emby|x64 = Release.Emby|x64 16 | Release|Any CPU = Release|Any CPU 17 | Release|x64 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {0D3F3273-1186-4EB6-892C-780F86479546}.Debug.Emby|Any CPU.ActiveCfg = Debug.Emby|Any CPU 21 | {0D3F3273-1186-4EB6-892C-780F86479546}.Debug.Emby|Any CPU.Build.0 = Debug.Emby|Any CPU 22 | {0D3F3273-1186-4EB6-892C-780F86479546}.Debug.Emby|x64.ActiveCfg = Debug.Emby|Any CPU 23 | {0D3F3273-1186-4EB6-892C-780F86479546}.Debug.Emby|x64.Build.0 = Debug.Emby|Any CPU 24 | {0D3F3273-1186-4EB6-892C-780F86479546}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {0D3F3273-1186-4EB6-892C-780F86479546}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {0D3F3273-1186-4EB6-892C-780F86479546}.Debug|x64.ActiveCfg = Debug|Any CPU 27 | {0D3F3273-1186-4EB6-892C-780F86479546}.Debug|x64.Build.0 = Debug|Any CPU 28 | {0D3F3273-1186-4EB6-892C-780F86479546}.Release.Emby|Any CPU.ActiveCfg = Release.Emby|Any CPU 29 | {0D3F3273-1186-4EB6-892C-780F86479546}.Release.Emby|Any CPU.Build.0 = Release.Emby|Any CPU 30 | {0D3F3273-1186-4EB6-892C-780F86479546}.Release.Emby|x64.ActiveCfg = Release.Emby|Any CPU 31 | {0D3F3273-1186-4EB6-892C-780F86479546}.Release.Emby|x64.Build.0 = Release.Emby|Any CPU 32 | {0D3F3273-1186-4EB6-892C-780F86479546}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {0D3F3273-1186-4EB6-892C-780F86479546}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {0D3F3273-1186-4EB6-892C-780F86479546}.Release|x64.ActiveCfg = Release|Any CPU 35 | {0D3F3273-1186-4EB6-892C-780F86479546}.Release|x64.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {99694DD0-8DB2-4D69-8E40-8FCFF41E0B4D} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | [{"name":"AdultsSubtitle","description":"AdultsSubtitle Plugin for Jellyfin","overview":"AdultsSubtitle Plugin for Jellyfin","owner":"AdultsSubtitle","category":"AdultsSubtitle","guid":"898269f2-f951-c3ff-b714-9e8f785be3b2","versions":[{"version":"1.0.3","changelog":"update version v1.0.3","targetAbi":"10.8.0.0","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.0.3/AdultsSubtitle.zip","checksum":"417aa3257fbf835c1a37408233c50b2a","timestamp":"2024-03-24T18:21:12Z"},{"version":"1.0.12","changelog":"update version v1.0.12","targetAbi":"10.8.0.0","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.0.12/AdultsSubtitle.zip","checksum":"b8a8e632d8475e26083a30abec436e9f","timestamp":"2024-03-24T14:50:03Z"},{"version":"1.1.0.0","changelog":"update version v1.1.0.0","targetAbi":"10.8.0.0","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.0.0/AdultsSubtitle.zip","checksum":"6c49a3d4922e2cc26a531aa15056a1af","timestamp":"2024-03-26T11:59:30Z"},{"version":"1.1.0.1","changelog":"update version v1.1.0.1","targetAbi":"10.8.0.0","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.0.1/AdultsSubtitle.zip","checksum":"0bc662c4523457e436c9f6685e057329","timestamp":"2024-03-30T17:14:24Z"},{"version":"1.1.0.2","changelog":"update version v1.1.0.2","targetAbi":"10.8.0.0","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.0.2/AdultsSubtitle.zip","checksum":"d83e82b4737db2fb3a8adb6c9242361d","timestamp":"2024-03-30T17:26:51Z"},{"version":"1.1.0.4","changelog":"update version v1.1.0.4","targetAbi":"10.8.13","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.0.4/AdultsSubtitle_v1.1.0.4.zip","checksum":"101a25e09cb8a2ed948d53edb845eb5e","timestamp":"2024-03-31T09:33:48Z"},{"version":"1.1.0.5","changelog":"update version v1.1.0.5","targetAbi":"10.8.13","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.0.5/AdultsSubtitle_v1.1.0.5.zip","checksum":"55a909791aff87d315646da3362afdcd","timestamp":"2024-03-31T09:39:41Z"},{"version":"1.1.0.6","changelog":"update version v1.1.0.6","targetAbi":"10.8.13","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.0.6/AdultsSubtitle_v1.1.0.6.zip","checksum":"715136ca735241498ed1e96c8fb6f7e4","timestamp":"2024-03-31T10:03:50Z"},{"version":"1.1.0.7","changelog":"update version v1.1.0.7","targetAbi":"10.8.13","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.0.7/AdultsSubtitle_v1.1.0.7.zip","checksum":"1467684a80947519c42a576777b9194d","timestamp":"2024-03-31T10:37:43Z"},{"version":"1.1.0.8","changelog":"update version v1.1.0.8","targetAbi":"10.8.13","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.0.8/AdultsSubtitle_v1.1.0.8.zip","checksum":"727f7a809abfc6e6023d7d849aa92d65","timestamp":"2024-04-03T13:08:02Z"},{"version":"1.1.0.9","changelog":"update version v1.1.0.9","targetAbi":"10.8.13","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.0.9/AdultsSubtitle_v1.1.0.9.zip","checksum":"f96586220aebc1532c7b6afbc7fac57e","timestamp":"2024-05-02T10:55:59Z"},{"version":"1.1.0.10","changelog":"update version v1.1.0.10","targetAbi":"10.8.13","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.0.10/AdultsSubtitle_v1.1.0.10.zip","checksum":"79bdc6444b238cd149dfefde14d40849","timestamp":"2024-05-02T11:14:24Z"},{"version":"1.1.1.1","changelog":"update version v1.1.1.1","targetAbi":"10.8.13","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.1.1/AdultsSubtitle_v1.1.1.1.zip","checksum":"d5a17e91424e154d475daa11fb02dac2","timestamp":"2024-09-15T02:56:06Z"},{"version":"1.1.1.2","changelog":"update version v1.1.1.2","targetAbi":"10.8.13","sourceUrl":"https://github.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/releases/download/v1.1.1.2/AdultsSubtitle_v1.1.1.2.zip","checksum":"aec94992191e4778eee45ed97dd6f29d","timestamp":"2025-05-12T06:51:53Z"}],"imageUrl":"https://raw.githubusercontent.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/master/Jellyfin-Plugin-AdultsSubtitle/logo.png"}] -------------------------------------------------------------------------------- /Jellyfin-Plugin-AdultsSubtitle/ScheduledTasks/UpdatePluginTask.cs: -------------------------------------------------------------------------------- 1 | #if !__EMBY__ 2 | using MediaBrowser.Common; 3 | using MediaBrowser.Common.Configuration; 4 | using MediaBrowser.Common.Plugins; 5 | using MediaBrowser.Model.Tasks; 6 | using MediaBrowser.Model.Updates; 7 | using Microsoft.Extensions.Logging; 8 | using System.IO.Compression; 9 | using System.Reflection; 10 | using System.Text.Json; 11 | 12 | namespace Jellyfin_Plugin_AdultsSubtitle.ScheduledTasks 13 | { 14 | public class UpdatePluginTask : IScheduledTask 15 | { 16 | public string Name => "Update Plugin"; 17 | 18 | public string Key => $"{AdultsSubtitlePlugin.Instance!.Name}UpdatePlugin"; 19 | 20 | public string Description => $"Updates {AdultsSubtitlePlugin.Instance!.Name} plugin to latest version."; 21 | 22 | public string Category => AdultsSubtitlePlugin.Instance!.Name; 23 | 24 | private readonly IHttpClientFactory _httpClientFactory; 25 | private readonly ILogger _logger; 26 | private readonly IPluginManager _pluginManager; 27 | private readonly IApplicationPaths _applicationPaths; 28 | private readonly IApplicationHost _applicationHost; 29 | public UpdatePluginTask(IHttpClientFactory httpClientFactory, IPluginManager pluginManager, IApplicationPaths applicationPaths, IApplicationHost applicationHost, ILogger logger) 30 | { 31 | _httpClientFactory = httpClientFactory; 32 | _pluginManager = pluginManager; 33 | _applicationPaths = applicationPaths; 34 | _applicationHost = applicationHost; 35 | _logger = logger; 36 | } 37 | public async Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken) 38 | { 39 | try 40 | { 41 | var curVersion = Assembly.GetExecutingAssembly().GetName().Version; 42 | var lastestVersion = await GetLatestVersionAsync(cancellationToken); 43 | _logger.LogInformation($"Updates {AdultsSubtitlePlugin.Instance!.Name} plugin to latest version:curVersion{curVersion} lastestVersion:{lastestVersion} "); 44 | if (curVersion != null && curVersion.CompareTo(lastestVersion.Value.Item1) < 0) 45 | { 46 | using var httpClient = _httpClientFactory.CreateClient(); 47 | var response = await httpClient.GetAsync(lastestVersion.Value.Item2, cancellationToken).ConfigureAwait(false); 48 | var zipStream = await response.Content.ReadAsStreamAsync(cancellationToken); 49 | using var ms = new MemoryStream(); 50 | await zipStream.CopyToAsync(ms, cancellationToken); 51 | ms.Position = 0; 52 | using var archive = new ZipArchive(ms); 53 | archive.ExtractToDirectory(Path.Combine(_applicationPaths.PluginsPath, $"AdultsSubtitle_{lastestVersion.Value.Item1}"), true); 54 | 55 | var curVersionPlugin = _pluginManager.GetPlugin(AdultsSubtitlePlugin.Instance.Id, curVersion); 56 | if (curVersionPlugin != null) 57 | _pluginManager.RemovePlugin(curVersionPlugin); 58 | _logger.LogInformation("remove cur version plugin"); 59 | _applicationHost.NotifyPendingRestart(); 60 | _logger.LogInformation("update plugin complete"); 61 | } 62 | } 63 | catch (Exception e) 64 | { 65 | _logger.LogError(e,"update plugin error"); 66 | } 67 | } 68 | public IEnumerable GetDefaultTriggers() 69 | { 70 | yield return new TaskTriggerInfo 71 | { 72 | Type = TaskTriggerInfo.TriggerDaily, 73 | TimeOfDayTicks = TimeSpan.FromHours(5).Ticks 74 | }; 75 | } 76 | 77 | 78 | 79 | private async Task<(Version,string)?> GetLatestVersionAsync(CancellationToken cancellationToken) 80 | { 81 | using var httpClient = _httpClientFactory.CreateClient(); 82 | var response = await httpClient.GetAsync("https://raw.githubusercontent.com/fallingrust/Jellyfin-Plugin-AdultsSubtitle/master/manifest.json", cancellationToken); 83 | var content = await response.Content.ReadAsStringAsync(cancellationToken); 84 | var packInfo = JsonSerializer.Deserialize>(content)?.FirstOrDefault(); 85 | if (packInfo != null) 86 | { 87 | var latestVersion = packInfo.Versions.OrderByDescending(p => p.VersionNumber).FirstOrDefault(); 88 | if (latestVersion != null && latestVersion.SourceUrl != null) 89 | return (latestVersion.VersionNumber, latestVersion.SourceUrl); 90 | } 91 | return null; 92 | } 93 | } 94 | } 95 | #endif -------------------------------------------------------------------------------- /Jellyfin-Plugin-AdultsSubtitle/AdultsSubtitleProvider.cs: -------------------------------------------------------------------------------- 1 | #if __EMBY__ 2 | using MediaBrowser.Controller.Providers; 3 | using MediaBrowser.Controller.Subtitles; 4 | using MediaBrowser.Model.Logging; 5 | using MediaBrowser.Model.Providers; 6 | 7 | 8 | namespace Jellyfin_Plugin_AdultsSubtitle 9 | { 10 | public class AdultsSubtitleProvider : ISubtitleProvider 11 | { 12 | 13 | public string Name => "Adults Subtitle"; 14 | private readonly ILogger _logger; 15 | 16 | public IEnumerable SupportedMediaTypes => new[] { VideoContentType.Movie }; 17 | 18 | 19 | public AdultsSubtitleProvider(ILogger logger) 20 | { 21 | _logger = logger; 22 | } 23 | public async Task GetSubtitles(string id, CancellationToken cancellationToken) 24 | { 25 | if (Api.DownloadUrls.TryGetValue(id, out var targetSub)) 26 | { 27 | _logger.Info($"start download subtitle {targetSub}"); 28 | using var client = new HttpClient(); 29 | var response = await client.GetAsync(targetSub.Item1, cancellationToken); 30 | var ms = new MemoryStream(); 31 | var stream = await response.Content.ReadAsStreamAsync(cancellationToken); 32 | await stream.CopyToAsync(ms, cancellationToken); 33 | ms.Position = 0; 34 | _logger.Info($"subtitle {targetSub} download comlete"); 35 | return new SubtitleResponse() 36 | { 37 | Format = "srt", 38 | Language = targetSub.Item2, 39 | Stream = ms, 40 | }; 41 | } 42 | throw new FileNotFoundException(); 43 | } 44 | 45 | public async Task> Search(SubtitleSearchRequest request, CancellationToken cancellationToken) 46 | { 47 | var fileInfo = new FileInfo(request.MediaPath); 48 | var searchName = fileInfo.Name.Replace(fileInfo.Extension, string.Empty); 49 | _logger.Info($"start search {searchName} {request.Language} subtitle "); 50 | if (!Api.LanguagesMaps.TryGetValue(request.Language, out var subCatLanguage)) 51 | { 52 | _logger.Info($"language({request.Language}) not support~"); 53 | return Enumerable.Empty(); 54 | } 55 | Api.DownloadUrls.Clear(); 56 | 57 | var results = new List(); 58 | using var client = new HttpClient(); 59 | var searchResult = await Api.SearchAsync(client, searchName, cancellationToken); 60 | _logger.Info($"search {searchName} {request.Language} subtitle result --->{searchResult} "); 61 | if (!string.IsNullOrWhiteSpace(searchResult)) 62 | { 63 | var downloadUrl = await Api.SearchDownloadUrlAsync(client, subCatLanguage, searchResult, cancellationToken); 64 | _logger.Info($"search {searchName} {request.Language} subtitle download url --->{downloadUrl} "); 65 | if (!string.IsNullOrWhiteSpace(downloadUrl)) 66 | { 67 | var id = Guid.NewGuid().ToString("N"); 68 | results.Add(new RemoteSubtitleInfo() 69 | { 70 | Format = "srt", 71 | Name = downloadUrl[(downloadUrl.LastIndexOf("/") + 1)..], 72 | ProviderName = Name, 73 | Id = id 74 | }); 75 | Api.DownloadUrls.TryAdd(id, (downloadUrl, request.Language)); 76 | } 77 | } 78 | return results; 79 | } 80 | } 81 | } 82 | #else 83 | using MediaBrowser.Controller.Providers; 84 | using MediaBrowser.Controller.Subtitles; 85 | using MediaBrowser.Model.Providers; 86 | 87 | using Microsoft.Extensions.Logging; 88 | 89 | 90 | namespace Jellyfin_Plugin_AdultsSubtitle 91 | { 92 | public class AdultsSubtitleProvider : ISubtitleProvider 93 | { 94 | 95 | public string Name => "Adults Subtitle"; 96 | private readonly ILogger _logger; 97 | private readonly IHttpClientFactory _httpClientFactory; 98 | public IEnumerable SupportedMediaTypes => [VideoContentType.Movie]; 99 | 100 | 101 | public AdultsSubtitleProvider(ILogger logger, IHttpClientFactory httpClientFactory) 102 | { 103 | _logger = logger; 104 | _httpClientFactory = httpClientFactory; 105 | } 106 | public async Task GetSubtitles(string id, CancellationToken cancellationToken) 107 | { 108 | if (Api.DownloadUrls.TryGetValue(id, out var targetSub)) 109 | { 110 | _logger.LogInformation($"start download subtitle {targetSub}"); 111 | using var client = new HttpClient(); 112 | var response = await client.GetAsync(targetSub.Item1, cancellationToken); 113 | var ms = new MemoryStream(); 114 | var stream = await response.Content.ReadAsStreamAsync(cancellationToken); 115 | await stream.CopyToAsync(ms, cancellationToken); 116 | ms.Position = 0; 117 | _logger.LogInformation($"subtitle {targetSub} download comlete"); 118 | return new SubtitleResponse() 119 | { 120 | Format = "srt", 121 | Language = targetSub.Item2, 122 | Stream = ms, 123 | }; 124 | } 125 | throw new FileNotFoundException(); 126 | } 127 | 128 | public async Task> Search(SubtitleSearchRequest request, CancellationToken cancellationToken) 129 | { 130 | var fileInfo = new FileInfo(request.MediaPath); 131 | var searchName = fileInfo.Name.Replace(fileInfo.Extension, string.Empty); 132 | _logger.LogInformation($"start search {searchName} {request.Language} subtitle "); 133 | if (!Api.LanguagesMaps.TryGetValue(request.Language,out var subCatLanguage)) 134 | { 135 | _logger.LogInformation($"language({request.Language}) not support~"); 136 | return Enumerable.Empty(); 137 | } 138 | Api.DownloadUrls.Clear(); 139 | 140 | var results = new List(); 141 | using var client = _httpClientFactory.CreateClient(); 142 | var searchResult = await Api.SearchAsync(client, searchName, cancellationToken); 143 | _logger.LogInformation($"search {searchName} {request.Language} subtitle result --->{searchResult} "); 144 | if (!string.IsNullOrWhiteSpace(searchResult)) 145 | { 146 | var downloadUrl = await Api.SearchDownloadUrlAsync(client, subCatLanguage, searchResult, cancellationToken); 147 | _logger.LogInformation($"search {searchName} {request.Language} subtitle download url --->{downloadUrl} "); 148 | if (!string.IsNullOrWhiteSpace(downloadUrl)) 149 | { 150 | var id = Guid.NewGuid().ToString("N"); 151 | results.Add(new RemoteSubtitleInfo() 152 | { 153 | Format = "srt", 154 | Name = downloadUrl[(downloadUrl.LastIndexOf('/') + 1)..], 155 | ProviderName = Name, 156 | Id = id 157 | }); 158 | Api.DownloadUrls.TryAdd(id, (downloadUrl, request.Language)); 159 | } 160 | } 161 | return results; 162 | } 163 | } 164 | } 165 | #endif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd 364 | *.zip 365 | Manifest/ 366 | -------------------------------------------------------------------------------- /Jellyfin-Plugin-AdultsSubtitle/ScheduledTasks/ScanSubtitlesTask.cs: -------------------------------------------------------------------------------- 1 | #if __EMBY__ 2 | 3 | using MediaBrowser.Controller.Entities; 4 | using MediaBrowser.Controller.Entities.Movies; 5 | using MediaBrowser.Controller.Library; 6 | using MediaBrowser.Controller.Subtitles; 7 | using MediaBrowser.Model.Entities; 8 | using MediaBrowser.Model.Logging; 9 | using MediaBrowser.Model.Tasks; 10 | using System.Reflection; 11 | 12 | namespace Jellyfin_Plugin_AdultsSubtitle.ScheduledTasks 13 | { 14 | public class ScanSubtitlesTask : IScheduledTask 15 | { 16 | public string Name => "Scan Subtitles"; 17 | 18 | public string Key => $"{AdultsSubtitlePlugin.Instance.Name}ScanSubtitles"; 19 | 20 | public string Description => "Scan subtitles and download missing subtitles"; 21 | 22 | public string Category => AdultsSubtitlePlugin.Instance.Name; 23 | private readonly ILibraryManager _libraryManager; 24 | private readonly ILogger _logger; 25 | private readonly ISubtitleManager _subtitleManager; 26 | 27 | public ScanSubtitlesTask(ILibraryManager libraryManager, ISubtitleManager subtitleManager, ILogger logger) 28 | { 29 | _subtitleManager = subtitleManager; 30 | _libraryManager = libraryManager; 31 | _logger = logger; 32 | } 33 | public async Task Execute(CancellationToken cancellationToken, IProgress progress) 34 | { 35 | var items = _libraryManager.GetItemList(new InternalItemsQuery() 36 | { 37 | IsVirtualItem = false, 38 | MediaTypes = new[] { MediaType.Video }, 39 | IncludeItemTypes = new[] { nameof(Movie) }, 40 | }); 41 | progress.Report(0); 42 | double index = 1.0; 43 | foreach (var item in items) 44 | { 45 | if (item is Movie movie) 46 | { 47 | var language = "chi"; 48 | var option = _libraryManager.GetLibraryOptions(item); 49 | var dirInfo = new DirectoryInfo(movie.ContainingFolderPath); 50 | 51 | if (option != null 52 | 53 | && !option.DisabledSubtitleFetchers.Contains(AdultsSubtitlePlugin.Instance.Name) 54 | && option.SubtitleFetcherOrder.Contains(AdultsSubtitlePlugin.Instance.Name) 55 | && Api.LanguagesMaps.TryGetValue(language, out var subCatLanguage) 56 | && !movie.FileNameWithoutExtension.ToLower().EndsWith("-c") 57 | && !dirInfo.GetFiles().Any(p => p.Name.Contains(movie.FileNameWithoutExtension) && p.Extension == ".srt")) 58 | { 59 | 60 | _logger.Info($"{movie.FileNameWithoutExtension} has no subtitle"); 61 | 62 | if (option.SubtitleDownloadLanguages != null && option.SubtitleDownloadLanguages.Length > 0) 63 | { 64 | language = option.SubtitleDownloadLanguages[0]; 65 | } 66 | 67 | using var client = new HttpClient(); 68 | try 69 | { 70 | var searchResult = await Api.SearchAsync(client, movie.FileNameWithoutExtension, cancellationToken); 71 | _logger.Info($"search {movie.FileNameWithoutExtension} {language} subtitle result --->{searchResult} "); 72 | if (!string.IsNullOrWhiteSpace(searchResult)) 73 | { 74 | var downloadUrl = await Api.SearchDownloadUrlAsync(client, subCatLanguage, searchResult, cancellationToken); 75 | if (!string.IsNullOrWhiteSpace(downloadUrl)) 76 | { 77 | var subName = movie.FileNameWithoutExtension + ".srt"; 78 | var subPath = Path.Combine(movie.ContainingFolderPath, subName); 79 | var response = await client.GetAsync(downloadUrl, cancellationToken); 80 | using var fs = File.OpenWrite(subPath); 81 | var stream = await response.Content.ReadAsStreamAsync(cancellationToken); 82 | await stream.CopyToAsync(fs, cancellationToken); 83 | } 84 | } 85 | } 86 | catch (Exception ex) 87 | { 88 | _logger.Error(ex.ToString()); 89 | } 90 | } 91 | progress.Report(index / items.Length); 92 | } 93 | index += 1; 94 | } 95 | } 96 | public IEnumerable GetDefaultTriggers() 97 | { 98 | yield return new TaskTriggerInfo 99 | { 100 | Type = TaskTriggerInfo.TriggerDaily, 101 | TimeOfDayTicks = TimeSpan.FromHours(3).Ticks 102 | }; 103 | } 104 | } 105 | } 106 | #else 107 | 108 | using Jellyfin.Data.Enums; 109 | using MediaBrowser.Controller.Entities; 110 | using MediaBrowser.Controller.Entities.Movies; 111 | using MediaBrowser.Controller.Library; 112 | using MediaBrowser.Controller.Subtitles; 113 | using MediaBrowser.Model.Tasks; 114 | using Microsoft.Extensions.Logging; 115 | 116 | namespace Jellyfin_Plugin_AdultsSubtitle.ScheduledTasks 117 | { 118 | public class ScanSubtitlesTask : IScheduledTask 119 | { 120 | public string Name => "Scan Subtitles"; 121 | 122 | public string Key => $"{AdultsSubtitlePlugin.Instance!.Name}ScanSubtitles"; 123 | 124 | public string Description => "Scan subtitles and download missing subtitles"; 125 | 126 | public string Category => AdultsSubtitlePlugin.Instance!.Name; 127 | private readonly ILibraryManager _libraryManager; 128 | private readonly ILogger _logger; 129 | private readonly ISubtitleManager _subtitleManager; 130 | private readonly IHttpClientFactory _httpClientFactory; 131 | public ScanSubtitlesTask(ILibraryManager libraryManager, ISubtitleManager subtitleManager, IHttpClientFactory httpClientFactory, ILogger logger) 132 | { 133 | _subtitleManager = subtitleManager; 134 | _libraryManager = libraryManager; 135 | _logger = logger; 136 | _httpClientFactory = httpClientFactory; 137 | } 138 | public async Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken) 139 | { 140 | var items = _libraryManager.GetItemList(new InternalItemsQuery() 141 | { 142 | IsVirtualItem = false, 143 | MediaTypes = [MediaType.Video], 144 | SourceTypes = [SourceType.Library], 145 | }); 146 | progress.Report(0); 147 | double index = 1.0; 148 | foreach (var item in items) 149 | { 150 | if (item is Movie movie) 151 | { 152 | var language = "chi"; 153 | var option = _libraryManager.GetLibraryOptions(item); 154 | var dirInfo = new DirectoryInfo(movie.ContainingFolderPath); 155 | 156 | if (option != null 157 | && !movie.HasSubtitles 158 | && !option.DisabledSubtitleFetchers.Contains(AdultsSubtitlePlugin.Instance!.Name) 159 | && option.SubtitleFetcherOrder.Contains(AdultsSubtitlePlugin.Instance.Name) 160 | && Api.LanguagesMaps.TryGetValue(language, out var subCatLanguage) 161 | && !movie.FileNameWithoutExtension.ToLower().EndsWith("-c") 162 | && !dirInfo.GetFiles().Any(p => p.Name.Contains(movie.FileNameWithoutExtension) && p.Extension == ".srt")) 163 | { 164 | 165 | _logger.LogInformation($"{movie.FileNameWithoutExtension} has no subtitle"); 166 | 167 | if (option.SubtitleDownloadLanguages != null && option.SubtitleDownloadLanguages.Length > 0) 168 | { 169 | language = option.SubtitleDownloadLanguages[0]; 170 | } 171 | 172 | using var client = _httpClientFactory.CreateClient(); 173 | try 174 | { 175 | var searchResult = await Api.SearchAsync(client, movie.FileNameWithoutExtension, cancellationToken); 176 | _logger.LogInformation($"search {movie.FileNameWithoutExtension} {language} subtitle result --->{searchResult} "); 177 | if (!string.IsNullOrWhiteSpace(searchResult)) 178 | { 179 | var downloadUrl = await Api.SearchDownloadUrlAsync(client, subCatLanguage, searchResult, cancellationToken); 180 | _logger.LogInformation($"search{movie.FileNameWithoutExtension} {language} subtitle download url --->{downloadUrl} "); 181 | if (!string.IsNullOrWhiteSpace(downloadUrl)) 182 | { 183 | _logger.LogInformation($"start download subtitle {downloadUrl}"); 184 | 185 | var response = await client.GetAsync(downloadUrl, cancellationToken); 186 | var ms = new MemoryStream(); 187 | var stream = await response.Content.ReadAsStreamAsync(cancellationToken); 188 | await stream.CopyToAsync(ms, cancellationToken); 189 | ms.Position = 0; 190 | _logger.LogInformation($"subtitle {downloadUrl} download comlete"); 191 | 192 | 193 | await _subtitleManager.UploadSubtitle(movie, new SubtitleResponse() 194 | { 195 | Format = "srt", 196 | Language = language, 197 | Stream = ms, 198 | }); 199 | } 200 | } 201 | } 202 | catch (Exception ex) 203 | { 204 | _logger.LogError(ex.ToString()); 205 | } 206 | } 207 | progress.Report(index / items.Count); 208 | } 209 | index += 1; 210 | } 211 | } 212 | public IEnumerable GetDefaultTriggers() 213 | { 214 | yield return new TaskTriggerInfo 215 | { 216 | Type = TaskTriggerInfo.TriggerDaily, 217 | TimeOfDayTicks = TimeSpan.FromHours(3).Ticks 218 | }; 219 | } 220 | } 221 | } 222 | #endif 223 | --------------------------------------------------------------------------------