Separate globals and initialize also from CinemaLibraryManager to allow migrations to run
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -8,6 +8,7 @@ using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using CinemaLib.API;
|
||||
using Jellyfin.Database.Implementations.Enums;
|
||||
using CinemaJellyfin;
|
||||
|
||||
namespace Jellyfin.Plugin.Cinema;
|
||||
|
||||
@@ -166,11 +167,11 @@ public abstract class CinemaFilterFolder : Folder
|
||||
|
||||
private static T CreateFilterFolderInternal<T>(CinemaFilterFolder? parent, string localizedName) where T : CinemaFilterFolder, new()
|
||||
{
|
||||
Guid folderId = CinemaHost.LibraryManager.GetNewItemId("folder", typeof(T));
|
||||
string folderPath = GetInternalMetadataPath(CinemaHost.InternalMetadataPath!, folderId);
|
||||
Guid folderId = CinemaGlobals.LibraryManager.GetNewItemId("folder", typeof(T));
|
||||
string folderPath = GetInternalMetadataPath(CinemaGlobals.InternalMetadataPath!, folderId);
|
||||
Directory.CreateDirectory(folderPath);
|
||||
|
||||
T? folder = CinemaHost.LibraryManager.GetItemById(folderId) as T;
|
||||
T? folder = CinemaGlobals.LibraryManager.GetItemById(folderId) as T;
|
||||
bool isNew;
|
||||
bool forceUpdate = false;
|
||||
if (isNew = folder == null)
|
||||
@@ -178,8 +179,8 @@ public abstract class CinemaFilterFolder : Folder
|
||||
folder = new T
|
||||
{
|
||||
Id = folderId,
|
||||
DateCreated = CinemaHost.FileSystem.GetCreationTimeUtc(folderPath),
|
||||
DateModified = CinemaHost.FileSystem.GetLastWriteTimeUtc(folderPath)
|
||||
DateCreated = CinemaGlobals.FileSystem.GetCreationTimeUtc(folderPath),
|
||||
DateModified = CinemaGlobals.FileSystem.GetLastWriteTimeUtc(folderPath)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -201,11 +202,11 @@ public abstract class CinemaFilterFolder : Folder
|
||||
if (isNew)
|
||||
{
|
||||
folder.OnMetadataChanged();
|
||||
CinemaHost.LibraryManager.CreateItem(folder, parent);
|
||||
CinemaGlobals.LibraryManager.CreateItem(folder, parent);
|
||||
}
|
||||
|
||||
folder.RefreshMetadata(
|
||||
new MetadataRefreshOptions(new DirectoryService(CinemaHost.FileSystem)) { ForceSave = !isNew && forceUpdate },
|
||||
new MetadataRefreshOptions(new DirectoryService(CinemaGlobals.FileSystem)) { ForceSave = !isNew && forceUpdate },
|
||||
default
|
||||
).GetAwaiter().GetResult();
|
||||
|
||||
|
||||
36
CinemaJellyfin/CinemaGlobals.cs
Normal file
36
CinemaJellyfin/CinemaGlobals.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.IO;
|
||||
|
||||
namespace CinemaJellyfin;
|
||||
|
||||
/// <summary>
|
||||
/// Global services that are resolved at startup and are
|
||||
/// otherwise inaccessible to some classes (mostly folders).
|
||||
/// </summary>
|
||||
static class CinemaGlobals
|
||||
{
|
||||
#pragma warning disable CS8618
|
||||
private static ILibraryManager _libraryManager;
|
||||
private static IServerConfigurationManager _config;
|
||||
private static IFileSystem _fileSystem;
|
||||
#pragma warning restore CS8618
|
||||
|
||||
internal static void Initialize(ILibraryManager libraryManager, IServerConfigurationManager config, IFileSystem fileSystem)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_config = config;
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
public static ILibraryManager LibraryManager => _libraryManager;
|
||||
|
||||
public static IFileSystem FileSystem => _fileSystem;
|
||||
|
||||
public static string InternalMetadataPath => _config.ApplicationPaths.InternalMetadataPath;
|
||||
|
||||
public static string PreferredCulture => _config.Configuration.PreferredMetadataLanguage;
|
||||
|
||||
public static string FallbackCulture => "en";
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq.Expressions;
|
||||
using CinemaJellyfin;
|
||||
using CinemaLib.Webshare;
|
||||
using Jellyfin.Plugin.Cinema.Configuration;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
@@ -19,9 +20,6 @@ sealed class CinemaHost : IHostedService
|
||||
#pragma warning disable CS8618
|
||||
// This instance is specially registered and gets created before all classes
|
||||
// except CinemaServiceRegistrator and CinemaPlugin.
|
||||
private static ILibraryManager _libraryManager;
|
||||
private static IServerConfigurationManager _config;
|
||||
private static IFileSystem _fileSystem;
|
||||
private static Session? _webshare;
|
||||
#pragma warning restore CS8618
|
||||
private readonly ILogger<CinemaHost> _logger;
|
||||
@@ -33,22 +31,10 @@ sealed class CinemaHost : IHostedService
|
||||
/// </summary>
|
||||
public CinemaHost(ILibraryManager libraryManager, IServerConfigurationManager config, IFileSystem fileSystem, ILogger<CinemaHost> logger)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_config = config;
|
||||
_fileSystem = fileSystem;
|
||||
CinemaGlobals.Initialize(libraryManager, config, fileSystem);
|
||||
this._logger = logger;
|
||||
}
|
||||
|
||||
public static ILibraryManager LibraryManager => _libraryManager;
|
||||
|
||||
public static string InternalMetadataPath => _config.ApplicationPaths.InternalMetadataPath;
|
||||
|
||||
public static IFileSystem FileSystem => _fileSystem;
|
||||
|
||||
public static string PreferredCulture => _config.Configuration.PreferredMetadataLanguage;
|
||||
|
||||
public static string FallbackCulture => "en";
|
||||
|
||||
public static Session? Webshare => _webshare;
|
||||
|
||||
public static async Task<bool> IsWebshareFreeAccount(CancellationToken cancel)
|
||||
|
||||
@@ -18,6 +18,9 @@ using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Jellyfin.Database.Implementations;
|
||||
using CinemaJellyfin;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
|
||||
namespace Jellyfin.Plugin.Cinema;
|
||||
|
||||
@@ -36,6 +39,9 @@ sealed class CinemaLibraryManager : ILibraryManager
|
||||
throw new InvalidOperationException("Original LibraryManager service not found.");
|
||||
this._inner = inner;
|
||||
this._userData = userData;
|
||||
|
||||
// We may run before CinemaHost if migrations are executed
|
||||
CinemaGlobals.Initialize(this, svc.GetRequiredService<IServerConfigurationManager>(), svc.GetRequiredService<IFileSystem>());
|
||||
}
|
||||
|
||||
#region ILibraryManager Members
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using CinemaJellyfin;
|
||||
using CinemaLib.API;
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
@@ -202,7 +203,7 @@ static class CinemaQueryExtensions
|
||||
{
|
||||
// HACK: We use RegisterItem that is volatile intead of CreateItem
|
||||
//_libraryManager.CreateItem(item, parentFolder);
|
||||
CinemaHost.LibraryManager.RegisterItem(item);
|
||||
CinemaGlobals.LibraryManager.RegisterItem(item);
|
||||
|
||||
if (media.cast != null && media.cast.Count > 0)
|
||||
{
|
||||
@@ -260,9 +261,9 @@ static class CinemaQueryExtensions
|
||||
InfoLabelI18n? preferred = null;
|
||||
InfoLabelI18n? fallback = null;
|
||||
foreach (InfoLabelI18n i in media.i18n_info_labels)
|
||||
if (i.lang == CinemaHost.PreferredCulture)
|
||||
if (i.lang == CinemaGlobals.PreferredCulture)
|
||||
preferred = i;
|
||||
else if (i.lang == CinemaHost.FallbackCulture)
|
||||
else if (i.lang == CinemaGlobals.FallbackCulture)
|
||||
fallback = i;
|
||||
else if (first == null)
|
||||
first = i;
|
||||
@@ -276,7 +277,7 @@ static class CinemaQueryExtensions
|
||||
internal static Guid GetMediaItemId(string csPrimaryId, string? csVersionId)
|
||||
{
|
||||
string idS = csVersionId == null ? csPrimaryId : (csPrimaryId + VersionSeparator + csVersionId);
|
||||
return CinemaHost.LibraryManager.GetNewItemId(idS, typeof(CinemaPlugin));
|
||||
return CinemaGlobals.LibraryManager.GetNewItemId(idS, typeof(CinemaPlugin));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -286,7 +287,7 @@ static class CinemaQueryExtensions
|
||||
where T : BaseItem, new()
|
||||
{
|
||||
Guid id = GetMediaItemId(csPrimaryId, csVersionId);
|
||||
T? item = CinemaHost.LibraryManager.GetItemById(id) as T;
|
||||
T? item = CinemaGlobals.LibraryManager.GetItemById(id) as T;
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user