增强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

@ -164,15 +164,38 @@ namespace N_m3u8DL_RE.Parser.Extractor
var segmentBaseElements = representation.Elements().Where(e => e.Name.LocalName == "SegmentBase"); var segmentBaseElements = representation.Elements().Where(e => e.Name.LocalName == "SegmentBase");
if (segmentBaseElements.Any()) if (segmentBaseElements.Any())
{ {
streamSpec.Playlist.MediaParts[0].MediaSegments.Add //处理init url
( var initializationElements = segmentBaseElements.First().Elements().Where(e => e.Name.LocalName == "Initialization");
new MediaSegment() if (initializationElements.Any())
{
var initialization = initializationElements.First();
var sourceURL = initialization.Attribute("sourceURL")?.Value;
if (sourceURL == null)
{ {
Index = 0, streamSpec.Playlist.MediaParts[0].MediaSegments.Add
Url = PreProcessUrl(segBaseUrl), (
Duration = XmlConvert.ToTimeSpan(periodDuration ?? mediaPresentationDuration ?? "PT0S").TotalSeconds new MediaSegment()
{
Index = 0,
Url = PreProcessUrl(segBaseUrl),
Duration = XmlConvert.ToTimeSpan(periodDuration ?? mediaPresentationDuration ?? "PT0S").TotalSeconds
}
);
} }
); else
{
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;
}
}
}
} }
//第二种形式 SegmentList.SegmentList //第二种形式 SegmentList.SegmentList
@ -180,17 +203,22 @@ namespace N_m3u8DL_RE.Parser.Extractor
if (segmentListElements.Any()) if (segmentListElements.Any())
{ {
var segmentList = segmentListElements.First(); var segmentList = segmentListElements.First();
var duration = segmentList.Attribute("duration")?.Value;
//处理init url //处理init url
var initialization = segmentList.Elements().First(e => e.Name.LocalName == "Initialization"); var initializationElements = segmentList.Elements().Where(e => e.Name.LocalName == "Initialization");
var initUrl = ParserUtil.CombineURL(segBaseUrl, initialization.Attribute("sourceURL")?.Value); if (initializationElements.Any())
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); var initialization = initializationElements.First();
streamSpec.Playlist.MediaInit.StartRange = start; var initUrl = ParserUtil.CombineURL(segBaseUrl, initialization.Attribute("sourceURL")?.Value);
streamSpec.Playlist.MediaInit.ExpectLength = expect; 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"); var segmentURLs = segmentList.Elements().Where(e => e.Name.LocalName == "SegmentURL");
@ -200,10 +228,11 @@ namespace N_m3u8DL_RE.Parser.Extractor
var mediaUrl = ParserUtil.CombineURL(segBaseUrl, segmentURL.Attribute("media")?.Value); var mediaUrl = ParserUtil.CombineURL(segBaseUrl, segmentURL.Attribute("media")?.Value);
var mediaRange = segmentURL.Attribute("range")?.Value; var mediaRange = segmentURL.Attribute("range")?.Value;
MediaSegment mediaSegment = new(); MediaSegment mediaSegment = new();
mediaSegment.Duration = Convert.ToDouble(duration);
mediaSegment.Url = PreProcessUrl(mediaUrl); mediaSegment.Url = PreProcessUrl(mediaUrl);
if (mediaRange != null) if (mediaRange != null)
{ {
var (start, expect) = ParserUtil.ParseRange(initRange); var (start, expect) = ParserUtil.ParseRange(mediaRange);
mediaSegment.StartRange = start; mediaSegment.StartRange = start;
mediaSegment.ExpectLength = expect; mediaSegment.ExpectLength = expect;
} }