Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Support cases where filename is entirely in the nzb file subject.

nzbdav-dev514baf0b7a43
diff --git a/backend/Extensions/NzbFileExtensions.cs b/backend/Extensions/NzbFileExtensions.cs
index 19f793ba..4ea20532 100644
--- a/backend/Extensions/NzbFileExtensions.cs
+++ b/backend/Extensions/NzbFileExtensions.cs
@@ -18,7 +18,8 @@ public static class NzbFileExtensions
return GetFirstValidNonEmptyFilename(
() => TryParseFilename1(file),
() => TryParseFilename2(file),
- () => TryParseFilename3(file)
+ () => TryParseFilename3(file),
+ () => TryParseFilename4(file)
);
}
@@ -47,6 +48,13 @@ public static class NzbFileExtensions
return match.Success ? match.Groups[1].Value : "";
}
+ private static string TryParseFilename4(this NzbFile file)
+ {
+ // example: `file.mkv` — no spaces allowed
+ var match = Regex.Match(file.Subject, @"^[^\s]+\.\w{2,6}$");
+ return match.Success ? match.Value : "";
+ }
+
private static string GetFirstValidNonEmptyFilename(params Func<string>[] funcs)
{
return funcs
diff --git a/backend/Services/FileProcessors/FileProcessor.cs b/backend/Services/FileProcessors/FileProcessor.cs
index 0384f663..3eecfbe3 100644
--- a/backend/Services/FileProcessors/FileProcessor.cs
+++ b/backend/Services/FileProcessors/FileProcessor.cs
@@ -17,7 +17,7 @@ public class FileProcessor(NzbFile nzbFile, UsenetStreamingClient usenet, Cancel
var firstSegment = nzbFile.Segments[0].MessageId.Value;
var header = await usenet.GetSegmentYencHeaderAsync(firstSegment, default);
var subjectFilename = nzbFile.GetSubjectFileName();
- var fileName = Path.GetFileName(subjectFilename != "" ? subjectFilename : header.FileName);
+ var fileName = GetFileName(subjectFilename, header.FileName);
return new Result()
{
@@ -27,6 +27,17 @@ public class FileProcessor(NzbFile nzbFile, UsenetStreamingClient usenet, Cancel
};
}
+ private static string GetFileName(string subjectFilename, string headerFilename)
+ {
+ // prioritize the subject filename with fallback to header filename
+ // unless the header filename has an `.mkv` extension while the subject filename doesn't.
+ subjectFilename = Path.GetFileName(subjectFilename);
+ headerFilename = Path.GetFileName(headerFilename);
+ if (subjectFilename != "" && Path.GetExtension(subjectFilename) == ".mkv") return subjectFilename;
+ if (headerFilename != "" && Path.GetExtension(headerFilename) == ".mkv") return headerFilename;
+ return subjectFilename != "" ? subjectFilename : headerFilename;
+ }
+
public new class Result : BaseProcessor.Result
{
public NzbFile NzbFile { get; init; } = null!;