diff options
author | siddharth ravikumar <s@ricketyspace.net> | 2022-11-26 18:50:27 -0500 |
---|---|---|
committer | siddharth ravikumar <s@ricketyspace.net> | 2022-11-26 18:50:27 -0500 |
commit | 3f22c834001583a2c604e249b07208e13c9ad083 (patch) | |
tree | 8df54dcc69bf7131270692498555fac3b0cfd4df /feed/feed.go | |
parent | 03fc3d3bab2b9c1008cd7c22622d5b92d354f272 (diff) |
feed: update `Feed.ydl`
- Change argument from url (string) to entry (schema.Entry)
- Add handling to set the media file name to the entry's title if the
entry is hosted at megaphone.fm
Diffstat (limited to 'feed/feed.go')
-rw-r--r-- | feed/feed.go | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/feed/feed.go b/feed/feed.go index abd4dc5..c2e6112 100644 --- a/feed/feed.go +++ b/feed/feed.go @@ -30,6 +30,19 @@ type Feed struct { Entries []schema.Entry } +var specialCharReplacer = strings.NewReplacer( + "'", "", + "’", "", + "(", "", + ")", "", + "[", "", + "]", "", + ":", "", + "/", "", + "?", "", + " ", "_", +) + func (feed *Feed) Validate(baseDumpDir string) error { _, err := os.Stat(baseDumpDir) if err != nil { @@ -209,28 +222,34 @@ func (feed *Feed) processEntry(entry schema.Entry, erc chan state.EntryResult) { // Download entry. fmt.Printf("[%s][%s] Going to download '%s'\n", feed.Id, entry.Id, entry.Title) - err := feed.ydl(entry.Link) + err := feed.ydl(entry) if err != nil { er.Err = err } erc <- er } -func (feed *Feed) ydl(url string) error { - if len(url) == 0 { +func (feed *Feed) ydl(entry schema.Entry) error { + if len(entry.Link) == 0 { return fmt.Errorf("URL invalid") } // Media file name. mediaName := "%(title)s-%(id)s.%(ext)s" - if strings.Contains(url, "buzzsprout.com") { - mediaName = path.Base(url) + switch { + case strings.Contains(entry.Link, "buzzsprout.com"): + mediaName = path.Base(entry.Link) + case strings.Contains(entry.Link, "megaphone.fm"): + mediaName = fmt.Sprintf( + "%s-%%(id)s.%%(ext)s", + specialCharReplacer.Replace(entry.Title), + ) } // Download url via youtube-dl outputTemplate := fmt.Sprintf("-o%s", path.Join(feed.DumpDir, mediaName)) - cmd := exec.Command(feed.YDLPath, "--no-progress", outputTemplate, url) + cmd := exec.Command(feed.YDLPath, "--no-progress", outputTemplate, entry.Link) _, err := cmd.CombinedOutput() if err != nil { return err |