Skip to content

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

C#

Ignore non-video files with missing articles.

nzbdav-dev62507fb9ab89
diff --git a/backend/Queue/FileProcessors/BaseProcessor.cs b/backend/Queue/FileProcessors/BaseProcessor.cs
index 3a7228b8..d7f4634b 100644
--- a/backend/Queue/FileProcessors/BaseProcessor.cs
+++ b/backend/Queue/FileProcessors/BaseProcessor.cs
@@ -2,6 +2,6 @@
public abstract class BaseProcessor
{
- public abstract Task<Result> ProcessAsync();
+ public abstract Task<Result?> ProcessAsync();
public class Result { }
}
\ No newline at end of file
diff --git a/backend/Queue/FileProcessors/FileProcessor.cs b/backend/Queue/FileProcessors/FileProcessor.cs
index 0ae97758..134a03ba 100644
--- a/backend/Queue/FileProcessors/FileProcessor.cs
+++ b/backend/Queue/FileProcessors/FileProcessor.cs
@@ -1,9 +1,17 @@
using NzbWebDAV.Clients;
+using NzbWebDAV.Exceptions;
+using NzbWebDAV.Utils;
+using Serilog;
using Usenet.Nzb;
namespace NzbWebDAV.Queue.FileProcessors;
-public class FileProcessor(NzbFile nzbFile, string filename, UsenetStreamingClient usenet, CancellationToken ct) : BaseProcessor
+public class FileProcessor(
+ NzbFile nzbFile,
+ string filename,
+ UsenetStreamingClient usenet,
+ CancellationToken ct
+) : BaseProcessor
{
public static bool CanProcess(string filename)
{
@@ -11,17 +19,28 @@ public class FileProcessor(NzbFile nzbFile, string filename, UsenetStreamingClie
return !filename.EndsWith(".par2", StringComparison.OrdinalIgnoreCase);
}
- public override async Task<BaseProcessor.Result> ProcessAsync()
+ public override async Task<BaseProcessor.Result?> ProcessAsync()
{
- var firstSegment = nzbFile.Segments[0].MessageId.Value;
- var header = await usenet.GetSegmentYencHeaderAsync(firstSegment, default);
+ try
+ {
+ var firstSegment = nzbFile.Segments[0].MessageId.Value;
+ var header = await usenet.GetSegmentYencHeaderAsync(firstSegment, ct);
+
+ return new Result()
+ {
+ NzbFile = nzbFile,
+ FileName = filename,
+ FileSize = header.FileSize,
+ };
+ }
- return new Result()
+ // Ignore missing articles if it's not a video file.
+ // In that case, simply skip the file altogether.
+ catch (UsenetArticleNotFoundException) when (!FilenameUtil.IsVideoFile(filename))
{
- NzbFile = nzbFile,
- FileName = filename,
- FileSize = header.FileSize,
- };
+ Log.Warning($"File `{filename}` has missing articles. Skipping file since it is not a video.");
+ return null;
+ }
}
public new class Result : BaseProcessor.Result
diff --git a/backend/Queue/FileProcessors/RarProcessor.cs b/backend/Queue/FileProcessors/RarProcessor.cs
index 5df32f32..c2dbc9b2 100644
--- a/backend/Queue/FileProcessors/RarProcessor.cs
+++ b/backend/Queue/FileProcessors/RarProcessor.cs
@@ -22,7 +22,7 @@ public class RarProcessor(
return IsRarFile(filename);
}
- public override async Task<BaseProcessor.Result> ProcessAsync()
+ public override async Task<BaseProcessor.Result?> ProcessAsync()
{
try
{
diff --git a/backend/Queue/QueueItemProcessor.cs b/backend/Queue/QueueItemProcessor.cs
index eb4e0cbe..c2f110ff 100644
--- a/backend/Queue/QueueItemProcessor.cs
+++ b/backend/Queue/QueueItemProcessor.cs
@@ -101,7 +101,10 @@ public class QueueItemProcessor(
.ToList();
// wait for all file processing tasks to finish
- var fileProcessingResults = await TaskUtil.WhenAllOrError(fileProcessingTasks, progress);
+ var fileProcessingResults = (await TaskUtil.WhenAllOrError(fileProcessingTasks, progress))
+ .Where(x => x is not null)
+ .Select(x => x!)
+ .ToList();
// update the database
await MarkQueueItemCompleted(startTime, error: null, () =>
diff --git a/backend/Queue/Validators/EnsureImportableVideoValidator.cs b/backend/Queue/Validators/EnsureImportableVideoValidator.cs
index 47d08f8c..c38a38a7 100644
--- a/backend/Queue/Validators/EnsureImportableVideoValidator.cs
+++ b/backend/Queue/Validators/EnsureImportableVideoValidator.cs
@@ -2,19 +2,12 @@
using NzbWebDAV.Database;
using NzbWebDAV.Database.Models;
using NzbWebDAV.Exceptions;
+using NzbWebDAV.Utils;
namespace NzbWebDAV.Queue.Validators;
public class EnsureImportableVideoValidator(DavDatabaseClient dbClient)
{
- private static readonly HashSet<string> VideoExtensions =
- [
- ".webm", ".m4v", ".3gp", ".nsv", ".ty", ".strm", ".rm", ".rmvb", ".m3u", ".ifo", ".mov", ".qt", ".divx",
- ".xvid", ".bivx", ".nrg", ".pva", ".wmv", ".asf", ".asx", ".ogm", ".ogv", ".m2v", ".avi", ".bin", ".dat",
- ".dvr-ms", ".mpg", ".mpeg", ".mp4", ".avc", ".vp3", ".svq3", ".nuv", ".viv", ".dv", ".fli", ".flv", ".wpl",
- ".img", ".iso", ".vob", ".mkv", ".mk3d", ".ts", ".wtv", ".m2ts"
- ];
-
public void ThrowIfValidationFails()
{
if (!IsValid())
@@ -29,7 +22,6 @@ public class EnsureImportableVideoValidator(DavDatabaseClient dbClient)
.Where(x => x.State == EntityState.Added)
.Select(x => x.Entity)
.Where(x => x.Type != DavItem.ItemType.Directory)
- .Select(x => Path.GetExtension(x.Name).ToLower())
- .Any(x => VideoExtensions.Contains(x));
+ .Any(x => FilenameUtil.IsVideoFile(x.Name));
}
}
\ No newline at end of file
diff --git a/backend/Utils/FilenameUtil.cs b/backend/Utils/FilenameUtil.cs
new file mode 100644
index 00000000..34c5edce
--- /dev/null
+++ b/backend/Utils/FilenameUtil.cs
@@ -0,0 +1,17 @@
+namespace NzbWebDAV.Utils;
+
+public class FilenameUtil
+{
+ private static readonly HashSet<string> VideoExtensions =
+ [
+ ".webm", ".m4v", ".3gp", ".nsv", ".ty", ".strm", ".rm", ".rmvb", ".m3u", ".ifo", ".mov", ".qt", ".divx",
+ ".xvid", ".bivx", ".nrg", ".pva", ".wmv", ".asf", ".asx", ".ogm", ".ogv", ".m2v", ".avi", ".bin", ".dat",
+ ".dvr-ms", ".mpg", ".mpeg", ".mp4", ".avc", ".vp3", ".svq3", ".nuv", ".viv", ".dv", ".fli", ".flv", ".wpl",
+ ".img", ".iso", ".vob", ".mkv", ".mk3d", ".ts", ".wtv", ".m2ts"
+ ];
+
+ public static bool IsVideoFile(string filename)
+ {
+ return VideoExtensions.Contains(Path.GetExtension(filename).ToLower());
+ }
+}
\ No newline at end of file