using System; using System.Collections.Generic; using System.Globalization; using Jellyfin.Plugin.MetaShark.Configuration; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Plugins; using MediaBrowser.Controller; using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Serialization; using Microsoft.AspNetCore.Http; namespace Jellyfin.Plugin.MetaShark; /// /// The main plugin. /// public class Plugin : BasePlugin, IHasWebPages { /// /// Gets the provider name. /// public const string PluginName = "MetaShark"; /// /// Gets the provider id. /// public const string ProviderId = "MetaSharkID"; private readonly IServerApplicationHost _appHost; /// /// Initializes a new instance of the class. /// /// Instance of the interface. /// Instance of the interface. public Plugin(IServerApplicationHost appHost, IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) : base(applicationPaths, xmlSerializer) { this._appHost = appHost; Plugin.Instance = this; } /// public override string Name => PluginName; /// public override Guid Id => Guid.Parse("9A19103F-16F7-4668-BE54-9A1E7A4F7556"); /// /// Gets the current plugin instance. /// public static Plugin? Instance { get; private set; } /// public IEnumerable GetPages() { return new[] { new PluginPageInfo { Name = this.Name, EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Configuration.configPage.html", GetType().Namespace), }, }; } public string GetLocalApiBaseUrl(string hostname = "127.0.0.1") { return this._appHost.GetSmartApiUrl(hostname); } public string GetApiBaseUrl(HttpRequest request) { int? requestPort = request.Host.Port; if (requestPort == null || (requestPort == 80 && string.Equals(request.Scheme, "http", StringComparison.OrdinalIgnoreCase)) || (requestPort == 443 && string.Equals(request.Scheme, "https", StringComparison.OrdinalIgnoreCase))) { requestPort = -1; } return this._appHost.GetLocalApiUrl(request.Host.Host, request.Scheme, requestPort); } }