Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实时解密情况下只有加密片段才调用mp4解密 #519

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -11,9 +13,11 @@
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; }

Check warning on line 20 in src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs

View workflow job for this annotation

GitHub Actions / build-linux-musl-arm64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 20 in src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs

View workflow job for this annotation

GitHub Actions / build-mac-x64-arm64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 20 in src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs

View workflow job for this annotation

GitHub Actions / build-linux-x64-arm64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 20 in src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs

View workflow job for this annotation

GitHub Actions / build-win-nt6_0-x86

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 20 in src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs

View workflow job for this annotation

GitHub Actions / build-win-x64-arm64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string? NameFromVar { get; set; } // MPD分段文件名

Expand Down
8 changes: 4 additions & 4 deletions src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private async Task<bool> DownloadStreamAsync(StreamSpec streamSpec, ProgressTask
// 从文件读取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));
Expand Down Expand Up @@ -225,7 +225,7 @@ private async Task<bool> DownloadStreamAsync(StreamSpec streamSpec, ProgressTask
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;
Expand All @@ -249,7 +249,7 @@ private async Task<bool> DownloadStreamAsync(StreamSpec streamSpec, ProgressTask
// 从文件读取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));
Expand Down Expand Up @@ -287,7 +287,7 @@ await Parallel.ForEachAsync(segments, options, async (seg, _) =>
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));
Expand Down
8 changes: 4 additions & 4 deletions src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private async Task<bool> RecordStreamAsync(StreamSpec streamSpec, ProgressTask t
// 从文件读取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));
Expand Down Expand Up @@ -270,7 +270,7 @@ private async Task<bool> RecordStreamAsync(StreamSpec streamSpec, ProgressTask t
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;
Expand All @@ -290,7 +290,7 @@ private async Task<bool> RecordStreamAsync(StreamSpec streamSpec, ProgressTask t
// 从文件读取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));
Expand Down Expand Up @@ -333,7 +333,7 @@ await Parallel.ForEachAsync(segments, options, async (seg, _) =>
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));
Expand Down
Loading