From d7f15fc3abfd03b420e6253ecfdbde3dd9e8bf1e Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Fri, 30 Jan 2026 13:08:10 -0500 Subject: [PATCH] Add base64 encoding for SquidWTF endpoint (without trailing slash) --- .../SquidWTF/SquidWTFDownloadService.cs | 86 +++---------------- .../SquidWTF/SquidWTFMetadataService.cs | 8 +- .../SquidWTF/SquidWTFStartupValidator.cs | 19 ++-- 3 files changed, 27 insertions(+), 86 deletions(-) diff --git a/allstarr/Services/SquidWTF/SquidWTFDownloadService.cs b/allstarr/Services/SquidWTF/SquidWTFDownloadService.cs index b4ca25b..d8fa30b 100644 --- a/allstarr/Services/SquidWTF/SquidWTFDownloadService.cs +++ b/allstarr/Services/SquidWTF/SquidWTFDownloadService.cs @@ -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,70 +45,25 @@ public class SquidWTFDownloadService : BaseDownloadService { _httpClient = httpClientFactory.CreateClient(); _squidwtfSettings = SquidWTFSettings.Value; - _currentApiBase = DecodeEndpoint(PrimaryEndpoint); + + // Decode the base URL + var bytes = Convert.FromBase64String(EncodedBaseUrl); + SquidWTFApiBase = Encoding.UTF8.GetString(bytes); } - private string DecodeEndpoint(string base64) - { - var bytes = Convert.FromBase64String(base64); - return Encoding.UTF8.GetString(bytes).TrimEnd('/'); - } - - private async Task 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(); - } - #region BaseDownloadService Implementation public override async Task IsAvailableAsync() { 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; + 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; } }); diff --git a/allstarr/Services/SquidWTF/SquidWTFMetadataService.cs b/allstarr/Services/SquidWTF/SquidWTFMetadataService.cs index f14a671..f2cc0b8 100644 --- a/allstarr/Services/SquidWTF/SquidWTFMetadataService.cs +++ b/allstarr/Services/SquidWTF/SquidWTFMetadataService.cs @@ -22,7 +22,9 @@ public class SquidWTFMetadataService : IMusicMetadataService private readonly ILogger _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, @@ -35,6 +37,10 @@ public class SquidWTFMetadataService : IMusicMetadataService _settings = settings.Value; _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", diff --git a/allstarr/Services/SquidWTF/SquidWTFStartupValidator.cs b/allstarr/Services/SquidWTF/SquidWTFStartupValidator.cs index feeb2c1..d39a06d 100644 --- a/allstarr/Services/SquidWTF/SquidWTFStartupValidator.cs +++ b/allstarr/Services/SquidWTF/SquidWTFStartupValidator.cs @@ -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,14 +23,11 @@ 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 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)