mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-10 07:58:39 -05:00
feat: Fork octo-fiestarr as allstarr with Jellyfin proxy improvements
Major changes: - Rename project from octo-fiesta to allstarr - Add Jellyfin proxy support alongside Subsonic/Navidrome - Implement fuzzy search with relevance scoring and Levenshtein distance - Add POST body logging for debugging playback progress issues - Separate local and external artists in search results - Add +5 score boost for external results to prioritize larger catalog(probably gonna reverse it) - Create FuzzyMatcher utility for intelligent search result scoring - Add ConvertPlaylistToJellyfinItem method for playlist support - Rename keys folder to apis and update gitignore - Filter search results by relevance score (>= 40) - Add Redis caching support with configurable settings - Update environment configuration with backend selection - Improve external provider integration (SquidWTF, Deezer, Qobuz) - Add tests for all services
This commit is contained in:
239
allstarr/Program.cs
Normal file
239
allstarr/Program.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
using allstarr.Models.Settings;
|
||||
using allstarr.Services;
|
||||
using allstarr.Services.Deezer;
|
||||
using allstarr.Services.Qobuz;
|
||||
using allstarr.Services.SquidWTF;
|
||||
using allstarr.Services.Local;
|
||||
using allstarr.Services.Validation;
|
||||
using allstarr.Services.Subsonic;
|
||||
using allstarr.Services.Jellyfin;
|
||||
using allstarr.Services.Common;
|
||||
using allstarr.Middleware;
|
||||
using allstarr.Filters;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Determine backend type FIRST
|
||||
var backendType = builder.Configuration.GetValue<BackendType>("Backend:Type");
|
||||
|
||||
// Configure Kestrel for large responses over VPN/Tailscale
|
||||
builder.WebHost.ConfigureKestrel(serverOptions =>
|
||||
{
|
||||
serverOptions.Limits.MaxResponseBufferSize = null; // Disable response buffering limit
|
||||
serverOptions.Limits.MaxRequestBodySize = null; // Allow large request bodies
|
||||
serverOptions.Limits.MinResponseDataRate = null; // Disable minimum data rate for slow connections
|
||||
});
|
||||
|
||||
// Add response compression for large JSON responses (helps with Tailscale/VPN MTU issues)
|
||||
builder.Services.AddResponseCompression(options =>
|
||||
{
|
||||
options.EnableForHttps = true;
|
||||
options.MimeTypes = new[] { "application/json", "text/json" };
|
||||
});
|
||||
|
||||
// Add services to the container - conditionally register controllers
|
||||
builder.Services.AddControllers()
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
// Use original property names (PascalCase) to match Jellyfin API
|
||||
options.JsonSerializerOptions.PropertyNamingPolicy = null;
|
||||
options.JsonSerializerOptions.DictionaryKeyPolicy = null;
|
||||
})
|
||||
.ConfigureApplicationPartManager(manager =>
|
||||
{
|
||||
// Remove the default controller feature provider
|
||||
var defaultProvider = manager.FeatureProviders
|
||||
.OfType<Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider>()
|
||||
.FirstOrDefault();
|
||||
if (defaultProvider != null)
|
||||
{
|
||||
manager.FeatureProviders.Remove(defaultProvider);
|
||||
}
|
||||
// Add our custom provider that filters by backend type
|
||||
manager.FeatureProviders.Add(new BackendControllerFeatureProvider(backendType));
|
||||
});
|
||||
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
// Exception handling
|
||||
builder.Services.AddExceptionHandler<GlobalExceptionHandler>();
|
||||
builder.Services.AddProblemDetails();
|
||||
|
||||
// Configuration - register both settings, active one determined by backend type
|
||||
builder.Services.Configure<SubsonicSettings>(
|
||||
builder.Configuration.GetSection("Subsonic"));
|
||||
builder.Services.Configure<JellyfinSettings>(
|
||||
builder.Configuration.GetSection("Jellyfin"));
|
||||
builder.Services.Configure<DeezerSettings>(
|
||||
builder.Configuration.GetSection("Deezer"));
|
||||
builder.Services.Configure<QobuzSettings>(
|
||||
builder.Configuration.GetSection("Qobuz"));
|
||||
builder.Services.Configure<RedisSettings>(
|
||||
builder.Configuration.GetSection("Redis"));
|
||||
|
||||
// Get shared settings from the active backend config
|
||||
MusicService musicService;
|
||||
bool enableExternalPlaylists;
|
||||
|
||||
if (backendType == BackendType.Jellyfin)
|
||||
{
|
||||
musicService = builder.Configuration.GetValue<MusicService>("Jellyfin:MusicService");
|
||||
enableExternalPlaylists = builder.Configuration.GetValue<bool>("Jellyfin:EnableExternalPlaylists", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default to Subsonic
|
||||
musicService = builder.Configuration.GetValue<MusicService>("Subsonic:MusicService");
|
||||
enableExternalPlaylists = builder.Configuration.GetValue<bool>("Subsonic:EnableExternalPlaylists", true);
|
||||
}
|
||||
|
||||
// Business services - shared across backends
|
||||
builder.Services.AddSingleton<RedisCacheService>();
|
||||
builder.Services.AddSingleton<ILocalLibraryService, LocalLibraryService>();
|
||||
|
||||
// Register backend-specific services
|
||||
if (backendType == BackendType.Jellyfin)
|
||||
{
|
||||
// Jellyfin services
|
||||
builder.Services.AddSingleton<JellyfinResponseBuilder>();
|
||||
builder.Services.AddSingleton<JellyfinModelMapper>();
|
||||
builder.Services.AddScoped<JellyfinProxyService>();
|
||||
builder.Services.AddScoped<JellyfinAuthFilter>();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Subsonic services (default)
|
||||
builder.Services.AddSingleton<SubsonicRequestParser>();
|
||||
builder.Services.AddSingleton<SubsonicResponseBuilder>();
|
||||
builder.Services.AddSingleton<SubsonicModelMapper>();
|
||||
builder.Services.AddScoped<SubsonicProxyService>();
|
||||
}
|
||||
|
||||
// Register music service based on configuration
|
||||
// IMPORTANT: Primary service MUST be registered LAST because ASP.NET Core DI
|
||||
// will use the last registered implementation when injecting IMusicMetadataService/IDownloadService
|
||||
if (musicService == MusicService.Qobuz)
|
||||
{
|
||||
// If playlists enabled, register Deezer FIRST (secondary provider)
|
||||
if (enableExternalPlaylists)
|
||||
{
|
||||
builder.Services.AddSingleton<IMusicMetadataService, DeezerMetadataService>();
|
||||
builder.Services.AddSingleton<IDownloadService, DeezerDownloadService>();
|
||||
builder.Services.AddSingleton<PlaylistSyncService>();
|
||||
}
|
||||
|
||||
// Qobuz services (primary) - registered LAST to be injected by default
|
||||
builder.Services.AddSingleton<QobuzBundleService>();
|
||||
builder.Services.AddSingleton<IMusicMetadataService, QobuzMetadataService>();
|
||||
builder.Services.AddSingleton<IDownloadService, QobuzDownloadService>();
|
||||
}
|
||||
else if (musicService == MusicService.Deezer)
|
||||
{
|
||||
// If playlists enabled, register Qobuz FIRST (secondary provider)
|
||||
if (enableExternalPlaylists)
|
||||
{
|
||||
builder.Services.AddSingleton<QobuzBundleService>();
|
||||
builder.Services.AddSingleton<IMusicMetadataService, QobuzMetadataService>();
|
||||
builder.Services.AddSingleton<IDownloadService, QobuzDownloadService>();
|
||||
builder.Services.AddSingleton<PlaylistSyncService>();
|
||||
}
|
||||
|
||||
// Deezer services (primary, default) - registered LAST to be injected by default
|
||||
builder.Services.AddSingleton<IMusicMetadataService, DeezerMetadataService>();
|
||||
builder.Services.AddSingleton<IDownloadService, DeezerDownloadService>();
|
||||
}
|
||||
else if (musicService == MusicService.SquidWTF)
|
||||
{
|
||||
// SquidWTF services
|
||||
builder.Services.AddSingleton<IMusicMetadataService, SquidWTFMetadataService>();
|
||||
builder.Services.AddSingleton<IDownloadService, SquidWTFDownloadService>();
|
||||
}
|
||||
|
||||
// Startup validation - register validators based on backend
|
||||
if (backendType == BackendType.Jellyfin)
|
||||
{
|
||||
builder.Services.AddSingleton<IStartupValidator, JellyfinStartupValidator>();
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Services.AddSingleton<IStartupValidator, SubsonicStartupValidator>();
|
||||
}
|
||||
|
||||
builder.Services.AddSingleton<IStartupValidator, DeezerStartupValidator>();
|
||||
builder.Services.AddSingleton<IStartupValidator, QobuzStartupValidator>();
|
||||
builder.Services.AddSingleton<IStartupValidator, SquidWTFStartupValidator>();
|
||||
|
||||
// Register orchestrator as hosted service
|
||||
builder.Services.AddHostedService<StartupValidationOrchestrator>();
|
||||
|
||||
// Register cache cleanup service (only runs when StorageMode is Cache)
|
||||
builder.Services.AddHostedService<CacheCleanupService>();
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddDefaultPolicy(policy =>
|
||||
{
|
||||
policy.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.WithExposedHeaders("X-Content-Duration", "X-Total-Count", "X-Nd-Authorization");
|
||||
});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
app.UseExceptionHandler(_ => { }); // Global exception handler
|
||||
|
||||
// Enable response compression EARLY in the pipeline
|
||||
app.UseResponseCompression();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseCors();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
// Health check endpoint for monitoring
|
||||
app.MapGet("/health", () => Results.Ok(new { status = "healthy", timestamp = DateTime.UtcNow }));
|
||||
|
||||
app.Run();
|
||||
|
||||
/// <summary>
|
||||
/// Controller feature provider that conditionally registers controllers based on backend type.
|
||||
/// This prevents route conflicts between JellyfinController and SubsonicController catch-all routes.
|
||||
/// </summary>
|
||||
class BackendControllerFeatureProvider : Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider
|
||||
{
|
||||
private readonly BackendType _backendType;
|
||||
|
||||
public BackendControllerFeatureProvider(BackendType backendType)
|
||||
{
|
||||
_backendType = backendType;
|
||||
}
|
||||
|
||||
protected override bool IsController(System.Reflection.TypeInfo typeInfo)
|
||||
{
|
||||
var isController = base.IsController(typeInfo);
|
||||
if (!isController) return false;
|
||||
|
||||
// Only register the controller matching the configured backend type
|
||||
return _backendType switch
|
||||
{
|
||||
BackendType.Jellyfin => typeInfo.Name == "JellyfinController",
|
||||
BackendType.Subsonic => typeInfo.Name == "SubsonicController",
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user