From f799a8ba8958f6f94f5e2e558a848eb007618e3a Mon Sep 17 00:00:00 2001 From: nilaoda Date: Sun, 10 Jul 2022 12:36:08 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E5=A4=9Aperiod=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E7=9B=B4=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extractor/DASHExtractor2.cs | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs index 7b85623..f0a3b79 100644 --- a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs +++ b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs @@ -153,7 +153,7 @@ namespace N_m3u8DL_RE.Parser.Extractor } //读取声道数量 - var audioChannelConfiguration = adaptationSet.Elements().Where(e => e.Name.LocalName == "AudioChannelConfiguration"); + var audioChannelConfiguration = adaptationSet.Elements().Concat(representation.Elements()).Where(e => e.Name.LocalName == "AudioChannelConfiguration"); if (audioChannelConfiguration.Any()) { streamSpec.Channels = audioChannelConfiguration.First().Attribute("value")?.Value; @@ -321,15 +321,18 @@ namespace N_m3u8DL_RE.Parser.Extractor var startNumber = Convert.ToInt64(startNumberStr); var duration = Convert.ToInt32(durationStr); var totalNumber = (long)Math.Ceiling(XmlConvert.ToTimeSpan(periodDuration ?? mediaPresentationDuration ?? "PT0S").TotalSeconds * timescale / duration); - //直播的情况,需要自己计算startNumber + //直播的情况,需要自己计算totalNumber if (totalNumber == 0 && isLive) { var now = publishTime == null ? DateTime.Now : DateTime.Parse(publishTime); var availableTime = DateTime.Parse(availabilityStartTime); var ts = now - availableTime; var updateTs = XmlConvert.ToTimeSpan(timeShiftBufferDepth); - //(当前时间到发布时间的时间差 - 最小刷新间隔) / 分片时长 - startNumber = (long)((ts.TotalSeconds - updateTs.TotalSeconds) * timescale / duration); + if (startNumberStr == null) + { + //(当前时间到发布时间的时间差 - 最小刷新间隔) / 分片时长 + startNumber = (long)((ts.TotalSeconds - updateTs.TotalSeconds) * timescale / duration); + } totalNumber = (long)(updateTs.TotalSeconds * timescale / duration); } for (long index = startNumber, segIndex = 0; index < startNumber + totalNumber; index++, segIndex++) @@ -358,19 +361,29 @@ namespace N_m3u8DL_RE.Parser.Extractor } } - //处理同一ID分散在不同Period的情况 这种情况作为新的part出现 + //处理同一ID分散在不同Period的情况 var _index = streamList.FindIndex(_f => _f.GroupId == streamSpec.GroupId && _f.Resolution == streamSpec.Resolution && _f.MediaType == streamSpec.MediaType); if (_index > -1) { - var startIndex = streamList[_index].Playlist?.MediaParts.Last().MediaSegments.Last().Index + 1; - foreach (var item in streamSpec.Playlist.MediaParts[0].MediaSegments) + if (isLive) { - item.Index = item.Index + startIndex.Value; + //直播,这种情况直接略过新的 + continue; } - streamList[_index].Playlist?.MediaParts.Add(new MediaPart() + else { - MediaSegments = streamSpec.Playlist.MediaParts[0].MediaSegments - }); + //点播,这种情况作为新的part出现 + var startIndex = streamList[_index].Playlist?.MediaParts.Last().MediaSegments.Last().Index + 1; + foreach (var item in streamSpec.Playlist.MediaParts[0].MediaSegments) + { + item.Index = item.Index + startIndex.Value; + } + streamList[_index].Playlist?.MediaParts.Add(new MediaPart() + { + MediaSegments = streamSpec.Playlist.MediaParts[0].MediaSegments + }); + + } } else {