summaryrefslogtreecommitdiffstats
path: root/feed/feed.go
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2021-11-28 23:40:12 -0500
committersiddharth <s@ricketyspace.net>2021-11-28 23:40:12 -0500
commit3dfa9558595304aeedc3384a6f84db8c9eb4d550 (patch)
treeb3823f38e4f481d01ea65ff2956f287d217f1192 /feed/feed.go
parent7e2f4a85ab0e4503262244281a348b7e8cd9e6f1 (diff)
feed: flesh out feed.processEntry
Diffstat (limited to 'feed/feed.go')
-rw-r--r--feed/feed.go34
1 files changed, 32 insertions, 2 deletions
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