-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
99 lines (84 loc) · 2.58 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"github.com/spf13/viper"
"os/user"
"path/filepath"
"strings"
//"github.com/dhowden/tag"
"log"
"os"
)
// The original Python file was just an imperative set of instructions
// Since I cannot replicate that here, I hope to just build a main function with calls to
// what I think are obvious disparate functions
// This main function brings everything together
func main() {
// TODO: this is how i think it ought to go. implement according
// read file and get metadata
// set up a feed
// process episodes and get them all in a row
// write feed
// First things first. Load up any variables you need from environment files.
// Put in a comma seperated list of env files to load
// figure out where go wants to put in env files
// 1. Load in my env, using Viper.
userHome, _ := user.Current()
viperConfigPath := filepath.Join(userHome.HomeDir, ".config", "rederb")
viper.AddConfigPath(viperConfigPath)
viper.SetConfigName(".env")
viper.SetConfigType("env")
err := viper.ReadInConfig()
if err != nil {
log.Fatal("Error loading environment file(s)")
}
// 2. Setup the environment.
BASE_URL := viper.GetString("BASE_URL")
fmt.Printf("BASE_URL = %s\n", BASE_URL)
AUTHOR_NAME := viper.Get("AUTHOR_NAME")
fmt.Printf("Feed author name: %v\n", AUTHOR_NAME)
SUB_PATH := os.Getenv("SUB_PATH")
if strings.TrimSpace(SUB_PATH) == "" {
SUB_PATH = viper.GetString("SUB_PATH")
}
FEED_URL := ""
if SUB_PATH != "" {
FEED_URL = fmt.Sprintf("%s/%s", BASE_URL, SUB_PATH)
} else {
FEED_URL = BASE_URL
}
fmt.Printf("Feed URL is: %s\n", FEED_URL)
// 3. trying to load metadata from files
if len(os.Args) != 2 {
fmt.Println("Usage: program <audio-file-path>")
os.Exit(1)
}
// currently just getting all the metadata from the first file
// and writing it to a file in the same folder as the audiobook
//filePath := os.Args[1]
//
//fileMetadata, err := getAudioFileMetadata(filePath)
//if err != nil {
// fmt.Printf("Error extracting metadata: %v\n", err)
// os.Exit(1)
//}
//prettyPrint(fileMetadata)
// Get cover art from the file
//if fileMetadata.Picture != nil {
// err := extractCoverArt(fileMetadata, filePath)
// if err != nil {
// fmt.Printf("Error extracting cover art: %v\n", err)
// }
//} else {
// fmt.Printf("No cover art found in the Metadata\n")
//}
}
//func getAudioFileMetadata(filePath string) (*MetadataInfo, error) {
// file, err := os.Open(filePath)
// if err != nil {
// return nil, fmt.Errorf("Error opening file: %w", err)
// }
// defer file.Close()
//func extractCoverArt(info *MetadataInfo, audioPath string) error {
//
//}