implement upload command

This commit is contained in:
Stefan Majewsky 2022-04-21 21:54:59 +02:00
parent ff145582b0
commit 74909d4218
3 changed files with 36 additions and 10 deletions

View File

@ -24,8 +24,6 @@ func main() {
case "help", "--help":
usage(0)
}
scanResult := Scan()
fmt.Printf("%#v", scanResult)
}
func must(err error) {

21
scan.go
View File

@ -65,9 +65,8 @@ func Scan() (result ScanResult) {
}
//parse input files
result.ParseShownotes(names[0])
chapterMarksPath := fmt.Sprintf("chapter-pentaradio-%04d-%02d-%02d.dat", result.Year, result.Month, result.Day)
result.ParseChapterMarks(chapterMarksPath)
result.ParseShownotes()
result.ParseChapterMarks()
//collect audio files
pattern := fmt.Sprintf("pentaradio-%04d-%02d-%02d.*", result.Year, result.Month, result.Day)
@ -87,8 +86,12 @@ var monthWords = []string{
"September", "Oktober", "November", "Dezember",
}
func (scan *ScanResult) ParseShownotes(path string) {
buf, err := os.ReadFile(path)
func (scan ScanResult) ShowNotesFile() string {
return fmt.Sprintf("shownotes-pentaradio-%04d-%02d-%02d.txt", scan.Year, scan.Month, scan.Day)
}
func (scan *ScanResult) ParseShownotes() {
buf, err := os.ReadFile(scan.ShowNotesFile())
must(err)
expectedTitle := fmt.Sprintf("Pentaradio vom %d. %s %d", scan.Day, monthWords[scan.Month], scan.Year)
@ -106,8 +109,12 @@ func (scan *ScanResult) ParseShownotes(path string) {
scan.Description = match[2]
}
func (scan *ScanResult) ParseChapterMarks(path string) {
buf, err := os.ReadFile(path)
func (scan ScanResult) ChapterMarksFile() string {
return fmt.Sprintf("chapter-pentaradio-%04d-%02d-%02d.dat", scan.Year, scan.Month, scan.Day)
}
func (scan *ScanResult) ParseChapterMarks() {
buf, err := os.ReadFile(scan.ChapterMarksFile())
must(err)
lineRx := regexp.MustCompile(`^(\d\d:\d\d:\d\d.\d\d\d) (\S.*?\S)(?: <(https?://.*)>)?$`)

View File

@ -6,6 +6,27 @@
package main
import (
"os"
"os/exec"
"strings"
)
func Upload(scan ScanResult) {
fail("unimplemented")
sftpCommands := []string{
"cd pentaradio/shownotes",
"put " + scan.ShowNotesFile(),
"cd ../chaptermarks",
"put " + scan.ChapterMarksFile(),
"cd ..",
}
for _, fileName := range scan.AudioFileNames {
sftpCommands = append(sftpCommands, "put "+fileName)
}
cmd := exec.Command("sftp", "-b", "-", "ftp.c3d2.de")
cmd.Stdin = strings.NewReader(strings.Join(sftpCommands, "\n") + "\n")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
must(cmd.Run())
}