Skip to content

Commit 21574d1

Browse files
Ignasi Foschifosch
authored andcommitted
Make epidator create the episode YAML file
Now epidator creates the episode YAML file, instead of printing it out to stdout, so there's no need to redirect the output.
1 parent c7594b0 commit 21574d1

File tree

4 files changed

+59
-94
lines changed

4 files changed

+59
-94
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,22 @@ export AWS_PROFILE=appu
4141

4242
#### Collect data for episode
4343

44-
The following command creates the episode configuration file, with the publishing details for this episode calculated.
44+
The following command creates the episode configuration file, with the publishing details for this episode calculated. The created file is named with the first part of the filename and in YAML format. In the example command, it would be named `mypodcast-XX.yaml`:
4545

4646
```
47-
./epidator mypodcast-XX.master.mp3 > mypodcast-XX.yaml
47+
./epidator mypodcast-XX.master.mp3
4848
```
4949

5050
#### Edit and upload the audio file
5151

5252
```
5353
docker build -t ghcr.io/edyo/appu:local appu/.
54-
./appu mypodcast-XX.yaml ghcr.io/edyo/appu:local /keybase/team/edyo/appu.credentials
54+
docker run --rm \
55+
-v ${PWD}/data/cfg:/home/appu/cfg \
56+
-v ${HOME}/.aws/credentials:/home/appu/.aws/credentials \
57+
-v ${PWD}/data/files:/home/appu/files \
58+
-v ${PWD}/data/podcast:/home/appu/podcast \
59+
ghcr.io/edyo/appu:local
5560
```
5661

5762
#### Download and update the feed

cmd/appu/main.go

Lines changed: 0 additions & 75 deletions
This file was deleted.

cmd/epidator/main.go

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,12 @@ import (
44
"fmt"
55
"log"
66
"os"
7+
"strings"
78

89
"github.com/EDyO/appu/pkg/appu"
910
"gopkg.in/yaml.v2"
1011
)
1112

12-
func printYAML(properties map[string]interface{}) error {
13-
outputData, err := yaml.Marshal(properties)
14-
if err != nil {
15-
return err
16-
}
17-
18-
fmt.Println(string(outputData))
19-
return nil
20-
}
21-
2213
func main() {
2314
log.SetFlags(0)
2415

@@ -36,5 +27,49 @@ func main() {
3627
log.Fatal(err)
3728
}
3829

39-
printYAML(details)
30+
outputData, err := yaml.Marshal(details)
31+
if err != nil {
32+
log.Fatal(err)
33+
}
34+
35+
filename := fmt.Sprintf(
36+
"%s.yaml",
37+
strings.Split(trackName, ".")[0],
38+
)
39+
err = os.WriteFile(filename, outputData, 0644)
40+
if err != nil {
41+
log.Fatalf("Error writing yaml file: %v", err)
42+
}
43+
44+
cfg, err := appu.LoadConfigYAML(filename)
45+
if err != nil {
46+
log.Fatalf("Error loading config file: %v", err)
47+
}
48+
49+
cwd, err := os.Getwd()
50+
if err != nil {
51+
log.Fatal(err)
52+
}
53+
54+
volumes := map[string]string{
55+
fmt.Sprintf("%s/data/aws", cwd): "/home/appu/.aws",
56+
fmt.Sprintf("%s/data/cfg", cwd): "/home/appu/cfg",
57+
fmt.Sprintf("%s/data/files", cwd): "/home/appu/files",
58+
fmt.Sprintf("%s/data/podcast", cwd): "/home/appu/podcast",
59+
}
60+
61+
if err := os.Mkdir(fmt.Sprintf("%s/data", cwd), 0755); err != nil {
62+
log.Fatal(err)
63+
}
64+
for directory := range volumes {
65+
if err := os.Mkdir(directory, 0755); err != nil {
66+
log.Fatal(err)
67+
}
68+
}
69+
70+
err = cfg.PrepareFiles()
71+
if err != nil {
72+
log.Fatalf("Config error: %v", err)
73+
}
74+
4075
}

pkg/appu/podcast.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ var GetFeed = func(URL string) (string, error) {
3838
return string(bodyBytes), nil
3939
}
4040

41-
var noMatchingScripts = fmt.Errorf(
41+
var errNoMatchingScripts = fmt.Errorf(
4242
"no matching scripts, please add a query returning one %s",
4343
"single document",
4444
)
4545

46-
var tooManyResults = func(r []*drive.File) (error) {
46+
var tooManyResults = func(r []*drive.File) error {
4747
return fmt.Errorf(
4848
"query returns too many documents (%v), %s",
4949
len(r),
@@ -64,7 +64,7 @@ var GetScript = func(episodeTag string) (string, error) {
6464
}
6565

6666
if len(q) == 0 {
67-
return "", noMatchingScripts
67+
return "", errNoMatchingScripts
6868
}
6969

7070
r, err := stationery.GetFiles(svc, q)
@@ -106,7 +106,7 @@ type Podcast struct {
106106
IntroURL string `yaml:"introURL"`
107107
EpisodeBucket string `yaml:"episodeBucket"`
108108
} `yaml:"directFields"`
109-
ScriptFieldHooks []ScriptFieldHook `yaml:"scriptFieldHooks"`
109+
ScriptFieldHooks []ScriptFieldHook `yaml:"scriptFieldHooks"`
110110
EpisodeScriptHooks map[string]string `yaml:"episodeScriptHooks"`
111111
trackName string
112112
scriptTree *html.Node
@@ -248,7 +248,7 @@ func (p *Podcast) extractPropertiesFromScript() {
248248
func getSingleHookDetails(
249249
hook ScriptFieldHook,
250250
htmlNode *html.Node,
251-
) (interface{}) {
251+
) interface{} {
252252
if hook.Attribute != "" {
253253
return htmlquery.SelectAttr(
254254
htmlNode,

0 commit comments

Comments
 (0)