diff options
| author | Serguey Parkhomovsky <xindigo@gmail.com> | 2025-12-08 21:22:49 -0800 |
|---|---|---|
| committer | Serguey Parkhomovsky <xindigo@gmail.com> | 2025-12-08 21:24:34 -0800 |
| commit | f61d7b3171f8e38a6dc814bdb4b136588cb3f2b1 (patch) | |
| tree | 14f97b390016c54d6d12006e71345cfaf95d5a99 | |
| parent | 37da816f24c15840756f0940f20210775f235881 (diff) | |
Read author from itunes:author
| -rw-r--r-- | main.go | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -28,6 +28,7 @@ type Channel struct { type Item struct { Title string `xml:"title"` + Author string `xml:"https://www.itunes.com/dtds/podcast-1.0.dtd author"` Link string `xml:"link"` Category string `xml:"category"` Enclosure Enclosure `xml:"enclosure"` @@ -68,13 +69,13 @@ func parseYearWeek(date string) (YearWeek, error) { return YearWeek{Year: year, Week: week}, nil } -func parseTitle(title string) (TitleAuthor, error) { +func parseTitle(title string) (string, error) { parts := strings.Split(title, " - ") if len(parts) < 3 { - return TitleAuthor{}, fmt.Errorf("expected 'Week - Author - Title', got '%s'", title) + return "", fmt.Errorf("expected 'Week - Author - Title', got '%s'", title) } - return TitleAuthor{Title: strings.Join(parts[2:], " - "), Author: parts[1]}, nil + return strings.Join(parts[2:], " - "), nil } // For some tracks, like https://weeklybeats.com/keff/music/evil-los-man, the WB RSS feed returns invalid XML bytes. Scrub these. @@ -186,19 +187,19 @@ func main() { // Insert items into database pageItems := 0 for _, item := range rss.Channel.Items { - titleAuthor, err := parseTitle(item.Title) + title, err := parseTitle(item.Title) if err != nil { - log.Printf("Failed to parse title for item '%s': %v", item.Title, err) + log.Printf("Failed to parse title for item '%s': %v", title, err) continue } yearWeek, err := parseYearWeek(item.Category) if err != nil { - log.Printf("Failed to parse date for item '%s': %v", item.Title, err) + log.Printf("Failed to parse date for item '%s': %v", title, err) continue } - _, err = insertStmt.Exec(titleAuthor.Title, item.Link, titleAuthor.Author, yearWeek.Week, yearWeek.Year, item.Enclosure.URL) + _, err = insertStmt.Exec(title, item.Link, item.Author, yearWeek.Week, yearWeek.Year, item.Enclosure.URL) if err != nil { log.Printf("Failed to insert item '%s': %v", item.Title, err) continue |
