-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtypes.go
More file actions
133 lines (110 loc) · 3.14 KB
/
Copy pathtypes.go
File metadata and controls
133 lines (110 loc) · 3.14 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"regexp"
"github.com/charmbracelet/bubbles/filepicker"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
type state int
const (
stateInputURL state = iota
stateFetching
stateSearching
statePickSearchResult
stateInfo
statePickDir
stateCreateDir
stateInputFilename
statePickFormat
statePickBrowser
stateDownloading
stateDone
stateError
)
var (
titleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("205")).Bold(true)
infoStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("211"))
errorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("9")).Bold(true)
helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241"))
successStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).Bold(true)
boldStyle = lipgloss.NewStyle().Bold(true)
progressRe = regexp.MustCompile(`(\d+(\.\d+)?)%`)
itemRe = regexp.MustCompile(`\[download\] Downloading item (\d+) of (\d+)`)
urlRe = regexp.MustCompile(`^https?://`)
)
type Config struct {
LastSaveDir string `yaml:"last_save_dir"`
DefaultFormat string `yaml:"default_format"`
Browser string `yaml:"browser"`
ArchivePath string `yaml:"archive_path"`
}
type formatItem struct {
label string
ext string
}
func (i formatItem) Title() string { return i.label }
func (i formatItem) Description() string { return "Download as " + i.ext }
func (i formatItem) FilterValue() string { return i.label }
type browserItem string
func (i browserItem) Title() string { return string(i) }
func (i browserItem) Description() string {
if i == "none" {
return "Do not use browser cookies"
}
return "Extract cookies from " + string(i)
}
func (i browserItem) FilterValue() string { return string(i) }
type searchResultItem struct {
title string
url string
dur string
}
func (i searchResultItem) Title() string { return i.title }
func (i searchResultItem) Description() string { return "Duration: " + i.dur + " | " + i.url }
func (i searchResultItem) FilterValue() string { return i.title }
type model struct {
state state
urlInput textinput.Model
filenameInput textinput.Model
mkdirInput textinput.Model
spinner spinner.Model
filepicker filepicker.Model
progress progress.Model
formatList list.Model
searchList list.Model
browserList list.Model
url string
videoTitle string
videoDuration float64
saveDir string
saveFilename string
selectedFormat string
downloadPercent float64
currentItem int
totalItems int
err error
doneMessage string
lastWindowHeight int
lastWindowWidth int
msgChan chan tea.Msg
config Config
}
type infoFetchedMsg struct {
title string
duration float64
}
type searchResultsMsg []list.Item
type progressMsg struct {
pct float64
current int
total int
}
type downloadDoneMsg struct {
message string
}
type errMsg struct{ err error }
func (e errMsg) Error() string { return e.err.Error() }