Files
stream-cinema/StreamCinemaJellyfin/Startup.cs
Roman Vaníček a52a756518
Some checks failed
continuous-integration/drone/push Build is failing
StreamCinemaJellyfin initial commit
2024-11-25 03:21:17 +01:00

112 lines
4.0 KiB
C#

using System;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.StreamCinema;
/// <summary>
/// Triggers start-up initialization for the entire Stream Cinema plugin.
/// </summary>
public sealed class Startup : IChannel
{
public Startup(ILibraryManager libraryManager, IServerConfigurationManager config, IFileSystem fileSystem, ILogger<Startup> logger)
{
// Make sure the Stream Cinema root folders are created
CreateRoot<StreamCinemaMoviesFolder>("movies", "Movies", libraryManager, config, fileSystem);
/*
pluginItems.Add(CreateMenuItem("movies", Resources.Movies, GetResourceUrl("movies.png")));
pluginItems.Add(CreateMenuItem("shows", Resources.Shows, GetResourceUrl("tvshows.png")));
pluginItems.Add(CreateMenuItem("tv", Resources.TvProgram, GetResourceUrl("tv-program.png")));
pluginItems.Add(CreateMenuItem("anime", Resources.Anime, GetResourceUrl("anime.png")));
pluginItems.Add(CreateMenuItem("concerts", Resources.Concerts, GetResourceUrl("music.png")));*/
}
private static void CreateRoot<T>(string idPrefix, string localizedName, ILibraryManager libraryManager, IServerConfigurationManager config, IFileSystem fileSystem) where T : StreamCinemaRootFolder, new()
{
string internalMetadataPath = config.ApplicationPaths.InternalMetadataPath;
Guid rootFolderId = libraryManager.GetNewItemId(StreamCinemaRootFolder.GetIdToHash("", idPrefix), typeof(StreamCinemaRootFolder));
string rootFolderPath = StreamCinemaRootFolder.GetInternalMetadataPath(internalMetadataPath, rootFolderId);
Directory.CreateDirectory(rootFolderPath);
StreamCinemaRootFolder? rootFolder = libraryManager.GetItemById(rootFolderId) as StreamCinemaRootFolder;
bool isNew;
bool forceUpdate = false;
if (isNew = rootFolder == null)
{
rootFolder = new T
{
Name = localizedName,
Id = rootFolderId,
DateCreated = fileSystem.GetCreationTimeUtc(rootFolderPath),
DateModified = fileSystem.GetLastWriteTimeUtc(rootFolderPath)
};
rootFolder.Initialize(libraryManager, idPrefix, internalMetadataPath);
}
rootFolder.Path = rootFolderPath;
rootFolder.ParentId = Guid.Empty;
if (isNew)
{
rootFolder.OnMetadataChanged();
libraryManager.CreateItem(rootFolder, null);
}
// We do not bother waiting for the task to finish
rootFolder.RefreshMetadata(
new MetadataRefreshOptions(new DirectoryService(fileSystem))
{
ForceSave = !isNew && forceUpdate
},
default).ConfigureAwait(false);
}
public string Name => "Stream Cinema startup";
public string Description => "";
public string DataVersion => "1";
public string HomePageUrl => "";
public ChannelParentalRating ParentalRating => ChannelParentalRating.GeneralAudience;
public InternalChannelFeatures GetChannelFeatures()
{
return new InternalChannelFeatures
{
// Anything that does not crash Jellyfin
ContentTypes = [ChannelMediaContentType.Movie],
MediaTypes = [ChannelMediaType.Video]
};
}
public Task<DynamicImageResponse> GetChannelImage(ImageType type, CancellationToken cancellationToken)
{
return Task.FromResult(new DynamicImageResponse { HasImage = false });
}
public Task<ChannelItemResult> GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken)
{
return Task.FromResult(new ChannelItemResult() { Items = new List<ChannelItemInfo>() });
}
public IEnumerable<ImageType> GetSupportedChannelImages()
{
return new List<ImageType> { ImageType.Primary };
}
public bool IsEnabledFor(string userId)
{
// Always hide us from user's view as there is no content here
return false;
}
}