From fce899c2e7cbb43a5427d2136f01bbcc1e8ebee2 Mon Sep 17 00:00:00 2001 From: iawia002 Date: Fri, 4 May 2018 09:07:52 +0800 Subject: [PATCH] main: read URLs from file, close #77 [ci skip] --- README.md | 22 +++++++++++++++++++++- config/config.go | 2 ++ main.go | 17 +++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 07c2cee7d..da188ba17 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,24 @@ $ annie -i https://www.bilibili.com/video/av21877586 https://www.bilibili.com/vi These URLs will be downloaded one by one. +You can also use the `-F` option to read URLs from file: + +```console +$ annie -F ~/Desktop/u.txt + + Site: 微博 weibo.com + Title: 在Google,我们设计什么? via@阑夕 + Type: video + Stream: + [default] ------------------- + Size: 19.19 MiB (20118196 Bytes) + # download with: annie -f default "URL" + + 19.19 MiB / 19.19 MiB [=================================] 100.00% 9.69 MiB/s 1s + +...... +``` + ### Resume a download Ctrl+C interrupts a download. @@ -372,6 +390,8 @@ $ annie -j https://www.bilibili.com/video/av20203945 $ annie -h Usage of annie: + -F string + URLs file -O string Specify the output file name -c string @@ -382,7 +402,7 @@ Usage of annie: -i Information only -j Print extracted data -n int - The number of download thread (default 10) + The number of download thread (default 10) -o string Specify the output path -p Download playlist diff --git a/config/config.go b/config/config.go index 6dbf5671d..d26a4a3f0 100644 --- a/config/config.go +++ b/config/config.go @@ -27,6 +27,8 @@ var ( ExtractedData bool // ThreadNumber the number of download thread ThreadNumber int + // File URLs file + File string ) // FakeHeaders fake http headers diff --git a/main.go b/main.go index c00d258ca..104e1dffe 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,12 @@ package main import ( + "bufio" "flag" "fmt" "log" "net/url" + "os" "github.com/iawia002/annie/config" "github.com/iawia002/annie/extractors" @@ -27,6 +29,7 @@ func init() { flag.StringVar(&config.OutputName, "O", "", "Specify the output file name") flag.BoolVar(&config.ExtractedData, "j", false, "Print extracted data") flag.IntVar(&config.ThreadNumber, "n", 10, "The number of download thread") + flag.StringVar(&config.File, "F", "", "URLs file") } func download(videoURL string) { @@ -94,6 +97,20 @@ func main() { if config.Debug { utils.PrintVersion() } + if config.File != "" { + file, err := os.Open(config.File) + if err != nil { + log.Fatal(err) + } + defer file.Close() + scanner := bufio.NewScanner(file) + for scanner.Scan() { + if scanner.Text() == "" { + continue + } + args = append(args, scanner.Text()) + } + } if len(args) < 1 { fmt.Println("Too few arguments") fmt.Println("Usage: annie [args] URLs...")