-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathytdlp.go
More file actions
51 lines (40 loc) · 1.06 KB
/
Copy pathytdlp.go
File metadata and controls
51 lines (40 loc) · 1.06 KB
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
package cmd
import (
"context"
"os"
"os/signal"
"github.com/spf13/cobra"
"github.com/tanq16/danzo/internal/display"
ytdlpjob "github.com/tanq16/danzo/internal/jobs/ytdlp"
"github.com/tanq16/danzo/utils"
)
var ytdlpFlags struct {
outputPath string
}
var ytdlpCmd = &cobra.Command{
Use: "ytdlp [URL] [--output OUTPUT_PATH]",
Short: "Download using yt-dlp",
Aliases: []string{"yt-dlp", "youtube-dl", "ytdl"},
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
hw := newHighway()
disp := display.New(display.DefaultConfig())
job := ytdlpjob.New(args[0], ytdlpFlags.outputPath)
disp.RegisterJob(job.ID())
hw.Submit(job)
disp.Start(hw.Progress())
err := hw.Run(ctx)
disp.Stop()
if err != nil {
utils.PrintFatal("yt-dlp download failed", err)
}
},
}
func newYtdlpCmd() *cobra.Command {
return ytdlpCmd
}
func init() {
ytdlpCmd.Flags().StringVarP(&ytdlpFlags.outputPath, "output", "o", "", "Output path for the download")
}