Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/N_m3u8DL-RE.Common/Resource/ResString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public static class ResString
public static string promptInfo => GetText("promptInfo");
public static string promptTitle => GetText("promptTitle");
public static string readingInfo => GetText("readingInfo");
public static string resolutionFilterNotMatch => GetText("resolutionFilterNotMatch");
public static string resolutionFilterExpectedActual => GetText("resolutionFilterExpectedActual");
public static string searchKey => GetText("searchKey");
public static string decryptionFailed => GetText("decryptionFailed");
public static string segmentCountCheckNotPass => GetText("segmentCountCheckNotPass");
Expand Down
12 changes: 12 additions & 0 deletions src/N_m3u8DL-RE.Common/Resource/StaticText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,18 @@ internal static class StaticText
zhTW: "讀取媒體訊息...",
enUS: "Reading media info..."
),
["resolutionFilterNotMatch"] = new TextContainer
(
zhCN: "-sv res 与实际视频分辨率不符",
zhTW: "-sv res 與實際影片解析度不符",
enUS: "-sv res does not match the actual video resolution"
),
["resolutionFilterExpectedActual"] = new TextContainer
(
zhCN: "期望: {} | 实际: {}",
zhTW: "期望: {} | 實際: {}",
enUS: "Expected: {} | Actual: {}"
),
["searchKey"] = new TextContainer
(
zhCN: "正在尝试从文本文件搜索KEY...",
Expand Down
28 changes: 28 additions & 0 deletions src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ private void ChangeSpecInfo(StreamSpec streamSpec, List<Mediainfo> mediainfos, r
}
}

private bool ValidateVideoResolution(StreamSpec streamSpec, List<Mediainfo> mediainfos)
{
var resolutionReg = DownloaderConfig.MyOptions.VideoFilter?.ResolutionReg;
if (resolutionReg == null)
return true;

if (streamSpec.MediaType is MediaType.AUDIO or MediaType.SUBTITLES)
return true;

var videoResolution = mediainfos.FirstOrDefault(m => m.Type == "Video" && !string.IsNullOrEmpty(m.Resolution))?.Resolution;
if (string.IsNullOrEmpty(videoResolution))
return true;

streamSpec.Resolution ??= videoResolution;
if (!resolutionReg.IsMatch(videoResolution))
{
Logger.ErrorMarkUp($"[red]{ResString.resolutionFilterNotMatch}[/]");
Logger.ErrorMarkUp($"[grey]{ResString.resolutionFilterExpectedActual}[/]", resolutionReg.ToString().EscapeMarkup(), videoResolution.EscapeMarkup());
return false;
}

return true;
}

private async Task<bool> DownloadStreamAsync(StreamSpec streamSpec, ProgressTask task, SpeedContainer speedContainer)
{
speedContainer.ResetVars();
Expand Down Expand Up @@ -203,6 +227,8 @@ private async Task<bool> DownloadStreamAsync(StreamSpec streamSpec, ProgressTask
Logger.WarnMarkUp(ResString.readingInfo);
mediaInfos = await MediainfoUtil.ReadInfoAsync(DownloaderConfig.MyOptions.FFmpegBinaryPath!, result.ActualFilePath);
mediaInfos.ForEach(info => Logger.InfoMarkUp(info.ToStringMarkUp()));
if (!ValidateVideoResolution(streamSpec, mediaInfos))
return false;
ChangeSpecInfo(streamSpec, mediaInfos, ref useAACFilter);
readInfo = true;
}
Expand Down Expand Up @@ -277,6 +303,8 @@ private async Task<bool> DownloadStreamAsync(StreamSpec streamSpec, ProgressTask
Logger.WarnMarkUp(ResString.readingInfo);
mediaInfos = await MediainfoUtil.ReadInfoAsync(DownloaderConfig.MyOptions.FFmpegBinaryPath!, result!.ActualFilePath);
mediaInfos.ForEach(info => Logger.InfoMarkUp(info.ToStringMarkUp()));
if (!ValidateVideoResolution(streamSpec, mediaInfos))
return false;
ChangeSpecInfo(streamSpec, mediaInfos, ref useAACFilter);
readInfo = true;
}
Expand Down
14 changes: 13 additions & 1 deletion src/N_m3u8DL-RE/Util/FilterUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ public static List<StreamSpec> DoFilterKeep(IEnumerable<StreamSpec> lists, Strea
if (filter.CodecsReg != null)
inputs = inputs.Where(i => i.Codecs != null && filter.CodecsReg.IsMatch(i.Codecs));
if (filter.ResolutionReg != null)
inputs = inputs.Where(i => i.Resolution != null && filter.ResolutionReg.IsMatch(i.Resolution));
{
var currentInputs = inputs.ToList();
var matched = currentInputs.Where(i => i.Resolution != null && filter.ResolutionReg.IsMatch(i.Resolution)).ToList();

if (matched.Count > 0)
{
inputs = matched;
}
else if (!(currentInputs.Count == 1 && string.IsNullOrEmpty(currentInputs[0].Resolution)))
{
inputs = [];
}
}
if (filter.FrameRateReg != null)
inputs = inputs.Where(i => i.FrameRate != null && filter.FrameRateReg.IsMatch($"{i.FrameRate}"));
if (filter.ChannelsReg != null)
Expand Down