Make sure directories are created.

This commit is contained in:
Michael Lehmann
2025-09-17 22:49:55 +02:00
parent a7d770bf28
commit 426e3ce84f
2 changed files with 16 additions and 7 deletions

View File

@@ -4,18 +4,12 @@ import (
"errors" "errors"
"fmt" "fmt"
"kattudden/newsboat-yt/config" "kattudden/newsboat-yt/config"
"kattudden/newsboat-yt/utils"
"os/exec" "os/exec"
) )
func YoutubeVideo(url string) error { func YoutubeVideo(url string) error {
conf, _ := config.New() conf, _ := config.New()
err := utils.EnsureDirectory(conf.DownloadPath)
if err != nil {
return errors.New("failed to create download directory!")
}
downloadBinary := "yt-dlp" downloadBinary := "yt-dlp"
output := fmt.Sprintf("%s/%%(title)s.%%(ext)s", conf.DownloadPath) output := fmt.Sprintf("%s/%%(title)s.%%(ext)s", conf.DownloadPath)
@@ -24,7 +18,7 @@ func YoutubeVideo(url string) error {
fmt.Println(cmd.String()) fmt.Println(cmd.String())
err = cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return errors.New("failed to download video!") return errors.New("failed to download video!")

15
main.go
View File

@@ -3,8 +3,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"kattudden/newsboat-yt/config"
"kattudden/newsboat-yt/database" "kattudden/newsboat-yt/database"
"kattudden/newsboat-yt/download" "kattudden/newsboat-yt/download"
"kattudden/newsboat-yt/utils"
) )
func main() { func main() {
@@ -14,6 +16,19 @@ func main() {
flag.Parse() flag.Parse()
conf, _ := config.New()
err := utils.EnsureDirectory(conf.DownloadPath)
if err != nil {
fmt.Println("failed to create download directory!")
return
}
err = utils.EnsureDirectory(conf.DatabaseDirectory)
if err != nil {
fmt.Println("failed to create database directory!")
return
}
if *newUrl != "" { if *newUrl != "" {
fmt.Println("Adding new URL.") fmt.Println("Adding new URL.")
database.InsertUrl(*newUrl) database.InsertUrl(*newUrl)