增强MPD适配性

This commit is contained in:
nilaoda 2022-07-10 03:00:41 +08:00
parent 14d69c805b
commit 76acf6c421
1 changed files with 46 additions and 17 deletions

View File

@ -163,6 +163,14 @@ namespace N_m3u8DL_RE.Parser.Extractor
//第一种形式 SegmentBase
var segmentBaseElements = representation.Elements().Where(e => e.Name.LocalName == "SegmentBase");
if (segmentBaseElements.Any())
{
//处理init url
var initializationElements = segmentBaseElements.First().Elements().Where(e => e.Name.LocalName == "Initialization");
if (initializationElements.Any())
{
var initialization = initializationElements.First();
var sourceURL = initialization.Attribute("sourceURL")?.Value;
if (sourceURL == null)
{
streamSpec.Playlist.MediaParts[0].MediaSegments.Add
(
@ -174,14 +182,8 @@ namespace N_m3u8DL_RE.Parser.Extractor
}
);
}
//第二种形式 SegmentList.SegmentList
var segmentListElements = representation.Elements().Where(e => e.Name.LocalName == "SegmentList");
if (segmentListElements.Any())
else
{
var segmentList = segmentListElements.First();
//处理init url
var initialization = segmentList.Elements().First(e => e.Name.LocalName == "Initialization");
var initUrl = ParserUtil.CombineURL(segBaseUrl, initialization.Attribute("sourceURL")?.Value);
var initRange = initialization.Attribute("range")?.Value;
streamSpec.Playlist.MediaInit = new MediaSegment();
@ -192,6 +194,32 @@ namespace N_m3u8DL_RE.Parser.Extractor
streamSpec.Playlist.MediaInit.StartRange = start;
streamSpec.Playlist.MediaInit.ExpectLength = expect;
}
}
}
}
//第二种形式 SegmentList.SegmentList
var segmentListElements = representation.Elements().Where(e => e.Name.LocalName == "SegmentList");
if (segmentListElements.Any())
{
var segmentList = segmentListElements.First();
var duration = segmentList.Attribute("duration")?.Value;
//处理init url
var initializationElements = segmentList.Elements().Where(e => e.Name.LocalName == "Initialization");
if (initializationElements.Any())
{
var initialization = initializationElements.First();
var initUrl = ParserUtil.CombineURL(segBaseUrl, initialization.Attribute("sourceURL")?.Value);
var initRange = initialization.Attribute("range")?.Value;
streamSpec.Playlist.MediaInit = new MediaSegment();
streamSpec.Playlist.MediaInit.Url = PreProcessUrl(initUrl);
if (initRange != null)
{
var (start, expect) = ParserUtil.ParseRange(initRange);
streamSpec.Playlist.MediaInit.StartRange = start;
streamSpec.Playlist.MediaInit.ExpectLength = expect;
}
}
//处理分片
var segmentURLs = segmentList.Elements().Where(e => e.Name.LocalName == "SegmentURL");
for (int segmentIndex = 0; segmentIndex < segmentURLs.Count(); segmentIndex++)
@ -200,10 +228,11 @@ namespace N_m3u8DL_RE.Parser.Extractor
var mediaUrl = ParserUtil.CombineURL(segBaseUrl, segmentURL.Attribute("media")?.Value);
var mediaRange = segmentURL.Attribute("range")?.Value;
MediaSegment mediaSegment = new();
mediaSegment.Duration = Convert.ToDouble(duration);
mediaSegment.Url = PreProcessUrl(mediaUrl);
if (mediaRange != null)
{
var (start, expect) = ParserUtil.ParseRange(initRange);
var (start, expect) = ParserUtil.ParseRange(mediaRange);
mediaSegment.StartRange = start;
mediaSegment.ExpectLength = expect;
}