This commit is contained in:
afkarxyz
2026-01-14 06:28:51 +07:00
parent 6e3ca48d3f
commit 2fc08de757
8 changed files with 318 additions and 185 deletions
+23 -1
View File
@@ -7,11 +7,20 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"spotiflac/backend"
"strings"
"time"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
var isrcRegex = regexp.MustCompile(`^[A-Z]{2}[A-Z0-9]{3}\d{2}\d{5}$`)
func isValidISRC(isrc string) bool {
return isrcRegex.MatchString(isrc)
}
type App struct {
ctx context.Context
}
@@ -336,6 +345,11 @@ func (a *App) DownloadTrack(req DownloadRequest) (DownloadResponse, error) {
}
deezerISRC := req.ISRC
if len(deezerISRC) != 12 || !isValidISRC(deezerISRC) {
deezerISRC = ""
}
if deezerISRC == "" && req.SpotifyID != "" {
songlinkClient := backend.NewSongLinkClient()
@@ -370,6 +384,7 @@ func (a *App) DownloadTrack(req DownloadRequest) (DownloadResponse, error) {
}
if err != nil {
backend.FailDownloadItem(itemID, fmt.Sprintf("Download failed: %v", err))
if filename != "" && !strings.HasPrefix(filename, "EXISTS:") {
@@ -828,16 +843,19 @@ type DownloadFFmpegResponse struct {
}
func (a *App) DownloadFFmpeg() DownloadFFmpegResponse {
runtime.EventsEmit(a.ctx, "ffmpeg:status", "starting")
err := backend.DownloadFFmpeg(func(progress int) {
fmt.Printf("[FFmpeg] Download progress: %d%%\n", progress)
runtime.EventsEmit(a.ctx, "ffmpeg:progress", progress)
})
if err != nil {
runtime.EventsEmit(a.ctx, "ffmpeg:status", "failed")
return DownloadFFmpegResponse{
Success: false,
Error: err.Error(),
}
}
runtime.EventsEmit(a.ctx, "ffmpeg:status", "completed")
return DownloadFFmpegResponse{
Success: true,
Message: "FFmpeg installed successfully",
@@ -1105,3 +1123,7 @@ func (a *App) LoadSettings() (map[string]interface{}, error) {
return settings, nil
}
func (a *App) CheckFFmpegInstalled() (bool, error) {
return backend.IsFFmpegInstalled()
}