From ef43b70409296e045615682741bfbffd4bcf39a8 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Sun, 21 Aug 2022 20:42:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9Bmpd?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF=E5=8F=8A?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=90=88=E5=B9=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs index a481378..6837eec 100644 --- a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs +++ b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs @@ -104,6 +104,9 @@ namespace N_m3u8DL_RE.Parser.Extractor //本Period时长 var periodDuration = period.Attribute("duration")?.Value; + //本Period ID + var periodId = period.Attribute("id")?.Value; + //最终分片会使用的baseurl var segBaseUrl = this.BaseUrl; @@ -136,6 +139,7 @@ namespace N_m3u8DL_RE.Parser.Extractor } var bandwidth = representation.Attribute("bandwidth"); StreamSpec streamSpec = new(); + streamSpec.PeriodId = periodId; streamSpec.Playlist = new Playlist(); streamSpec.Playlist.MediaParts.Add(new MediaPart()); streamSpec.GroupId = representation.Attribute("id")?.Value; @@ -229,7 +233,7 @@ namespace N_m3u8DL_RE.Parser.Extractor var segmentList = representation.Elements().Where(e => e.Name.LocalName == "SegmentList").FirstOrDefault(); if (segmentList != null) { - var duration = segmentList.Attribute("duration")?.Value; + var durationStr = segmentList.Attribute("duration")?.Value; //处理init url var initialization = segmentList.Elements().Where(e => e.Name.LocalName == "Initialization").FirstOrDefault(); if (initialization != null) @@ -247,13 +251,16 @@ namespace N_m3u8DL_RE.Parser.Extractor } //处理分片 var segmentURLs = segmentList.Elements().Where(e => e.Name.LocalName == "SegmentURL"); + var timescaleStr = segmentList.Attribute("timescale")?.Value ?? "1"; for (int segmentIndex = 0; segmentIndex < segmentURLs.Count(); segmentIndex++) { var segmentURL = segmentURLs.ElementAt(segmentIndex); var mediaUrl = ParserUtil.CombineURL(segBaseUrl, segmentURL.Attribute("media")?.Value!); var mediaRange = segmentURL.Attribute("mediaRange")?.Value; + var timesacle = Convert.ToInt32(timescaleStr); + var duration = Convert.ToInt64(durationStr); MediaSegment mediaSegment = new(); - mediaSegment.Duration = Convert.ToDouble(duration); + mediaSegment.Duration = duration / (double)timesacle; mediaSegment.Url = mediaUrl; mediaSegment.Index = segmentIndex; if (mediaRange != null) @@ -401,7 +408,7 @@ namespace N_m3u8DL_RE.Parser.Extractor } //处理同一ID分散在不同Period的情况 - var _index = streamList.FindIndex(_f => _f.GroupId == streamSpec.GroupId && _f.Resolution == streamSpec.Resolution && _f.MediaType == streamSpec.MediaType); + var _index = streamList.FindIndex(_f => _f.PeriodId != streamSpec.PeriodId && _f.GroupId == streamSpec.GroupId && _f.Resolution == streamSpec.Resolution && _f.MediaType == streamSpec.MediaType); if (_index > -1) { if (isLive)