Skip to content

Commit

Permalink
恢复默认使用ffmpeg解密
Browse files Browse the repository at this point in the history
  • Loading branch information
nilaoda committed Nov 29, 2024
1 parent 8095c6e commit 94d368b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/N_m3u8DL-RE.Common/Resource/ResString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class ResString
public static string cmd_uiLanguage => GetText("cmd_uiLanguage");
public static string cmd_urlProcessorArgs => GetText("cmd_urlProcessorArgs");
public static string cmd_useShakaPackager => GetText("cmd_useShakaPackager");
public static string cmd_useMp4decrypt => GetText("cmd_useMp4decrypt");
public static string cmd_decryptionEngine => GetText("cmd_decryptionEngine");
public static string cmd_concurrentDownload => GetText("cmd_concurrentDownload");
public static string cmd_useSystemProxy => GetText("cmd_useSystemProxy");
public static string cmd_customProxy => GetText("cmd_customProxy");
Expand Down
14 changes: 7 additions & 7 deletions src/N_m3u8DL-RE.Common/Resource/StaticText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,15 @@ internal class StaticText
),
["cmd_useShakaPackager"] = new TextContainer
(
zhCN: "解密时使用shaka-packager替代ffmpeg",
zhTW: "解密時使用shaka-packager替代ffmpeg",
enUS: "Use shaka-packager instead of ffmpeg to decrypt"
zhCN: "解密时使用shaka-packager替代mp4decrypt",
zhTW: "解密時使用shaka-packager替代mp4decrypt",
enUS: "Use shaka-packager instead of mp4decrypt to decrypt"
),
["cmd_useMp4decrypt"] = new TextContainer
["cmd_decryptionEngine"] = new TextContainer
(
zhCN: "解密时使用mp4decrypt替代ffmpeg",
zhTW: "解密時使用mp4decrypt替代ffmpeg",
enUS: "Use mp4decrypt instead of ffmpeg to decrypt"
zhCN: "设置解密时使用的第三方程序",
zhTW: "設置解密時使用的第三方程序",
enUS: "Set the third-party program used for decryption"
),
["cmd_concurrentDownload"] = new TextContainer
(
Expand Down
8 changes: 4 additions & 4 deletions src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ internal partial class CommandInvoker
private static readonly Option<bool> WriteMetaJson = new(["--write-meta-json"], description: ResString.cmd_writeMetaJson, getDefaultValue: () => true);
private static readonly Option<bool> AppendUrlParams = new(["--append-url-params"], description: ResString.cmd_appendUrlParams, getDefaultValue: () => false);
private static readonly Option<bool> MP4RealTimeDecryption = new (["--mp4-real-time-decryption"], description: ResString.cmd_MP4RealTimeDecryption, getDefaultValue: () => false);
private static readonly Option<bool> UseShakaPackager = new (["--use-shaka-packager"], description: ResString.cmd_useShakaPackager, getDefaultValue: () => false);
private static readonly Option<bool> UseMp4Decrypt = new (["--use-mp4decrypt"], description: ResString.cmd_useMp4decrypt, getDefaultValue: () => false);
private static readonly Option<bool> UseShakaPackager = new (["--use-shaka-packager"], description: ResString.cmd_useShakaPackager, getDefaultValue: () => false) { IsHidden = true };
private static readonly Option<DecryptEngine> DecryptionEngine = new (["--decryption-engine"], description: ResString.cmd_decryptionEngine, getDefaultValue: () => DecryptEngine.MP4DECRYPT);
private static readonly Option<bool> ForceAnsiConsole = new(["--force-ansi-console"], description: ResString.cmd_forceAnsiConsole);
private static readonly Option<bool> NoAnsiColor = new(["--no-ansi-color"], description: ResString.cmd_noAnsiColor);
private static readonly Option<string?> DecryptionBinaryPath = new(["--decryption-binary-path"], description: ResString.cmd_decryptionBinaryPath) { ArgumentHelpName = "PATH" };
Expand Down Expand Up @@ -524,7 +524,7 @@ protected override MyOption GetBoundValue(BindingContext bindingContext)
UrlProcessorArgs = bindingContext.ParseResult.GetValueForOption(UrlProcessorArgs),
MP4RealTimeDecryption = bindingContext.ParseResult.GetValueForOption(MP4RealTimeDecryption),
UseShakaPackager = bindingContext.ParseResult.GetValueForOption(UseShakaPackager),
UseMp4Decrypt = bindingContext.ParseResult.GetValueForOption(UseMp4Decrypt),
DecryptionEngine = bindingContext.ParseResult.GetValueForOption(DecryptionEngine),
DecryptionBinaryPath = bindingContext.ParseResult.GetValueForOption(DecryptionBinaryPath),
FFmpegBinaryPath = bindingContext.ParseResult.GetValueForOption(FFmpegBinaryPath),
KeyTextFile = bindingContext.ParseResult.GetValueForOption(KeyTextFile),
Expand Down Expand Up @@ -617,7 +617,7 @@ public static async Task<int> InvokeArgs(string[] args, Func<MyOption, Task> act
Input, TmpDir, SaveDir, SaveName, BaseUrl, ThreadCount, DownloadRetryCount, HttpRequestTimeout, ForceAnsiConsole, NoAnsiColor,AutoSelect, SkipMerge, SkipDownload, CheckSegmentsCount,
BinaryMerge, UseFFmpegConcatDemuxer, DelAfterDone, NoDateInfo, NoLog, WriteMetaJson, AppendUrlParams, ConcurrentDownload, Headers, /**SavePattern,**/ SubOnly, SubtitleFormat, AutoSubtitleFix,
FFmpegBinaryPath,
LogLevel, UILanguage, UrlProcessorArgs, Keys, KeyTextFile, DecryptionBinaryPath, UseShakaPackager, UseMp4Decrypt, MP4RealTimeDecryption,
LogLevel, UILanguage, UrlProcessorArgs, Keys, KeyTextFile, DecryptionEngine, DecryptionBinaryPath, UseShakaPackager, MP4RealTimeDecryption,
MaxSpeed,
MuxAfterDone,
CustomHLSMethod, CustomHLSKey, CustomHLSIv, UseSystemProxy, CustomProxy, CustomRange, TaskStartAt,
Expand Down
14 changes: 3 additions & 11 deletions src/N_m3u8DL-RE/CommandLine/MyOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,12 @@ internal class MyOption
/// <summary>
/// See: <see cref="CommandInvoker.UseShakaPackager"/>.
/// </summary>
[Obsolete("Use DecryptionEngine instead")]
public bool UseShakaPackager { get; set; }
/// <summary>
/// See: <see cref="CommandInvoker.UseMp4Decrypt"/>.
/// See: <see cref="CommandInvoker.DecryptionEngine"/>.
/// </summary>
public bool UseMp4Decrypt { get; set; }
public DecryptEngine DecryptionEngine { get; set; }
/// <summary>
/// See: <see cref="CommandInvoker.MuxAfterDone"/>.
/// </summary>
Expand Down Expand Up @@ -270,13 +271,4 @@ internal class MyOption
/// See: <see cref="CommandInvoker.LiveFixVttByAudio"/>.
/// </summary>
public bool LiveFixVttByAudio { get; set; }

public DecryptEngine GetDecryptEngine()
{
if (UseShakaPackager)
return DecryptEngine.SHAKA_PACKAGER;
if (UseMp4Decrypt)
return DecryptEngine.MP4DECRYPT;
return DecryptEngine.FFMPEG;
}
}
10 changes: 5 additions & 5 deletions src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private async Task<bool> DownloadStreamAsync(StreamSpec streamSpec, ProgressTask
var headers = DownloaderConfig.Headers;

var decryptionBinaryPath = DownloaderConfig.MyOptions.DecryptionBinaryPath!;
var decryptEngine = DownloaderConfig.MyOptions.GetDecryptEngine();
var decryptEngine = DownloaderConfig.MyOptions.DecryptionEngine;
var mp4InitFile = "";
var currentKID = "";
var readInfo = false; // 是否读取过
Expand Down Expand Up @@ -171,7 +171,7 @@ private async Task<bool> DownloadStreamAsync(StreamSpec streamSpec, ProgressTask
mp4Info = MP4DecryptUtil.GetMP4Info(result.ActualFilePath);
currentKID = mp4Info.KID;
// try shaka packager, which can handle WebM
if (string.IsNullOrEmpty(currentKID) && DownloaderConfig.MyOptions.UseShakaPackager) {
if (string.IsNullOrEmpty(currentKID) && DownloaderConfig.MyOptions.DecryptionEngine == DecryptEngine.SHAKA_PACKAGER) {
currentKID = MP4DecryptUtil.ReadInitShaka(result.ActualFilePath, decryptionBinaryPath);
}
// 从文件读取KEY
Expand Down Expand Up @@ -243,7 +243,7 @@ private async Task<bool> DownloadStreamAsync(StreamSpec streamSpec, ProgressTask
currentKID = MP4DecryptUtil.GetMP4Info(result.ActualFilePath).KID;
}
// try shaka packager, which can handle WebM
if (string.IsNullOrEmpty(currentKID) && DownloaderConfig.MyOptions.UseShakaPackager) {
if (string.IsNullOrEmpty(currentKID) && DownloaderConfig.MyOptions.DecryptionEngine == DecryptEngine.SHAKA_PACKAGER) {
currentKID = MP4DecryptUtil.ReadInitShaka(result.ActualFilePath, decryptionBinaryPath);
}
// 从文件读取KEY
Expand Down Expand Up @@ -590,7 +590,7 @@ await Parallel.ForEachAsync(segments, options, async (seg, _) =>
{
currentKID = MP4DecryptUtil.GetMP4Info(output).KID;
// try shaka packager, which can handle WebM
if (string.IsNullOrEmpty(currentKID) && DownloaderConfig.MyOptions.UseShakaPackager) {
if (string.IsNullOrEmpty(currentKID) && DownloaderConfig.MyOptions.DecryptionEngine == DecryptEngine.SHAKA_PACKAGER) {
currentKID = MP4DecryptUtil.ReadInitShaka(output, decryptionBinaryPath);
}
// 从文件读取KEY
Expand Down Expand Up @@ -654,7 +654,7 @@ public async Task<bool> StartDownloadAsync()
}
progress.Columns(progressColumns);

if (DownloaderConfig.MyOptions is { MP4RealTimeDecryption: true, UseShakaPackager: false, Keys.Length: > 0 })
if (DownloaderConfig.MyOptions is { MP4RealTimeDecryption: true, DecryptionEngine: not DecryptEngine.SHAKA_PACKAGER, Keys.Length: > 0 })
Logger.WarnMarkUp($"[darkorange3_1]{ResString.realTimeDecMessage}[/]");

await progress.StartAsync(async ctx =>
Expand Down
4 changes: 2 additions & 2 deletions src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private async Task<bool> RecordStreamAsync(StreamSpec streamSpec, ProgressTask t
var saveDir = DownloaderConfig.MyOptions.SaveDir ?? Environment.CurrentDirectory;
var saveName = DownloaderConfig.MyOptions.SaveName != null ? $"{DownloaderConfig.MyOptions.SaveName}.{streamSpec.Language}".TrimEnd('.') : dirName;
var headers = DownloaderConfig.Headers;
var decryptEngine = DownloaderConfig.MyOptions.GetDecryptEngine();
var decryptEngine = DownloaderConfig.MyOptions.DecryptionEngine;

Logger.Debug($"dirName: {dirName}; tmpDir: {tmpDir}; saveDir: {saveDir}; saveName: {saveName}");

Expand Down Expand Up @@ -840,7 +840,7 @@ await progress.StartAsync(async ctx =>
DownloaderConfig.MyOptions.ConcurrentDownload = true;
DownloaderConfig.MyOptions.MP4RealTimeDecryption = true;
DownloaderConfig.MyOptions.LiveRecordLimit = DownloaderConfig.MyOptions.LiveRecordLimit ?? TimeSpan.MaxValue;
if (DownloaderConfig.MyOptions is { MP4RealTimeDecryption: true, UseShakaPackager: false, Keys.Length: > 0 })
if (DownloaderConfig.MyOptions is { MP4RealTimeDecryption: true, DecryptionEngine: not DecryptEngine.SHAKA_PACKAGER, Keys.Length: > 0 })
Logger.WarnMarkUp($"[darkorange3_1]{ResString.realTimeDecMessage}[/]");
var limit = DownloaderConfig.MyOptions.LiveRecordLimit;
if (limit != TimeSpan.MaxValue)
Expand Down
14 changes: 10 additions & 4 deletions src/N_m3u8DL-RE/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using N_m3u8DL_RE.CommandLine;
using System.Net;
using System.Net.Http.Headers;
using N_m3u8DL_RE.Enum;

namespace N_m3u8DL_RE;

Expand Down Expand Up @@ -109,10 +110,15 @@ static async Task DoWorkAsync(MyOption option)
{
throw new ArgumentException("MuxAfterDone disabled, MuxImports not allowed!");
}

if (option.UseShakaPackager)
{
option.DecryptionEngine = DecryptEngine.SHAKA_PACKAGER;
}

if (option is { UseShakaPackager: true, UseMp4Decrypt: true })
if (option is { UseShakaPackager: true, DecryptionEngine: DecryptEngine.FFMPEG or DecryptEngine.MP4DECRYPT })
{
throw new ArgumentException("UseShakaPackager and UseMp4Decrypt cannot be enabled simultaneously!");
throw new ArgumentException("UseShakaPackager and Mp4DecryptEngine not match!");
}

// LivePipeMux开启时 LiveRealTimeMerge必须开启
Expand Down Expand Up @@ -148,7 +154,7 @@ static async Task DoWorkAsync(MyOption option)
{
if (string.IsNullOrEmpty(option.DecryptionBinaryPath))
{
if (option.UseShakaPackager)
if (option.DecryptionEngine is DecryptEngine.SHAKA_PACKAGER)
{
var file = GlobalUtil.FindExecutable("shaka-packager");
var file2 = GlobalUtil.FindExecutable("packager-linux-x64");
Expand All @@ -158,7 +164,7 @@ static async Task DoWorkAsync(MyOption option)
option.DecryptionBinaryPath = file ?? file2 ?? file3 ?? file4;
Logger.Extra($"shaka-packager => {option.DecryptionBinaryPath}");
}
else if (option.UseMp4Decrypt)
else if (option.DecryptionEngine is DecryptEngine.MP4DECRYPT)
{
var file = GlobalUtil.FindExecutable("mp4decrypt");
if (file == null) throw new FileNotFoundException("mp4decrypt not found!");
Expand Down

0 comments on commit 94d368b

Please sign in to comment.