From 5972cee7fffba483cb7b4d9ca63d21e968bc926e Mon Sep 17 00:00:00 2001 From: nilaoda Date: Mon, 12 Dec 2022 21:17:10 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E9=87=8D=E8=AF=95=E4=B8=8A=E9=99=90?= =?UTF-8?q?=E5=90=8E=E6=AD=A3=E5=B8=B8=E8=BE=93=E5=87=BA=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE/Downloader/SimpleDownloader.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/N_m3u8DL-RE/Downloader/SimpleDownloader.cs b/src/N_m3u8DL-RE/Downloader/SimpleDownloader.cs index 4780a08..b8113e9 100644 --- a/src/N_m3u8DL-RE/Downloader/SimpleDownloader.cs +++ b/src/N_m3u8DL-RE/Downloader/SimpleDownloader.cs @@ -128,6 +128,10 @@ namespace N_m3u8DL_RE.Downloader await Task.Delay(1000); goto retry; } + else + { + Logger.WarnMarkUp($"[grey]{ex.Message.EscapeMarkup()}[/]"); + } //throw new Exception("download failed", ex); return null; } From 9cc077d8855bb8b1e4ab044e2ce14a3ea587f77c Mon Sep 17 00:00:00 2001 From: nilaoda Date: Tue, 13 Dec 2022 22:16:31 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E6=9D=A1=E6=8F=8F=E8=BF=B0=E6=96=87=E6=9C=AC=E7=9A=84=E9=95=BF?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs index 7991643..6f4eaf8 100644 --- a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs +++ b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs @@ -799,7 +799,7 @@ namespace N_m3u8DL_RE.DownloadManager //创建任务 var dic = SelectedSteams.Select(item => { - var task = ctx.AddTask(item.ToShortString(), autoStart: false, maxValue: 0); + var task = ctx.AddTask(item.ToShortShortString(), autoStart: false, maxValue: 0); SpeedContainerDic[task.Id] = new SpeedContainer(); //速度计算 LastFileNameDic[task.Id] = ""; DateTimeDic[task.Id] = 0L; From 44cc97357fa2e9d14382a83b0684c68467c77903 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Mon, 19 Dec 2022 15:08:27 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=20#84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs index addc7ff..eef2469 100644 --- a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs +++ b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs @@ -323,7 +323,7 @@ namespace N_m3u8DL_RE.DownloadManager //校验分片数量 if (DownloaderConfig.MyOptions.CheckSegmentsCount && FileDic.Values.Any(s => s == null)) { - Logger.WarnMarkUp(ResString.segmentCountCheckNotPass, totalCount, FileDic.Values.Where(s => s != null).Count()); + Logger.ErrorMarkUp(ResString.segmentCountCheckNotPass, totalCount, FileDic.Values.Where(s => s != null).Count()); return false; } @@ -670,6 +670,8 @@ namespace N_m3u8DL_RE.DownloadManager var task = kp.Value; var result = await DownloadStreamAsync(kp.Key, task, SpeedContainerDic[task.Id]); Results[kp.Key] = result; + //失败不再下载后续 + if (!result) break; } } else From fa7ff57fae4c471ce45424badd5389fce5c99f27 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Mon, 19 Dec 2022 15:29:18 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=A3=E5=AF=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HLS/DefaultHLSContentProcessor.cs | 4 ++- .../Downloader/SimpleDownloader.cs | 9 +++++- src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs | 28 +++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSContentProcessor.cs b/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSContentProcessor.cs index 260fbca..47535f4 100644 --- a/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSContentProcessor.cs +++ b/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSContentProcessor.cs @@ -22,6 +22,8 @@ namespace N_m3u8DL_RE.Parser.Processor.HLS private static partial Regex OrderFixRegex(); [GeneratedRegex("#EXT-X-MAP.*\\.apple\\.com/")] private static partial Regex ATVRegex(); + [GeneratedRegex("(#EXT-X-KEY:[\\s\\S]*?)(#EXT-X-DISCONTINUITY|#EXT-X-ENDLIST)")] + private static partial Regex ATVRegex2(); public override bool CanProcess(ExtractorType extractorType, string rawText, ParserConfig parserConfig) => extractorType == ExtractorType.HLS; @@ -80,7 +82,7 @@ namespace N_m3u8DL_RE.Parser.Processor.HLS if (m3u8Content.Contains("#EXT-X-DISCONTINUITY") && m3u8Content.Contains("#EXT-X-MAP") && (m3u8Url.Contains(".apple.com/") || ATVRegex().IsMatch(m3u8Content))) { //只取加密部分即可 - Regex ykmap = DNSPRegex(); + Regex ykmap = ATVRegex2(); if (ykmap.IsMatch(m3u8Content)) { m3u8Content = "#EXTM3U\r\n" + ykmap.Match(m3u8Content).Groups[1].Value + "\r\n#EXT-X-ENDLIST"; diff --git a/src/N_m3u8DL-RE/Downloader/SimpleDownloader.cs b/src/N_m3u8DL-RE/Downloader/SimpleDownloader.cs index b8113e9..1fe73a2 100644 --- a/src/N_m3u8DL-RE/Downloader/SimpleDownloader.cs +++ b/src/N_m3u8DL-RE/Downloader/SimpleDownloader.cs @@ -85,12 +85,19 @@ namespace N_m3u8DL_RE.Downloader cancellationTokenSource = new(); var des = Path.ChangeExtension(path, null); - //已下载过跳过 + //已下载跳过 if (File.Exists(des)) { return new DownloadResult() { ActualContentLength = 0, ActualFilePath = des }; } + //已解密跳过 + var dec = Path.Combine(Path.GetDirectoryName(des)!, Path.GetFileNameWithoutExtension(des) + "_dec" + Path.GetExtension(des)); + if (File.Exists(dec)) + { + return new DownloadResult() { ActualContentLength = 0, ActualFilePath = dec }; + } + //另起线程进行监控 using var watcher = Task.Factory.StartNew(async () => { diff --git a/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs b/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs index cab5038..e715bda 100644 --- a/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs +++ b/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs @@ -7,17 +7,26 @@ namespace N_m3u8DL_RE.Util { internal class MP4DecryptUtil { + private static string ZeroKid = "00000000000000000000000000000000"; public static async Task DecryptAsync(bool shakaPackager, string bin, string[]? keys, string source, string dest, string? kid, string init = "") { if (keys == null || keys.Length == 0) return false; - var keyPair = keys.First(); + string? keyPair = null; + string? trackId = null; if (!string.IsNullOrEmpty(kid)) { var test = keys.Where(k => k.StartsWith(kid)); if (test.Any()) keyPair = test.First(); } + //Apple + if (kid == ZeroKid) + { + keyPair = keys.First(); + trackId = "1"; + } + if (keyPair == null) return false; //shakaPackager 无法单独解密init文件 @@ -37,12 +46,19 @@ namespace N_m3u8DL_RE.Util enc = tmpFile; } - cmd = $"--enable_raw_key_decryption input=\"{enc}\",stream=0,output=\"{dest}\" " + - $"--keys key_id={keyPair.Split(':')[0]}:key={keyPair.Split(':')[1]}"; + cmd = $"--quiet --enable_raw_key_decryption input=\"{enc}\",stream=0,output=\"{dest}\" " + + $"--keys {(trackId != null ? $"label={trackId}:" : "")}key_id={ZeroKid}:key={keyPair.Split(':')[1]}"; } else { - cmd = string.Join(" ", keys.Select(k => $"--key {k}")); + if (trackId == null) + { + cmd = string.Join(" ", keys.Select(k => $"--key {k}")); + } + else + { + cmd = string.Join(" ", keys.Select(k => $"--key {trackId}:{k.Split(':')[1]}")); + } if (init != "") { cmd += $" --fragments-info \"{init}\" "; @@ -69,8 +85,8 @@ namespace N_m3u8DL_RE.Util { FileName = name, Arguments = arg, - RedirectStandardOutput = true, - RedirectStandardError = true, + //RedirectStandardOutput = true, + //RedirectStandardError = true, CreateNoWindow = true, UseShellExecute = false })!.WaitForExitAsync(); From b46af31f959a3cb8d2c3f761db3c5e5d5f5e7e99 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Mon, 19 Dec 2022 15:32:55 +0800 Subject: [PATCH 5/7] v0.1.5.1 --- src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 2 +- src/N_m3u8DL-RE/N_m3u8DL-RE.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs index 07d0b92..d7322d2 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) 20221212"; + public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20221219"; [GeneratedRegex("((best|worst)\\d*|all)")] private static partial Regex ForStrRegex(); diff --git a/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj b/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj index 99c4537..56497e9 100644 --- a/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj +++ b/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj @@ -7,7 +7,7 @@ enable preview enable - 0.1.5 + 0.1.5.1 AnyCPU;x64 From 3b901afd6296c82e18bc14c33ec706022004366f Mon Sep 17 00:00:00 2001 From: nilaoda Date: Tue, 20 Dec 2022 11:50:15 +0800 Subject: [PATCH 6/7] =?UTF-8?q?shaka=E8=A7=A3=E5=AF=86bug=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE/N_m3u8DL-RE.csproj | 2 +- src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj b/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj index 56497e9..e9274da 100644 --- a/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj +++ b/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj @@ -7,7 +7,7 @@ enable preview enable - 0.1.5.1 + 0.1.5.2 AnyCPU;x64 diff --git a/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs b/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs index e715bda..99b8f3b 100644 --- a/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs +++ b/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs @@ -47,7 +47,7 @@ namespace N_m3u8DL_RE.Util } cmd = $"--quiet --enable_raw_key_decryption input=\"{enc}\",stream=0,output=\"{dest}\" " + - $"--keys {(trackId != null ? $"label={trackId}:" : "")}key_id={ZeroKid}:key={keyPair.Split(':')[1]}"; + $"--keys {(trackId != null ? $"label={trackId}:" : "")}key_id={(trackId != null ? ZeroKid : kid)}:key={keyPair.Split(':')[1]}"; } else { From dbd81abcc44aab8aac461088fc2beaa6c11b1e27 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Tue, 20 Dec 2022 11:51:25 +0800 Subject: [PATCH 7/7] 20221220 --- src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs index d7322d2..feea8c7 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) 20221219"; + public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20221220"; [GeneratedRegex("((best|worst)\\d*|all)")] private static partial Regex ForStrRegex();