mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-22 10:04:44 +01:00
updated nuget
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using MediaBrowser.Common.ScheduledTasks;
|
||||
using MediaBrowser.Controller.LiveTv;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
{
|
||||
class CleanDatabaseScheduledTask : IScheduledTask, IConfigurableScheduledTask
|
||||
{
|
||||
private readonly ILiveTvManager _liveTvManager;
|
||||
|
||||
public CleanDatabaseScheduledTask(ILiveTvManager liveTvManager)
|
||||
{
|
||||
_liveTvManager = liveTvManager;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Clean TV Database"; }
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get { return "Deletes old programs from the tv database."; }
|
||||
}
|
||||
|
||||
public string Category
|
||||
{
|
||||
get { return "Live TV"; }
|
||||
}
|
||||
|
||||
public Task Execute(System.Threading.CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
var manager = (LiveTvManager)_liveTvManager;
|
||||
|
||||
return manager.CleanDatabase(progress, cancellationToken);
|
||||
}
|
||||
|
||||
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
|
||||
{
|
||||
return new ITaskTrigger[]
|
||||
{
|
||||
new IntervalTrigger{ Interval = TimeSpan.FromHours(24)}
|
||||
};
|
||||
}
|
||||
|
||||
public bool IsHidden
|
||||
{
|
||||
get { return _liveTvManager.ActiveService == null; }
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IUserDataManager _userDataManager;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IMediaEncoder _mediaEncoder;
|
||||
private readonly ITaskManager _taskManager;
|
||||
|
||||
private readonly LiveTvDtoService _tvDtoService;
|
||||
@@ -50,7 +49,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
private List<Guid> _channelIdList = new List<Guid>();
|
||||
private Dictionary<Guid, LiveTvProgram> _programs = new Dictionary<Guid, LiveTvProgram>();
|
||||
|
||||
public LiveTvManager(IServerConfigurationManager config, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, IMediaEncoder mediaEncoder, ITaskManager taskManager)
|
||||
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
public LiveTvManager(IServerConfigurationManager config, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, ITaskManager taskManager)
|
||||
{
|
||||
_config = config;
|
||||
_fileSystem = fileSystem;
|
||||
@@ -58,7 +59,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
_itemRepo = itemRepo;
|
||||
_userManager = userManager;
|
||||
_libraryManager = libraryManager;
|
||||
_mediaEncoder = mediaEncoder;
|
||||
_taskManager = taskManager;
|
||||
_userDataManager = userDataManager;
|
||||
|
||||
@@ -706,6 +706,20 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
}
|
||||
|
||||
internal async Task RefreshChannels(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
await _refreshSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
await RefreshChannelsInternal(progress, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_refreshSemaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RefreshChannelsInternal(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
// Avoid implicitly captured closure
|
||||
var service = ActiveService;
|
||||
@@ -795,21 +809,39 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
double percent = numComplete;
|
||||
percent /= allChannelsList.Count;
|
||||
|
||||
progress.Report(70 * percent + 10);
|
||||
progress.Report(80 * percent + 10);
|
||||
}
|
||||
|
||||
_programs = programs.ToDictionary(i => i.Id);
|
||||
progress.Report(80);
|
||||
progress.Report(90);
|
||||
|
||||
// Load these now which will prefetch metadata
|
||||
await GetRecordings(new RecordingQuery(), cancellationToken).ConfigureAwait(false);
|
||||
progress.Report(85);
|
||||
|
||||
await DeleteOldPrograms(_programs.Keys.ToList(), progress, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
public async Task CleanDatabase(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var service = ActiveService;
|
||||
|
||||
if (service == null)
|
||||
{
|
||||
progress.Report(100);
|
||||
return;
|
||||
}
|
||||
|
||||
await _refreshSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
await DeleteOldPrograms(_programs.Keys.ToList(), progress, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_refreshSemaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteOldPrograms(List<Guid> currentIdList, IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var list = _itemRepo.GetItemsOfType(typeof(LiveTvProgram)).ToList();
|
||||
@@ -829,7 +861,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
double percent = numComplete;
|
||||
percent /= list.Count;
|
||||
|
||||
progress.Report(15 * percent + 85);
|
||||
progress.Report(100 * percent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -178,6 +178,7 @@
|
||||
<Compile Include="Library\Validators\StudiosValidator.cs" />
|
||||
<Compile Include="Library\Validators\YearsPostScanTask.cs" />
|
||||
<Compile Include="LiveTv\ChannelImageProvider.cs" />
|
||||
<Compile Include="LiveTv\CleanDatabaseScheduledTask.cs" />
|
||||
<Compile Include="LiveTv\LiveTvDtoService.cs" />
|
||||
<Compile Include="LiveTv\LiveTvManager.cs" />
|
||||
<Compile Include="LiveTv\ProgramImageProvider.cs" />
|
||||
|
||||
Reference in New Issue
Block a user