Browse Source

add image download setting

Luke Pulverenti 9 years ago
parent
commit
2c3113ced7

+ 2 - 0
MediaBrowser.Model/Configuration/ServerConfiguration.cs

@@ -204,6 +204,8 @@ namespace MediaBrowser.Model.Configuration
 
 
         public int MigrationVersion { get; set; }
         public int MigrationVersion { get; set; }
 
 
+        public bool DownloadImagesInAdvance { get; set; }
+        
         /// <summary>
         /// <summary>
         /// Initializes a new instance of the <see cref="ServerConfiguration" /> class.
         /// Initializes a new instance of the <see cref="ServerConfiguration" /> class.
         /// </summary>
         /// </summary>

+ 11 - 0
MediaBrowser.Providers/Manager/ItemImageProvider.cs

@@ -18,6 +18,7 @@ using System.Threading;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using CommonIO;
 using CommonIO;
 using MediaBrowser.Controller.Entities.Audio;
 using MediaBrowser.Controller.Entities.Audio;
+using MediaBrowser.Controller.LiveTv;
 using MediaBrowser.Model.MediaInfo;
 using MediaBrowser.Model.MediaInfo;
 
 
 namespace MediaBrowser.Providers.Manager
 namespace MediaBrowser.Providers.Manager
@@ -520,6 +521,16 @@ namespace MediaBrowser.Providers.Manager
 
 
         private bool EnableImageStub(IHasImages item, ImageType type)
         private bool EnableImageStub(IHasImages item, ImageType type)
         {
         {
+            if (item is LiveTvProgram)
+            {
+                return true;
+            }
+
+            if (_config.Configuration.DownloadImagesInAdvance)
+            {
+                return false;
+            }
+
             if (item.LocationType == LocationType.Remote || item.LocationType == LocationType.Virtual)
             if (item.LocationType == LocationType.Remote || item.LocationType == LocationType.Virtual)
             {
             {
                 return true;
                 return true;

+ 18 - 6
MediaBrowser.Providers/Manager/MetadataService.cs

@@ -283,12 +283,7 @@ namespace MediaBrowser.Providers.Manager
 
 
                     if (!string.IsNullOrWhiteSpace(person.ImageUrl) && !personEntity.HasImage(ImageType.Primary))
                     if (!string.IsNullOrWhiteSpace(person.ImageUrl) && !personEntity.HasImage(ImageType.Primary))
                     {
                     {
-                        personEntity.SetImage(new ItemImageInfo
-                        {
-                            Path = person.ImageUrl,
-                            Type = ImageType.Primary,
-                            IsPlaceholder = true
-                        }, 0);
+                        await AddPersonImage(personEntity, person.ImageUrl, cancellationToken).ConfigureAwait(false);
 
 
                         saveEntity = true;
                         saveEntity = true;
                         updateType = updateType | ItemUpdateType.ImageUpdate;
                         updateType = updateType | ItemUpdateType.ImageUpdate;
@@ -302,6 +297,23 @@ namespace MediaBrowser.Providers.Manager
             }
             }
         }
         }
 
 
+        private async Task AddPersonImage(Person personEntity, string imageUrl, CancellationToken cancellationToken)
+        {
+            if (ServerConfigurationManager.Configuration.DownloadImagesInAdvance)
+            {
+                await ProviderManager.SaveImage(personEntity, imageUrl, null, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
+            }
+            else
+            {
+                personEntity.SetImage(new ItemImageInfo
+                {
+                    Path = imageUrl,
+                    Type = ImageType.Primary,
+                    IsPlaceholder = true
+                }, 0);
+            }
+        }
+
         private readonly Task _cachedTask = Task.FromResult(true);
         private readonly Task _cachedTask = Task.FromResult(true);
         protected virtual Task AfterMetadataRefresh(TItemType item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
         protected virtual Task AfterMetadataRefresh(TItemType item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
         {
         {

+ 19 - 0
MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs

@@ -729,6 +729,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
             var recordingFileName = _fileSystem.GetValidFilename(RecordingHelper.GetRecordingName(timer, info)).Trim() + ".ts";
             var recordingFileName = _fileSystem.GetValidFilename(RecordingHelper.GetRecordingName(timer, info)).Trim() + ".ts";
 
 
             recordPath = Path.Combine(recordPath, recordingFileName);
             recordPath = Path.Combine(recordPath, recordingFileName);
+            recordPath = EnsureFileUnique(recordPath);
             _fileSystem.CreateDirectory(Path.GetDirectoryName(recordPath));
             _fileSystem.CreateDirectory(Path.GetDirectoryName(recordPath));
 
 
             var recordingId = info.Id.GetMD5().ToString("N");
             var recordingId = info.Id.GetMD5().ToString("N");
@@ -862,6 +863,24 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
             }
             }
         }
         }
 
 
+        private string EnsureFileUnique(string path)
+        {
+            var originalPath = path;
+            var index = 1;
+
+            while (_fileSystem.FileExists(path))
+            {
+                var parent = Path.GetDirectoryName(originalPath);
+                var name = Path.GetFileNameWithoutExtension(originalPath);
+                name += "-" + index.ToString(CultureInfo.InvariantCulture);
+
+                path = Path.ChangeExtension(Path.Combine(parent, name), Path.GetExtension(originalPath));
+                index++;
+            }
+
+            return path;
+        }
+
         private async Task<IRecorder> GetRecorder()
         private async Task<IRecorder> GetRecorder()
         {
         {
             if (GetConfiguration().EnableRecordingEncoding)
             if (GetConfiguration().EnableRecordingEncoding)