Skip to content

Commit

Permalink
main: read URLs from file, close #77 [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
iawia002 committed May 4, 2018
1 parent 5c05150 commit fce899c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<kbd>Ctrl</kbd>+<kbd>C</kbd> interrupts a download.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var (
ExtractedData bool
// ThreadNumber the number of download thread
ThreadNumber int
// File URLs file
File string
)

// FakeHeaders fake http headers
Expand Down
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"bufio"
"flag"
"fmt"
"log"
"net/url"
"os"

"github.com/iawia002/annie/config"
"github.com/iawia002/annie/extractors"
Expand All @@ -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) {
Expand Down Expand Up @@ -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...")
Expand Down

0 comments on commit fce899c

Please sign in to comment.