Пример #1
0
        private static void CreateChunks2(MultiSourceDASHDownloadState state, List <MultiSourceChunk> chunks, SimpleStreamMap chunkStreamMap)
        {
            var i = 0;

            if (state.Demuxed && state.VideoSegments != null && state.AudioSegments != null)
            {
                for (; i < Math.Min(state.AudioChunkCount, state.VideoChunkCount); i++)
                {
                    var chunk1 = CreateChunk(state.VideoSegments[i], 0);
                    chunks.Add(chunk1);
                    chunkStreamMap.StreamMap[chunk1.Id] = Path.Combine(state.TempDirectory, "1_" + chunk1.Id + FileHelper.GetFileName(chunk1.Uri));

                    var chunk2 = CreateChunk(state.AudioSegments[i], 1);
                    chunks.Add(chunk2);
                    chunkStreamMap.StreamMap[chunk2.Id] = Path.Combine(state.TempDirectory, "2_" + chunk2.Id + FileHelper.GetFileName(chunk2.Uri));
                }
                for (; i < state.VideoChunkCount; i++)
                {
                    var chunk = CreateChunk(state.VideoSegments[i], 0);
                    chunks.Add(chunk);
                    chunkStreamMap.StreamMap[chunk.Id] = Path.Combine(state.TempDirectory, "1_" + chunk.Id + FileHelper.GetFileName(chunk.Uri));
                }
                for (; i < state.AudioChunkCount; i++)
                {
                    var chunk = CreateChunk(state.AudioSegments[i], 1);
                    chunks.Add(chunk);
                    chunkStreamMap.StreamMap[chunk.Id] = Path.Combine(state.TempDirectory, "2_" + chunk.Id + FileHelper.GetFileName(chunk.Uri));
                }
            }
        }
Пример #2
0
        private static void CreateChunks1(MultiSourceDASHDownloadState state, List <MultiSourceChunk> chunks, SimpleStreamMap chunkStreamMap)
        {
            var i        = 0;
            var segments = state.VideoSegments ?? state.AudioSegments;

            if (segments != null)
            {
                for (; i < state.VideoChunkCount; i++)
                {
                    var chunk = CreateChunk(segments[i], 0);
                    chunks.Add(chunk);
                    chunkStreamMap.StreamMap[chunk.Id] = Path.Combine(state.TempDirectory, "1_" + chunk.Id + FileHelper.GetFileName(chunk.Uri));
                }
            }
        }
Пример #3
0
        public MultiSourceDASHDownloader(MultiSourceDASHDownloadInfo info, IHttpClient http = null,
                                         BaseMediaProcessor mediaProcessor = null,
                                         AuthenticationInfo?authentication = null, ProxyInfo?proxy = null) : base(info, http, mediaProcessor)
        {
            var state = new MultiSourceDASHDownloadState
            {
                Id             = base.Id,
                Demuxed        = info.VideoSegments != null && info.AudioSegments != null,
                Cookies        = info.Cookies,
                Headers        = info.Headers,
                Url            = info.Url,
                Authentication = authentication,
                Proxy          = proxy,
                TempDirectory  = Path.Combine(Config.Instance.TempDir, Id)
            };

            if (state.Authentication == null)
            {
                state.Authentication = Helpers.GetAuthenticationInfoFromConfig(new Uri(info.Url));
            }

            this._state         = state;
            this.TargetFileName = FileHelper.SanitizeFileName(info.File);

            state.FileSize = -1;
            var i = 0;

            if (state.Demuxed)
            {
                state.AudioChunkCount = info.AudioSegments.Count;
                state.VideoChunkCount = info.VideoSegments.Count;

                state.AudioSegments = info.AudioSegments;
                state.VideoSegments = info.VideoSegments;

                state.Duration             = info.Duration;
                state.AudioContainerFormat = info.AudioFormat ?? FileExtensionHelper.GetExtensionFromMimeType(info.AudioMimeType)
                                             ?? GuessContainerFormatFromPlaylist(info.AudioSegments);
                state.VideoContainerFormat = info.VideoFormat ?? FileExtensionHelper.GetExtensionFromMimeType(info.VideoMimeType)
                                             ?? GuessContainerFormatFromPlaylist(info.VideoSegments);

                CreateChunks2(state, _chunks, _chunkStreamMap);

                //for (; i < Math.Min(this._state.AudioChunkCount, this._state.VideoChunkCount); i++)
                //{
                //    var chunk1 = CreateChunk(info.VideoSegments[i], 0);
                //    _chunks.Add(chunk1);
                //    _chunkStreamMap.StreamMap[chunk1.Id] = Path.Combine(_state.TempDirectory, "1_" + chunk1.Id + FileHelper.GetFileName(chunk1.Uri));

                //    var chunk2 = CreateChunk(info.AudioSegments[i], 1);
                //    _chunks.Add(chunk2);
                //    _chunkStreamMap.StreamMap[chunk2.Id] = Path.Combine(_state.TempDirectory, "2_" + chunk2.Id + FileHelper.GetFileName(chunk2.Uri));
                //}
                //for (; i < this._state.VideoChunkCount; i++)
                //{
                //    var chunk = CreateChunk(info.VideoSegments[i], 0);
                //    _chunks.Add(chunk);
                //    _chunkStreamMap.StreamMap[chunk.Id] = Path.Combine(_state.TempDirectory, "1_" + chunk.Id + FileHelper.GetFileName(chunk.Uri));
                //}
                //for (; i < this._state.AudioChunkCount; i++)
                //{
                //    var chunk = CreateChunk(info.AudioSegments[i], 1);
                //    _chunks.Add(chunk);
                //    _chunkStreamMap.StreamMap[chunk.Id] = Path.Combine(_state.TempDirectory, "2_" + chunk.Id + FileHelper.GetFileName(chunk.Uri));
                //}

                var ext = FileExtensionHelper.GetExtensionFromMimeType(info.VideoMimeType) ??
                          FileExtensionHelper.GuessContainerFormatFromSegmentExtension(state.VideoContainerFormat);

                //if (!(string.IsNullOrWhiteSpace(state.VideoContainerFormat) || state.VideoContainerFormat == "."))
                //{
                //    ext = Helpers.GetExtensionFromMimeType(info.VideoMimeType)
                //    ?? Helpers.GuessContainerFormatFromSegmentExtension(
                //        state.VideoContainerFormat.ToLowerInvariant(), true);
                //}
                TargetFileName = Path.GetFileNameWithoutExtension(TargetFileName ?? "video")
                                 + ext;
            }
            else
            {
                var segments = info.VideoSegments ?? info.AudioSegments;
                state.VideoChunkCount = segments.Count;
                state.VideoSegments   = segments;
                state.Duration        = info.Duration;

                CreateChunks1(state, _chunks, _chunkStreamMap);

                //for (; i < this._state.VideoChunkCount; i++)
                //{
                //    var chunk = CreateChunk(segments[i], 0);
                //    _chunks.Add(chunk);
                //    _chunkStreamMap.StreamMap[chunk.Id] = Path.Combine(_state.TempDirectory, "1_" + chunk.Id + FileHelper.GetFileName(chunk.Uri));
                //}

                state.VideoContainerFormat = GuessContainerFormatFromPlaylist(segments);
                var ext = FileExtensionHelper.GuessContainerFormatFromSegmentExtension(
                    this._state.VideoContainerFormat.ToLowerInvariant());
                TargetFileName = Path.GetFileNameWithoutExtension(TargetFileName ?? "video")
                                 + ext;
            }
        }