Skip to content

Commit 514baf0

Browse files
committed
Support cases where filename is entirely in the nzb file subject.
1 parent 1d0153d commit 514baf0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

backend/Extensions/NzbFileExtensions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public static string GetSubjectFileName(this NzbFile file)
1818
return GetFirstValidNonEmptyFilename(
1919
() => TryParseFilename1(file),
2020
() => TryParseFilename2(file),
21-
() => TryParseFilename3(file)
21+
() => TryParseFilename3(file),
22+
() => TryParseFilename4(file)
2223
);
2324
}
2425

@@ -47,6 +48,13 @@ private static string TryParseFilename3(this NzbFile file)
4748
return match.Success ? match.Groups[1].Value : "";
4849
}
4950

51+
private static string TryParseFilename4(this NzbFile file)
52+
{
53+
// example: `file.mkv` — no spaces allowed
54+
var match = Regex.Match(file.Subject, @"^[^\s]+\.\w{2,6}$");
55+
return match.Success ? match.Value : "";
56+
}
57+
5058
private static string GetFirstValidNonEmptyFilename(params Func<string>[] funcs)
5159
{
5260
return funcs

backend/Services/FileProcessors/FileProcessor.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static bool CanProcess(NzbFile file)
1717
var firstSegment = nzbFile.Segments[0].MessageId.Value;
1818
var header = await usenet.GetSegmentYencHeaderAsync(firstSegment, default);
1919
var subjectFilename = nzbFile.GetSubjectFileName();
20-
var fileName = Path.GetFileName(subjectFilename != "" ? subjectFilename : header.FileName);
20+
var fileName = GetFileName(subjectFilename, header.FileName);
2121

2222
return new Result()
2323
{
@@ -27,6 +27,17 @@ public static bool CanProcess(NzbFile file)
2727
};
2828
}
2929

30+
private static string GetFileName(string subjectFilename, string headerFilename)
31+
{
32+
// prioritize the subject filename with fallback to header filename
33+
// unless the header filename has an `.mkv` extension while the subject filename doesn't.
34+
subjectFilename = Path.GetFileName(subjectFilename);
35+
headerFilename = Path.GetFileName(headerFilename);
36+
if (subjectFilename != "" && Path.GetExtension(subjectFilename) == ".mkv") return subjectFilename;
37+
if (headerFilename != "" && Path.GetExtension(headerFilename) == ".mkv") return headerFilename;
38+
return subjectFilename != "" ? subjectFilename : headerFilename;
39+
}
40+
3041
public new class Result : BaseProcessor.Result
3142
{
3243
public NzbFile NzbFile { get; init; } = null!;

0 commit comments

Comments
 (0)