From ba3c47e27d231002b52db5343bf5971168de3aa7 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Sun, 20 Nov 2022 20:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96m4s=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs | 2 ++ .../Extractor/DASHExtractor2.cs | 15 ++++++++++++--- .../DownloadManager/SimpleLiveRecordManager2.cs | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs b/src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs index 6623891..918b016 100644 --- a/src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs +++ b/src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs @@ -21,6 +21,8 @@ namespace N_m3u8DL_RE.Common.Entity public string Url { get; set; } + public string? NameFromVar { get; set; } //MPD分段文件名 + public override bool Equals(object? obj) { return obj is MediaSegment segment && diff --git a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs index 1f2d4aa..db25579 100644 --- a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs +++ b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs @@ -337,9 +337,12 @@ namespace N_m3u8DL_RE.Parser.Extractor var _repeatCount = Convert.ToInt64(_repeatCountStr); varDic[DASHTags.TemplateTime] = currentTime; varDic[DASHTags.TemplateNumber] = segNumber++; - var mediaUrl = ParserUtil.ReplaceVars(ParserUtil.CombineURL(segBaseUrl, media!), varDic); + var oriUrl = ParserUtil.CombineURL(segBaseUrl, media!); + var mediaUrl = ParserUtil.ReplaceVars(oriUrl, varDic); MediaSegment mediaSegment = new(); mediaSegment.Url = mediaUrl; + if (oriUrl.Contains(DASHTags.TemplateTime)) + mediaSegment.NameFromVar = currentTime.ToString(); mediaSegment.Duration = _duration / (double)timescale; mediaSegment.Index = segIndex++; streamSpec.Playlist.MediaParts[0].MediaSegments.Add(mediaSegment); @@ -354,10 +357,13 @@ namespace N_m3u8DL_RE.Parser.Extractor MediaSegment _mediaSegment = new(); varDic[DASHTags.TemplateTime] = currentTime; varDic[DASHTags.TemplateNumber] = segNumber++; - var _mediaUrl = ParserUtil.ReplaceVars(ParserUtil.CombineURL(segBaseUrl, media!), varDic); + var _oriUrl = ParserUtil.CombineURL(segBaseUrl, media!); + var _mediaUrl = ParserUtil.ReplaceVars(_oriUrl, varDic); _mediaSegment.Url = _mediaUrl; _mediaSegment.Index = segIndex++; _mediaSegment.Duration = _duration / (double)timescale; + if (_oriUrl.Contains(DASHTags.TemplateTime)) + _mediaSegment.NameFromVar = currentTime.ToString(); streamSpec.Playlist.MediaParts[0].MediaSegments.Add(_mediaSegment); } currentTime += _duration; @@ -387,9 +393,12 @@ namespace N_m3u8DL_RE.Parser.Extractor for (long index = startNumber, segIndex = 0; index < startNumber + totalNumber; index++, segIndex++) { varDic[DASHTags.TemplateNumber] = index; - var mediaUrl = ParserUtil.ReplaceVars(ParserUtil.CombineURL(segBaseUrl, media!), varDic); + var oriUrl = ParserUtil.CombineURL(segBaseUrl, media!); + var mediaUrl = ParserUtil.ReplaceVars(oriUrl, varDic); MediaSegment mediaSegment = new(); mediaSegment.Url = mediaUrl; + if (oriUrl.Contains(DASHTags.TemplateNumber)) + mediaSegment.NameFromVar = index.ToString(); mediaSegment.Index = isLive ? index : segIndex; //直播直接用startNumber mediaSegment.Duration = duration / (double)timescale; streamSpec.Playlist.MediaParts[0].MediaSegments.Add(mediaSegment); diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs index ccf634c..3a5d0fd 100644 --- a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs +++ b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs @@ -98,6 +98,11 @@ namespace N_m3u8DL_RE.DownloadManager /// private string GetSegmentName(MediaSegment segment, bool allHasDatetime, bool allSamePath) { + if (!string.IsNullOrEmpty(segment.NameFromVar)) + { + return segment.NameFromVar; + } + bool hls = StreamExtractor.ExtractorType == ExtractorType.HLS; string name = OtherUtil.GetFileNameFromInput(segment.Url, false); @@ -105,6 +110,7 @@ namespace N_m3u8DL_RE.DownloadManager { name = OtherUtil.GetValidFileName(segment.Url.Split('?').Last(), "_"); } + if (hls && allHasDatetime) { name = GetUnixTimestamp(segment.DateTime!.Value).ToString();