Skip to content

Instantly share code, notes, and snippets.

@jtagcat
Created June 18, 2022 20:19
Show Gist options
  • Save jtagcat/fa5c0693652e297900056dbb0c03a344 to your computer and use it in GitHub Desktop.
Save jtagcat/fa5c0693652e297900056dbb0c03a344 to your computer and use it in GitHub Desktop.
Quick and dirty golang for generating a static podcast out of files.
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
"time"
"github.com/eduncan911/podcast"
)
func main() {
o, err := os.Open("/hardcoded.tsv") //TODO: first: id / filename; second: title; third: desc
if err != nil {
panic(err)
}
defer o.Close()
r := csv.NewReader(o)
r.Comma = '\t'
records, err := r.ReadAll()
if err != nil {
log.Fatal(err)
}
baseurl := "https://foobar/" //TODO:
ptime := time.Unix(123, 0) // DATE
p := podcast.New( //TODO:
"TITLE",
"URL/LINK",
"DESCRIPTION",
&ptime, &ptime,
)
p.AddImage(baseurl + "FILENAME.jpg") //TODO:
p.AddAuthor("asdaskjdasldj", "") //TODO:
p.AddCategory("asdjasjdasdlaks", []string{}) //TODO:
p.Language = "et-ee"
for i, track := range records {
filename := track[0] + ".mp3"
ti, err := os.Stat("/mp3/files/are/here/" + filename) //TODO:
if err != nil {
panic(err)
}
_, err = p.AddItem(podcast.Item{
Title: track[1],
Description: track[2],
Enclosure: &podcast.Enclosure{
URL: baseurl + filename,
Type: podcast.MP3,
Length: ti.Size(),
},
})
if err != nil {
panic(err)
}
}
if err := p.Encode(os.Stdout); err != nil {
fmt.Println("error writing to stdout:", err.Error())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment