From 09379d60cd42ffbf379ee6ed3aeb53028719e5a8 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Mon, 18 Jul 2022 23:32:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B8=E5=AF=B9BaseURL?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=94=99=E4=BD=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extractor/DASHExtractor2.cs | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs index 4455d20..212e8f0 100644 --- a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs +++ b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs @@ -108,6 +108,8 @@ namespace N_m3u8DL_RE.Parser.Extractor //处理baseurl嵌套 segBaseUrl = ExtendBaseUrl(period, segBaseUrl); + var adaptationSetsBaseUrl = segBaseUrl; + //本Period中的全部AdaptationSet var adaptationSets = period.Elements().Where(e => e.Name.LocalName == "AdaptationSet"); foreach (var adaptationSet in adaptationSets) @@ -115,6 +117,8 @@ namespace N_m3u8DL_RE.Parser.Extractor //处理baseurl嵌套 segBaseUrl = ExtendBaseUrl(adaptationSet, segBaseUrl); + var representationsBaseUrl = segBaseUrl; + var mimeType = adaptationSet.Attribute("contentType")?.Value ?? adaptationSet.Attribute("mimeType")?.Value; var frameRate = GetFrameRate(adaptationSet); //本AdaptationSet中的全部Representation @@ -401,35 +405,40 @@ namespace N_m3u8DL_RE.Parser.Extractor if (isLive) { //直播,这种情况直接略过新的 - continue; } else { //点播,这种情况作为新的part出现 - var startIndex = streamList[_index].Playlist?.MediaParts.Last().MediaSegments.Last().Index + 1; - foreach (var item in streamSpec.Playlist.MediaParts[0].MediaSegments) + var startIndex = streamList[_index].Playlist!.MediaParts.Last().MediaSegments.Last().Index + 1; + var enumerator = streamSpec.Playlist.MediaParts[0].MediaSegments.GetEnumerator(); + while (enumerator.MoveNext()) { - item.Index = item.Index + startIndex!.Value; + enumerator.Current.Index += startIndex; } - streamList[_index].Playlist?.MediaParts.Add(new MediaPart() + streamList[_index].Playlist!.MediaParts.Add(new MediaPart() { MediaSegments = streamSpec.Playlist.MediaParts[0].MediaSegments }); - } } else { + if (streamSpec.MediaType == MediaType.SUBTITLES && streamSpec.Extension == "mp4") + { + streamSpec.Extension = "m4s"; + } //分片默认后缀m4s if (streamSpec.Extension == null || streamSpec.Playlist.MediaParts.Sum(x => x.MediaSegments.Count) > 1) { streamSpec.Extension = "m4s"; } streamList.Add(streamSpec); - //将segBaseUrl恢复 (重要) - segBaseUrl = this.BaseUrl; } + //恢复BaseURL相对位置 + segBaseUrl = representationsBaseUrl; } + //恢复BaseURL相对位置 + segBaseUrl = adaptationSetsBaseUrl; } }