private async Task DownloadChannelContent(QueryResult <BaseItemDto> result, string path, CancellationToken cancellationToken, IProgress <double> progress) { var numComplete = 0; var options = _config.GetChannelsConfiguration(); foreach (var item in result.Items) { if (options.DownloadingChannels.Contains(item.ChannelId)) { try { await DownloadChannelItem(item, options, cancellationToken, path); } catch (OperationCanceledException) { break; } catch (Exception ex) { _logger.ErrorException("Error downloading channel content for {0}", ex, item.Name); } } numComplete++; double percent = numComplete; percent /= result.Items.Length; progress.Report(percent * 100); } progress.Report(100); }
private async Task DownloadChannelContent(QueryResult <BaseItem> result, string path, CancellationToken cancellationToken, IProgress <double> progress) { var numComplete = 0; var options = _config.GetChannelsConfiguration(); foreach (var item in result.Items) { var channelItem = item as IChannelMediaItem; if (channelItem != null) { var channelFeatures = _manager.GetChannelFeatures(channelItem.ChannelId); if (channelFeatures.SupportsContentDownloading) { if (options.DownloadingChannels.Contains(channelItem.ChannelId)) { try { await DownloadChannelItem(channelItem, options, cancellationToken, path); } catch (OperationCanceledException) { break; } catch (ChannelDownloadException) { // Logged at lower levels } catch (Exception ex) { _logger.ErrorException("Error downloading channel content for {0}", ex, item.Name); } } } } numComplete++; double percent = numComplete; percent /= result.Items.Length; progress.Report(percent * 100); } progress.Report(100); }
private IEnumerable <ChannelMediaInfo> SortMediaInfoResults(IEnumerable <ChannelMediaInfo> channelMediaSources) { var list = channelMediaSources.ToList(); var options = _config.GetChannelsConfiguration(); var width = options.PreferredStreamingWidth; if (width.HasValue) { var val = width.Value; var res = list .OrderBy(i => (i.Width.HasValue && i.Width.Value <= val ? 0 : 1)) .ThenBy(i => Math.Abs((i.Width ?? 0) - val)) .ThenByDescending(i => i.Width ?? 0) .ThenBy(list.IndexOf) .ToList(); return(res); } return(list .OrderByDescending(i => i.Width ?? 0) .ThenBy(list.IndexOf)); }