using System; using System.Collections.Generic; using System.Data; using System.Linq; using Jellyfin.Plugin.TubeArchivistMetadata.Utilities; using MediaBrowser.Model.Plugins; using Microsoft.Extensions.Logging; namespace Jellyfin.Plugin.TubeArchivistMetadata.Configuration { /// /// Plugin configuration. /// public class PluginConfiguration : BasePluginConfiguration { private ILogger _logger; private string _tubeArchivistUrl; private string _tubeArchivistApiKey; private HashSet _jfUsernamesTo; /// /// Initializes a new instance of the class. /// public PluginConfiguration() { if (Plugin.Instance == null) { throw new DataException("Uninitialized plugin!"); } else { _logger = Plugin.Instance.Logger; } CollectionTitle = string.Empty; _tubeArchivistUrl = string.Empty; _tubeArchivistApiKey = string.Empty; MaxDescriptionLength = 500; JFTAProgressSync = false; JFUsernameFrom = string.Empty; TAJFProgressSync = false; JFTAPlaylistsSync = false; JFTAPlaylistsDelete = false; TAJFPlaylistsSync = false; TAJFPlaylistsDelete = false; _jfUsernamesTo = new HashSet(); TAJFProgressTaskInterval = 60; JFTAPlaylistsSyncTaskInterval = 60; TAJFPlaylistsSyncTaskInterval = 60; } /// /// Gets or sets TubeArchivist collection display name. /// public string CollectionTitle { get; set; } /// /// Gets or sets TubeArchivist URL. /// public string TubeArchivistUrl { get { return _tubeArchivistUrl; } set { if (value.StartsWith("http://", StringComparison.CurrentCulture) || value.StartsWith("https://", StringComparison.CurrentCulture)) { _tubeArchivistUrl = Utils.SanitizeUrl(value); } else { _logger.LogInformation("{Message}", "Given TubeArchivist URL contains no schema. Adding http://..."); _tubeArchivistUrl = Utils.SanitizeUrl("http://" + value); } Plugin.Instance?.LogTAApiConnectionStatus(); } } /// /// Gets or sets TubeArchivist API key. /// public string TubeArchivistApiKey { get { return _tubeArchivistApiKey; } set { _tubeArchivistApiKey = value; Plugin.Instance?.LogTAApiConnectionStatus(); Plugin.Instance?.UpdateAuthorizationHeader(value); } } /// /// Gets or sets maximum series and episodes overviews length. /// public int MaxDescriptionLength { get; set; } /// /// Gets or sets a value indicating whether to enable TA->JF playback progress synchronization. /// public bool TAJFProgressSync { get; set; } /// /// Gets or sets a value indicating whether to enable JF->TA playback progress synchronization. /// public bool JFTAProgressSync { get; set; } /// /// Gets or sets a value indicating whether to enable JF->TA playlists synchronization. /// public bool JFTAPlaylistsSync { get; set; } /// /// Gets or sets a value indicating whether to delete playlists from TA when not found on JF. /// public bool JFTAPlaylistsDelete { get; set; } /// /// Gets or sets a value indicating whether to enable TA->JF playlists synchronization. /// public bool TAJFPlaylistsSync { get; set; } /// /// Gets or sets a value indicating whether to delete playlists from JF when not found on TA. /// public bool TAJFPlaylistsDelete { get; set; } /// /// Gets or sets the playback progress owner Jellyfin username to synchronize data to TubeArchivist. /// public string JFUsernameFrom { get; set; } /// /// Gets or sets the playback progress owners Jellyfin usernames to synchronize data from TubeArchivist. /// public string JFUsernamesTo { get { _logger.LogInformation("JFUsernamesTo configured: {Message}", string.Join(", ", _jfUsernamesTo)); return string.Join(", ", _jfUsernamesTo); } set { // Clear existing usernames _jfUsernamesTo.Clear(); // Split by comma, then trim each part to remove leading/trailing spaces foreach (var username in value.Split(',')) { var trimmedUsername = username.Trim(); if (!string.IsNullOrEmpty(trimmedUsername)) { _jfUsernamesTo.Add(trimmedUsername); } } _logger.LogInformation("Set JFUsernamesTo to: {Message}", string.Join(", ", _jfUsernamesTo)); } } /// /// Gets or sets the interval in seconds at which the TubeArchivist to Jellyfin playback progress synchronization task should run. /// It requires Jellyfin server restart to take effect. /// public int TAJFProgressTaskInterval { get; set; } /// /// Gets or sets the interval in seconds at which the Jellyfin to TubeArchivist playlists synchronization task should run. /// It requires Jellyfin server restart to take effect. /// public int JFTAPlaylistsSyncTaskInterval { get; set; } /// /// Gets or sets the interval in seconds at which the TubeArchivist to Jellyfin playlists synchronization task should run. /// It requires Jellyfin server restart to take effect. /// public int TAJFPlaylistsSyncTaskInterval { get; set; } /// /// Gets or sets the preferred numbering scheme for episodes (index number) in Jellyfin. /// public NumberingScheme EpisodeNumberingScheme { get; set; } = NumberingScheme.Default; /// /// Gets the playback progress owners Jellyfin usernames to synchronize data from TubeArchivist. /// /// An array of usernames. public HashSet GetJFUsernamesToArray() { return _jfUsernamesTo; } } }