139 lines
5.5 KiB
C#
139 lines
5.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using MediaBrowser.Common.Plugins;
|
|
using MediaBrowser.Model.Drawing;
|
|
using MediaBrowser.Common.Configuration;
|
|
using MediaBrowser.Model.Plugins;
|
|
using MediaBrowser.Model.Serialization;
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
namespace NFOGuard.Emby.Plugin
|
|
{
|
|
public class Plugin : BasePlugin<PluginConfiguration>
|
|
{
|
|
private Guid _id = new Guid("B2C3D4E5-6789-ABCD-EF01-23456789ABCE"); // Completely new GUID to clear cache
|
|
|
|
public override string Name => "DateSync";
|
|
|
|
public override string Description => "Synchronizes TV episode PremiereDate to DateCreated to preserve import dates in Emby";
|
|
|
|
public override Guid Id => _id;
|
|
|
|
public override string ConfigurationFileName => "datesync.xml";
|
|
|
|
public static Plugin Instance { get; private set; }
|
|
|
|
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
|
|
: base(applicationPaths, xmlSerializer)
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registers machine and checks for automatic subscription activation
|
|
/// </summary>
|
|
public async Task<string> RegisterAndCheckSubscriptionAsync(string userEmail, ILogger logger)
|
|
{
|
|
try
|
|
{
|
|
var licenseManager = new LicenseManager(logger);
|
|
|
|
// Register machine first
|
|
var registrationResult = await licenseManager.RegisterMachineAsync(userEmail);
|
|
|
|
// Then check for existing subscription
|
|
await licenseManager.CheckAndActivateLicenseAsync();
|
|
|
|
return registrationResult;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return $"Registration error: {ex.Message}";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets current license status and usage information
|
|
/// </summary>
|
|
public string GetLicenseStatus(ILogger logger)
|
|
{
|
|
try
|
|
{
|
|
var freeTierManager = new FreeTierManager(logger);
|
|
var licenseManager = new LicenseManager(logger);
|
|
var machineId = licenseManager.GetMachineIdentifier();
|
|
|
|
if (Configuration.LicenseValid)
|
|
{
|
|
return $"✅ Subscription Active\nMachine ID: {machineId}\nStatus: Unlimited processing enabled\n\nSubscription automatically detected via Patreon/PayPal.";
|
|
}
|
|
else
|
|
{
|
|
var usageInfo = freeTierManager.GetUsageInfo();
|
|
var trialInfo = licenseManager.IsTrialExpired() ? "Trial expired" : $"Trial active ({Math.Max(0, (Configuration.InstallDate.AddDays(30) - DateTime.UtcNow).Days)} days remaining)";
|
|
return $"🆓 Free Tier Active\nMachine ID: {machineId}\nUsage: {usageInfo}\nTrial: {trialInfo}\n\nTo unlock unlimited processing:\n• Subscribe: https://patreon.com/nfoguard\n• PayPal: https://nfoguard.com/paypal\n\nActivation is automatic within 24 hours.";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return $"Error getting license status: {ex.Message}";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Manually checks for subscription updates
|
|
/// </summary>
|
|
public async Task<string> RefreshSubscriptionStatusAsync(ILogger logger)
|
|
{
|
|
try
|
|
{
|
|
var licenseManager = new LicenseManager(logger);
|
|
var wasLicensed = Configuration.LicenseValid;
|
|
|
|
await licenseManager.CheckAndActivateLicenseAsync();
|
|
|
|
if (!wasLicensed && Configuration.LicenseValid)
|
|
{
|
|
return "✅ Subscription found and activated! Unlimited processing enabled.";
|
|
}
|
|
else if (wasLicensed && !Configuration.LicenseValid)
|
|
{
|
|
return "⚠️ Subscription expired or cancelled. Switched to free tier.";
|
|
}
|
|
else if (Configuration.LicenseValid)
|
|
{
|
|
return "✅ Subscription is still active.";
|
|
}
|
|
else
|
|
{
|
|
return "🆓 No active subscription found. Still using free tier.";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return $"Error checking subscription: {ex.Message}";
|
|
}
|
|
}
|
|
}
|
|
|
|
public class PluginConfiguration : BasePluginConfiguration
|
|
{
|
|
public bool EnableRealTimeSync { get; set; } = true;
|
|
public bool EnableScheduledTask { get; set; } = true;
|
|
public bool LogVerbose { get; set; } = true; // Enabled by default for diagnostic version
|
|
public bool LicenseValid { get; set; } = false;
|
|
public string RegisteredEmail { get; set; } = string.Empty;
|
|
public DateTime InstallDate { get; set; } = DateTime.MinValue;
|
|
public DateTime LastLicenseCheck { get; set; } = DateTime.MinValue;
|
|
|
|
// Free tier tracking
|
|
public DateTime LastProcessingReset { get; set; } = DateTime.MinValue;
|
|
public int ProcessedThisMonth { get; set; } = 0;
|
|
public int MonthlyProcessingLimit { get; set; } = 0; // 0 = no limit (full version)
|
|
|
|
// Machine registration
|
|
public bool MachineRegistered { get; set; } = false;
|
|
public string MachineId { get; set; } = string.Empty;
|
|
}
|
|
} |