Skip to content

Commit

Permalink
Added script and document
Browse files Browse the repository at this point in the history
  • Loading branch information
lukecold committed Nov 21, 2015
1 parent 8dfdd89 commit bf993ac
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ Specify a video repository using absolute path (If you are a Windows user, I hig
```
gotube -d -id C0DPdy98e4c -q medium -ext video/mp4 -rep /Users/yourusername/Documents/videos
```
Try search by keywords and see what would return:
```
gotube -l -s "curry highlights"
```
Try get more results by querying top k results explicitly (If k is larger than the number of all videos return, the program would return all the videos):
```
gotube -l -s "curry highlights" -k 5
```
Download all of them:
```
gotube -d -s "curry highlights" -k 5 -rep /Users/yourusername/Documents/videos
```

#Library usage
```go
Expand Down
4 changes: 2 additions & 2 deletions api/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type Video struct {
* that shared the same YouTube url.
*/
type VideoList struct {
Title string
Videos []Video
Title string
Videos []Video
}

/*
Expand Down
39 changes: 29 additions & 10 deletions script.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ func main() {
isRetList := flag.Bool("l", false, "use this flag to retrieve video list")
url := flag.String("url", "", "video url")
id := flag.String("id", "", "video id")
search := flag.String("-search", "", "search by key words")
flag.StringVar(search, "s", "", "search by key words")
search := flag.String("-search", "", "search by key words (specify top k with command -k)")
flag.StringVar(search, "s", "", "search by key words (specify top k with command -k)")
k := flag.Int("k", 1, "return top k results, only valid with key word searching")
rep := flag.String("-videorepository", "", "(optional) repository to store videos")
flag.StringVar(rep, "rep", "", "(optional) repository to store videos")
quality := flag.String("-quality", "", "(optional) video quality. e.g. medium")
Expand Down Expand Up @@ -69,26 +70,44 @@ func main() {
} else if *id != "" {
vl, err = GetVideoListFromId(*id)
} else {
ids, err := GetTopKVideoIds(*search, 1)
ids, err := GetTopKVideoIds(*search, *k)
if err != nil {
log.Fatal(err)
}
vl, err = GetVideoListFromId(ids[0])
if *isRetList {
fmt.Printf("The top %v results for key words \"%v\" are:\n\n", *k, *search)
}
for _, vid := range ids {
vl, err = GetVideoListFromId(vid)
if err != nil {
log.Fatal(err)
}
Exec(vl, *isDownload, *isRetList, *rep, *quality, *extension)
}
return
}
if err != nil {
log.Fatal(err)
}
//Choose either downloading or retrieving video list
if *isDownload {
err = vl.Download(*rep, *quality, *extension)
Exec(vl, *isDownload, *isRetList, *rep, *quality, *extension)
}

/*
* Choose either downloading or retrieving video list
*/
func Exec(vl VideoList, isDownload, isRetList bool, rep, quality, extension string) {
if isDownload {
fmt.Printf("Downloading %v...\n", vl.Title)
err := vl.Download(rep, quality, extension)
if err != nil {
log.Fatal(err)
}
} else if *isRetList {
err = vl.Filter(*quality, *extension)
} else if isRetList {
fmt.Printf("Videos under the name of %v:\n", vl.Title)
err := vl.Filter(quality, extension)
if err != nil {
log.Fatal(err)
}
fmt.Println(vl)
}
}
}

0 comments on commit bf993ac

Please sign in to comment.