summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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