This repository has been archived by the owner on Sep 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ydl.ahk
176 lines (138 loc) · 4.06 KB
/
ydl.ahk
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
SetWorkingDir, % A_ScriptDir
#SingleInstance, force
#NoEnv
; In case the script is compiled
FileInstall, LICENSE, LICENSE, 1
FileInstall, README.md, README.md, 1
FileInstall, icon.png, icon.png
FileInstall, retry.cmd, retry.cmd
FileInstall, terminal-format.cmd, terminal-format.cmd
FileInstall, update.ahk, update.ahk
FileInstall, update-run-once.ahk, update-run-once.ahk
FileInstall, Channel.conf, Channel.conf
FileInstall, Default.conf, Default.conf
FileInstall, Folder.conf, Folder.conf
FileInstall, Playlist Reverse.conf, Playlist Reverse.conf
FileInstall, Playlist.conf, Playlist.conf
;=================================
Menu, Tray, Icon, icon.png
Menu, Tray, Tip, % SCRNAME
#NoTrayIcon
EnvSet, ydl_dir, % A_ScriptDir
global SCRNAME:="YT-DLP Launcher"
global Path := getOpt("path", A_WorkingDir "\Download")
, Opts := getOpt("opts")
, Prof := getOpt("prof", "<None>")
, Sign := getOpt("sign", ">=")
, Res := getOpt("res", "720")
, Log := getOpt("log", False, "Hidden")
, Upd := getOpt("update", True, "Hidden")
, Def := getOpt("opts",, "Hidden")
, URL := ""
Gui, Margin, 10, 10
Gui, Add, Text, W50 Right ym+5, URLs
Gui, Add, Edit, vURL x+m W400 yp-5 R5
Gui, Add, Text, W50 Right xm y+15, Options
Gui, Add, Edit, vOpts x+m W400 yp-5 R2, % Opts
Gui, Add, Text, W50 Right y+15 xm, Path
Gui, Add, Edit, vPath x+m W380 yp-5, % Path
Gui, Add, Button, gPathClicked yp-1 x+0 W20, ...
Gui, Add, Text, xm y+15 W50 Right, Resolution
Gui, Add, DropDownList, vSign x+m yp-5 W40 section, >=|<=
guiSet("Sign", Sign, "ChooseString")
Gui, Add, ComboBox, vRes gResChanged x+m yp W70, Audio|Smallest|144|360|480|720|1080|2160|Largest
guiSet("Res", Res)
ResChanged()
Gui, Add, Text, x+m yp+5 W50 Right, Profile
Gui, Add, ComboBox, vProf x+m yp-5 W100, % createProfList()
guiSet("Prof", Prof)
Gui, Add, Button, Default gDownload yp-1 xs+330 W70, Download
Gui, Show,, % SCRNAME
Return
GuiClose:
ExitApp
Download(){
Gui, +OwnDialogs
Gui, Submit, NoHide
if !validate()
return
urls := "-- """ RegexReplace(url,"S)\s+", """ """) """"
getAud := Res="audio"? "-x -f ba" : ""
prof := Prof="<None>"? "" : "--config-location """ Prof ".conf"""
reverseSort := Sign==">=" || Res="smallest"
resolution := isInteger(Res)? ":" Res :""
format := "-S """ (reverseSort?"+":"") "res" resolution """"
homePath := "-P ""home:" Path """"
update := Upd? "-U" :""
EnvSet, ydl_home, % Path
cmd := "retry.cmd yt-dlp " update " " homePath " " prof " " format " " getAud " " Def " " Opts " " urls
if Log
log(cmd)
run, % cmd
}
validate(){
if !URL{
msgbox, % 48+4+256, % SCRNAME, No URL given. `nAre you sure you want to continue?
IfMsgBox, No
return False
}
if (isInteger(Res) && Res<=0) || (!isInteger(Res) && !inStr("audio`nsmallest`nlargest", Res))
return showErr("Resolution", Res)
Path:=RegExReplace(Path, "\\$")
FileCreateDir, % Path
if !InStr(FileExist(Path), "D")
return showErr("Path", Path)
if (Prof!="<None>" && !FileExist(Prof ".conf"))
return showErr("Profile", Prof)
saveOpt("path", Path)
saveOpt("profile", Prof)
saveOpt("opts", Opts)
saveOpt("sign", Sign)
saveOpt("res", Res)
return true
}
PathClicked(){
Gui, +OwnDialogs
GuiControlGet, current,, Path
FileSelectFolder, folder, % current, 3
guiSet("Path", folder? folder :current)
}
ResChanged(){
GuiControlGet, current,, Res
if isInteger(current)
GuiControl, Enable, Sign
else
GuiControl, Disable, Sign
}
createProfList() {
ret:="<None>"
Loop, Files, *.conf
{
if (A_LoopFileName!="yt-dlp.conf")
ret.="|" subStr(A_LoopFileName, 1, -5)
}
return ret
}
log(cmd){
FormatTime, timestamp,, yyyy-MM-dd HH:mm:ss
FileAppend, % "`n[" timestamp "]`t" cmd, % A_ScriptFullPath ".log"
}
showErr(key, val) {
msgbox, 16, % SCRNAME, "%val%" is not a valid %key%
return false
}
saveOpt(key, val, sect:="Options") {
IniWrite, % val, % A_ScriptFullPath ".ini", % sect, % key
}
getOpt(key, def:=" ", sect:="Options") {
IniRead, out, % A_ScriptFullPath ".ini", % sect, % key, % def
return out
}
guiSet(key, val, type="Text") {
GuiControl, % type, % key, % val
}
isInteger(x) {
if x is Integer
return True
return False
}