.skip off musicbrainz
This commit is contained in:
@@ -1041,10 +1041,17 @@ func (a *App) CheckAPIStatus(apiType string, apiURL string) bool {
|
|||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if apiType == "musicbrainz" {
|
||||||
|
backend.SetMusicBrainzStatusCheckResult(false)
|
||||||
|
}
|
||||||
fmt.Printf("CheckAPIStatus timeout/error for %s (%s): %v\n", apiType, apiURL, err)
|
fmt.Printf("CheckAPIStatus timeout/error for %s (%s): %v\n", apiType, apiURL, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if apiType == "musicbrainz" {
|
||||||
|
backend.SetMusicBrainzStatusCheckResult(isOnline)
|
||||||
|
}
|
||||||
|
|
||||||
return isOnline
|
return isOnline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -252,6 +252,9 @@ func (a *AmazonDownloader) DownloadByURL(amazonURL, outputDir, quality, filename
|
|||||||
}
|
}
|
||||||
res.ISRC = isrc
|
res.ISRC = isrc
|
||||||
if isrc != "" {
|
if isrc != "" {
|
||||||
|
if ShouldSkipMusicBrainzMetadataFetch() {
|
||||||
|
fmt.Println("Skipping MusicBrainz metadata fetch because status check is offline.")
|
||||||
|
} else {
|
||||||
fmt.Println("Fetching MusicBrainz metadata...")
|
fmt.Println("Fetching MusicBrainz metadata...")
|
||||||
if fetchedMeta, err := FetchMusicBrainzMetadata(isrc, spotifyTrackName, spotifyArtistName, spotifyAlbumName, useSingleGenre, embedGenre); err == nil {
|
if fetchedMeta, err := FetchMusicBrainzMetadata(isrc, spotifyTrackName, spotifyArtistName, spotifyAlbumName, useSingleGenre, embedGenre); err == nil {
|
||||||
res.Metadata = fetchedMeta
|
res.Metadata = fetchedMeta
|
||||||
@@ -260,6 +263,7 @@ func (a *AmazonDownloader) DownloadByURL(amazonURL, outputDir, quality, filename
|
|||||||
fmt.Printf("Warning: Failed to fetch MusicBrainz metadata: %v\n", err)
|
fmt.Printf("Warning: Failed to fetch MusicBrainz metadata: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
metaChan <- res
|
metaChan <- res
|
||||||
}()
|
}()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const (
|
|||||||
musicBrainzRequestRetryWait = 3 * time.Second
|
musicBrainzRequestRetryWait = 3 * time.Second
|
||||||
musicBrainzMinRequestInterval = 1100 * time.Millisecond
|
musicBrainzMinRequestInterval = 1100 * time.Millisecond
|
||||||
musicBrainzThrottleCooldownOn503 = 5 * time.Second
|
musicBrainzThrottleCooldownOn503 = 5 * time.Second
|
||||||
|
musicBrainzStatusCheckSkipWindow = 5 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
type musicBrainzStatusError struct {
|
type musicBrainzStatusError struct {
|
||||||
@@ -46,8 +47,35 @@ var (
|
|||||||
musicBrainzThrottleMu sync.Mutex
|
musicBrainzThrottleMu sync.Mutex
|
||||||
musicBrainzNextRequest time.Time
|
musicBrainzNextRequest time.Time
|
||||||
musicBrainzBlockedTill time.Time
|
musicBrainzBlockedTill time.Time
|
||||||
|
|
||||||
|
musicBrainzStatusMu sync.RWMutex
|
||||||
|
musicBrainzLastCheckedAt time.Time
|
||||||
|
musicBrainzLastCheckedOnline bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func SetMusicBrainzStatusCheckResult(online bool) {
|
||||||
|
musicBrainzStatusMu.Lock()
|
||||||
|
defer musicBrainzStatusMu.Unlock()
|
||||||
|
|
||||||
|
musicBrainzLastCheckedAt = time.Now()
|
||||||
|
musicBrainzLastCheckedOnline = online
|
||||||
|
}
|
||||||
|
|
||||||
|
func ShouldSkipMusicBrainzMetadataFetch() bool {
|
||||||
|
musicBrainzStatusMu.RLock()
|
||||||
|
defer musicBrainzStatusMu.RUnlock()
|
||||||
|
|
||||||
|
if musicBrainzLastCheckedAt.IsZero() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if musicBrainzLastCheckedOnline {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return time.Since(musicBrainzLastCheckedAt) <= musicBrainzStatusCheckSkipWindow
|
||||||
|
}
|
||||||
|
|
||||||
type MusicBrainzRecordingResponse struct {
|
type MusicBrainzRecordingResponse struct {
|
||||||
Recordings []struct {
|
Recordings []struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
@@ -216,6 +244,11 @@ func FetchMusicBrainzMetadata(isrc, title, artist, album string, useSingleGenre
|
|||||||
return cached.(Metadata), nil
|
return cached.(Metadata), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ShouldSkipMusicBrainzMetadataFetch() {
|
||||||
|
resultErr = fmt.Errorf("skipping MusicBrainz lookup because the latest status check reported offline")
|
||||||
|
return meta, resultErr
|
||||||
|
}
|
||||||
|
|
||||||
musicBrainzInflightMu.Lock()
|
musicBrainzInflightMu.Lock()
|
||||||
if call, ok := musicBrainzInflight[cacheKey]; ok {
|
if call, ok := musicBrainzInflight[cacheKey]; ok {
|
||||||
musicBrainzInflightMu.Unlock()
|
musicBrainzInflightMu.Unlock()
|
||||||
|
|||||||
@@ -408,6 +408,10 @@ func (q *QobuzDownloader) DownloadTrackWithISRC(isrc, outputDir, quality, filena
|
|||||||
metaChan := make(chan Metadata, 1)
|
metaChan := make(chan Metadata, 1)
|
||||||
if embedGenre && isrc != "" {
|
if embedGenre && isrc != "" {
|
||||||
go func() {
|
go func() {
|
||||||
|
if ShouldSkipMusicBrainzMetadataFetch() {
|
||||||
|
fmt.Println("Skipping MusicBrainz metadata fetch because status check is offline.")
|
||||||
|
metaChan <- Metadata{}
|
||||||
|
} else {
|
||||||
fmt.Println("Fetching MusicBrainz metadata...")
|
fmt.Println("Fetching MusicBrainz metadata...")
|
||||||
if fetchedMeta, err := FetchMusicBrainzMetadata(isrc, spotifyTrackName, spotifyArtistName, spotifyAlbumName, useSingleGenre, embedGenre); err == nil {
|
if fetchedMeta, err := FetchMusicBrainzMetadata(isrc, spotifyTrackName, spotifyArtistName, spotifyAlbumName, useSingleGenre, embedGenre); err == nil {
|
||||||
fmt.Println("✓ MusicBrainz metadata fetched")
|
fmt.Println("✓ MusicBrainz metadata fetched")
|
||||||
@@ -416,6 +420,7 @@ func (q *QobuzDownloader) DownloadTrackWithISRC(isrc, outputDir, quality, filena
|
|||||||
fmt.Printf("Warning: Failed to fetch MusicBrainz metadata: %v\n", err)
|
fmt.Printf("Warning: Failed to fetch MusicBrainz metadata: %v\n", err)
|
||||||
metaChan <- Metadata{}
|
metaChan <- Metadata{}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
} else {
|
} else {
|
||||||
close(metaChan)
|
close(metaChan)
|
||||||
|
|||||||
@@ -493,6 +493,9 @@ func (t *TidalDownloader) DownloadByURL(tidalURL, outputDir, quality, filenameFo
|
|||||||
}
|
}
|
||||||
res.ISRC = isrc
|
res.ISRC = isrc
|
||||||
if isrc != "" {
|
if isrc != "" {
|
||||||
|
if ShouldSkipMusicBrainzMetadataFetch() {
|
||||||
|
fmt.Println("Skipping MusicBrainz metadata fetch because status check is offline.")
|
||||||
|
} else {
|
||||||
fmt.Println("Fetching MusicBrainz metadata...")
|
fmt.Println("Fetching MusicBrainz metadata...")
|
||||||
if fetchedMeta, err := FetchMusicBrainzMetadata(isrc, trackTitle, artistName, albumTitle, useSingleGenre, embedGenre); err == nil {
|
if fetchedMeta, err := FetchMusicBrainzMetadata(isrc, trackTitle, artistName, albumTitle, useSingleGenre, embedGenre); err == nil {
|
||||||
res.Metadata = fetchedMeta
|
res.Metadata = fetchedMeta
|
||||||
@@ -501,6 +504,7 @@ func (t *TidalDownloader) DownloadByURL(tidalURL, outputDir, quality, filenameFo
|
|||||||
fmt.Printf("Warning: Failed to fetch MusicBrainz metadata: %v\n", err)
|
fmt.Printf("Warning: Failed to fetch MusicBrainz metadata: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
metaChan <- res
|
metaChan <- res
|
||||||
}()
|
}()
|
||||||
} else {
|
} else {
|
||||||
@@ -657,6 +661,9 @@ func (t *TidalDownloader) DownloadByURLWithFallback(tidalURL, outputDir, quality
|
|||||||
}
|
}
|
||||||
res.ISRC = isrc
|
res.ISRC = isrc
|
||||||
if isrc != "" {
|
if isrc != "" {
|
||||||
|
if ShouldSkipMusicBrainzMetadataFetch() {
|
||||||
|
fmt.Println("Skipping MusicBrainz metadata fetch because status check is offline.")
|
||||||
|
} else {
|
||||||
fmt.Println("Fetching MusicBrainz metadata...")
|
fmt.Println("Fetching MusicBrainz metadata...")
|
||||||
if fetchedMeta, err := FetchMusicBrainzMetadata(isrc, trackTitle, artistName, albumTitle, useSingleGenre, embedGenre); err == nil {
|
if fetchedMeta, err := FetchMusicBrainzMetadata(isrc, trackTitle, artistName, albumTitle, useSingleGenre, embedGenre); err == nil {
|
||||||
res.Metadata = fetchedMeta
|
res.Metadata = fetchedMeta
|
||||||
@@ -665,6 +672,7 @@ func (t *TidalDownloader) DownloadByURLWithFallback(tidalURL, outputDir, quality
|
|||||||
fmt.Printf("Warning: Failed to fetch MusicBrainz metadata: %v\n", err)
|
fmt.Printf("Warning: Failed to fetch MusicBrainz metadata: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
metaChan <- res
|
metaChan <- res
|
||||||
}()
|
}()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user