Skip to content

Commit 62507fb

Browse files
committed
Ignore non-video files with missing articles.
1 parent cc879a5 commit 62507fb

File tree

6 files changed

+53
-22
lines changed

6 files changed

+53
-22
lines changed

backend/Queue/FileProcessors/BaseProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
public abstract class BaseProcessor
44
{
5-
public abstract Task<Result> ProcessAsync();
5+
public abstract Task<Result?> ProcessAsync();
66
public class Result { }
77
}

backend/Queue/FileProcessors/FileProcessor.cs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,46 @@
11
using NzbWebDAV.Clients;
2+
using NzbWebDAV.Exceptions;
3+
using NzbWebDAV.Utils;
4+
using Serilog;
25
using Usenet.Nzb;
36

47
namespace NzbWebDAV.Queue.FileProcessors;
58

6-
public class FileProcessor(NzbFile nzbFile, string filename, UsenetStreamingClient usenet, CancellationToken ct) : BaseProcessor
9+
public class FileProcessor(
10+
NzbFile nzbFile,
11+
string filename,
12+
UsenetStreamingClient usenet,
13+
CancellationToken ct
14+
) : BaseProcessor
715
{
816
public static bool CanProcess(string filename)
917
{
1018
// skip par2 files
1119
return !filename.EndsWith(".par2", StringComparison.OrdinalIgnoreCase);
1220
}
1321

14-
public override async Task<BaseProcessor.Result> ProcessAsync()
22+
public override async Task<BaseProcessor.Result?> ProcessAsync()
1523
{
16-
var firstSegment = nzbFile.Segments[0].MessageId.Value;
17-
var header = await usenet.GetSegmentYencHeaderAsync(firstSegment, default);
24+
try
25+
{
26+
var firstSegment = nzbFile.Segments[0].MessageId.Value;
27+
var header = await usenet.GetSegmentYencHeaderAsync(firstSegment, ct);
28+
29+
return new Result()
30+
{
31+
NzbFile = nzbFile,
32+
FileName = filename,
33+
FileSize = header.FileSize,
34+
};
35+
}
1836

19-
return new Result()
37+
// Ignore missing articles if it's not a video file.
38+
// In that case, simply skip the file altogether.
39+
catch (UsenetArticleNotFoundException) when (!FilenameUtil.IsVideoFile(filename))
2040
{
21-
NzbFile = nzbFile,
22-
FileName = filename,
23-
FileSize = header.FileSize,
24-
};
41+
Log.Warning($"File `{filename}` has missing articles. Skipping file since it is not a video.");
42+
return null;
43+
}
2544
}
2645

2746
public new class Result : BaseProcessor.Result

backend/Queue/FileProcessors/RarProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static bool CanProcess(string filename)
2222
return IsRarFile(filename);
2323
}
2424

25-
public override async Task<BaseProcessor.Result> ProcessAsync()
25+
public override async Task<BaseProcessor.Result?> ProcessAsync()
2626
{
2727
try
2828
{

backend/Queue/QueueItemProcessor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ private async Task ProcessQueueItemAsync(DateTime startTime)
101101
.ToList();
102102

103103
// wait for all file processing tasks to finish
104-
var fileProcessingResults = await TaskUtil.WhenAllOrError(fileProcessingTasks, progress);
104+
var fileProcessingResults = (await TaskUtil.WhenAllOrError(fileProcessingTasks, progress))
105+
.Where(x => x is not null)
106+
.Select(x => x!)
107+
.ToList();
105108

106109
// update the database
107110
await MarkQueueItemCompleted(startTime, error: null, () =>

backend/Queue/Validators/EnsureImportableVideoValidator.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,12 @@
22
using NzbWebDAV.Database;
33
using NzbWebDAV.Database.Models;
44
using NzbWebDAV.Exceptions;
5+
using NzbWebDAV.Utils;
56

67
namespace NzbWebDAV.Queue.Validators;
78

89
public class EnsureImportableVideoValidator(DavDatabaseClient dbClient)
910
{
10-
private static readonly HashSet<string> VideoExtensions =
11-
[
12-
".webm", ".m4v", ".3gp", ".nsv", ".ty", ".strm", ".rm", ".rmvb", ".m3u", ".ifo", ".mov", ".qt", ".divx",
13-
".xvid", ".bivx", ".nrg", ".pva", ".wmv", ".asf", ".asx", ".ogm", ".ogv", ".m2v", ".avi", ".bin", ".dat",
14-
".dvr-ms", ".mpg", ".mpeg", ".mp4", ".avc", ".vp3", ".svq3", ".nuv", ".viv", ".dv", ".fli", ".flv", ".wpl",
15-
".img", ".iso", ".vob", ".mkv", ".mk3d", ".ts", ".wtv", ".m2ts"
16-
];
17-
1811
public void ThrowIfValidationFails()
1912
{
2013
if (!IsValid())
@@ -29,7 +22,6 @@ private bool IsValid()
2922
.Where(x => x.State == EntityState.Added)
3023
.Select(x => x.Entity)
3124
.Where(x => x.Type != DavItem.ItemType.Directory)
32-
.Select(x => Path.GetExtension(x.Name).ToLower())
33-
.Any(x => VideoExtensions.Contains(x));
25+
.Any(x => FilenameUtil.IsVideoFile(x.Name));
3426
}
3527
}

backend/Utils/FilenameUtil.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace NzbWebDAV.Utils;
2+
3+
public class FilenameUtil
4+
{
5+
private static readonly HashSet<string> VideoExtensions =
6+
[
7+
".webm", ".m4v", ".3gp", ".nsv", ".ty", ".strm", ".rm", ".rmvb", ".m3u", ".ifo", ".mov", ".qt", ".divx",
8+
".xvid", ".bivx", ".nrg", ".pva", ".wmv", ".asf", ".asx", ".ogm", ".ogv", ".m2v", ".avi", ".bin", ".dat",
9+
".dvr-ms", ".mpg", ".mpeg", ".mp4", ".avc", ".vp3", ".svq3", ".nuv", ".viv", ".dv", ".fli", ".flv", ".wpl",
10+
".img", ".iso", ".vob", ".mkv", ".mk3d", ".ts", ".wtv", ".m2ts"
11+
];
12+
13+
public static bool IsVideoFile(string filename)
14+
{
15+
return VideoExtensions.Contains(Path.GetExtension(filename).ToLower());
16+
}
17+
}

0 commit comments

Comments
 (0)