implement upload command
This commit is contained in:
parent
ff145582b0
commit
74909d4218
2
main.go
2
main.go
|
@ -24,8 +24,6 @@ func main() {
|
||||||
case "help", "--help":
|
case "help", "--help":
|
||||||
usage(0)
|
usage(0)
|
||||||
}
|
}
|
||||||
scanResult := Scan()
|
|
||||||
fmt.Printf("%#v", scanResult)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func must(err error) {
|
func must(err error) {
|
||||||
|
|
21
scan.go
21
scan.go
|
@ -65,9 +65,8 @@ func Scan() (result ScanResult) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//parse input files
|
//parse input files
|
||||||
result.ParseShownotes(names[0])
|
result.ParseShownotes()
|
||||||
chapterMarksPath := fmt.Sprintf("chapter-pentaradio-%04d-%02d-%02d.dat", result.Year, result.Month, result.Day)
|
result.ParseChapterMarks()
|
||||||
result.ParseChapterMarks(chapterMarksPath)
|
|
||||||
|
|
||||||
//collect audio files
|
//collect audio files
|
||||||
pattern := fmt.Sprintf("pentaradio-%04d-%02d-%02d.*", result.Year, result.Month, result.Day)
|
pattern := fmt.Sprintf("pentaradio-%04d-%02d-%02d.*", result.Year, result.Month, result.Day)
|
||||||
|
@ -87,8 +86,12 @@ var monthWords = []string{
|
||||||
"September", "Oktober", "November", "Dezember",
|
"September", "Oktober", "November", "Dezember",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scan *ScanResult) ParseShownotes(path string) {
|
func (scan ScanResult) ShowNotesFile() string {
|
||||||
buf, err := os.ReadFile(path)
|
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)
|
must(err)
|
||||||
|
|
||||||
expectedTitle := fmt.Sprintf("Pentaradio vom %d. %s %d", scan.Day, monthWords[scan.Month], scan.Year)
|
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]
|
scan.Description = match[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scan *ScanResult) ParseChapterMarks(path string) {
|
func (scan ScanResult) ChapterMarksFile() string {
|
||||||
buf, err := os.ReadFile(path)
|
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)
|
must(err)
|
||||||
|
|
||||||
lineRx := regexp.MustCompile(`^(\d\d:\d\d:\d\d.\d\d\d) (\S.*?\S)(?: <(https?://.*)>)?$`)
|
lineRx := regexp.MustCompile(`^(\d\d:\d\d:\d\d.\d\d\d) (\S.*?\S)(?: <(https?://.*)>)?$`)
|
||||||
|
|
23
upload.go
23
upload.go
|
@ -6,6 +6,27 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
func Upload(scan ScanResult) {
|
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())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue