ソースを参照

~/.bin/ydl.go: A tool to simplify downloading with youtube-dl

Written in Go because of url-escaping problems with bash.

It specifies the maximum resolution (720p), and sets the `--no-mtime`
option which makes the files easier to find for me.  (Otherwise
youtube-dl would use something like an "upload timestamp", which ended
up being really confusing.
Lucas Stadler 8 年 前
コミット
8663ab08fc
共有1 個のファイルを変更した38 個の追加0 個の削除を含む
  1. 38 0
      .bin/ydl.go

+ 38 - 0
.bin/ydl.go

@ -0,0 +1,38 @@
1
package main
2
3
import (
4
	"fmt"
5
	"os"
6
	"os/exec"
7
	"regexp"
8
)
9
10
var isYoutube = regexp.MustCompile(`(www\.)youtube\.com|youtu\.be`)
11
12
func main() {
13
	url := os.Args[1]
14
	cmd := exec.Command("youtube-dl", "--no-mtime")
15
	cmd.Stdin = os.Stdin
16
	cmd.Stderr = os.Stderr
17
	cmd.Stdout = os.Stdout
18
19
	if isYoutube.MatchString(url) {
20
		// download youtube video in a lower resolution (saving bandwidth/space)
21
		cmd.Args = append(cmd.Args, "-f", "[height <=? 720]")
22
	}
23
24
	cmd.Args = append(cmd.Args, os.Args[1:]...)
25
	printCommand(cmd)
26
	err := cmd.Run()
27
	if err != nil {
28
		fmt.Println("error...", err)
29
		os.Exit(1)
30
	}
31
}
32
33
func printCommand(cmd *exec.Cmd) {
34
	for _, arg := range cmd.Args {
35
		fmt.Printf("%s ", arg)
36
	}
37
	fmt.Println()
38
}