diff --git a/src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs b/src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs index 4055ee1..1606d57 100644 --- a/src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs +++ b/src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs @@ -1,4 +1,6 @@ -namespace N_m3u8DL_RE.Common.Entity; +using N_m3u8DL_RE.Common.Enum; + +namespace N_m3u8DL_RE.Common.Entity; public class MediaSegment { @@ -11,7 +13,9 @@ public class MediaSegment public long? StopRange => (StartRange != null && ExpectLength != null) ? StartRange + ExpectLength - 1 : null; public long? ExpectLength { get; set; } - public EncryptInfo EncryptInfo { get; set; } = new EncryptInfo(); + public EncryptInfo EncryptInfo { get; set; } = new(); + + public bool IsEncrypted => EncryptInfo.Method != EncryptMethod.NONE; public string Url { get; set; } diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs index b3dfe1e..7226679 100644 --- a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs +++ b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs @@ -177,7 +177,7 @@ internal class SimpleDownloadManager // 从文件读取KEY await SearchKeyAsync(currentKID); // 实时解密 - if (DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID) && StreamExtractor.ExtractorType != ExtractorType.MSS) + if (streamSpec.Playlist.MediaInit.IsEncrypted && DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID) && StreamExtractor.ExtractorType != ExtractorType.MSS) { var enc = result.ActualFilePath; var dec = Path.Combine(Path.GetDirectoryName(enc)!, Path.GetFileNameWithoutExtension(enc) + "_dec" + Path.GetExtension(enc)); @@ -225,7 +225,7 @@ internal class SimpleDownloadManager var processor = new MSSMoovProcessor(streamSpec); var header = processor.GenHeader(File.ReadAllBytes(result.ActualFilePath)); await File.WriteAllBytesAsync(FileDic[streamSpec.Playlist!.MediaInit!]!.ActualFilePath, header); - if (DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID)) + if (seg.IsEncrypted && DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID)) { // 需要重新解密init var enc = FileDic[streamSpec.Playlist!.MediaInit!]!.ActualFilePath; @@ -249,7 +249,7 @@ internal class SimpleDownloadManager // 从文件读取KEY await SearchKeyAsync(currentKID); // 实时解密 - if (DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID)) + if (seg.IsEncrypted && DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID)) { var enc = result.ActualFilePath; var dec = Path.Combine(Path.GetDirectoryName(enc)!, Path.GetFileNameWithoutExtension(enc) + "_dec" + Path.GetExtension(enc)); @@ -287,7 +287,7 @@ internal class SimpleDownloadManager if (result != null && result.Success) task.Increment(1); // 实时解密 - if (DownloaderConfig.MyOptions.MP4RealTimeDecryption && result != null && result.Success && !string.IsNullOrEmpty(currentKID)) + if (seg.IsEncrypted && DownloaderConfig.MyOptions.MP4RealTimeDecryption && result != null && result.Success && !string.IsNullOrEmpty(currentKID)) { var enc = result.ActualFilePath; var dec = Path.Combine(Path.GetDirectoryName(enc)!, Path.GetFileNameWithoutExtension(enc) + "_dec" + Path.GetExtension(enc)); diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs index 51eafd8..a31eff8 100644 --- a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs +++ b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs @@ -211,7 +211,7 @@ internal class SimpleLiveRecordManager2 // 从文件读取KEY await SearchKeyAsync(currentKID); // 实时解密 - if (DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID) && StreamExtractor.ExtractorType != ExtractorType.MSS) + if (streamSpec.Playlist.MediaInit.IsEncrypted && DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID) && StreamExtractor.ExtractorType != ExtractorType.MSS) { var enc = result.ActualFilePath; var dec = Path.Combine(Path.GetDirectoryName(enc)!, Path.GetFileNameWithoutExtension(enc) + "_dec" + Path.GetExtension(enc)); @@ -270,7 +270,7 @@ internal class SimpleLiveRecordManager2 var processor = new MSSMoovProcessor(streamSpec); var header = processor.GenHeader(File.ReadAllBytes(result.ActualFilePath)); await File.WriteAllBytesAsync(FileDic[streamSpec.Playlist!.MediaInit!]!.ActualFilePath, header); - if (DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID)) + if (seg.IsEncrypted && DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID)) { // 需要重新解密init var enc = FileDic[streamSpec.Playlist!.MediaInit!]!.ActualFilePath; @@ -290,7 +290,7 @@ internal class SimpleLiveRecordManager2 // 从文件读取KEY await SearchKeyAsync(currentKID); // 实时解密 - if (DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID)) + if (seg.IsEncrypted && DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID)) { var enc = result.ActualFilePath; var dec = Path.Combine(Path.GetDirectoryName(enc)!, Path.GetFileNameWithoutExtension(enc) + "_dec" + Path.GetExtension(enc)); @@ -333,7 +333,7 @@ internal class SimpleLiveRecordManager2 if (result != null && result.Success) task.Increment(1); // 实时解密 - if (DownloaderConfig.MyOptions.MP4RealTimeDecryption && result != null && result.Success && !string.IsNullOrEmpty(currentKID)) + if (seg.IsEncrypted && DownloaderConfig.MyOptions.MP4RealTimeDecryption && result != null && result.Success && !string.IsNullOrEmpty(currentKID)) { var enc = result.ActualFilePath; var dec = Path.Combine(Path.GetDirectoryName(enc)!, Path.GetFileNameWithoutExtension(enc) + "_dec" + Path.GetExtension(enc));