Skip to content

Commit

Permalink
Merge pull request #125 from harshithmohan/jf-10.9
Browse files Browse the repository at this point in the history
Changes for Jellyfin 10.9
  • Loading branch information
vosmiic authored May 13, 2024
2 parents aabfbce + 051e365 commit 3e84a6c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
COPY . /app

RUN dotnet publish --configuration Release --output bin
RUN dotnet publish --configuration Release --property:PublishDir=bin

FROM alpine as final
WORKDIR /app
Expand Down
14 changes: 14 additions & 0 deletions PluginServiceRegistrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using MediaBrowser.Controller;
using MediaBrowser.Controller.Plugins;
using Microsoft.Extensions.DependencyInjection;

namespace jellyfin_ani_sync;

public class PluginServiceRegistrator : IPluginServiceRegistrator
{
public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost)
{
serviceCollection.AddHostedService<SessionServerEntry>();
serviceCollection.AddHostedService<UserDataServerEntry>();
}
}
18 changes: 9 additions & 9 deletions SessionServerEntry.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.IO;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace jellyfin_ani_sync {
public class SessionServerEntry : IServerEntryPoint {
public class SessionServerEntry : IHostedService {
private readonly IHttpClientFactory _httpClientFactory;
private readonly IServerApplicationHost _serverApplicationHost;
private readonly IHttpContextAccessor _httpContextAccessor;
Expand Down Expand Up @@ -40,11 +41,16 @@ public SessionServerEntry(ISessionManager sessionManager, ILoggerFactory loggerF
_fileSystem = fileSystem;
}

public Task RunAsync() {
public Task StartAsync(CancellationToken cancellationToken) {
_sessionManager.PlaybackStopped += PlaybackStopped;
return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken) {
_sessionManager.PlaybackStopped -= PlaybackStopped;
return Task.CompletedTask;
}

public async void PlaybackStopped(object sender, PlaybackStopEventArgs e) {
try {
UpdateProviderStatus updateProviderStatus = new UpdateProviderStatus(_fileSystem, _libraryManager, _loggerFactory, _httpContextAccessor, _serverApplicationHost, _httpClientFactory, _applicationPaths);
Expand All @@ -55,11 +61,5 @@ public async void PlaybackStopped(object sender, PlaybackStopEventArgs e) {
_logger.LogError($"Fatal error occured during anime sync job: {exception}");
}
}


public void Dispose() {
_sessionManager.PlaybackStopped -= PlaybackStopped;
GC.SuppressFinalize(this);
}
}
}
3 changes: 2 additions & 1 deletion Sync/SyncProviderFromLocal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using jellyfin_ani_sync.Helpers;
using Jellyfin.Data.Enums;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
Expand Down Expand Up @@ -94,7 +95,7 @@ private List<Episode> GetMaxEpisodeAndCompletedTime(Series series) {
}

var query = new InternalItemsQuery(_userManager.GetUserById(_userId)) {
MediaTypes = new []{"Video"},
MediaTypes = [ MediaType.Video ],
ParentId = season.ParentId,
ParentIndexNumber = season.IndexNumber,
Recursive = true
Expand Down
21 changes: 11 additions & 10 deletions UserDataServerEntry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#nullable enable
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller;
Expand All @@ -12,10 +12,11 @@
using MediaBrowser.Model.IO;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace jellyfin_ani_sync {
public class UserDataServerEntry : IServerEntryPoint {
public class UserDataServerEntry : IHostedService {
private readonly IUserDataManager _userDataManager;
private readonly IFileSystem _fileSystem;
private readonly ILibraryManager _libraryManager;
Expand Down Expand Up @@ -48,12 +49,17 @@ public UserDataServerEntry(IUserDataManager userDataManager,
_taskProcessMarkedMedia = new TaskProcessMarkedMedia(loggerFactory, _libraryManager, _fileSystem, _memoryCache, _httpContextAccessor, _serverApplicationHost, _httpClientFactory, _applicationPaths);
}

public Task RunAsync() {
public Task StartAsync(CancellationToken cancellationToken) {
_userDataManager.UserDataSaved += UserDataManagerOnUserDataSaved;
return Task.CompletedTask;
}

private void UserDataManagerOnUserDataSaved(object sender, UserDataSaveEventArgs e) {
public Task StopAsync(CancellationToken cancellationToken) {
_userDataManager.UserDataSaved -= UserDataManagerOnUserDataSaved;
return Task.CompletedTask;
}

private void UserDataManagerOnUserDataSaved(object? sender, UserDataSaveEventArgs e) {
if (e.SaveReason == UserDataSaveReason.TogglePlayed && Plugin.Instance?.PluginConfiguration.watchedTickboxUpdatesProvider == true) {
if (!e.UserData.Played || e.Item is not Video) return;
// asynchronous call so it doesn't prevent the UI marking the media as watched
Expand All @@ -64,10 +70,5 @@ private void UserDataManagerOnUserDataSaved(object sender, UserDataSaveEventArgs
}
}
}

public void Dispose() {
_userDataManager.UserDataSaved -= UserDataManagerOnUserDataSaved;
GC.SuppressFinalize(this);
}
}
}
}
4 changes: 2 additions & 2 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name: "Ani-Sync"
guid: "c78f11cf-93e6-4423-8c42-d2c255b70e47"
version: "1.4"
targetAbi: "10.8.0.0"
framework: "net6.0"
targetAbi: "10.9.0.0"
framework: "net8.0"
owner: "vosmiic"
overview: "Synchronize anime watch status"
description: >
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.0",
"version": "8.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
}
Expand Down
8 changes: 4 additions & 4 deletions jellyfin-ani-sync.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>jellyfin_ani_sync</RootNamespace>
</PropertyGroup>

Expand All @@ -14,10 +14,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.8.13" />
<PackageReference Include="Jellyfin.Model" Version="10.8.13" />
<PackageReference Include="Jellyfin.Controller" Version="10.9.1" />
<PackageReference Include="Jellyfin.Model" Version="10.9.1" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="System.Collections" Version="4.3.0" />
</ItemGroup>

Expand Down

0 comments on commit 3e84a6c

Please sign in to comment.