dll integration

This commit is contained in:
2025-09-12 09:04:23 -04:00
parent dcbb25ca9e
commit 08cddf7799
57 changed files with 3293 additions and 1 deletions
@@ -0,0 +1,246 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Security;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Security;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
namespace Emby.Security;
public class PluginSecurityManager : IServerEntryPoint, IDisposable
{
private const string MBValidateUrl = "https://mb3admin.com/admin/service/registration/validate";
private readonly IHttpClient _httpClient;
private readonly IJsonSerializer _jsonSerializer;
private readonly IServerApplicationHost _appHost;
private readonly ILogger _logger;
private readonly IApplicationPaths _appPaths;
private readonly IFileSystem _fileSystem;
private readonly ICryptoProvider _cryptographyProvider;
private readonly ISecurityManager _securityManager;
private readonly IEncryptionManager _encryption;
public static PluginSecurityManager Current;
private readonly Dictionary<string, RegRecord> _regRecordCache = new Dictionary<string, RegRecord>();
private SemaphoreSlim _regLock = new SemaphoreSlim(1, 1);
public PluginSecurityManager(IServerApplicationHost appHost, IHttpClient httpClient, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, ILogManager logManager, IFileSystem fileSystem, ICryptoProvider cryptographyProvider, ISecurityManager securityManager, IEncryptionManager encryption)
{
if (httpClient == null)
{
throw new ArgumentNullException("httpClient");
}
_appHost = appHost;
_httpClient = httpClient;
_jsonSerializer = jsonSerializer;
_appPaths = appPaths;
_fileSystem = fileSystem;
_cryptographyProvider = cryptographyProvider;
_securityManager = securityManager;
_encryption = encryption;
_logger = logManager.GetLogger("Plugin");
Current = this;
}
public void Run()
{
}
public void Dispose()
{
}
private string GetCacheFilePath(string feature)
{
string text = GetType().FullName + GetCacheKey(feature);
text = BaseExtensions.GetMD5(text).ToString("N");
return Path.Combine(_appPaths.PluginConfigurationsPath, text);
}
private RegRecord GetCachedRegRecord(string feature)
{
lock (_regRecordCache)
{
if (_regRecordCache.TryGetValue(GetCacheKey(feature), out var value))
{
return value;
}
}
string cacheFilePath = GetCacheFilePath(feature);
try
{
string text = _encryption.DecryptString(_fileSystem.ReadAllText(cacheFilePath));
RegRecord value = _jsonSerializer.DeserializeFromString<RegRecord>(text);
if (value != null)
{
return value;
}
}
catch (Exception)
{
}
return null;
}
private string GetCacheKey(string feature)
{
string text = _securityManager.SupporterKey;
if (string.IsNullOrWhiteSpace(text))
{
text = "none";
}
return text + "-" + feature;
}
private void DeleteCachedRecord(string feature)
{
lock (_regRecordCache)
{
_regRecordCache.Remove(GetCacheKey(feature));
}
try
{
_fileSystem.DeleteFile(GetCacheFilePath(feature));
}
catch
{
}
}
private void SaveCachedRecord(string feature, RegRecord record)
{
lock (_regRecordCache)
{
_regRecordCache[GetCacheKey(feature)] = record;
}
string cacheFilePath = GetCacheFilePath(feature);
string text = _jsonSerializer.SerializeToString((object)record);
string text2 = _encryption.EncryptString(text);
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(cacheFilePath));
_fileSystem.WriteAllText(cacheFilePath, text2);
}
public async Task<RegRecord> GetRegistrationStatus(string feature, CancellationToken cancellationToken)
{
await _regLock.WaitAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
try
{
return await GetRegistrationStatusInternal(feature, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
}
finally
{
_regLock.Release();
}
}
private bool CheckRegistrationWithServer(DateTime lastChecked, bool registered)
{
if (registered || string.IsNullOrWhiteSpace(_securityManager.SupporterKey))
{
if (DateTime.UtcNow.AddDays(-1.0) > lastChecked)
{
return true;
}
}
else if (DateTime.UtcNow.AddHours(-1.0) > lastChecked)
{
return true;
}
return false;
}
private async Task<RegRecord> GetRegistrationStatusInternal(string feature, CancellationToken cancellationToken)
{
RegRecord regInfo = GetCachedRegRecord(feature);
DateTime lastChecked = regInfo?.lastChecked ?? DateTime.MinValue;
DateTime expDate = regInfo?.expDate ?? DateTime.MinValue;
bool registered = regInfo?.registered ?? false;
string supporterKey = _securityManager.SupporterKey;
if (CheckRegistrationWithServer(lastChecked, registered))
{
Dictionary<string, string> postData = new Dictionary<string, string>
{
{ "feature", feature },
{ "key", supporterKey },
{
"mac",
((IApplicationHost)_appHost).SystemId
},
{
"systemid",
((IApplicationHost)_appHost).SystemId
},
{
"platform",
((IApplicationHost)_appHost).OperatingSystemDisplayName
}
};
try
{
HttpRequestOptions val = new HttpRequestOptions
{
Url = "https://mb3admin.com/admin/service/registration/validate",
EnableHttpCompression = false,
BufferContent = false,
CancellationToken = cancellationToken
};
val.SetPostData((IDictionary<string, string>)postData);
HttpResponseInfo val2 = await _httpClient.SendAsync(val, "POST").ConfigureAwait(continueOnCapturedContext: false);
try
{
using Stream stream = val2.Content;
regInfo = _jsonSerializer.DeserializeFromStream<RegRecord>(stream);
regInfo.lastChecked = DateTime.UtcNow;
SaveCachedRecord(feature, regInfo);
}
finally
{
((IDisposable)val2)?.Dispose();
}
}
catch (Exception ex)
{
_logger.ErrorException("Error checking registration status of {0}", ex, new object[1] { feature });
int num = 14;
DateTime dateTime = new DateTime[2]
{
expDate,
lastChecked.AddDays(num)
}.Min();
if (dateTime > DateTime.UtcNow.AddDays(num))
{
dateTime = DateTime.MinValue;
}
regInfo = new RegRecord
{
registered = (regInfo != null && regInfo.registered && dateTime >= DateTime.UtcNow && expDate >= DateTime.UtcNow),
expDate = expDate
};
}
}
return regInfo;
}
}
@@ -0,0 +1,40 @@
using System;
namespace Emby.Security;
public class RegRecord
{
public string featId { get; set; }
public bool registered { get; set; }
public DateTime expDate { get; set; }
public string key { get; set; }
public DateTime lastChecked { get; set; }
public bool isTrial
{
get
{
if (expDate > DateTime.UtcNow)
{
return !registered;
}
return false;
}
}
public bool isValid
{
get
{
if (!isTrial)
{
return registered;
}
return true;
}
}
}
@@ -0,0 +1,258 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Emby.Security;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Security;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Notifications;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Plugins.TimeLord.ScheduledTasks;
public class TLTVScheduledTask : IScheduledTask
{
private readonly ILogger _logger;
private readonly ILibraryManager _libraryManager;
private readonly IMediaEncoder _mediaEncoder;
private readonly IFileSystem _fileSystem;
private readonly IApplicationPaths _appPaths;
private readonly ILibraryMonitor _libraryMonitor;
private readonly IUserManager _userManager;
private readonly INotificationManager _notificationManager;
private readonly IItemRepository _itemRepo;
public string Category => "Time Lord";
public string Key => "TimeLordTV";
public string Description => "Sets the Episode Date Added to the original airdate (Episodes)";
public string Name => "Change episode date added to original airdate";
public TLTVScheduledTask(ILibraryManager libraryManager, ILogger logger, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IApplicationPaths appPaths, ILibraryMonitor libraryMonitor, ISecurityManager securityManager, IUserManager userManager, INotificationManager notificationManager, IItemRepository itemRepo)
{
_libraryManager = libraryManager;
_logger = logger;
_userManager = userManager;
_mediaEncoder = mediaEncoder;
_fileSystem = fileSystem;
_appPaths = appPaths;
_libraryMonitor = libraryMonitor;
_notificationManager = notificationManager;
_itemRepo = itemRepo;
}
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{
RegRecord registration = await PluginSecurityManager.Current.GetRegistrationStatus("TimeLord", cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
Plugin.Instance.Registration = registration;
_logger.Info("TimeLordTV Registration Status - Registered: {0} In trial: {2} Expiration Date: {1} Is Valid: {3}", new object[4]
{
Plugin.Instance.Registration.registered,
Plugin.Instance.Registration.expDate,
Plugin.Instance.Registration.isTrial,
Plugin.Instance.Registration.isValid
});
if (Plugin.Instance.Registration.isTrial)
{
_logger.Info(((BasePlugin)Plugin.Instance).Name + " You are Using the Trial Version, Please Consider purchasing to continue using the plugin after the trial period", new object[0]);
}
if (!Plugin.Instance.Registration.isValid)
{
_logger.Info(((BasePlugin)Plugin.Instance).Name + " Trial Expired, Please register to continue using the plugin", new object[0]);
return;
}
_logger.Info("TimeLordTV :: Start :", (object[])null);
try
{
_logger.Info("TimeLord :: Rework Series Dates :: Start", (object[])null);
AggregateFolder rootFolder = _libraryManager.RootFolder;
InternalItemsQuery val = new InternalItemsQuery();
val.IncludeItemTypes = new string[1] { typeof(Series).Name };
val.Recursive = true;
BaseItem[] itemList = ((Folder)rootFolder).GetItemList(val);
int num = 0;
BaseItem[] array = itemList;
foreach (BaseItem val2 in array)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
if (val2.PremiereDate.HasValue && val2.DateCreated != val2.PremiereDate.Value && val2.PremiereDate.HasValue)
{
val2.DateCreated = val2.PremiereDate.Value;
try
{
val2.UpdateToRepository((ItemUpdateType)16);
}
catch
{
}
}
}
catch (OperationCanceledException)
{
break;
}
catch (Exception ex2)
{
_logger.ErrorException("TimeLordTV :: Error messing about with {0}", ex2, new object[1] { val2.Name });
}
num++;
double num2 = num;
num2 *= 100.0;
progress.Report(num2);
}
}
catch (Exception ex3)
{
_logger.ErrorException("TimeLord :: Error {0}", ex3, Array.Empty<object>());
}
try
{
_logger.Info("TimeLord :: Rework Season Dates :: Start", (object[])null);
AggregateFolder rootFolder2 = _libraryManager.RootFolder;
InternalItemsQuery val = new InternalItemsQuery();
val.IncludeItemTypes = new string[1] { typeof(Season).Name };
val.Recursive = true;
BaseItem[] itemList2 = ((Folder)rootFolder2).GetItemList(val);
_logger.Info("TimeLord :: Rework Season Dates :: Count ::" + itemList2.Count(), (object[])null);
int num3 = 0;
BaseItem[] array = itemList2;
for (int i = 0; i < array.Length; i++)
{
Season val3 = (Season)array[i];
try
{
cancellationToken.ThrowIfCancellationRequested();
if (((BaseItem)val3).PremiereDate.HasValue && ((BaseItem)val3).DateCreated != ((BaseItem)val3).PremiereDate.Value && ((BaseItem)val3).PremiereDate.HasValue)
{
((BaseItem)val3).DateCreated = ((BaseItem)val3).PremiereDate.Value;
try
{
((BaseItem)val3).UpdateToRepository((ItemUpdateType)16);
_logger.Info("TimeLordTV :: Updated :: " + ((BaseItem)val3).Name, (object[])null);
}
catch
{
}
}
}
catch (OperationCanceledException)
{
_logger.Info("TimeLordTV :: Canceled", (object[])null);
break;
}
catch (Exception ex5)
{
_logger.ErrorException("TimeLordTV :: Error messing about with {0}", ex5, new object[1] { ((BaseItem)val3).Name });
}
num3++;
double num4 = num3;
num4 /= (double)itemList2.Count();
num4 *= 100.0;
progress.Report(num4);
}
}
catch (Exception ex6)
{
_logger.ErrorException("TimeLord :: Error {0}", ex6, Array.Empty<object>());
}
try
{
_logger.Info("TimeLord :: Rework Episode Dates :: Start", (object[])null);
AggregateFolder rootFolder3 = _libraryManager.RootFolder;
InternalItemsQuery val = new InternalItemsQuery();
val.IncludeItemTypes = new string[1] { typeof(Episode).Name };
val.Recursive = true;
List<BaseItem> list = ((Folder)rootFolder3).GetItemList(val).Where(delegate(BaseItem val5)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if ((int)val5.LocationType == 0)
{
DateTimeOffset dateCreated = val5.DateCreated;
DateTimeOffset? premiereDate = val5.PremiereDate;
if (premiereDate.HasValue && dateCreated > premiereDate.GetValueOrDefault() && val5.PremiereDate.HasValue)
{
return !val5.IsLocked;
}
}
return false;
}).ToList();
_logger.Info("TimeLord :: Rework Episode Dates :: Count ::" + list.Count, (object[])null);
int num5 = 0;
foreach (Episode item in list)
{
Episode val4 = item;
try
{
cancellationToken.ThrowIfCancellationRequested();
if (((BaseItem)val4).PremiereDate.HasValue && ((BaseItem)val4).DateCreated != ((BaseItem)val4).PremiereDate.Value && ((BaseItem)val4).PremiereDate.HasValue)
{
((BaseItem)val4).DateCreated = ((BaseItem)val4).PremiereDate.Value;
try
{
((BaseItem)val4).UpdateToRepository((ItemUpdateType)16);
_logger.Info("TimeLordTV :: Updated :: " + ((BaseItem)val4).Name, (object[])null);
}
catch
{
}
}
}
catch (OperationCanceledException)
{
_logger.Info("TimeLordTV :: Canceled", (object[])null);
break;
}
catch (Exception ex8)
{
_logger.ErrorException("TimeLordTV :: Error messing about with {0}", ex8, new object[1] { ((BaseItem)val4).Name });
}
num5++;
double num6 = num5;
num6 /= (double)list.Count;
num6 *= 100.0;
progress.Report(num6);
}
}
catch (Exception ex9)
{
_logger.ErrorException("TimeLord :: Error {0}", ex9, Array.Empty<object>());
}
}
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
return (IEnumerable<TaskTriggerInfo>)(object)new TaskTriggerInfo[1]
{
new TaskTriggerInfo
{
Type = "DailyTrigger",
TimeOfDayTicks = TimeSpan.FromHours(5.0).Ticks
}
};
}
}
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>MediaBrowser.Plugins.TimeLord</AssemblyName>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<LangVersion>12.0</LangVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<None Remove="MediaBrowser.Plugins.TimeLord.thumb.png" />
<EmbeddedResource Include="MediaBrowser.Plugins.TimeLord.thumb.png" LogicalName="MediaBrowser.Plugins.TimeLord.thumb.png" />
</ItemGroup>
<ItemGroup>
<Reference Include="MediaBrowser.Controller" />
<Reference Include="MediaBrowser.Common" />
<Reference Include="MediaBrowser.Model" />
</ItemGroup>
</Project>
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

@@ -0,0 +1,35 @@
using System;
using System.IO;
using Emby.Security;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Drawing;
namespace MediaBrowser.Plugins.TimeLord;
public class Plugin : BasePlugin, IHasThumbImage
{
private Guid _id = new Guid("3A7EF733-F70B-4947-9E03-2813B5A423E3");
public RegRecord Registration;
public override string Name => "TimeLordTV";
public override string Description => "Set Episode Added date to the original airdate for the Epsiode.";
public override Guid Id => _id;
public ImageFormat ThumbImageFormat => (ImageFormat)3;
public static Plugin Instance { get; private set; }
public Stream GetThumbImage()
{
Type type = ((object)this).GetType();
return type.Assembly.GetManifestResourceStream(type.Namespace + ".thumb.png");
}
public Plugin()
{
Instance = this;
}
}
@@ -0,0 +1,17 @@
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
[assembly: ComVisible(false)]
[assembly: Guid("3A7EF733-F70B-4947-9E03-2813B5A423E3")]
[assembly: AssemblyCompany("ScoobydooProject.com")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2019 ScoobydooProject.com")]
[assembly: AssemblyDescription("Wayback Machine for TV Episodes")]
[assembly: AssemblyFileVersion("19.08.03.1105")]
[assembly: AssemblyInformationalVersion("3.2.32.14")]
[assembly: AssemblyProduct("MediaBrowser.Plugins.TimeLord")]
[assembly: AssemblyTitle("MediaBrowser.Plugins.TimeLord")]
[assembly: AssemblyVersion("19.8.3.1105")]