From 418547d5a26e999588c68812aab6e7439de630e8 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Wed, 21 Dec 2022 18:37:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=98=E9=87=8F=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E5=92=8C=E7=BB=84=E8=A3=85URL=E7=9A=84=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extractor/DASHExtractor2.cs | 26 +++++++++++-------- src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs index 81a52ad..055eeea 100644 --- a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs +++ b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs @@ -312,13 +312,14 @@ namespace N_m3u8DL_RE.Parser.Extractor var initialization = segmentTemplate.Attribute("initialization")?.Value ?? segmentTemplateOuter.Attribute("initialization")?.Value; if (initialization != null) { - var initUrl = ParserUtil.ReplaceVars(ParserUtil.CombineURL(segBaseUrl, initialization), varDic); + var _init = ParserUtil.ReplaceVars(initialization, varDic); + var initUrl = ParserUtil.CombineURL(segBaseUrl, _init); streamSpec.Playlist.MediaInit = new MediaSegment(); streamSpec.Playlist.MediaInit.Index = -1; //便于排序 streamSpec.Playlist.MediaInit.Url = initUrl; } //处理分片 - var media = segmentTemplate.Attribute("media")?.Value ?? segmentTemplateOuter.Attribute("media")?.Value; + var mediaTemplate = segmentTemplate.Attribute("media")?.Value ?? segmentTemplateOuter.Attribute("media")?.Value; var segmentTimeline = segmentTemplate.Elements().Where(e => e.Name.LocalName == "SegmentTimeline").FirstOrDefault(); if (segmentTimeline != null) { @@ -340,11 +341,12 @@ namespace N_m3u8DL_RE.Parser.Extractor var _repeatCount = Convert.ToInt64(_repeatCountStr); varDic[DASHTags.TemplateTime] = currentTime; varDic[DASHTags.TemplateNumber] = segNumber++; - var oriUrl = ParserUtil.CombineURL(segBaseUrl, media!); - var mediaUrl = ParserUtil.ReplaceVars(oriUrl, varDic); + var hasTime = mediaTemplate!.Contains(DASHTags.TemplateTime); + var media = ParserUtil.ReplaceVars(mediaTemplate!, varDic); + var mediaUrl = ParserUtil.CombineURL(segBaseUrl, media!); MediaSegment mediaSegment = new(); mediaSegment.Url = mediaUrl; - if (oriUrl.Contains(DASHTags.TemplateTime)) + if (hasTime) mediaSegment.NameFromVar = currentTime.ToString(); mediaSegment.Duration = _duration / (double)timescale; mediaSegment.Index = segIndex++; @@ -360,12 +362,13 @@ namespace N_m3u8DL_RE.Parser.Extractor MediaSegment _mediaSegment = new(); varDic[DASHTags.TemplateTime] = currentTime; varDic[DASHTags.TemplateNumber] = segNumber++; - var _oriUrl = ParserUtil.CombineURL(segBaseUrl, media!); - var _mediaUrl = ParserUtil.ReplaceVars(_oriUrl, varDic); + var _hashTime = mediaTemplate!.Contains(DASHTags.TemplateTime); + var _media = ParserUtil.ReplaceVars(mediaTemplate!, varDic); + var _mediaUrl = ParserUtil.CombineURL(segBaseUrl, _media); _mediaSegment.Url = _mediaUrl; _mediaSegment.Index = segIndex++; _mediaSegment.Duration = _duration / (double)timescale; - if (_oriUrl.Contains(DASHTags.TemplateTime)) + if (_hashTime) _mediaSegment.NameFromVar = currentTime.ToString(); streamSpec.Playlist.MediaParts[0].MediaSegments.Add(_mediaSegment); } @@ -396,11 +399,12 @@ namespace N_m3u8DL_RE.Parser.Extractor for (long index = startNumber, segIndex = 0; index < startNumber + totalNumber; index++, segIndex++) { varDic[DASHTags.TemplateNumber] = index; - var oriUrl = ParserUtil.CombineURL(segBaseUrl, media!); - var mediaUrl = ParserUtil.ReplaceVars(oriUrl, varDic); + var hasNumber = mediaTemplate!.Contains(DASHTags.TemplateNumber); + var media = ParserUtil.ReplaceVars(mediaTemplate!, varDic); + var mediaUrl = ParserUtil.CombineURL(segBaseUrl, media!); MediaSegment mediaSegment = new(); mediaSegment.Url = mediaUrl; - if (oriUrl.Contains(DASHTags.TemplateNumber)) + if (hasNumber) mediaSegment.NameFromVar = index.ToString(); mediaSegment.Index = isLive ? index : segIndex; //直播直接用startNumber mediaSegment.Duration = duration / (double)timescale; diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs index feea8c7..d21e89d 100644 --- a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs +++ b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs @@ -18,7 +18,7 @@ namespace N_m3u8DL_RE.CommandLine { internal partial class CommandInvoker { - public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20221220"; + public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20221221"; [GeneratedRegex("((best|worst)\\d*|all)")] private static partial Regex ForStrRegex();