diff --git a/src/N_m3u8DL-RE.Common/Resource/ResString.cs b/src/N_m3u8DL-RE.Common/Resource/ResString.cs index a50ae5d..0c9437b 100644 --- a/src/N_m3u8DL-RE.Common/Resource/ResString.cs +++ b/src/N_m3u8DL-RE.Common/Resource/ResString.cs @@ -12,6 +12,7 @@ namespace N_m3u8DL_RE.Common.Resource public static string autoBinaryMerge { get => GetText("autoBinaryMerge"); } public static string autoBinaryMerge2 { get => GetText("autoBinaryMerge2"); } public static string autoBinaryMerge3 { get => GetText("autoBinaryMerge3"); } + public static string autoBinaryMerge4 { get => GetText("autoBinaryMerge4"); } public static string badM3u8 { get => GetText("badM3u8"); } public static string binaryMerge { get => GetText("binaryMerge"); } public static string checkingLast { get => GetText("checkingLast"); } diff --git a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs index 0b195e4..c4676da 100644 --- a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs +++ b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs @@ -28,6 +28,12 @@ namespace N_m3u8DL_RE.Common.Resource zhTW: "檢測到無法識別的加密方式,自動開啟二進位制合併", enUS: "An unrecognized encryption method is detected, binary merging is automatically enabled" ), + ["autoBinaryMerge4"] = new TextContainer + ( + zhCN: "检测到CENC加密方式,自动开启二进制合并", + zhTW: "檢測到CENC加密方式,自動開啟二進位制合併", + enUS: "When CENC encryption is detected, binary merging is automatically enabled" + ), ["badM3u8"] = new TextContainer ( zhCN: "错误的m3u8", diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs index ab69db4..d731249 100644 --- a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs +++ b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs @@ -95,6 +95,13 @@ namespace N_m3u8DL_RE.DownloadManager //开始下载 Logger.InfoMarkUp(ResString.startDownloading + streamSpec.ToShortString()); + //对于CENC,全部自动开启二进制合并 + if (!DownloaderConfig.BinaryMerge && totalCount >= 1 && streamSpec.Playlist!.MediaParts.First().MediaSegments.First().EncryptInfo.Method == Common.Enum.EncryptMethod.CENC) + { + DownloaderConfig.BinaryMerge = true; + Logger.WarnMarkUp($"[darkorange3_1]{ResString.autoBinaryMerge4}[/]"); + } + //下载init if (streamSpec.Playlist?.MediaInit != null) { @@ -447,42 +454,41 @@ namespace N_m3u8DL_RE.DownloadManager } } - //调用mp4decrypt解密 - if (mergeSuccess && File.Exists(output) && !DownloaderConfig.MP4RealTimeDecryption && DownloaderConfig.Keys != null && DownloaderConfig.Keys.Length > 0) + //重新读取init信息 + if (mergeSuccess && totalCount >= 1 && string.IsNullOrEmpty(currentKID) && streamSpec.Playlist!.MediaParts.First().MediaSegments.First().EncryptInfo.Method == Common.Enum.EncryptMethod.CENC) { - if (totalCount >= 1 && streamSpec.Playlist!.MediaParts.First().MediaSegments.First().EncryptInfo.Method != Common.Enum.EncryptMethod.NONE) + using (var fs = File.OpenRead(output)) { - if (string.IsNullOrEmpty(currentKID)) + var header = new byte[4096]; //4KB + fs.Read(header); + currentKID = ReadInit(header); + //从文件读取KEY + var _key = await MP4DecryptUtil.SearchKeyFromFile(DownloaderConfig.KeyTextFile, currentKID); + if (_key != null) { - using (var fs = File.OpenRead(output)) - { - var header = new byte[4096]; //4KB - fs.Read(header); - currentKID = ReadInit(header); - //从文件读取KEY - var _key = await MP4DecryptUtil.SearchKeyFromFile(DownloaderConfig.KeyTextFile, currentKID); - if (_key != null) - { - if (DownloaderConfig.Keys == null) - DownloaderConfig.Keys = new string[] { _key }; - else - DownloaderConfig.Keys = DownloaderConfig.Keys.Concat(new string[] { _key }).ToArray(); - } - } - } - var enc = output; - var dec = Path.Combine(Path.GetDirectoryName(enc)!, Path.GetFileNameWithoutExtension(enc) + "_dec" + Path.GetExtension(enc)); - Logger.InfoMarkUp($"[grey]Decrypting...[/]"); - var result = await MP4DecryptUtil.DecryptAsync(DownloaderConfig.UseShakaPackager, mp4decrypt, DownloaderConfig.Keys, enc, dec, currentKID); - if (result) - { - File.Delete(enc); - File.Move(dec, enc); - output = dec; + if (DownloaderConfig.Keys == null) + DownloaderConfig.Keys = new string[] { _key }; + else + DownloaderConfig.Keys = DownloaderConfig.Keys.Concat(new string[] { _key }).ToArray(); } } } + //调用mp4decrypt解密 + if (mergeSuccess && File.Exists(output) && !string.IsNullOrEmpty(currentKID) && !DownloaderConfig.MP4RealTimeDecryption && DownloaderConfig.Keys != null && DownloaderConfig.Keys.Length > 0) + { + var enc = output; + var dec = Path.Combine(Path.GetDirectoryName(enc)!, Path.GetFileNameWithoutExtension(enc) + "_dec" + Path.GetExtension(enc)); + Logger.InfoMarkUp($"[grey]Decrypting...[/]"); + var result = await MP4DecryptUtil.DecryptAsync(DownloaderConfig.UseShakaPackager, mp4decrypt, DownloaderConfig.Keys, enc, dec, currentKID); + if (result) + { + File.Delete(enc); + File.Move(dec, enc); + output = dec; + } + } + return true; }