Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Added NzbFile.GetSegmentIds() extension method.
nzbdav-dev06ff7252f3ff
diff --git a/backend/Clients/UsenetStreamingClient.cs b/backend/Clients/UsenetStreamingClient.csindex eda26a06..8d41a484 100644--- a/backend/Clients/UsenetStreamingClient.cs+++ b/backend/Clients/UsenetStreamingClient.cs@@ -2,6 +2,7 @@using NzbWebDAV.Clients.Connections;using NzbWebDAV.Config;using NzbWebDAV.Exceptions;+using NzbWebDAV.Extensions;using NzbWebDAV.Streams;using NzbWebDAV.Websocket;using Usenet.Nntp.Responses;@@ -84,11 +85,16 @@ public class UsenetStreamingClientpublic async Task<NzbFileStream> GetFileStream(NzbFile nzbFile, int concurrentConnections, CancellationToken ct){- var segmentIds = nzbFile.Segments.Select(x => x.MessageId.Value).ToArray();+ var segmentIds = nzbFile.GetSegmentIds();var fileSize = await _client.GetFileSizeAsync(nzbFile, cancellationToken: ct);return new NzbFileStream(segmentIds, fileSize, _client, concurrentConnections);}+ public NzbFileStream GetFileStream(NzbFile nzbFile, long fileSize, int concurrentConnections)+ {+ return new NzbFileStream(nzbFile.GetSegmentIds(), fileSize, _client, concurrentConnections);+ }+public NzbFileStream GetFileStream(string[] segmentIds, long fileSize, int concurrentConnections){return new NzbFileStream(segmentIds, fileSize, _client, concurrentConnections);diff --git a/backend/Extensions/NzbFileExtensions.cs b/backend/Extensions/NzbFileExtensions.csindex 1f01211b..82bc8059 100644--- a/backend/Extensions/NzbFileExtensions.cs+++ b/backend/Extensions/NzbFileExtensions.cs@@ -5,6 +5,13 @@ namespace NzbWebDAV.Extensions;public static class NzbFileExtensions{+ public static string[] GetSegmentIds(this NzbFile file)+ {+ return file.Segments+ .Select(x => x.MessageId.Value)+ .ToArray();+ }+public static string[] GetOrderedSegmentIds(this NzbFile file){return file.Segmentsdiff --git a/backend/Queue/DeobfuscationSteps/2.GetPar2FileDescriptors/GetPar2FileDescriptorsStep.cs b/backend/Queue/DeobfuscationSteps/2.GetPar2FileDescriptors/GetPar2FileDescriptorsStep.csindex ff20518d..e6e60be7 100644--- a/backend/Queue/DeobfuscationSteps/2.GetPar2FileDescriptors/GetPar2FileDescriptorsStep.cs+++ b/backend/Queue/DeobfuscationSteps/2.GetPar2FileDescriptors/GetPar2FileDescriptorsStep.cs@@ -1,4 +1,5 @@using NzbWebDAV.Clients;+using NzbWebDAV.Extensions;using NzbWebDAV.Par2Recovery;using NzbWebDAV.Par2Recovery.Packets;using NzbWebDAV.Queue.DeobfuscationSteps._1.FetchFirstSegment;@@ -23,7 +24,7 @@ public static class GetPar2FileDescriptorsStep// return all file descriptorsvar fileDescriptors = new List<FileDesc>();- var segments = par2Index.NzbFile.Segments.Select(x => x.MessageId.Value).ToArray();+ var segments = par2Index.NzbFile.GetSegmentIds();var filesize = par2Index.NzbFile.Segments.Count == 1? par2Index.Header!.PartOffset + par2Index.Header!.PartSize: await client.GetFileSizeAsync(par2Index.NzbFile, cancellationToken);diff --git a/backend/Queue/FileAggregators/FileAggregator.cs b/backend/Queue/FileAggregators/FileAggregator.csindex 99006fb2..9ab6d635 100644--- a/backend/Queue/FileAggregators/FileAggregator.cs+++ b/backend/Queue/FileAggregators/FileAggregator.cs@@ -1,5 +1,6 @@using NzbWebDAV.Database;using NzbWebDAV.Database.Models;+using NzbWebDAV.Extensions;using NzbWebDAV.Queue.FileProcessors;namespace NzbWebDAV.Queue.FileAggregators;@@ -24,7 +25,7 @@ public class FileAggregator(DavDatabaseClient dbClient, DavItem mountDirectory)var davNzbFile = new DavNzbFile(){Id = davItem.Id,- SegmentIds = result.NzbFile.Segments.Select(x => x.MessageId.Value).ToArray(),+ SegmentIds = result.NzbFile.GetSegmentIds(),};dbClient.Ctx.Items.Add(davItem);diff --git a/backend/Queue/FileAggregators/RarAggregator.cs b/backend/Queue/FileAggregators/RarAggregator.csindex 1e7ff62f..765f01f7 100644--- a/backend/Queue/FileAggregators/RarAggregator.cs+++ b/backend/Queue/FileAggregators/RarAggregator.cs@@ -1,5 +1,6 @@using NzbWebDAV.Database;using NzbWebDAV.Database.Models;+using NzbWebDAV.Extensions;using NzbWebDAV.Queue.FileProcessors;using NzbWebDAV.Utils;@@ -25,11 +26,11 @@ public class RarAggregator(DavDatabaseClient dbClient, DavItem mountDirectory) :foreach (var fileSegment in archivePart.StoredFileSegments){if (!archiveFiles.ContainsKey(fileSegment.PathWithinArchive))- archiveFiles.Add(fileSegment.PathWithinArchive, new List<DavRarFile.RarPart>());+ archiveFiles.Add(fileSegment.PathWithinArchive, []);archiveFiles[fileSegment.PathWithinArchive].Add(new DavRarFile.RarPart(){- SegmentIds = archivePart.NzbFile.Segments.Select(x => x.MessageId.Value).ToArray(),+ SegmentIds = archivePart.NzbFile.GetSegmentIds(),PartSize = archivePart.PartSize,Offset = fileSegment.Offset,ByteCount = fileSegment.ByteCount,diff --git a/backend/Queue/FileProcessors/RarProcessor.cs b/backend/Queue/FileProcessors/RarProcessor.csindex 2d0b15d6..44e2b00c 100644--- a/backend/Queue/FileProcessors/RarProcessor.cs+++ b/backend/Queue/FileProcessors/RarProcessor.cs@@ -104,9 +104,8 @@ public class RarProcessor(private async Task<NzbFileStream> GetNzbFileStream(){- var segments = nzbFile.Segments.Select(x => x.MessageId.Value).ToArray();var filesize = fileinfo.FileSize ?? await usenet.GetFileSizeAsync(nzbFile, ct);- return usenet.GetFileStream(segments, filesize, concurrentConnections: 1);+ return usenet.GetFileStream(nzbFile, filesize, concurrentConnections: 1);}public new class Result : BaseProcessor.Result