.fix spotify rate limit issue

This commit is contained in:
afkarxyz
2026-03-25 16:17:44 +07:00
parent 4e7fc468cd
commit b31e1fe565
6 changed files with 797 additions and 419 deletions
+5 -1
View File
@@ -389,11 +389,15 @@ func (a *App) DownloadTrack(req DownloadRequest) (DownloadResponse, error) {
close(lyricsChan)
}
if req.Service == "qobuz" {
go func() {
client := backend.NewSongLinkClient()
isrc, _ := client.GetISRC(req.SpotifyID)
isrc, _ := client.GetISRCDirect(req.SpotifyID)
isrcChan <- isrc
}()
} else {
close(isrcChan)
}
} else {
close(lyricsChan)
close(isrcChan)
+4 -59
View File
@@ -5,7 +5,6 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
@@ -19,12 +18,6 @@ type AmazonDownloader struct {
regions []string
}
type SongLinkResponse struct {
LinksByPlatform map[string]struct {
URL string `json:"url"`
} `json:"linksByPlatform"`
}
type AmazonStreamResponse struct {
StreamURL string `json:"streamUrl"`
DecryptionKey string `json:"decryptionKey"`
@@ -40,65 +33,17 @@ func NewAmazonDownloader() *AmazonDownloader {
}
func (a *AmazonDownloader) GetAmazonURLFromSpotify(spotifyTrackID string) (string, error) {
spotifyBase := "https://open.spotify.com/track/"
spotifyURL := fmt.Sprintf("%s%s", spotifyBase, spotifyTrackID)
apiBase := "https://api.song.link/v1-alpha.1/links?url="
apiURL := fmt.Sprintf("%s%s", apiBase, url.QueryEscape(spotifyURL))
req, err := http.NewRequest("GET", apiURL, nil)
if err != nil {
return "", fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36")
fmt.Println("Getting Amazon URL...")
resp, err := a.client.Do(req)
client := NewSongLinkClient()
urls, err := client.GetAllURLsFromSpotify(spotifyTrackID, "")
if err != nil {
return "", fmt.Errorf("failed to get Amazon URL: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", fmt.Errorf("API returned status %d", resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("failed to read response body: %w", err)
}
if len(body) == 0 {
return "", fmt.Errorf("API returned empty response")
}
var songLinkResp SongLinkResponse
if err := json.Unmarshal(body, &songLinkResp); err != nil {
bodyStr := string(body)
if len(bodyStr) > 200 {
bodyStr = bodyStr[:200] + "..."
}
return "", fmt.Errorf("failed to decode response: %w (response: %s)", err, bodyStr)
}
amazonLink, ok := songLinkResp.LinksByPlatform["amazonMusic"]
if !ok || amazonLink.URL == "" {
amazonURL := normalizeAmazonMusicURL(urls.AmazonURL)
if amazonURL == "" {
return "", fmt.Errorf("amazon Music link not found")
}
amazonURL := amazonLink.URL
if strings.Contains(amazonURL, "trackAsin=") {
parts := strings.Split(amazonURL, "trackAsin=")
if len(parts) > 1 {
trackAsin := strings.Split(parts[1], "&")[0]
amazonURL = fmt.Sprintf("https://music.amazon.com/tracks/%s?musicTerritory=US", trackAsin)
}
}
fmt.Printf("Found Amazon URL: %s\n", amazonURL)
return amazonURL, nil
}
+1 -1
View File
@@ -365,7 +365,7 @@ func (q *QobuzDownloader) DownloadTrack(spotifyID, outputDir, quality, filenameF
var deezerISRC string
if spotifyID != "" {
songlinkClient := NewSongLinkClient()
isrc, err := songlinkClient.GetISRC(spotifyID)
isrc, err := songlinkClient.GetISRCDirect(spotifyID)
if err != nil {
return "", fmt.Errorf("failed to get ISRC: %v", err)
}
+784 -324
View File
File diff suppressed because it is too large Load Diff
+4 -35
View File
@@ -8,7 +8,6 @@ import (
"io"
"math/rand"
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
@@ -91,47 +90,17 @@ func (t *TidalDownloader) GetAvailableAPIs() ([]string, error) {
}
func (t *TidalDownloader) GetTidalURLFromSpotify(spotifyTrackID string) (string, error) {
spotifyBase := "https://open.spotify.com/track/"
spotifyURL := fmt.Sprintf("%s%s", spotifyBase, spotifyTrackID)
apiBase := "https://api.song.link/v1-alpha.1/links?url="
apiURL := fmt.Sprintf("%s%s", apiBase, url.QueryEscape(spotifyURL))
req, err := http.NewRequest("GET", apiURL, nil)
if err != nil {
return "", fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36")
fmt.Println("Getting Tidal URL...")
resp, err := t.client.Do(req)
client := NewSongLinkClient()
urls, err := client.GetAllURLsFromSpotify(spotifyTrackID, "")
if err != nil {
return "", fmt.Errorf("failed to get Tidal URL: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", fmt.Errorf("API returned status %d", resp.StatusCode)
}
var songLinkResp struct {
LinksByPlatform map[string]struct {
URL string `json:"url"`
} `json:"linksByPlatform"`
}
if err := json.NewDecoder(resp.Body).Decode(&songLinkResp); err != nil {
return "", fmt.Errorf("failed to decode response: %w", err)
}
tidalLink, ok := songLinkResp.LinksByPlatform["tidal"]
if !ok || tidalLink.URL == "" {
tidalURL := urls.TidalURL
if tidalURL == "" {
return "", fmt.Errorf("tidal link not found")
}
tidalURL := tidalLink.URL
fmt.Printf("Found Tidal URL: %s\n", tidalURL)
return tidalURL, nil
}
+1 -1
View File
@@ -161,7 +161,7 @@ export function SettingsPage({ onUnsavedChangesChange, onResetRequest, }: Settin
</Button>
<Button variant={activeTab === "api" ? "default" : "ghost"} size="sm" onClick={() => setActiveTab("api")} className="rounded-b-none gap-2">
<Router className="h-4 w-4"/>
API Status
Status
</Button>
</div>