andrade-soulseek-downloader
Version:
Simple, safe Soulseek download library with built-in rate limiting to prevent bans
72 lines • 3 kB
TypeScript
import { SoulseekSearchResult, SearchOptions, DownloadConfig } from '../shared';
/**
* Main downloader class for Soulseek operations.
* Handles connection, search, and download with rate limiting.
*/
export declare class SoulseekDownloader {
private client;
private isConnected;
private downloadConfig;
private failedUsers;
private logger;
private rateLimiter;
private youtubeDownloader;
private static activeInstance;
/**
* @param config - Download configuration options
*/
constructor(config?: DownloadConfig);
/** Validates required environment variables */
private validateEnvironment;
/** Establishes connection to Soulseek network */
connect(): Promise<void>;
/** Disconnects from Soulseek and cleans up */
disconnect(): Promise<void>;
private sanitizeQuery;
private generateFileName;
private delay;
private formatSpeed;
private matchesArtistAndTitle;
/**
* Searches for tracks on Soulseek network.
* @param options - Search configuration
* @returns Array of search results sorted by quality
*/
search(options: SearchOptions): Promise<SoulseekSearchResult[]>;
/**
* Downloads a file from Soulseek peer.
* @param result - Search result to download
* @param artist - Artist name for filename
* @param title - Track title for filename
* @param folderName - Optional subfolder name within SOULSEEK_DOWNLOAD_DIR
* @param customFileName - Optional custom filename (without extension)
* @param abortSignal - Optional abort signal to cancel download
* @param isRacing - Whether this is part of a race (uses temp filename)
* @returns Object with download path and timeout status
*/
download(result: SoulseekSearchResult, artist: string, title: string, folderName?: string, customFileName?: string, abortSignal?: AbortSignal, isRacing?: boolean): Promise<{
path: string | null;
timeout: boolean;
cancelled?: boolean;
}>;
/**
* Races multiple downloads in parallel and returns the first successful one.
* @param candidates - Array of search results to try downloading
* @param artist - Artist name
* @param title - Track title
* @param folderName - Optional subfolder name
* @param customFileName - Optional custom filename
* @returns Path to downloaded file or null if all failed
*/
private raceDownloads;
/**
* Performs search and download with quality-first strategy.
* @param artist - Artist name
* @param title - Track title
* @param folderName - Optional subfolder name within SOULSEEK_DOWNLOAD_DIR
* @param customFileName - Optional custom filename (without extension)
* @returns Path to downloaded file or null if failed
*/
searchAndDownload(artist: string, title: string, folderName?: string, customFileName?: string): Promise<string | null>;
}
//# sourceMappingURL=soulseek-downloader.d.ts.map