From e23101315437c2731650a01b3b2a0a648f867ce0 Mon Sep 17 00:00:00 2001 From: Matthew Nau Date: Wed, 16 Mar 2022 23:31:35 -0400 Subject: change favicon color made favicon a blue gradient for better visibility in darkmode browsers; reference to the original soulseek color --- src/web/public/favicon.ico | Bin 1150 -> 15086 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to 'src') diff --git a/src/web/public/favicon.ico b/src/web/public/favicon.ico index 6c4ad2c2..c49cae35 100644 Binary files a/src/web/public/favicon.ico and b/src/web/public/favicon.ico differ -- cgit v1.2.3 From 98eda1c5485195da455c3a7d4d9c6b8fd677226c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 18 Mar 2022 15:48:32 -0500 Subject: add taglib --- src/slskd/slskd.csproj | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj index 70c689b8..251412e9 100644 --- a/src/slskd/slskd.csproj +++ b/src/slskd/slskd.csproj @@ -76,6 +76,7 @@ + -- cgit v1.2.3 From 0f12d85c5babd68d8b3702279cfcb7255978a9a9 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 18 Mar 2022 15:48:43 -0500 Subject: move Share --- src/slskd/Shares/Domain/Share.cs | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/slskd/Shares/Domain/Share.cs (limited to 'src') diff --git a/src/slskd/Shares/Domain/Share.cs b/src/slskd/Shares/Domain/Share.cs new file mode 100644 index 00000000..890c8565 --- /dev/null +++ b/src/slskd/Shares/Domain/Share.cs @@ -0,0 +1,75 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Shares +{ + using System.Linq; + using System.Text.RegularExpressions; + + /// + /// A file share. + /// + public sealed class Share + { + /// + /// Initializes a new instance of the class. + /// + /// + public Share(string share) + { + Raw = share; + IsExcluded = share.StartsWith('-') || share.StartsWith('!'); + + if (IsExcluded) + { + share = share[1..]; + } + + // test to see whether an alias has been specified + var matches = Regex.Matches(share, @"^\[(.*)\](.*)$"); + + if (matches.Any()) + { + // split the alias from the path, and validate the alias + var groups = matches[0].Groups; + Alias = groups[1].Value; + LocalPath = groups[2].Value; + } + else + { + Alias = share.Split(new[] { '/', '\\' }).Last(); + LocalPath = share; + } + + var parent = System.IO.Directory.GetParent(LocalPath).FullName.TrimEnd('/', '\\'); + + Mask = Compute.MaskHash(parent); + + var maskedPath = LocalPath.ReplaceFirst(parent, Mask); + + var aliasedSegment = LocalPath[(parent.Length + 1)..]; + RemotePath = maskedPath.ReplaceFirst(aliasedSegment, Alias); + } + + public string Alias { get; init; } + public bool IsExcluded { get; init; } + public string LocalPath { get; init; } + public string Mask { get; init; } + public string Raw { get; init; } + public string RemotePath { get; init; } + } +} -- cgit v1.2.3 From cac0d9ea1826e226e04eab5bed22f8571c8bec7a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 18 Mar 2022 15:49:00 -0500 Subject: add logic to create File with metadata --- src/slskd/Shares/Extensions.cs | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/slskd/Shares/Extensions.cs (limited to 'src') diff --git a/src/slskd/Shares/Extensions.cs b/src/slskd/Shares/Extensions.cs new file mode 100644 index 00000000..aa1936b5 --- /dev/null +++ b/src/slskd/Shares/Extensions.cs @@ -0,0 +1,66 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +using System.IO; + +namespace slskd.Shares +{ + using System.Collections.Generic; + using System.Linq; + using Soulseek; + + public static class Extensions + { + 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 HashSet SupportedExtensions = AudioExtensions.Concat(VideoExtensions).ToHashSet(); + + public static File ToSoulseekFile(this string filename, Share share) + { + var code = 1; + var maskedFilename = filename.ReplaceFirst(share.LocalPath, share.RemotePath); + var size = new FileInfo(filename).Length; + var extension = Path.GetExtension(filename)[1..].ToLowerInvariant(); + List attributeList = default; + + if (SupportedExtensions.Contains(extension)) + { + attributeList = new List(); + + try + { + var file = TagLib.File.Create(filename); + + attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds)); + attributeList.Add(new FileAttribute(FileAttributeType.BitRate, file.Properties.AudioBitrate)); + + if (file.Properties.BitsPerSample > 0) + { + attributeList.Add(new FileAttribute(FileAttributeType.SampleRate, file.Properties.AudioSampleRate)); + attributeList.Add(new FileAttribute(FileAttributeType.BitDepth, file.Properties.BitsPerSample)); + } + } + catch + { + // unsupported or corrupt file, noop + } + } + + return new File(code, maskedFilename, size, extension, attributeList); + } + } +} -- cgit v1.2.3 From ca97a7f48b1a1782a4fb38d9ee86c41a04fd58cc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 18 Mar 2022 15:49:10 -0500 Subject: gather metadata when processing shares --- src/slskd/Shares/SharedFileCache.cs | 48 +------------------------------------ 1 file changed, 1 insertion(+), 47 deletions(-) (limited to 'src') diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index ad2468da..f13eaad4 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -249,7 +249,7 @@ namespace slskd.Shares try { var newFiles = System.IO.Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly) - .Select(f => new File(1, f.ReplaceFirst(share.LocalPath, share.RemotePath), new FileInfo(f).Length, Path.GetExtension(f))) + .Select(f => f.ToSoulseekFile(share)) .ToDictionary(f => f.Filename, f => f); // merge the new dictionary with the rest this will overwrite any duplicate keys, but keys are the fully @@ -462,51 +462,5 @@ namespace slskd.Shares MaskedFiles = new Dictionary(); State.SetValue(state => state with { Directories = 0, Files = 0 }); } - - private sealed class Share - { - public Share(string share) - { - Raw = share; - IsExcluded = share.StartsWith('-') || share.StartsWith('!'); - - if (IsExcluded) - { - share = share[1..]; - } - - // test to see whether an alias has been specified - var matches = Regex.Matches(share, @"^\[(.*)\](.*)$"); - - if (matches.Any()) - { - // split the alias from the path, and validate the alias - var groups = matches[0].Groups; - Alias = groups[1].Value; - LocalPath = groups[2].Value; - } - else - { - Alias = share.Split(new[] { '/', '\\' }).Last(); - LocalPath = share; - } - - var parent = System.IO.Directory.GetParent(LocalPath).FullName.TrimEnd('/', '\\'); - - Mask = Compute.MaskHash(parent); - - var maskedPath = LocalPath.ReplaceFirst(parent, Mask); - - var aliasedSegment = LocalPath[(parent.Length + 1)..]; - RemotePath = maskedPath.ReplaceFirst(aliasedSegment, Alias); - } - - public string Alias { get; init; } - public bool IsExcluded { get; init; } - public string LocalPath { get; init; } - public string Mask { get; init; } - public string Raw { get; init; } - public string RemotePath { get; init; } - } } } \ No newline at end of file -- cgit v1.2.3 From 1deff8981e2f8dd8edb077501a6fbc106ff17988 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 20 Mar 2022 20:57:34 -0500 Subject: dispose TagLib files --- src/slskd/Shares/Extensions.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Shares/Extensions.cs b/src/slskd/Shares/Extensions.cs index aa1936b5..01e7e000 100644 --- a/src/slskd/Shares/Extensions.cs +++ b/src/slskd/Shares/Extensions.cs @@ -40,10 +40,11 @@ namespace slskd.Shares if (SupportedExtensions.Contains(extension)) { attributeList = new List(); + TagLib.File file = default; try { - var file = TagLib.File.Create(filename); + file = TagLib.File.Create(filename, TagLib.ReadStyle.Average); attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds)); attributeList.Add(new FileAttribute(FileAttributeType.BitRate, file.Properties.AudioBitrate)); @@ -58,6 +59,10 @@ namespace slskd.Shares { // unsupported or corrupt file, noop } + finally + { + file?.Dispose(); + } } return new File(code, maskedFilename, size, extension, attributeList); -- cgit v1.2.3 From ef73185e540d66a650164909993e84c6e3396aa5 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 20 Mar 2022 21:06:15 -0500 Subject: move extension method to SoulseekFileFactory --- src/slskd/Shares/Extensions.cs | 71 ------------------------------ src/slskd/Shares/SharedFileCache.cs | 10 +++-- src/slskd/Shares/SoulseekFileFactory.cs | 76 +++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 74 deletions(-) delete mode 100644 src/slskd/Shares/Extensions.cs create mode 100644 src/slskd/Shares/SoulseekFileFactory.cs (limited to 'src') diff --git a/src/slskd/Shares/Extensions.cs b/src/slskd/Shares/Extensions.cs deleted file mode 100644 index 01e7e000..00000000 --- a/src/slskd/Shares/Extensions.cs +++ /dev/null @@ -1,71 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// - -using System.IO; - -namespace slskd.Shares -{ - using System.Collections.Generic; - using System.Linq; - using Soulseek; - - public static class Extensions - { - 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 HashSet SupportedExtensions = AudioExtensions.Concat(VideoExtensions).ToHashSet(); - - public static File ToSoulseekFile(this string filename, Share share) - { - var code = 1; - var maskedFilename = filename.ReplaceFirst(share.LocalPath, share.RemotePath); - var size = new FileInfo(filename).Length; - var extension = Path.GetExtension(filename)[1..].ToLowerInvariant(); - List attributeList = default; - - if (SupportedExtensions.Contains(extension)) - { - attributeList = new List(); - TagLib.File file = default; - - try - { - file = TagLib.File.Create(filename, TagLib.ReadStyle.Average); - - attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds)); - attributeList.Add(new FileAttribute(FileAttributeType.BitRate, file.Properties.AudioBitrate)); - - if (file.Properties.BitsPerSample > 0) - { - attributeList.Add(new FileAttribute(FileAttributeType.SampleRate, file.Properties.AudioSampleRate)); - attributeList.Add(new FileAttribute(FileAttributeType.BitDepth, file.Properties.BitsPerSample)); - } - } - catch - { - // unsupported or corrupt file, noop - } - finally - { - file?.Dispose(); - } - } - - return new File(code, maskedFilename, size, extension, attributeList); - } - } -} diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index f13eaad4..d68cbc3b 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -86,10 +86,13 @@ namespace slskd.Shares /// Initializes a new instance of the class. /// /// + /// public SharedFileCache( - IOptionsMonitor optionsMonitor) + IOptionsMonitor optionsMonitor, + ISoulseekFileFactory soulseekFileFactory = null) { OptionsMonitor = optionsMonitor; + SoulseekFileFactory = soulseekFileFactory ?? new SoulseekFileFactory(); } /// @@ -105,6 +108,7 @@ namespace slskd.Shares private List Shares { get; set; } private SqliteConnection SQLite { get; set; } private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1); + private ISoulseekFileFactory SoulseekFileFactory { get; } /// /// Returns the contents of the cache. @@ -249,8 +253,8 @@ namespace slskd.Shares try { var newFiles = System.IO.Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly) - .Select(f => f.ToSoulseekFile(share)) - .ToDictionary(f => f.Filename, f => f); + .Select(filename => SoulseekFileFactory.Create(filename, 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 // qualified name the only time this *should* cause problems is if one of the shares is a subdirectory of another. diff --git a/src/slskd/Shares/SoulseekFileFactory.cs b/src/slskd/Shares/SoulseekFileFactory.cs new file mode 100644 index 00000000..b7223c56 --- /dev/null +++ b/src/slskd/Shares/SoulseekFileFactory.cs @@ -0,0 +1,76 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +using System.IO; + +namespace slskd.Shares +{ + using System.Collections.Generic; + using System.Linq; + using Soulseek; + + public interface ISoulseekFileFactory + { + File Create(string filename, string localPath, string remotePath); + } + + 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 HashSet SupportedExtensions = AudioExtensions.Concat(VideoExtensions).ToHashSet(); + + public File Create(string filename, string localPath, string remotePath) + { + 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; + + if (SupportedExtensions.Contains(extension)) + { + attributeList = new List(); + TagLib.File file = default; + + try + { + file = TagLib.File.Create(filename, TagLib.ReadStyle.Average); + + attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds)); + attributeList.Add(new FileAttribute(FileAttributeType.BitRate, file.Properties.AudioBitrate)); + + if (file.Properties.BitsPerSample > 0) + { + attributeList.Add(new FileAttribute(FileAttributeType.SampleRate, file.Properties.AudioSampleRate)); + attributeList.Add(new FileAttribute(FileAttributeType.BitDepth, file.Properties.BitsPerSample)); + } + } + catch + { + // unsupported or corrupt file, noop + } + finally + { + file?.Dispose(); + } + } + + return new File(code, maskedFilename, size, extension, attributeList); + } + } +} -- cgit v1.2.3 From dfeed19ea66c19dfa05ea913d0c3c3d8d1b26169 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 20 Mar 2022 21:20:57 -0500 Subject: use the official TagLib nuget --- src/slskd/slskd.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj index 251412e9..e2c34310 100644 --- a/src/slskd/slskd.csproj +++ b/src/slskd/slskd.csproj @@ -76,7 +76,7 @@ - + -- cgit v1.2.3 From 3b82defbf5d27411c84fd06a2b69ab2d85fd3aaa Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 20 Mar 2022 21:21:06 -0500 Subject: read images lazily --- src/slskd/Shares/SoulseekFileFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Shares/SoulseekFileFactory.cs b/src/slskd/Shares/SoulseekFileFactory.cs index b7223c56..0e345c05 100644 --- a/src/slskd/Shares/SoulseekFileFactory.cs +++ b/src/slskd/Shares/SoulseekFileFactory.cs @@ -49,7 +49,7 @@ namespace slskd.Shares try { - file = TagLib.File.Create(filename, TagLib.ReadStyle.Average); + file = TagLib.File.Create(filename, TagLib.ReadStyle.Average | TagLib.ReadStyle.PictureLazy); attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds)); attributeList.Add(new FileAttribute(FileAttributeType.BitRate, file.Properties.AudioBitrate)); -- cgit v1.2.3 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 From 4f459248d7d2ee624490cd41bc085a66f4d76787 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 22 Mar 2022 10:40:51 -0500 Subject: identify VBR files, reorder attributes to ensure client compatibility --- src/slskd/Shares/SoulseekFileFactory.cs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/slskd/Shares/SoulseekFileFactory.cs b/src/slskd/Shares/SoulseekFileFactory.cs index 7ff2d9d7..ccc3e6b0 100644 --- a/src/slskd/Shares/SoulseekFileFactory.cs +++ b/src/slskd/Shares/SoulseekFileFactory.cs @@ -72,11 +72,23 @@ namespace slskd.Shares { file = TagLib.File.Create(filename, TagLib.ReadStyle.Average | TagLib.ReadStyle.PictureLazy); - attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds)); - attributeList.Add(new FileAttribute(FileAttributeType.BitRate, file.Properties.AudioBitrate)); + // try to mimick the behavior of existing clients by providing attributes selectively and in a specific order, + // depending on whether files use a lossless or lossy codec. lossless files should have BitsPerSample, while lossy + // will not. this may not be the best way to determine this. + bool isLossless = file.Properties.BitsPerSample > 0; - if (file.Properties.BitsPerSample > 0) + if (!isLossless) { + // per Nicotine+ docs, Soulseek NS, Nicotine+, Museek+, SoulSeeX all send bit rate, length, then VBR + attributeList.Add(new FileAttribute(FileAttributeType.BitRate, file.Properties.AudioBitrate)); + attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds)); + attributeList.Add(new FileAttribute(FileAttributeType.VariableBitRate, IsVBR(file) ? 1 : 0)); + } + else + { + // SoulseekQt 2015-6-12 and later provides the length, sample rate and bit depth for lossless files + // bitrate can be deduced from this information + attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds)); attributeList.Add(new FileAttribute(FileAttributeType.SampleRate, file.Properties.AudioSampleRate)); attributeList.Add(new FileAttribute(FileAttributeType.BitDepth, file.Properties.BitsPerSample)); } @@ -93,5 +105,16 @@ namespace slskd.Shares return new File(code, maskedFilename, size, extension, attributeList); } + + private bool IsVBR(TagLib.File file) + { + static bool HasVBRIHeader(TagLib.Mpeg.AudioHeader header) => header.VBRIHeader.Present && header.VBRIHeader.TotalSize > 0; + static bool HasXingHeader(TagLib.Mpeg.AudioHeader header) => header.XingHeader.Present && header.XingHeader.TotalSize > 0; + + return file.Properties.Codecs.Any(c => + (c is TagLib.Mpeg.AudioHeader h && (HasVBRIHeader(h) || HasXingHeader(h))) + || c is TagLib.Aac.AudioHeader + || c is TagLib.Ogg.Codec); + } } } \ No newline at end of file -- cgit v1.2.3 From 6fc228ade7a3b564dff1249daa1e68f49c93014a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 23 Mar 2022 03:33:39 +0000 Subject: Bump node-forge from 1.2.1 to 1.3.0 in /src/web Bumps [node-forge](https://github.com/digitalbazaar/forge) from 1.2.1 to 1.3.0. - [Release notes](https://github.com/digitalbazaar/forge/releases) - [Changelog](https://github.com/digitalbazaar/forge/blob/main/CHANGELOG.md) - [Commits](https://github.com/digitalbazaar/forge/compare/v1.2.1...v1.3.0) --- updated-dependencies: - dependency-name: node-forge dependency-type: indirect ... Signed-off-by: dependabot[bot] --- src/web/package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/web/package-lock.json b/src/web/package-lock.json index fc5fb063..4dac4452 100644 --- a/src/web/package-lock.json +++ b/src/web/package-lock.json @@ -12956,9 +12956,9 @@ } }, "node_modules/node-forge": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.2.1.tgz", - "integrity": "sha512-Fcvtbb+zBcZXbTTVwqGA5W+MKBj56UjVRevvchv5XrcyXbmNdesfZL37nlcWOfpgHhgmxApw3tQbTr4CqNmX4w==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.0.tgz", + "integrity": "sha512-08ARB91bUi6zNKzVmaj3QO7cr397uiDT2nJ63cHjyNtCTWIgvS47j3eT0WfzUwS9+6Z5YshRaoasFkXCKrIYbA==", "dev": true, "engines": { "node": ">= 6.13.0" @@ -29165,9 +29165,9 @@ } }, "node-forge": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.2.1.tgz", - "integrity": "sha512-Fcvtbb+zBcZXbTTVwqGA5W+MKBj56UjVRevvchv5XrcyXbmNdesfZL37nlcWOfpgHhgmxApw3tQbTr4CqNmX4w==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.0.tgz", + "integrity": "sha512-08ARB91bUi6zNKzVmaj3QO7cr397uiDT2nJ63cHjyNtCTWIgvS47j3eT0WfzUwS9+6Z5YshRaoasFkXCKrIYbA==", "dev": true }, "node-int64": { -- cgit v1.2.3 From 2b64f48bc6acb79bd2844333afea7e7a70d77a22 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 23 Mar 2022 10:14:33 -0500 Subject: move Info factory to extensions --- src/slskd/Users/Domain/Info.cs | 24 +----------------------- src/slskd/Users/Extensions.cs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/slskd/Users/Domain/Info.cs b/src/slskd/Users/Domain/Info.cs index aaf19942..e3969f17 100644 --- a/src/slskd/Users/Domain/Info.cs +++ b/src/slskd/Users/Domain/Info.cs @@ -17,35 +17,13 @@ namespace slskd.Users { - using System; - using System.ComponentModel.DataAnnotations; - using Soulseek; - - public class Info + public record Info { - [Key] - public string Username { get; init; } public string Description { get; init; } public bool HasFreeUploadSlot { get; init; } public bool HasPicture { get; init; } public byte[] Picture { get; init; } public int QueueLength { get; init; } public int UploadSlots { get; init; } - public DateTime UpdatedAt { get; init; } - - public static Info FromSoulseekUserInfo(string username, UserInfo info) - { - return new Info() - { - Username = username, - Description = info.Description, - HasFreeUploadSlot = info.HasFreeUploadSlot, - HasPicture = info.HasPicture, - Picture = info.Picture, - QueueLength = info.QueueLength, - UploadSlots = info.UploadSlots, - UpdatedAt = DateTime.UtcNow, - }; - } } } diff --git a/src/slskd/Users/Extensions.cs b/src/slskd/Users/Extensions.cs index 846fd125..d2189a20 100644 --- a/src/slskd/Users/Extensions.cs +++ b/src/slskd/Users/Extensions.cs @@ -47,5 +47,20 @@ namespace slskd.Users IsPrivileged = s.IsPrivileged, Presence = s.Presence, }; + + /// + /// Converts to . + /// + /// The UserInfo instance to convert. + /// The converted instance. + public static Info ToInfo(this UserInfo i) => new() + { + Description = i.Description, + HasFreeUploadSlot = i.HasFreeUploadSlot, + HasPicture = i.HasPicture, + Picture = i.Picture, + QueueLength = i.QueueLength, + UploadSlots = i.UploadSlots, + }; } } -- cgit v1.2.3 From cff862e12a846c6328d5cf77e2b12187cc6d4e30 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 23 Mar 2022 10:16:58 -0500 Subject: don't save user info to a database --- src/slskd/Users/IUserService.cs | 5 ++--- src/slskd/Users/UserService.cs | 39 +++------------------------------------ 2 files changed, 5 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/slskd/Users/IUserService.cs b/src/slskd/Users/IUserService.cs index e78b1b1c..88090f9f 100644 --- a/src/slskd/Users/IUserService.cs +++ b/src/slskd/Users/IUserService.cs @@ -47,9 +47,8 @@ namespace slskd.Users /// Retrieves peer . /// /// The username of the peer. - /// A value indicating whether the local cache should be bypassed. - /// The cached or retrieved info. - Task GetInfoAsync(string username, bool bypassCache = false); + /// The retrieved info. + Task GetInfoAsync(string username); /// /// Retrieves a peer's IP endpoint, including their IP address and listen port. diff --git a/src/slskd/Users/UserService.cs b/src/slskd/Users/UserService.cs index f081d8b1..aa2ae234 100644 --- a/src/slskd/Users/UserService.cs +++ b/src/slskd/Users/UserService.cs @@ -19,13 +19,11 @@ using Microsoft.Extensions.Options; namespace slskd.Users { - using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading.Tasks; - using Microsoft.EntityFrameworkCore; using Serilog; using Soulseek; @@ -34,27 +32,21 @@ namespace slskd.Users /// public class UserService : IUserService { - private const int CacheTTLSeconds = 300; - /// /// Initializes a new instance of the class. /// /// /// - /// The database context to use. /// public UserService( ISoulseekClient soulseekClient, IStateMutator stateMutator, - IDbContextFactory contextFactory, IOptionsMonitor optionsMonitor) { Client = soulseekClient; StateMutator = stateMutator; - ContextFactory = contextFactory; - OptionsMonitor = optionsMonitor; OptionsMonitor.OnChange(options => Configure(options)); @@ -87,7 +79,6 @@ namespace slskd.Users public IReadOnlyList WatchedUsernames => WatchedUsernamesDictionary.Keys.ToList().AsReadOnly(); private ISoulseekClient Client { get; } - private IDbContextFactory ContextFactory { get; } private string LastOptionsHash { get; set; } private ILogger Log { get; set; } = Serilog.Log.ForContext(); private IOptionsMonitor OptionsMonitor { get; } @@ -130,35 +121,11 @@ namespace slskd.Users /// Retrieves peer . /// /// The username of the peer. - /// A value indicating whether the local cache should be bypassed. - /// The cached or retrieved info. - public async Task GetInfoAsync(string username, bool bypassCache = false) + /// The retrieved info. + public async Task GetInfoAsync(string username) { - using var context = ContextFactory.CreateDbContext(); - - var info = await context.Info.AsNoTracking().FirstOrDefaultAsync(peer => peer.Username == username); - var peerExists = info != default; - - if (!bypassCache && peerExists && info.UpdatedAt < DateTime.UtcNow.AddSeconds(CacheTTLSeconds)) - { - return info; - } - var soulseekUserInfo = await Client.GetUserInfoAsync(username); - info = Info.FromSoulseekUserInfo(username, soulseekUserInfo); - - if (peerExists) - { - context.Update(info); - } - else - { - context.Add(info); - } - - await context.SaveChangesAsync(); - - return info; + return soulseekUserInfo.ToInfo(); } /// -- cgit v1.2.3 From bf27026a4b13d49eb85bb881ea2353b9c417c7bf Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 23 Mar 2022 10:17:09 -0500 Subject: rename Peers to Users --- src/slskd/Users/API/Controllers/UsersController.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/slskd/Users/API/Controllers/UsersController.cs b/src/slskd/Users/API/Controllers/UsersController.cs index e7eb5256..2439785e 100644 --- a/src/slskd/Users/API/Controllers/UsersController.cs +++ b/src/slskd/Users/API/Controllers/UsersController.cs @@ -40,17 +40,17 @@ namespace slskd.Users.API /// /// /// - /// - public UsersController(ISoulseekClient soulseekClient, IBrowseTracker browseTracker, IUserService peerService) + /// + public UsersController(ISoulseekClient soulseekClient, IBrowseTracker browseTracker, IUserService userService) { Client = soulseekClient; BrowseTracker = browseTracker; - Peers = peerService; + Users = userService; } private IBrowseTracker BrowseTracker { get; } private ISoulseekClient Client { get; } - private IUserService Peers { get; } + private IUserService Users { get; } /// /// Retrieves the address of the specified . @@ -66,7 +66,7 @@ namespace slskd.Users.API { try { - var endpoint = await Peers.GetIPEndPointAsync(username); + var endpoint = await Users.GetIPEndPointAsync(username); return Ok(endpoint); } catch (UserOfflineException ex) @@ -127,17 +127,16 @@ namespace slskd.Users.API /// Retrieves information about the specified . /// /// The username of the user. - /// Bypasses the internal cache and requests the latest information from the peer. /// [HttpGet("{username}/info")] [Authorize] [ProducesResponseType(typeof(Info), 200)] [ProducesResponseType(404)] - public async Task Info([FromRoute, Required] string username, [FromQuery]bool bypassCache = false) + public async Task Info([FromRoute, Required] string username) { try { - var response = await Peers.GetInfoAsync(username, bypassCache); + var response = await Users.GetInfoAsync(username); return Ok(response); } catch (UserOfflineException ex) @@ -159,7 +158,7 @@ namespace slskd.Users.API { try { - var response = await Peers.GetStatusAsync(username); + var response = await Users.GetStatusAsync(username); return Ok(response); } catch (UserOfflineException ex) -- cgit v1.2.3 From d0698f7aa7a4c9537c9d1bfbc30a93fec877b58d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 23 Mar 2022 10:17:17 -0500 Subject: remove UserDbContext --- src/slskd/Users/UserDbContext.cs | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 src/slskd/Users/UserDbContext.cs (limited to 'src') diff --git a/src/slskd/Users/UserDbContext.cs b/src/slskd/Users/UserDbContext.cs deleted file mode 100644 index 4d0fd08c..00000000 --- a/src/slskd/Users/UserDbContext.cs +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// - -namespace slskd.Users -{ - using Microsoft.EntityFrameworkCore; - - public class UserDbContext : DbContext - { - public UserDbContext(DbContextOptions options) - : base(options) - { - Database.EnsureCreated(); - } - - public DbSet Info { get; set; } - } -} -- cgit v1.2.3 From 7777cf6c2dcf91051d58d01b4bde6301e3f9387b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 23 Mar 2022 10:17:36 -0500 Subject: remove UserDbContext factory --- src/slskd/Startup.cs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src') diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index b1af2482..29f9717f 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -224,11 +224,6 @@ namespace slskd options.UseSqlite($"Data Source={Path.Combine(Program.AppDirectory, "data", "search.db")}"); }); - services.AddDbContextFactory(options => - { - options.UseSqlite($"Data Source={Path.Combine(Program.AppDirectory, "data", "users.db")}"); - }); - services.AddHttpClient(); // add a partially configured instance of SoulseekClient. the Application instance will @@ -403,7 +398,6 @@ namespace slskd try { using var search = GetFactory().CreateDbContext(); - using var peer = GetFactory().CreateDbContext(); } catch (Exception ex) { -- cgit v1.2.3 From 920fc07cb9377539e9169b51b2e7f1d2d60976a1 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 26 Mar 2022 12:36:19 -0500 Subject: add formatAttributes --- src/web/src/lib/util.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/web/src/lib/util.js b/src/web/src/lib/util.js index 86bd6977..32c55090 100644 --- a/src/web/src/lib/util.js +++ b/src/web/src/lib/util.js @@ -34,6 +34,20 @@ export const getDirectoryName = (fullPath) => { return path; } +export const formatAttributes = ({ bitRate, isVariableBitRate, bitDepth, sampleRate }) => { + const isLossless = !!sampleRate && !!bitDepth; + + if (isLossless) { + return `${bitDepth}/${sampleRate/1000}kHz`; + } + + if (isVariableBitRate) { + return `${bitRate}kbps, VBR` + } + + return bitRate ? `${bitRate}kbps` : '' +} + /* https://www.npmjs.com/package/js-file-download * * Copyright 2017 Kenneth Jiang -- cgit v1.2.3 From 5ee68ee6782c1c75e78a1f25d2169cff3c803667 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 26 Mar 2022 12:36:32 -0500 Subject: increase metadata column width --- src/web/src/components/App.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/web/src/components/App.css b/src/web/src/components/App.css index 720d5f5e..6244cdf8 100644 --- a/src/web/src/components/App.css +++ b/src/web/src/components/App.css @@ -68,8 +68,8 @@ body { width: 100px; } -.filelist-bitrate { - width: 70px; +.filelist-attributes { + width: 115px; } .filelist-length{ -- cgit v1.2.3 From b8548f3b055ba5858c182604f9b098a82a3e54d5 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 26 Mar 2022 12:36:41 -0500 Subject: format attributes --- src/web/src/components/Shared/FileList.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/web/src/components/Shared/FileList.js b/src/web/src/components/Shared/FileList.js index e470563f..f38e602d 100644 --- a/src/web/src/components/Shared/FileList.js +++ b/src/web/src/components/Shared/FileList.js @@ -1,6 +1,6 @@ import React from 'react'; -import { formatSeconds, formatBytes, getFileName } from '../../lib/util'; +import { formatSeconds, formatBytes, getFileName, formatAttributes } from '../../lib/util'; import { Header, @@ -44,7 +44,7 @@ const FileList = ({ directoryName, files, locked, onSelectionChange, disabled, o File Size - Bitrate + Attributes Length @@ -61,7 +61,7 @@ const FileList = ({ directoryName, files, locked, onSelectionChange, disabled, o {locked ? : ''}{getFileName(f.filename)} {formatBytes(f.size)} - {f.bitRate} + {formatAttributes(f)} {formatSeconds(f.length)} )} -- cgit v1.2.3