From 3dfa9558595304aeedc3384a6f84db8c9eb4d550 Mon Sep 17 00:00:00 2001 From: siddharth Date: Sun, 28 Nov 2021 23:40:12 -0500 Subject: feed: flesh out feed.processEntry --- feed/feed.go | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'feed') diff --git a/feed/feed.go b/feed/feed.go index 7e0df4c..180a2ac 100644 --- a/feed/feed.go +++ b/feed/feed.go @@ -9,6 +9,7 @@ import ( "io" "net/http" "os" + "os/exec" "path" "time" @@ -170,11 +171,40 @@ func (feed *Feed) processEntry(entry schema.Entry, erc chan state.EntryResult) { // Init EntryResult. er := state.EntryResult{entry.Id, entry.Title, nil} - // TODO: Download Entry - + // Download entry. + err := feed.ydl(entry.Link) + if err != nil { + er.Err = err + } erc <- er } +func (feed *Feed) ydl(url string) error { + if len(url) == 0 { + return fmt.Errorf("URL invalid") + } + + // Change working directory to feed's dumpdir. + wd, err := os.Getwd() + if err != nil { + return err + } + defer os.Chdir(wd) + err = os.Chdir(feed.DumpDir) + if err != nil { + return err + } + + // Download url via youtube-dl + cmd := exec.Command(feed.YDLPath, "--no-progress", url) + out, err := cmd.CombinedOutput() + fmt.Printf("[%s]: %s", feed.Id, out) + if err != nil { + return err + } + return nil +} + // Unmarshal raw feed into an object. func (feed *Feed) unmarshal(bs []byte) error { var err error -- cgit v1.2.3