Files
nfoguard/decompiled-TimeLord/MediaBrowser.Plugins.TimeLord.ScheduledTasks/TLTVScheduledTask.cs
T
2025-09-12 09:04:23 -04:00

259 lines
8.4 KiB
C#

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
}
};
}
}