From fbd7db198afece0a6182c109a1e6a60a08fed89d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 21 Mar 2022 10:27:39 -0500 Subject: docs and logs --- src/slskd/Shares/SharedFileCache.cs | 2 +- src/slskd/Shares/SoulseekFileFactory.cs | 35 ++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index d68cbc3b..02068e2a 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -253,7 +253,7 @@ namespace slskd.Shares try { var newFiles = System.IO.Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly) - .Select(filename => SoulseekFileFactory.Create(filename, share.LocalPath, share.RemotePath)) + .Select(filename => SoulseekFileFactory.Create(filename, maskedFilename: filename.ReplaceFirst(share.LocalPath, share.RemotePath))) .ToDictionary(file => file.Filename, file => file); // merge the new dictionary with the rest this will overwrite any duplicate keys, but keys are the fully diff --git a/src/slskd/Shares/SoulseekFileFactory.cs b/src/slskd/Shares/SoulseekFileFactory.cs index 0e345c05..7ff2d9d7 100644 --- a/src/slskd/Shares/SoulseekFileFactory.cs +++ b/src/slskd/Shares/SoulseekFileFactory.cs @@ -19,25 +19,46 @@ using System.IO; namespace slskd.Shares { + using System; using System.Collections.Generic; using System.Linq; + using Serilog; using Soulseek; + /// + /// Creates instances of . + /// public interface ISoulseekFileFactory { - File Create(string filename, string localPath, string remotePath); + /// + /// Creates an instance of from the given path. + /// + /// The fully qualified path to the file. + /// The masked filename. + /// The created instance. + File Create(string filename, string maskedFilename); } + /// + /// Creates instances of . + /// public class SoulseekFileFactory : ISoulseekFileFactory { - private static readonly string[] VideoExtensions = { "mkv", "ogv", "avi", "wmv", "asf", "mp4", "m4p", "m4v", "mpg", "mpe", "mpv", "mpg", "m2v" }; private static readonly string[] AudioExtensions = { "aa", "aax", "aac", "aiff", "ape", "dsf", "flac", "m4a", "m4b", "m4p", "mp3", "mpc", "mpp", "ogg", "oga", "wav", "wma", "wv", "webm" }; + private static readonly string[] VideoExtensions = { "mkv", "ogv", "avi", "wmv", "asf", "mp4", "m4p", "m4v", "mpg", "mpe", "mpv", "mpg", "m2v" }; private static readonly HashSet SupportedExtensions = AudioExtensions.Concat(VideoExtensions).ToHashSet(); - public File Create(string filename, string localPath, string remotePath) + private ILogger Log { get; } = Serilog.Log.ForContext(); + + /// + /// Creates an instance of from the given path. + /// + /// The fully qualified path to the file. + /// The masked filename. + /// The created instance. + public File Create(string filename, string maskedFilename) { var code = 1; - var maskedFilename = filename.ReplaceFirst(localPath, remotePath); var size = new FileInfo(filename).Length; var extension = Path.GetExtension(filename)[1..].ToLowerInvariant(); List attributeList = default; @@ -60,9 +81,9 @@ namespace slskd.Shares attributeList.Add(new FileAttribute(FileAttributeType.BitDepth, file.Properties.BitsPerSample)); } } - catch + catch (Exception ex) { - // unsupported or corrupt file, noop + Log.Warning("Failed to read metadata from file '{Filename}'; the file is an unsupported format or may be corrupt ({ExceptionType})", filename, ex.GetType().Name); } finally { @@ -73,4 +94,4 @@ namespace slskd.Shares return new File(code, maskedFilename, size, extension, attributeList); } } -} +} \ No newline at end of file -- cgit v1.2.3