Enable headless/library usage of sldl#164
Merged
fiso64 merged 6 commits intofiso64:masterfrom Mar 24, 2026
Merged
Conversation
added 6 commits
March 24, 2026 18:42
When no console output is configured (e.g. when used as a library), OutputConfigs has no matching element, causing .First() to throw InvalidOperationException. Use FirstOrDefault with a null check instead.
Expose the internal appCts cancellation token so callers using sldl as a library can cancel a running download job.
Environment.Exit() kills the entire hosting process when sldl is used as a library. Replace error exits with thrown exceptions (caught by the caller) and help/version exits with early returns.
Add IProgressReporter with hooks for track list, download progress, track state changes, overall progress, and job completion. Integrate callbacks into Searcher and Downloader services.
- Upgrade target framework from net6.0 to net8.0 - Make Program class internal to avoid conflicts with host app - Add --no-listen flag and enableListener:false support to avoid port bind failures when used as a library
Owner
|
Good stuff! I was planning to add a server mode that would expose an http API, but this is quicker if the gui is .net based (besides these changes would be needed either way). Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes it possible to use sldl as an in-process library (e.g. from an ASP.NET host) rather than only as a standalone CLI tool.
Changes
IProgressReporter interface — New callback interface (
IProgressReporter) that receives track list, download progress, track state changes, and job completion events. Integrated intoSearcherandDownloader. ANullProgressReporteris used by default so existing CLI behavior is unchanged. Also includes aJsonStreamProgressReporterimplementation for structured output.Remove Environment.Exit() calls — All 8
Environment.Exit()calls across Spotify.cs, MusicBrainz.cs, Config.cs, and Help.cs are replaced with thrown exceptions (for errors) or early returns (for--help/--version). This prevents the host process from being killed when sldl encounters an error.Public Cancel() on DownloaderApplication — Exposes the internal
appCtscancellation token so callers can stop a running download.Logger.SetConsoleLogLevel tolerance — Uses
FirstOrDefaultinstead ofFirstso it doesn't throw when no console output is configured (library consumers may not callLogger.AddConsole()).Headless support —
Programclass madeinternalto avoid conflicts with the host app's entry point. Added--no-listenflag that setslistenPort = null, which creates the Soulseek client withenableListener: falseto avoid port bind failures in server environments.net8.0 — Target framework upgraded from net6.0 to net8.0.
Motivation
I'm building a web UI (slsk-batchdl-gui) that calls
DownloaderApplication.RunAsync()directly from a Blazor Server app. These changes were the minimum needed to make that work without forking the entire codebase.Backward compatibility
NullProgressReporteris the default,Programis still the entry point when built standalone, andEnvironment.Exitreplacements throw the same errors that would have been fatal anyway.--no-listenflag is opt-in.