160 lines
5.4 KiB
C#
160 lines
5.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.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.TimeLordMovies.ScheduledTasks;
|
|
|
|
public class TLTrailersScheduledTask : 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 => "TimeLordMovies";
|
|
|
|
public string Description => "Sets the Trailer Date Added to the original premier date (Trailer)";
|
|
|
|
public string Name => "Change Trailer date added to original Premier date";
|
|
|
|
public TLTrailersScheduledTask(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("TimeLordMovies", cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
|
|
Plugin.Instance.Registration = registration;
|
|
_logger.Info("TimeLordMovies 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("TimeLordMovies :: Start :", (object[])null);
|
|
try
|
|
{
|
|
_logger.Info("TimeLord :: Rework Trailer Dates :: Start", (object[])null);
|
|
AggregateFolder rootFolder = _libraryManager.RootFolder;
|
|
InternalItemsQuery val = new InternalItemsQuery();
|
|
val.IncludeItemTypes = new string[1] { typeof(Trailer).Name };
|
|
val.Recursive = true;
|
|
List<BaseItem> list = ((Folder)rootFolder).GetItemList(val).Where(delegate(BaseItem i)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
if ((int)i.LocationType != 0)
|
|
{
|
|
DateTimeOffset dateCreated = i.DateCreated;
|
|
DateTimeOffset? premiereDate = i.PremiereDate;
|
|
if (premiereDate.HasValue && dateCreated > premiereDate.GetValueOrDefault() && i.PremiereDate.HasValue)
|
|
{
|
|
return !i.IsLocked;
|
|
}
|
|
}
|
|
return false;
|
|
}).ToList();
|
|
int num = 0;
|
|
foreach (Trailer item in list)
|
|
{
|
|
Trailer val2 = item;
|
|
try
|
|
{
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
((BaseItem)val2).DateCreated = ((BaseItem)val2).PremiereDate.Value;
|
|
try
|
|
{
|
|
((BaseItem)val2).UpdateToRepository((ItemUpdateType)16);
|
|
_logger.Info("TimeLord.Trailers :: Updated :: " + ((BaseItem)val2).Name, (object[])null);
|
|
}
|
|
catch
|
|
{
|
|
_logger.Info("TimeLord.Trailers :: Updated :: " + ((BaseItem)val2).Name, (object[])null);
|
|
}
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
_logger.Info("TimeLord.Trailers :: Canceled", (object[])null);
|
|
break;
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
_logger.ErrorException("TimeLord.Trailers :: Error messing about with {0}", ex2, new object[1] { ((BaseItem)val2).Name });
|
|
}
|
|
num++;
|
|
double num2 = num;
|
|
num2 /= (double)list.Count();
|
|
num2 *= 100.0;
|
|
progress.Report(num2);
|
|
}
|
|
}
|
|
catch (Exception ex3)
|
|
{
|
|
_logger.ErrorException("TimeLord.Trailers :: Error {0}", ex3, 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
|
|
}
|
|
};
|
|
}
|
|
}
|