├── Payloads ├── Jellyfin │ ├── JellyfinSearchResult.cs │ └── JellyfinItem.cs ├── Jellyseerr │ ├── JellyseerrMediaSearchResult.cs │ ├── JellyseerrSearchResult.cs │ ├── JellySeerrTv.cs │ ├── JellySeerrMovie.cs │ ├── JellyseerrSearchMediaResult.cs │ └── JellyseerrMedia.cs ├── Radarr │ ├── RadarrNotificationPayload.cs │ ├── RadarrMovie.cs │ ├── RadarrMovieFileMediaInfo.cs │ └── RadarrMovieFile.cs └── Sonarr │ ├── SonarrEpisode.cs │ ├── SonarrSeries.cs │ ├── SonarrNotificationPayload.cs │ └── SonarrEpisodeFile.cs ├── appsettings.Development.json ├── .dockerignore ├── JellyseerrSync.csproj ├── JellyseerrSync.http ├── appsettings.json ├── Dockerfile ├── JellyseerrSync.sln ├── Properties └── launchSettings.json ├── .gitattributes ├── README.md ├── .gitignore └── Program.cs /Payloads/Jellyfin/JellyfinSearchResult.cs: -------------------------------------------------------------------------------- 1 | public class JellyfinSearchResult 2 | { 3 | public List Items { get; set; } 4 | } 5 | -------------------------------------------------------------------------------- /Payloads/Jellyfin/JellyfinItem.cs: -------------------------------------------------------------------------------- 1 | public class JellyfinItem 2 | { 3 | public string Id { get; set; } 4 | public string Name { get; set; } 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Payloads/Jellyseerr/JellyseerrMediaSearchResult.cs: -------------------------------------------------------------------------------- 1 | public class JellyseerrMediaSearchResult 2 | { 3 | public List Results { get; set; } 4 | } 5 | -------------------------------------------------------------------------------- /Payloads/Jellyseerr/JellyseerrSearchResult.cs: -------------------------------------------------------------------------------- 1 | public class JellyseerrSearchResult 2 | { 3 | public List Results { get; set; } 4 | } 5 | -------------------------------------------------------------------------------- /Payloads/Jellyseerr/JellySeerrTv.cs: -------------------------------------------------------------------------------- 1 | public class JellySeerrTv 2 | { 3 | public int Id { get; set; } 4 | 5 | public JellyseerrMedia MediaInfo { get; set; } 6 | } 7 | -------------------------------------------------------------------------------- /appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Payloads/Jellyseerr/JellySeerrMovie.cs: -------------------------------------------------------------------------------- 1 | public class JellySeerrMovie 2 | { 3 | public int Id { get; set; } 4 | 5 | public JellyseerrMedia MediaInfo { get; set; } 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Payloads/Jellyseerr/JellyseerrSearchMediaResult.cs: -------------------------------------------------------------------------------- 1 | public class JellyseerrSearchMediaResult 2 | { 3 | public int Id { get; set; } 4 | public JellyseerrMedia MediaInfo { get; set; } 5 | } 6 | -------------------------------------------------------------------------------- /Payloads/Jellyseerr/JellyseerrMedia.cs: -------------------------------------------------------------------------------- 1 | public class JellyseerrMedia 2 | { 3 | public int Id { get; set; } 4 | public int TmdbId { get; set; } 5 | 6 | public int? TvdbId { get; set; } 7 | public string MediaType { get; set; } 8 | 9 | public string JellyfinMediaId { get; set; } 10 | 11 | public string JellyfinMediaId4k { get; set; } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Payloads/Radarr/RadarrNotificationPayload.cs: -------------------------------------------------------------------------------- 1 | public class RadarrNotificationPayload 2 | { 3 | public string EventType { get; set; } 4 | public string InstanceName { get; set; } 5 | public string ApplicationUrl { get; set; } 6 | 7 | public RadarrMovie Movie { get; set; } 8 | 9 | public RadarrMovieFile MovieFile { get; set; } 10 | 11 | public string DeleteReason { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /Payloads/Sonarr/SonarrEpisode.cs: -------------------------------------------------------------------------------- 1 | public class SonarrEpisode 2 | { 3 | public int Id { get; set; } 4 | public int EpisodeNumber { get; set; } 5 | public int SeasonNumber { get; set; } 6 | public string Title { get; set; } 7 | public string Overview { get; set; } 8 | public string AirDate { get; set; } 9 | public DateTime? AirDateUtc { get; set; } 10 | public int SeriesId { get; set; } 11 | } 12 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | LICENSE 25 | README.md -------------------------------------------------------------------------------- /Payloads/Sonarr/SonarrSeries.cs: -------------------------------------------------------------------------------- 1 | public class SonarrSeries 2 | { 3 | public int Id { get; set; } 4 | public string Title { get; set; } 5 | public string TitleSlug { get; set; } 6 | public string Path { get; set; } 7 | public int TvdbId { get; set; } 8 | public int TvMazeId { get; set; } 9 | public string ImdbId { get; set; } 10 | //public SeriesTypes Type { get; set; } 11 | public int Year { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /Payloads/Radarr/RadarrMovie.cs: -------------------------------------------------------------------------------- 1 | public class RadarrMovie 2 | { 3 | public int Id { get; set; } 4 | public string Title { get; set; } 5 | public int Year { get; set; } 6 | public string FilePath { get; set; } 7 | public string ReleaseDate { get; set; } 8 | public string FolderPath { get; set; } 9 | public int TmdbId { get; set; } 10 | public string ImdbId { get; set; } 11 | public string Overview { get; set; } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Payloads/Sonarr/SonarrNotificationPayload.cs: -------------------------------------------------------------------------------- 1 | public class SonarrNotificationPayload 2 | { 3 | public string EventType { get; set; } 4 | public string InstanceName { get; set; } 5 | public string ApplicationUrl { get; set; } 6 | 7 | public SonarrSeries Series { get; set; } 8 | 9 | //public List Episodes { get; set; } 10 | 11 | //public SonarrEpisodeFile EpisodeFile { get; set; } 12 | 13 | public string DeleteReason { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /Payloads/Radarr/RadarrMovieFileMediaInfo.cs: -------------------------------------------------------------------------------- 1 | public class RadarrMovieFileMediaInfo 2 | { 3 | public decimal AudioChannels { get; set; } 4 | public string AudioCodec { get; set; } 5 | public List AudioLanguages { get; set; } 6 | public int Height { get; set; } 7 | public int Width { get; set; } 8 | public List Subtitles { get; set; } 9 | public string VideoCodec { get; set; } 10 | public string VideoDynamicRange { get; set; } 11 | public string VideoDynamicRangeType { get; set; } 12 | } -------------------------------------------------------------------------------- /Payloads/Sonarr/SonarrEpisodeFile.cs: -------------------------------------------------------------------------------- 1 | public class SonarrEpisodeFile 2 | { 3 | 4 | public int Id { get; set; } 5 | public string RelativePath { get; set; } 6 | public string Path { get; set; } 7 | public string Quality { get; set; } 8 | public int QualityVersion { get; set; } 9 | public string ReleaseGroup { get; set; } 10 | public string SceneName { get; set; } 11 | public long Size { get; set; } 12 | public DateTime DateAdded { get; set; } 13 | //public WebhookEpisodeFileMediaInfo MediaInfo { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /Payloads/Radarr/RadarrMovieFile.cs: -------------------------------------------------------------------------------- 1 | public class RadarrMovieFile 2 | { 3 | public int Id { get; set; } 4 | public string RelativePath { get; set; } 5 | public string Path { get; set; } 6 | public string Quality { get; set; } 7 | public int QualityVersion { get; set; } 8 | public string ReleaseGroup { get; set; } 9 | public string SceneName { get; set; } 10 | public string IndexerFlags { get; set; } 11 | public long Size { get; set; } 12 | public DateTime DateAdded { get; set; } 13 | public RadarrMovieFileMediaInfo MediaInfo { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /JellyseerrSync.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | disable 6 | enable 7 | 2e34aaf0-4eff-4a4b-9853-d48a32b159c3 8 | Linux 9 | . 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /JellyseerrSync.http: -------------------------------------------------------------------------------- 1 | @JellyseerrSync_HostAddress = http://localhost:5258 2 | 3 | GET {{JellyseerrSync_HostAddress}}/syncdeleted/movies 4 | 5 | ### 6 | 7 | POST {{JellyseerrSync_HostAddress}}/radarr/notification 8 | Content-Type: application/json 9 | 10 | { 11 | "instanceName": "test", 12 | "eventType": "MovieFileDelete", 13 | "DeleteReason": "", 14 | "movie": {"TmdbId" : 1}, 15 | "movieFile": {} 16 | } 17 | ### 18 | 19 | POST {{JellyseerrSync_HostAddress}}/sonarr/notification 20 | Content-Type: application/json 21 | 22 | { 23 | "instanceName": "test", 24 | "eventType": "SeriesDelete", 25 | "DeleteReason": "", 26 | "series": {"Title": "Test"} 27 | } 28 | ### 29 | 30 | -------------------------------------------------------------------------------- /appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | }, 7 | "File": { //Refer to https://github.com/nreco/logging for configuration 8 | "Path": "JellyseerrSync.log", //You can use something like : var/log/JellyseerrSync.log in linux 9 | "Append": true, 10 | "MinLevel": "Information", // min level for the file logger 11 | "FileSizeLimitBytes": 0, // use to activate rolling file behaviour 12 | "MaxRollingFiles": 0 // use to specify max number of log files 13 | } 14 | }, 15 | "AllowedHosts": "*", 16 | "JELLYSEERR_APIKEY": "", 17 | "JELLYFIN_APIKEY": "", 18 | "JELLYFIN_HOST_URL": "http://192.168.1.10:8096/", 19 | "JELLYSEERR_HOST_URL": "http://192.168.1.11:5055/" 20 | } 21 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | #See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. 2 | 3 | FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base 4 | WORKDIR /app 5 | EXPOSE 80 6 | EXPOSE 443 7 | 8 | FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build 9 | ARG BUILD_CONFIGURATION=Release 10 | WORKDIR /src 11 | COPY ["JellyseerrSync.csproj", "."] 12 | RUN dotnet restore "./JellyseerrSync.csproj" 13 | COPY . . 14 | WORKDIR "/src/." 15 | RUN dotnet build "JellyseerrSync.csproj" -c $BUILD_CONFIGURATION -o /app/build 16 | 17 | FROM build AS publish 18 | RUN dotnet publish "JellyseerrSync.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false 19 | 20 | FROM base AS final 21 | WORKDIR /app 22 | COPY --from=publish /app/publish . 23 | ENTRYPOINT ["dotnet", "JellyseerrSync.dll"] -------------------------------------------------------------------------------- /JellyseerrSync.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34112.27 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JellyseerrSync", "JellyseerrSync.csproj", "{43C0189A-E2FE-474D-B90B-83EBF2EFB9E4}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FD6462CB-F65C-46AE-B349-9B76486AA362}" 9 | ProjectSection(SolutionItems) = preProject 10 | jellyseerr.http = jellyseerr.http 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {43C0189A-E2FE-474D-B90B-83EBF2EFB9E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {43C0189A-E2FE-474D-B90B-83EBF2EFB9E4}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {43C0189A-E2FE-474D-B90B-83EBF2EFB9E4}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {43C0189A-E2FE-474D-B90B-83EBF2EFB9E4}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | GlobalSection(ExtensibilityGlobals) = postSolution 28 | SolutionGuid = {E57126F2-9AF9-4C3A-93C0-7488812B3F15} 29 | EndGlobalSection 30 | EndGlobal 31 | -------------------------------------------------------------------------------- /Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "http": { 4 | "commandName": "Project", 5 | "launchBrowser": true, 6 | "launchUrl": "", 7 | "environmentVariables": { 8 | "ASPNETCORE_ENVIRONMENT": "Development" 9 | }, 10 | "dotnetRunMessages": true, 11 | "applicationUrl": "http://localhost:5258" 12 | }, 13 | "https": { 14 | "commandName": "Project", 15 | "launchBrowser": true, 16 | "launchUrl": "", 17 | "environmentVariables": { 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | }, 20 | "dotnetRunMessages": true, 21 | "applicationUrl": "https://localhost:7016;http://localhost:5258" 22 | }, 23 | "IIS Express": { 24 | "commandName": "IISExpress", 25 | "launchBrowser": true, 26 | "launchUrl": "", 27 | "environmentVariables": { 28 | "ASPNETCORE_ENVIRONMENT": "Development" 29 | } 30 | }, 31 | "Docker": { 32 | "commandName": "Docker", 33 | "launchBrowser": true, 34 | "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", 35 | "environmentVariables": { 36 | "ASPNETCORE_URLS": "https://+:443;http://+:80" 37 | }, 38 | "publishAllPorts": true, 39 | "useSSL": true 40 | } 41 | }, 42 | "$schema": "https://json.schemastore.org/launchsettings.json", 43 | "iisSettings": { 44 | "windowsAuthentication": false, 45 | "anonymousAuthentication": true, 46 | "iisExpress": { 47 | "applicationUrl": "http://localhost:45864", 48 | "sslPort": 44386 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JellyseerrSync 2 | 3 | ## Archived 4 | 5 | With the release of jellyseer v1.8.0 https://github.com/Fallenbagel/jellyseerr/releases/tag/v1.8.0 a feature was implemented to properly remove media automatically on scan : Fallenbagel/jellyseerr#522 6 | This means that this repository / application should no longer be needed from jellyseerr v1.8.0+. 7 | This repository will no longer have updates and it is archived. All the docker images will still be available for usage. 8 | 9 | ## The Problem 10 | If media gets deleted from jellyfin, jellyseerr does not get updated and so media still shows as Available. See https://github.com/Fallenbagel/jellyseerr/issues/84 11 | 12 | This app provides kinda of an hacky way to keep jellyseerr synced, while jellyseerr does not provide a fix. 13 | 14 | ## Notifications 15 | Clean up the availability on Jellyseerr by using the Radarr and Sonarr Webhook to listen to the **MovieFileDelete** and **EpisodeFileDelete** events. 16 | 17 | ### Radarr 18 | 19 | Set up the webhook notification to listen to the Notification "**On Movie File Delete**" on **http://ip_or_url/radarr/notification** 20 | 21 | ### Sonarr 22 | 23 | Set up the webhook notification to listen to the Notification "**On Series Delete**", "**On Episode File Delete**" on **http://ip_or_url/sonarr/notification** 24 | 25 | It is of note that upon an episode being deleted, the entire series just gets cleared currently. As there seems to be no way to determine if there are episodes still left or not. Jellyseerr recurring Sonarr Scan 26 | job should refresh any entry that might have been cleared, but it's still actually available. 27 | 28 | ## Sync 29 | By visiting **http://ip_or_url/syncdeleted/movies** the app will query Jellyseerr for every movie that's marked as Available, and verify whether a corresponding item exists in the Jellyfin database. If it does not, it clears the movie entry on Jellyseerr. 30 | A log is provided with every movie entry that was cleared. 31 | 32 | ## Logs 33 | Logs are provided on the root of the app if you use the default configuration, and can be accessed by visiting **http://ip_or_url/logs** or the file **JellyseerrSync.log**. 34 | You can choose not to log to file by 35 | - Not providing the Logging variables 36 | - Setting the environment variable **Logging:File:Path** to an empty string or not providing it at all. 37 | - Setting the Logging:File:MinLevel to None 38 | 39 | ## How to Deploy 40 | A docker image has been provided: 41 | https://hub.docker.com/r/dockerdaverick/jellyseerrsync 42 | 43 | Example usage: 44 | 45 | Docker-compose: 46 | ``` 47 | version: "3.9" 48 | name: jellyseerr-notifications 49 | services: 50 | 51 | jellyseerr-notifications: 52 | image: dockerdaverick/jellyseerrsync:latest 53 | environment: 54 | # Refer to https://github.com/nreco/logging for logging configuration 55 | - Logging:File:Path=JellyseerrSync.log 56 | - Logging:File:Append=true 57 | - Logging:File:MinLevel=Information # min level for the file logger (Trace,Debug,Information,Warning,Error,Critical,None) 58 | - Logging:File:FileSizeLimitBytes=0 # use to activate rolling file behaviour 59 | - Logging:File:MaxRollingFiles=0 # use to specify max number of log files 60 | - JELLYSEERR_APIKEY=MYAPIKEY 61 | - JELLYFIN_APIKEY=MYAPIKEY 62 | - JELLYSEERR_HOST_URL=http://192.168.1.11:5055/ 63 | - JELLYFIN_HOST_URL=http://192.168.1.10:8096/ 64 | ports: 65 | - 50580:80 66 | restart: unless-stopped 67 | ``` 68 | 69 | -------------------------------------------------------------------------------- /.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 -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | using System.Text; 4 | 5 | var builder = WebApplication.CreateBuilder( args ); 6 | 7 | var configuration = new ConfigurationBuilder() 8 | .SetBasePath( Directory.GetCurrentDirectory() ) 9 | .AddJsonFile( "appsettings.json", optional: true, reloadOnChange: true ) 10 | .AddEnvironmentVariables() 11 | .AddUserSecrets( typeof( Program ).Assembly ) 12 | .Build(); 13 | 14 | var JELLYSEERR_APIKEY = configuration.GetSection( "JELLYSEERR_APIKEY" ).Value; 15 | var JELLYFIN_APIKEY = configuration.GetSection( "JELLYFIN_APIKEY" ).Value; 16 | var JELLYSEERR_HOST_URL = configuration.GetSection( "JELLYSEERR_HOST_URL" ).Value; 17 | var JELLYFIN_HOST_URL = configuration.GetSection( "JELLYFIN_HOST_URL" ).Value; 18 | 19 | var LOG_FILE_PATH = configuration.GetSection( "Logging:File:Path" ).Value; 20 | 21 | ArgumentNullException.ThrowIfNullOrEmpty( JELLYSEERR_APIKEY ); 22 | ArgumentNullException.ThrowIfNullOrEmpty( JELLYSEERR_HOST_URL ); 23 | ArgumentNullException.ThrowIfNullOrEmpty( JELLYFIN_HOST_URL ); 24 | ArgumentNullException.ThrowIfNullOrEmpty( JELLYFIN_APIKEY ); 25 | 26 | var JELLYSEERR_URI = new Uri( JELLYSEERR_HOST_URL ); 27 | var JELLYFIN_URI = new Uri( JELLYFIN_HOST_URL ); 28 | 29 | builder.Services.AddLogging( loggingBuilder => 30 | { 31 | var loggingSection = configuration.GetSection( "Logging" ); 32 | loggingBuilder.AddFile( loggingSection ); 33 | } ); 34 | 35 | builder.Services.AddHttpClient( "Jellyseerr", ( client ) => 36 | { 37 | client.BaseAddress = new Uri( JELLYSEERR_URI, "api/v1/" ); 38 | client.DefaultRequestHeaders.Add( "X-Api-Key", JELLYSEERR_APIKEY ); 39 | } ); 40 | 41 | builder.Services.AddHttpClient( "Jellyfin", ( client ) => 42 | { 43 | client.BaseAddress = JELLYFIN_URI; 44 | client.DefaultRequestHeaders.Add( "Authorization", $"MediaBrowser Token=\"{JELLYFIN_APIKEY}\"" ); 45 | } ); 46 | 47 | var app = builder.Build(); 48 | 49 | app.MapGet( "/", async ( context ) => await context.Response.WriteAsync( @" 50 | Notification Endpoints: 51 | /radarr/notification 52 | /sonarr/notification 53 | 54 | It is of note that any series episode deletion assumes the entire series is deleted. As there seems to be no way to determine if there are episodes left. 55 | 56 | Sync Endpoints: 57 | /syncdeleted/movies 58 | 59 | This endpoint will query Jellyseerr for all movies that are marked as Available and then query Jellyfin for all the movies that are marked as Available in Jellyseerr. 60 | If a movie is not found in Jellyfin it will be cleared from Jellyseerr. 61 | 62 | Log Endpoints: 63 | /logs 64 | 65 | This endpoint will try to return the log file content if it exists. 66 | " ) ); 67 | 68 | app.MapGet( "/logs", async ( HttpResponse response ) => 69 | { 70 | var log = "No log file found"; 71 | 72 | if ( !string.IsNullOrWhiteSpace( LOG_FILE_PATH ) ) 73 | { 74 | try 75 | { 76 | StringBuilder sb = new StringBuilder(); 77 | using ( var logFile = new FileStream( LOG_FILE_PATH, FileMode.Open, FileAccess.Read, FileShare.ReadWrite ) ) 78 | using ( var sr = new StreamReader( logFile ) ) 79 | { 80 | while ( !sr.EndOfStream ) 81 | { 82 | sb.AppendLine( sr.ReadLine() ); 83 | } 84 | } 85 | log = sb.ToString(); 86 | } 87 | catch ( Exception ex ) 88 | { 89 | log = $"Tried reading the file : {LOG_FILE_PATH}, but the following error occurred: {ex}"; 90 | } 91 | } 92 | 93 | response.StatusCode = 200; 94 | 95 | response.ContentType = "text/plain"; 96 | response.ContentLength = null; 97 | response.Headers.Add( "Content-Encoding", "identity" ); 98 | response.Headers.Add( "Transfer-Encoding", "identity" ); 99 | 100 | await response.WriteAsync( log ); 101 | await response.CompleteAsync(); 102 | } ); 103 | 104 | app.MapGet( "/syncdeleted/movies", async ( [FromServices] IHttpClientFactory httpClientFactory, [FromServices] ILogger logger, HttpResponse response ) => 105 | { 106 | var log = await SyncDeletedMovies( httpClientFactory, logger ); 107 | 108 | response.StatusCode = 200; 109 | 110 | response.ContentType = "text/plain"; 111 | response.ContentLength = null; 112 | response.Headers.Add( "Content-Encoding", "identity" ); 113 | response.Headers.Add( "Transfer-Encoding", "identity" ); 114 | 115 | await response.WriteAsync( log ); 116 | await response.CompleteAsync(); 117 | } ); 118 | 119 | app.MapPost( "/radarr/notification", ( [FromServices] IHttpClientFactory httpClientFactory, [FromServices] ILogger logger, [FromBody] RadarrNotificationPayload payload ) 120 | => ProcessRadarrNotification( httpClientFactory, logger, payload ) ); 121 | 122 | app.MapPost( "/sonarr/notification", ( [FromServices] IHttpClientFactory httpClientFactory, [FromServices] ILogger logger, [FromBody] SonarrNotificationPayload payload ) 123 | => ProcessSonarrNotification( httpClientFactory, logger, payload ) ); 124 | 125 | app.Run(); 126 | 127 | 128 | async Task ProcessRadarrNotification( IHttpClientFactory httpClientFactory, ILogger logger, RadarrNotificationPayload payload ) 129 | { 130 | logger.LogInformation( "Processing Radarr Notification" ); 131 | logger.LogInformation( "Received the following Notification: {Notification}", System.Text.Json.JsonSerializer.Serialize( payload ) ); 132 | 133 | try 134 | { 135 | if ( payload.EventType.Equals( "MovieFileDelete", StringComparison.InvariantCultureIgnoreCase ) && ( payload.DeleteReason is null || !payload.DeleteReason.Equals( "upgrade", StringComparison.InvariantCultureIgnoreCase ) ) ) 136 | { 137 | logger.LogInformation( "Processing MovieFileDelete" ); 138 | 139 | await RunMovieClear( httpClientFactory, logger, payload ); 140 | } 141 | else 142 | { 143 | logger.LogInformation( "Nothing to Process" ); 144 | } 145 | 146 | } 147 | catch ( Exception ex ) 148 | { 149 | logger.LogError( "An error has occurred: {Exception}", ex ); 150 | } 151 | } 152 | 153 | async Task ProcessSonarrNotification( IHttpClientFactory httpClientFactory, ILogger logger, SonarrNotificationPayload payload ) 154 | { 155 | logger.LogInformation( "Processing Sonarr Notification" ); 156 | logger.LogInformation( "Received the following Notification: {Notification}", System.Text.Json.JsonSerializer.Serialize( payload ) ); 157 | 158 | try 159 | { 160 | if ( payload.EventType.Equals( "SeriesDelete", StringComparison.InvariantCultureIgnoreCase ) && ( payload.DeleteReason is null || !payload.DeleteReason.Equals( "upgrade", StringComparison.InvariantCultureIgnoreCase ) ) ) 161 | { 162 | logger.LogInformation( "Processing SeriesDelete" ); 163 | 164 | await RunEpisodeClear( httpClientFactory, logger, payload ); 165 | } 166 | else if ( payload.EventType.Equals( "EpisodeFileDelete", StringComparison.InvariantCultureIgnoreCase ) && ( payload.DeleteReason is null || !payload.DeleteReason.Equals( "upgrade", StringComparison.InvariantCultureIgnoreCase ) ) ) 167 | { 168 | logger.LogInformation( "Processing EpisodeFileDelete" ); 169 | 170 | await RunEpisodeClear( httpClientFactory, logger, payload ); 171 | } 172 | else 173 | { 174 | logger.LogInformation( "Nothing to Process" ); 175 | } 176 | } 177 | catch ( Exception ex ) 178 | { 179 | logger.LogError( "An error has occurred: {Exception}", ex ); 180 | } 181 | }; 182 | 183 | 184 | 185 | async Task SyncDeletedMovies( IHttpClientFactory httpClientFactory, ILogger logger ) 186 | { 187 | var batchSize = 100; 188 | 189 | logger.LogInformation( "Processing Deleted Movies Sync..." ); 190 | var log = new StringBuilder(); 191 | 192 | try 193 | { 194 | log.AppendLine( "Processing Deleted Movies Sync..." ); 195 | 196 | 197 | var jellyfinClient = httpClientFactory.CreateClient( "Jellyfin" ); 198 | var jellyseerrClient = httpClientFactory.CreateClient( "Jellyseerr" ); 199 | 200 | var searchMessage = "Searching JellySeerr media..."; 201 | log.AppendLine( searchMessage ); 202 | logger.LogInformation( searchMessage ); 203 | 204 | var searchResult = await jellyseerrClient.GetFromJsonAsync( $"media?take=999&skip=0&filter=available&sort=added" ); 205 | var availableMovies = searchResult.Results.Where( x => x.MediaType.Equals( "movie", StringComparison.InvariantCultureIgnoreCase ) ); 206 | 207 | 208 | var moviesIds = availableMovies 209 | .Where( x => !string.IsNullOrWhiteSpace( x.JellyfinMediaId ) || !string.IsNullOrWhiteSpace( x.JellyfinMediaId4k ) ) 210 | .Select( x => new 211 | { 212 | Id = string.IsNullOrWhiteSpace( x.JellyfinMediaId ) 213 | ? Guid.Parse( x.JellyfinMediaId4k ).ToString( "d" ) 214 | : Guid.Parse( x.JellyfinMediaId ).ToString( "d" ), 215 | MediaId = x.Id, 216 | TmdbId = x.TmdbId 217 | } ); 218 | 219 | 220 | var jellyseerrMoviesCount = moviesIds.Count(); 221 | var totalMessage = $"Total Jellyseerr Movies found as Available: {jellyseerrMoviesCount}"; 222 | log.AppendLine( totalMessage ); 223 | logger.LogInformation( totalMessage ); 224 | 225 | var existingJellyfinItems = new List(); 226 | for ( int i = 0; i < jellyseerrMoviesCount; i += batchSize ) 227 | { 228 | var batch = moviesIds.Skip( i ).Take( batchSize ); 229 | var jellySearchResult = await jellyfinClient.GetFromJsonAsync( $"Items?ids={string.Join( ",", batch.Select( x => x.Id ) )}&enableTotalRecordCount=false&enableImages=false" ); 230 | 231 | existingJellyfinItems.AddRange( jellySearchResult.Items ); 232 | } 233 | 234 | var notFoundMovies = moviesIds.Where( x => !existingJellyfinItems.Any( y => Guid.Parse( y.Id ) == Guid.Parse( x.Id ) ) ); 235 | 236 | var notFoundMessage = "Jellyfin movies/items that were not found: " + notFoundMovies.Count(); 237 | log.AppendLine( notFoundMessage ); 238 | logger.LogInformation( notFoundMessage ); 239 | 240 | if ( notFoundMovies.Any() ) 241 | { 242 | foreach ( var notFoundMovie in notFoundMovies ) 243 | { 244 | var clearMessage = $"Clearing: {new Uri( JELLYSEERR_URI, $"movie/{notFoundMovie.TmdbId}" )}"; 245 | log.AppendLine( clearMessage ); 246 | logger.LogInformation( clearMessage ); 247 | await jellyseerrClient.DeleteAsync( $"media/{notFoundMovie.MediaId}" ); 248 | } 249 | } 250 | } 251 | catch ( Exception ex ) 252 | { 253 | log.AppendLine( "An error has occurred: " ); 254 | log.AppendLine( ex.ToString() ); 255 | } 256 | return log.ToString(); 257 | } 258 | 259 | static async Task RunMovieClear( IHttpClientFactory httpClientFactory, ILogger logger, RadarrNotificationPayload payload ) 260 | { 261 | var client = httpClientFactory.CreateClient( "Jellyseerr" ); 262 | var response = await client.GetAsync( $"movie/{payload.Movie.TmdbId}" ); 263 | 264 | if ( !response.IsSuccessStatusCode ) 265 | { 266 | logger.LogWarning( "No entry was cleared. Could not find an entry for this movie." ); 267 | return; 268 | } 269 | 270 | var movie = await response.Content.ReadFromJsonAsync(); 271 | logger.LogInformation( "Clearing entry... with TmdbId: {TmdbId} | JellySeerr MediaId: {JellySeerrMediaId}", movie.MediaInfo.TmdbId, movie.MediaInfo.Id ); 272 | await client.DeleteAsync( $"media/{movie.MediaInfo.Id}" ); 273 | } 274 | 275 | static async Task RunEpisodeClear( IHttpClientFactory httpClientFactory, ILogger logger, SonarrNotificationPayload payload ) 276 | { 277 | var client = httpClientFactory.CreateClient( "Jellyseerr" ); 278 | 279 | logger.LogInformation( "Searching Jellyseerr for... {Title}", payload.Series.Title ); 280 | 281 | var searchResult = await client.GetFromJsonAsync( $"search?query={Uri.EscapeDataString( payload.Series.Title )}&page=1&language=en" ); 282 | 283 | if ( searchResult is not null && searchResult.Results?.Count > 0 ) 284 | { 285 | var foundMedia = searchResult.Results.FirstOrDefault( x => x.MediaInfo?.TvdbId == payload.Series.TvdbId ); 286 | if ( foundMedia is not null ) 287 | { 288 | logger.LogInformation( "Clearing entry... with TmdbId: {TmdbId} | JellySeerr MediaId: {JellySeerrMediaId}", foundMedia.MediaInfo.TmdbId, foundMedia.MediaInfo.Id ); 289 | await client.DeleteAsync( $"media/{foundMedia.MediaInfo.Id}" ); 290 | } 291 | else 292 | { 293 | logger.LogWarning( "No entry was cleared. Could not find an entry for this series." ); 294 | } 295 | } 296 | else 297 | { 298 | logger.LogWarning( "Could not find this series: {Title}", payload.Series.Title ); 299 | } 300 | } --------------------------------------------------------------------------------