v7.0.6
This commit is contained in:
@@ -6,8 +6,10 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
goRuntime "runtime"
|
||||
"spotiflac/backend"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -31,6 +33,14 @@ func NewApp() *App {
|
||||
|
||||
func (a *App) startup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
|
||||
if err := backend.InitHistoryDB("SpotiFLAC"); err != nil {
|
||||
fmt.Printf("Failed to init history DB: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) shutdown(ctx context.Context) {
|
||||
backend.CloseHistoryDB()
|
||||
}
|
||||
|
||||
type SpotifyMetadataRequest struct {
|
||||
@@ -471,6 +481,40 @@ func (a *App) DownloadTrack(req DownloadRequest) (DownloadResponse, error) {
|
||||
|
||||
backend.CompleteDownloadItem(itemID, filename, 0)
|
||||
}
|
||||
|
||||
go func(fPath, track, artist, album, sID, cover, format string) {
|
||||
quality := "Unknown"
|
||||
durationStr := "--:--"
|
||||
|
||||
meta, err := backend.GetTrackMetadata(fPath)
|
||||
if err == nil && meta != nil {
|
||||
quality = fmt.Sprintf("%d-bit/%.1fkHz", meta.BitsPerSample, float64(meta.SampleRate)/1000.0)
|
||||
d := int(meta.Duration)
|
||||
durationStr = fmt.Sprintf("%d:%02d", d/60, d%60)
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
item := backend.HistoryItem{
|
||||
SpotifyID: sID,
|
||||
Title: track,
|
||||
Artists: artist,
|
||||
Album: album,
|
||||
DurationStr: durationStr,
|
||||
CoverURL: cover,
|
||||
Quality: quality,
|
||||
Format: format,
|
||||
Path: fPath,
|
||||
}
|
||||
|
||||
if item.Format == "" || item.Format == "LOSSLESS" {
|
||||
ext := filepath.Ext(fPath)
|
||||
if len(ext) > 1 {
|
||||
item.Format = strings.ToUpper(ext[1:])
|
||||
}
|
||||
}
|
||||
backend.AddHistoryItem(item, "SpotiFLAC")
|
||||
}(filename, req.TrackName, req.ArtistName, req.AlbumName, req.SpotifyID, req.CoverURL, req.AudioFormat)
|
||||
}
|
||||
|
||||
return DownloadResponse{
|
||||
@@ -544,6 +588,14 @@ func (a *App) Quit() {
|
||||
panic("quit")
|
||||
}
|
||||
|
||||
func (a *App) GetDownloadHistory() ([]backend.HistoryItem, error) {
|
||||
return backend.GetHistoryItems("SpotiFLAC")
|
||||
}
|
||||
|
||||
func (a *App) ClearDownloadHistory() error {
|
||||
return backend.ClearHistory("SpotiFLAC")
|
||||
}
|
||||
|
||||
func (a *App) AnalyzeTrack(filePath string) (string, error) {
|
||||
if filePath == "" {
|
||||
return "", fmt.Errorf("file path is required")
|
||||
@@ -1127,3 +1179,59 @@ func (a *App) LoadSettings() (map[string]interface{}, error) {
|
||||
func (a *App) CheckFFmpegInstalled() (bool, error) {
|
||||
return backend.IsFFmpegInstalled()
|
||||
}
|
||||
|
||||
func (a *App) GetOSInfo() (string, error) {
|
||||
osType := goRuntime.GOOS
|
||||
arch := goRuntime.GOARCH
|
||||
|
||||
switch osType {
|
||||
case "windows":
|
||||
out, err := exec.Command("wmic", "os", "get", "Caption,Version", "/value").Output()
|
||||
if err != nil {
|
||||
outVer, errVer := exec.Command("cmd", "/c", "ver").Output()
|
||||
if errVer != nil {
|
||||
return fmt.Sprintf("Windows %s", arch), nil
|
||||
}
|
||||
return strings.TrimSpace(string(outVer)), nil
|
||||
}
|
||||
|
||||
lines := strings.Split(string(out), "\n")
|
||||
var caption, version string
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.HasPrefix(line, "Caption=") {
|
||||
caption = strings.TrimPrefix(line, "Caption=")
|
||||
} else if strings.HasPrefix(line, "Version=") {
|
||||
version = strings.TrimPrefix(line, "Version=")
|
||||
}
|
||||
}
|
||||
if caption != "" && version != "" {
|
||||
return fmt.Sprintf("%s (%s, %s)", caption, version, arch), nil
|
||||
}
|
||||
return strings.TrimSpace(string(out)), nil
|
||||
|
||||
case "darwin":
|
||||
out, err := exec.Command("sw_vers", "-productVersion").Output()
|
||||
if err != nil {
|
||||
return fmt.Sprintf("macOS %s", arch), nil
|
||||
}
|
||||
version := strings.TrimSpace(string(out))
|
||||
return fmt.Sprintf("macOS %s (%s)", version, arch), nil
|
||||
|
||||
case "linux":
|
||||
out, err := exec.Command("cat", "/etc/os-release").Output()
|
||||
if err == nil {
|
||||
lines := strings.Split(string(out), "\n")
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(line, "PRETTY_NAME=") {
|
||||
name := strings.Trim(strings.TrimPrefix(line, "PRETTY_NAME="), "\"")
|
||||
return fmt.Sprintf("%s (%s)", name, arch), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("Linux %s", arch), nil
|
||||
|
||||
default:
|
||||
return fmt.Sprintf("%s %s", osType, arch), nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user