diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Channels/ChannelDownloadScheduledTask.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Channels/ChannelDownloadScheduledTask.cs | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelDownloadScheduledTask.cs b/MediaBrowser.Server.Implementations/Channels/ChannelDownloadScheduledTask.cs index ce5c41f89..39f747e0a 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelDownloadScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelDownloadScheduledTask.cs @@ -7,6 +7,7 @@ using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Channels; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Logging; using MediaBrowser.Model.MediaInfo; @@ -71,7 +72,7 @@ namespace MediaBrowser.Server.Implementations.Channels var startingPercent = numComplete * percentPerUser * 100; var innerProgress = new ActionableProgress<double>(); - innerProgress.RegisterAction(p => progress.Report(startingPercent + (.8 * p))); + innerProgress.RegisterAction(p => progress.Report(startingPercent + (percentPerUser * p))); await DownloadContent(user, cancellationToken, innerProgress).ConfigureAwait(false); @@ -146,13 +147,15 @@ namespace MediaBrowser.Server.Implementations.Channels { var numComplete = 0; + var options = _config.GetChannelsConfiguration(); + foreach (var item in result.Items) { - if (_config.Configuration.ChannelOptions.DownloadingChannels.Contains(item.ChannelId)) + if (options.DownloadingChannels.Contains(item.ChannelId)) { try { - await DownloadChannelItem(item, cancellationToken, path); + await DownloadChannelItem(item, options, cancellationToken, path); } catch (OperationCanceledException) { @@ -174,9 +177,18 @@ namespace MediaBrowser.Server.Implementations.Channels } private async Task DownloadChannelItem(BaseItemDto item, + ChannelOptions channelOptions, CancellationToken cancellationToken, string path) { + if (channelOptions.DownloadSizeLimit.HasValue) + { + if (IsSizeLimitReached(path, channelOptions.DownloadSizeLimit.Value)) + { + return; + } + } + var sources = await _manager.GetChannelItemMediaSources(item.Id, cancellationToken) .ConfigureAwait(false); @@ -218,7 +230,8 @@ namespace MediaBrowser.Server.Implementations.Channels if (item.IsVideo && response.ContentType.StartsWith("video/", StringComparison.OrdinalIgnoreCase)) { var extension = response.ContentType.Split('/') - .Last(); + .Last() + .Replace("quicktime", "mov", StringComparison.OrdinalIgnoreCase); destination += "." + extension; } @@ -237,7 +250,7 @@ namespace MediaBrowser.Server.Implementations.Channels throw new ApplicationException("Unexpected response type encountered: " + response.ContentType); } - File.Move(response.TempFilePath, destination); + File.Copy(response.TempFilePath, destination, true); await RefreshMediaSourceItem(destination, cancellationToken).ConfigureAwait(false); @@ -251,6 +264,25 @@ namespace MediaBrowser.Server.Implementations.Channels } } + private bool IsSizeLimitReached(string path, double gbLimit) + { + var byteLimit = gbLimit*1000000000; + + long total = 0; + + foreach (var file in new DirectoryInfo(path).EnumerateFiles("*", SearchOption.AllDirectories)) + { + total += file.Length; + + if (total >= byteLimit) + { + return true; + } + } + + return false; + } + private async Task RefreshMediaSourceItems(IEnumerable<MediaSourceInfo> items, CancellationToken cancellationToken) { foreach (var item in items) @@ -282,12 +314,14 @@ namespace MediaBrowser.Server.Implementations.Channels private void CleanChannelContent(CancellationToken cancellationToken) { - if (!_config.Configuration.ChannelOptions.MaxDownloadAge.HasValue) + var options = _config.GetChannelsConfiguration(); + + if (!options.MaxDownloadAge.HasValue) { return; } - var minDateModified = DateTime.UtcNow.AddDays(0 - _config.Configuration.ChannelOptions.MaxDownloadAge.Value); + var minDateModified = DateTime.UtcNow.AddDays(0 - options.MaxDownloadAge.Value); var path = _manager.ChannelDownloadPath; |
