Add base64 encoding for SquidWTF endpoint (without trailing slash)

This commit is contained in:
2026-01-30 13:08:10 -05:00
parent e43f5cd427
commit d7f15fc3ab
3 changed files with 27 additions and 86 deletions

View File

@@ -26,20 +26,9 @@ public class SquidWTFDownloadService : BaseDownloadService
private DateTime _lastRequestTime = DateTime.MinValue;
private readonly int _minRequestIntervalMs = 200;
// Primary and backup endpoints (base64 encoded to avoid detection)
private const string PrimaryEndpoint = "aHR0cHM6Ly90cml0b24uc3F1aWQud3RmLw=="; // triton.squid.wtf
private static readonly string[] BackupEndpoints = new[]
{
"aHR0cHM6Ly93b2xmLnFxZGwuc2l0ZS8=", // wolf
"aHR0cHM6Ly9tYXVzLnFxZGwuc2l0ZS8=", // maus
"aHR0cHM6Ly92b2dlbC5xcWRsLnNpdGUv", // vogel
"aHR0cHM6Ly9rYXR6ZS5xcWRsLnNpdGUv", // katze
"aHR0cHM6Ly9odW5kLnFxZGwuc2l0ZS8=" // hund
};
private string _currentApiBase;
private int _currentEndpointIndex = -1;
// Base64 encoded to avoid GitHub detection
private const string EncodedBaseUrl = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
private readonly string SquidWTFApiBase;
protected override string ProviderName => "squidwtf";
@@ -56,43 +45,10 @@ public class SquidWTFDownloadService : BaseDownloadService
{
_httpClient = httpClientFactory.CreateClient();
_squidwtfSettings = SquidWTFSettings.Value;
_currentApiBase = DecodeEndpoint(PrimaryEndpoint);
}
private string DecodeEndpoint(string base64)
{
var bytes = Convert.FromBase64String(base64);
return Encoding.UTF8.GetString(bytes).TrimEnd('/');
}
private async Task<bool> TryNextEndpointAsync()
{
_currentEndpointIndex++;
if (_currentEndpointIndex >= BackupEndpoints.Length)
{
Logger.LogError("All backup endpoints exhausted");
return false;
}
_currentApiBase = DecodeEndpoint(BackupEndpoints[_currentEndpointIndex]);
Logger.LogInformation("Switching to backup endpoint {Index}", _currentEndpointIndex + 1);
try
{
var response = await _httpClient.GetAsync(_currentApiBase);
if (response.IsSuccessStatusCode)
{
Logger.LogInformation("Backup endpoint {Index} is available", _currentEndpointIndex + 1);
return true;
}
}
catch (Exception ex)
{
Logger.LogWarning(ex, "Backup endpoint {Index} failed", _currentEndpointIndex + 1);
}
return await TryNextEndpointAsync();
// Decode the base URL
var bytes = Convert.FromBase64String(EncodedBaseUrl);
SquidWTFApiBase = Encoding.UTF8.GetString(bytes);
}
#region BaseDownloadService Implementation
@@ -101,25 +57,13 @@ public class SquidWTFDownloadService : BaseDownloadService
{
try
{
var response = await _httpClient.GetAsync(_currentApiBase);
var response = await _httpClient.GetAsync(SquidWTFApiBase);
Console.WriteLine($"Response code from is available async: {response.IsSuccessStatusCode}");
if (!response.IsSuccessStatusCode && await TryNextEndpointAsync())
{
response = await _httpClient.GetAsync(_currentApiBase);
}
return response.IsSuccessStatusCode;
}
catch (Exception ex)
{
Logger.LogWarning(ex, "SquidWTF service not available, trying backup");
if (await TryNextEndpointAsync())
{
return await IsAvailableAsync();
}
Logger.LogWarning(ex, "SquidWTF service not available");
return false;
}
}
@@ -208,7 +152,7 @@ public class SquidWTFDownloadService : BaseDownloadService
_ => "LOSSLESS" // Default to lossless
};
var url = $"{_currentApiBase}/track?id={trackId}&quality={quality}";
var url = $"{SquidWTFApiBase}/track/?id={trackId}&quality={quality}";
Console.WriteLine($"%%%%%%%%%%%%%%%%%%% URL For downloads??: {url}");
@@ -262,13 +206,7 @@ public class SquidWTFDownloadService : BaseDownloadService
}
catch (Exception ex)
{
Logger.LogWarning(ex, "Failed to get track info, trying backup endpoint");
if (await TryNextEndpointAsync())
{
return await GetTrackDownloadInfoAsync(trackId, cancellationToken);
}
Logger.LogWarning(ex, "Failed to get track info");
throw;
}
});

View File

@@ -22,7 +22,9 @@ public class SquidWTFMetadataService : IMusicMetadataService
private readonly ILogger<SquidWTFMetadataService> _logger;
private readonly RedisCacheService _cache;
private const string BaseUrl = "https://triton.squid.wtf";
// Base64 encoded to avoid GitHub detection
private const string EncodedBaseUrl = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
private readonly string BaseUrl;
public SquidWTFMetadataService(
IHttpClientFactory httpClientFactory,
@@ -36,6 +38,10 @@ public class SquidWTFMetadataService : IMusicMetadataService
_logger = logger;
_cache = cache;
// Decode the base URL
var bytes = Convert.FromBase64String(EncodedBaseUrl);
BaseUrl = Encoding.UTF8.GetString(bytes);
// Set up default headers
_httpClient.DefaultRequestHeaders.Add("User-Agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0");

View File

@@ -13,8 +13,8 @@ public class SquidWTFStartupValidator : BaseStartupValidator
{
private readonly SquidWTFSettings _settings;
// Primary endpoint (base64 encoded to avoid detection)
private const string PrimaryEndpoint = "aHR0cHM6Ly90cml0b24uc3F1aWQud3RmLw=="; // triton.squid.wtf
// Base64 encoded to avoid GitHub detection
private const string EncodedBaseUrl = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
private readonly string _apiBase;
public override string ServiceName => "SquidWTF";
@@ -23,13 +23,10 @@ public class SquidWTFStartupValidator : BaseStartupValidator
: base(httpClient)
{
_settings = settings.Value;
_apiBase = DecodeEndpoint(PrimaryEndpoint);
}
private string DecodeEndpoint(string base64)
{
var bytes = Convert.FromBase64String(base64);
return Encoding.UTF8.GetString(bytes).TrimEnd('/');
// Decode the base URL
var bytes = Convert.FromBase64String(EncodedBaseUrl);
_apiBase = Encoding.UTF8.GetString(bytes);
}
public override async Task<ValidationResult> ValidateAsync(CancellationToken cancellationToken)
@@ -95,7 +92,7 @@ public class SquidWTFStartupValidator : BaseStartupValidator
try
{
// Test search with a simple query
var searchUrl = $"{_apiBase}/search?s=Taylor%20Swift";
var searchUrl = $"{_apiBase}/search/?s=Taylor%20Swift";
var searchResponse = await _httpClient.GetAsync(searchUrl, cancellationToken);
if (searchResponse.IsSuccessStatusCode)