private async Task DownloadChannelItem(IChannelMediaItem item, ChannelOptions channelOptions, CancellationToken cancellationToken, string path) { var itemId = item.Id.ToString("N"); var sources = await _manager.GetStaticMediaSources(item, true, cancellationToken) .ConfigureAwait(false); var cachedVersions = sources.Where(i => i.Protocol == MediaProtocol.File).ToList(); if (cachedVersions.Count > 0) { await RefreshMediaSourceItems(cachedVersions, cancellationToken).ConfigureAwait(false); return; } var limit = GetDownloadLimit(channelOptions); if (limit.HasValue) { if (IsSizeLimitReached(path, limit.Value)) { return; } } var destination = Path.Combine(path, item.ChannelId, itemId); await _manager.DownloadChannelItem(item, destination, new Progress <double>(), cancellationToken) .ConfigureAwait(false); await RefreshMediaSourceItem(destination, cancellationToken).ConfigureAwait(false); }
public IEnumerable <MediaSourceInfo> GetCachedChannelItemMediaSources(IChannelMediaItem item) { var filenamePrefix = item.Id.ToString("N"); var parentPath = Path.Combine(ChannelDownloadPath, item.ChannelId); try { var files = new DirectoryInfo(parentPath).EnumerateFiles("*", SearchOption.TopDirectoryOnly); if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase)) { files = files.Where(i => EntityResolutionHelper.IsVideoFile(i.FullName)); } else { files = files.Where(i => EntityResolutionHelper.IsAudioFile(i.FullName)); } var file = files .FirstOrDefault(i => i.Name.StartsWith(filenamePrefix, StringComparison.OrdinalIgnoreCase)); if (file != null) { var cachedItem = _libraryManager.ResolvePath(file); if (cachedItem != null) { var hasMediaSources = _libraryManager.GetItemById(cachedItem.Id) as IHasMediaSources; if (hasMediaSources != null) { var source = hasMediaSources.GetMediaSources(true).FirstOrDefault(); if (source != null) { source.Type = MediaSourceType.Cache; return(new[] { source }); } } } } } catch (DirectoryNotFoundException) { } return(new List <MediaSourceInfo>()); }
private MediaSourceInfo GetMediaSource(IChannelMediaItem item, ChannelMediaInfo info) { var id = info.Path.GetMD5().ToString("N"); var source = new MediaSourceInfo { MediaStreams = GetMediaStreams(info).ToList(), Container = info.Container, Protocol = info.Protocol, Path = info.Path, RequiredHttpHeaders = info.RequiredHttpHeaders, RunTimeTicks = item.RunTimeTicks, Name = id, Id = id }; return(source); }
private MediaSourceInfo GetMediaSource(IChannelMediaItem item, ChannelMediaInfo info) { var id = info.Path.GetMD5().ToString("N"); var source = new MediaSourceInfo { MediaStreams = GetMediaStreams(info).ToList(), Container = info.Container, LocationType = info.IsRemote ? LocationType.Remote : LocationType.FileSystem, Path = info.Path, RequiredHttpHeaders = info.RequiredHttpHeaders, RunTimeTicks = item.RunTimeTicks, Name = id, Id = id }; return(source); }
private async Task DownloadChannelItem(IChannelMediaItem item, CancellationToken cancellationToken, string path) { var itemId = item.Id.ToString("N"); var sources = await _manager.GetStaticMediaSources(item, true, cancellationToken) .ConfigureAwait(false); var cachedVersions = sources.Where(i => i.Protocol == MediaProtocol.File).ToList(); if (cachedVersions.Count > 0) { await RefreshMediaSourceItems(cachedVersions, cancellationToken).ConfigureAwait(false); return; } var limit = GetDownloadLimit(); if (limit.HasValue) { if (IsSizeLimitReached(path, limit.Value)) { return; } } var destination = Path.Combine(path, item.ChannelId, itemId); await _manager.DownloadChannelItem(item, destination, new Progress<double>(), cancellationToken) .ConfigureAwait(false); await RefreshMediaSourceItem(destination, cancellationToken).ConfigureAwait(false); }
private MediaSourceInfo GetMediaSource(IChannelMediaItem item, ChannelMediaInfo info) { var id = info.Path.GetMD5().ToString("N"); var source = new MediaSourceInfo { MediaStreams = GetMediaStreams(info).ToList(), Container = info.Container, Protocol = info.Protocol, Path = info.Path, RequiredHttpHeaders = info.RequiredHttpHeaders, RunTimeTicks = item.RunTimeTicks, Name = id, Id = id }; return source; }
public IEnumerable<MediaSourceInfo> GetCachedChannelItemMediaSources(IChannelMediaItem item) { var filenamePrefix = item.Id.ToString("N"); var parentPath = Path.Combine(ChannelDownloadPath, item.ChannelId); try { var files = new DirectoryInfo(parentPath).EnumerateFiles("*", SearchOption.TopDirectoryOnly); if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase)) { files = files.Where(i => EntityResolutionHelper.IsVideoFile(i.FullName)); } else { files = files.Where(i => EntityResolutionHelper.IsAudioFile(i.FullName)); } var file = files .FirstOrDefault(i => i.Name.StartsWith(filenamePrefix, StringComparison.OrdinalIgnoreCase)); if (file != null) { var cachedItem = _libraryManager.ResolvePath(file); if (cachedItem != null) { var hasMediaSources = _libraryManager.GetItemById(cachedItem.Id) as IHasMediaSources; if (hasMediaSources != null) { var source = hasMediaSources.GetMediaSources(true).FirstOrDefault(); if (source != null) { source.Type = MediaSourceType.Cache; return new[] { source }; } } } } } catch (DirectoryNotFoundException) { } return new List<MediaSourceInfo>(); }