适配多period下的直播

This commit is contained in:
nilaoda 2022-07-10 12:36:08 +08:00
parent d5f8c49e5d
commit f799a8ba89
1 changed files with 24 additions and 11 deletions

View File

@ -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()) if (audioChannelConfiguration.Any())
{ {
streamSpec.Channels = audioChannelConfiguration.First().Attribute("value")?.Value; streamSpec.Channels = audioChannelConfiguration.First().Attribute("value")?.Value;
@ -321,15 +321,18 @@ namespace N_m3u8DL_RE.Parser.Extractor
var startNumber = Convert.ToInt64(startNumberStr); var startNumber = Convert.ToInt64(startNumberStr);
var duration = Convert.ToInt32(durationStr); var duration = Convert.ToInt32(durationStr);
var totalNumber = (long)Math.Ceiling(XmlConvert.ToTimeSpan(periodDuration ?? mediaPresentationDuration ?? "PT0S").TotalSeconds * timescale / duration); var totalNumber = (long)Math.Ceiling(XmlConvert.ToTimeSpan(periodDuration ?? mediaPresentationDuration ?? "PT0S").TotalSeconds * timescale / duration);
//直播的情况,需要自己计算startNumber //直播的情况,需要自己计算totalNumber
if (totalNumber == 0 && isLive) if (totalNumber == 0 && isLive)
{ {
var now = publishTime == null ? DateTime.Now : DateTime.Parse(publishTime); var now = publishTime == null ? DateTime.Now : DateTime.Parse(publishTime);
var availableTime = DateTime.Parse(availabilityStartTime); var availableTime = DateTime.Parse(availabilityStartTime);
var ts = now - availableTime; var ts = now - availableTime;
var updateTs = XmlConvert.ToTimeSpan(timeShiftBufferDepth); var updateTs = XmlConvert.ToTimeSpan(timeShiftBufferDepth);
if (startNumberStr == null)
{
//(当前时间到发布时间的时间差 - 最小刷新间隔) / 分片时长 //(当前时间到发布时间的时间差 - 最小刷新间隔) / 分片时长
startNumber = (long)((ts.TotalSeconds - updateTs.TotalSeconds) * timescale / duration); startNumber = (long)((ts.TotalSeconds - updateTs.TotalSeconds) * timescale / duration);
}
totalNumber = (long)(updateTs.TotalSeconds * timescale / duration); totalNumber = (long)(updateTs.TotalSeconds * timescale / duration);
} }
for (long index = startNumber, segIndex = 0; index < startNumber + totalNumber; index++, segIndex++) for (long index = startNumber, segIndex = 0; index < startNumber + totalNumber; index++, segIndex++)
@ -358,10 +361,18 @@ 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); var _index = streamList.FindIndex(_f => _f.GroupId == streamSpec.GroupId && _f.Resolution == streamSpec.Resolution && _f.MediaType == streamSpec.MediaType);
if (_index > -1) if (_index > -1)
{ {
if (isLive)
{
//直播,这种情况直接略过新的
continue;
}
else
{
//点播这种情况作为新的part出现
var startIndex = streamList[_index].Playlist?.MediaParts.Last().MediaSegments.Last().Index + 1; var startIndex = streamList[_index].Playlist?.MediaParts.Last().MediaSegments.Last().Index + 1;
foreach (var item in streamSpec.Playlist.MediaParts[0].MediaSegments) foreach (var item in streamSpec.Playlist.MediaParts[0].MediaSegments)
{ {
@ -371,6 +382,8 @@ namespace N_m3u8DL_RE.Parser.Extractor
{ {
MediaSegments = streamSpec.Playlist.MediaParts[0].MediaSegments MediaSegments = streamSpec.Playlist.MediaParts[0].MediaSegments
}); });
}
} }
else else
{ {