feat: add file exists check

This commit is contained in:
2026-02-19 16:01:56 +01:00
parent 80e2d868d2
commit ecc4564ff7
2 changed files with 24 additions and 0 deletions

View File

@@ -69,6 +69,16 @@ func (app *App) Download(url string, outputFile string, serviceString string, qu
return err 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) err = app.DownloadFromUrl(downloadUrl, outputFile)
if err != nil { if err != nil {
return err return err

View File

@@ -3,6 +3,7 @@ package lib
import ( import (
"errors" "errors"
"fmt" "fmt"
"os"
"path" "path"
"strings" "strings"
) )
@@ -97,3 +98,16 @@ func GetFormatFromQuality(quality string) (string, error) {
return "", errors.New("Invalid quality.") 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
}