mirror of
https://github.com/Superredstone/spotiflac-cli.git
synced 2026-03-07 20:18:07 +01:00
feat: add file exists check
This commit is contained in:
@@ -69,6 +69,16 @@ func (app *App) Download(url string, outputFile string, serviceString string, qu
|
||||
return err
|
||||
}
|
||||
|
||||
fileExists, err := FileExists(outputFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if fileExists {
|
||||
app.log("File " + outputFile + " already exists")
|
||||
return nil
|
||||
}
|
||||
|
||||
err = app.DownloadFromUrl(downloadUrl, outputFile)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
14
lib/utils.go
14
lib/utils.go
@@ -3,6 +3,7 @@ package lib
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
@@ -97,3 +98,16 @@ func GetFormatFromQuality(quality string) (string, error) {
|
||||
return "", errors.New("Invalid quality.")
|
||||
}
|
||||
}
|
||||
|
||||
func FileExists(file string) (bool, error) {
|
||||
_, err := os.Stat(file)
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return false, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user