Luke Pulverenti 11 роки тому
батько
коміт
f0f897e97e

+ 1 - 1
MediaBrowser.Dlna/PlayTo/SsdpHttpClient.cs

@@ -98,7 +98,7 @@ namespace MediaBrowser.Dlna.PlayTo
             }
         }
 
-        public Task<HttpResponseInfo> PostSoapDataAsync(Uri url, string soapAction, string postData, string header = null, int timeOut = 20000)
+        private Task<HttpResponseInfo> PostSoapDataAsync(Uri url, string soapAction, string postData, string header = null, int timeOut = 20000)
         {
             if (!soapAction.StartsWith("\""))
                 soapAction = "\"" + soapAction + "\"";

+ 1 - 2
MediaBrowser.Providers/All/LocalImageProvider.cs

@@ -2,7 +2,6 @@
 using MediaBrowser.Controller.Entities.Audio;
 using MediaBrowser.Controller.Entities.Movies;
 using MediaBrowser.Controller.Entities.TV;
-using MediaBrowser.Controller.LiveTv;
 using MediaBrowser.Controller.Providers;
 using MediaBrowser.Model.Entities;
 using System;
@@ -188,7 +187,7 @@ namespace MediaBrowser.Providers.All
         {
             PopulateBackdrops(images, files, imagePrefix, "backdrop", "backdrop", ImageType.Backdrop);
 
-            if (string.IsNullOrEmpty(item.Path))
+            if (!string.IsNullOrEmpty(item.Path))
             {
                 var name = Path.GetFileNameWithoutExtension(item.Path);
 

+ 58 - 0
MediaBrowser.Server.Implementations/LiveTv/CleanDatabaseScheduledTask.cs

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

+ 41 - 9
MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs

@@ -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,19 +809,37 @@ 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);
+            progress.Report(100);
+        }
+
+        public async Task CleanDatabase(IProgress<double> progress, CancellationToken cancellationToken)
+        {
+            var service = ActiveService;
 
-            await DeleteOldPrograms(_programs.Keys.ToList(), progress, cancellationToken).ConfigureAwait(false);
+            if (service == null)
+            {
+                progress.Report(100);
+                return;
+            }
+            
+            await _refreshSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
 
-            progress.Report(100);
+            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)
@@ -829,7 +861,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
                 double percent = numComplete;
                 percent /= list.Count;
 
-                progress.Report(15 * percent + 85);
+                progress.Report(100 * percent);
             }
         }
 

+ 1 - 0
MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj

@@ -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" />

+ 1 - 1
MediaBrowser.ServerApplication/ApplicationHost.cs

@@ -438,7 +438,7 @@ namespace MediaBrowser.ServerApplication
                 MediaEncoder);
             RegisterSingleInstance(EncodingManager);
 
-            LiveTvManager = new LiveTvManager(ServerConfigurationManager, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, MediaEncoder, TaskManager);
+            LiveTvManager = new LiveTvManager(ServerConfigurationManager, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager);
             RegisterSingleInstance(LiveTvManager);
 
             var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));

+ 2 - 2
Nuget/MediaBrowser.Common.Internal.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
     <metadata>
         <id>MediaBrowser.Common.Internal</id>
-        <version>3.0.332</version>
+        <version>3.0.333</version>
         <title>MediaBrowser.Common.Internal</title>
         <authors>Luke</authors>
         <owners>ebr,Luke,scottisafool</owners>
@@ -12,7 +12,7 @@
         <description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
         <copyright>Copyright © Media Browser 2013</copyright>
         <dependencies>
-            <dependency id="MediaBrowser.Common" version="3.0.332" />
+            <dependency id="MediaBrowser.Common" version="3.0.333" />
             <dependency id="NLog" version="2.1.0" />
             <dependency id="SimpleInjector" version="2.4.1" />
             <dependency id="sharpcompress" version="0.10.2" />

+ 1 - 1
Nuget/MediaBrowser.Common.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
     <metadata>
         <id>MediaBrowser.Common</id>
-        <version>3.0.332</version>
+        <version>3.0.333</version>
         <title>MediaBrowser.Common</title>
         <authors>Media Browser Team</authors>
         <owners>ebr,Luke,scottisafool</owners>

+ 2 - 2
Nuget/MediaBrowser.Server.Core.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
     <metadata>
         <id>MediaBrowser.Server.Core</id>
-        <version>3.0.332</version>
+        <version>3.0.333</version>
         <title>Media Browser.Server.Core</title>
         <authors>Media Browser Team</authors>
         <owners>ebr,Luke,scottisafool</owners>
@@ -12,7 +12,7 @@
         <description>Contains core components required to build plugins for Media Browser Server.</description>
         <copyright>Copyright © Media Browser 2013</copyright>
         <dependencies>
-            <dependency id="MediaBrowser.Common" version="3.0.332" />
+            <dependency id="MediaBrowser.Common" version="3.0.333" />
         </dependencies>
     </metadata>
     <files>