-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
60 lines (50 loc) · 1.17 KB
/
main.go
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
// Copyright (c) Liam Stanley <[email protected]>. All rights reserved. Use of
// this source code is governed by the MIT license that can be found in
// the LICENSE file.
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"time"
"github.com/lrstanley/go-ytdlp"
)
func main() {
// If yt-dlp isn't installed yet, download and cache it for further use.
ytdlp.MustInstall(context.TODO(), nil)
dl := ytdlp.New().
PrintJSON().
NoProgress().
FormatSort("res,ext:mp4:m4a").
RecodeVideo("mp4").
NoPlaylist().
NoOverwrites().
Continue().
ProgressFunc(100*time.Millisecond, func(prog ytdlp.ProgressUpdate) {
fmt.Printf( //nolint:forbidigo
"%s @ %s [eta: %s] :: %s\n",
prog.Status,
prog.PercentString(),
prog.ETA(),
prog.Filename,
)
}).
Output("%(extractor)s - %(title)s.%(ext)s")
r, err := dl.Run(context.TODO(), "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
if err != nil {
panic(err)
}
f, err := os.Create("results.json")
if err != nil {
panic(err)
}
defer f.Close()
enc := json.NewEncoder(f)
enc.SetIndent("", " ")
if err = enc.Encode(r); err != nil {
panic(err)
}
log.Println("wrote results to results.json")
}