youtubedl.go 996 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package youtube_dl

import (
	"encoding/json"
	"log"
	"os/exec"
	"strings"
)

func runYoutubeDL(args []string) (output []byte, err error) {
	cmd := exec.Command("youtube-dl", args...)
	output, err = cmd.Output()
	if err != nil {
		return nil, err
	}

	return output, nil
}

func getVideoInfo(id string) (info map[string]interface{}, err error) {

	args := []string{
		"--skip-download",
		"-J",
		"https://youtu.be/" + id,
	}

	output, err := runYoutubeDL(args)
	if err != nil {
		return info, err
	}

	err = json.Unmarshal(output, &info)
	if err != nil {
		return info, err
	}

	return info, err
}

type SubList struct {
	AutomaticCaptions map[string][]string
	Subtitles         map[string][]string
}

func listSubs(id string) (subs string, err error) {
	args := []string{
		"--skip-download",
		"--list-subs",
		"https://youtu.be/" + id,
	}
	output, err := runYoutubeDL(args)

	lines := strings.Split(string(output), "\n")

	for _, line := range lines {
		log.Print(line)
	}

	return "", nil
}