-
Notifications
You must be signed in to change notification settings - Fork 3
/
ytdl-ResolveWindow_V2 (1).lua
154 lines (109 loc) · 3.01 KB
/
ytdl-ResolveWindow_V2 (1).lua
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
local ui = fu.UIManager
local disp = bmd.UIDispatcher(ui)
local width,height = 600,600
local clock = os.clock
function sleep(n) -- seconds
local t0 = clock()
while clock() - t0 <= n do end
end
win = disp:AddWindow({
ID = 'MyWin',
WindowTitle = 'youtube-dl',
Geometry = {100,100,width,height},
Spacing = 15,
Margin = 20,
ui:VGroup{
ID = 'root',
ui:HGroup{
ui:LineEdit{ ID = "inputurl",
PlaceholderText = "Enter a video's url",
Text = "",
Weight = 1.5,
MinimumSize = {150, 24} },
ui:Button{ID='geturl', Text='Get Formats', weight=1.5},
},
ui:HGroup{
ui:TextEdit{ID='formats', Text = '[yt-dl] \n [info] Available formats (Choose an MP4)', ReadOnly = true,},
},
ui:HGroup{
ui:LineEdit{ ID = "userformat",
PlaceholderText = "Leave blank on stock sites",
Text = "",
Weight = 1.5,
MinimumSize = {150, 24} },
ui:Button{ID='getvidf', Text='Get video', weight=1.5},
},
},
})
itm=win:GetItems()
resolve = Resolve()
projectManager = resolve:GetProjectManager()
project = projectManager:GetCurrentProject()
mediapool = project:GetMediaPool()
folder = mediapool:GetCurrentFolder()
mediastorage=resolve:GetMediaStorage()
mtdvol=mediastorage:GetMountedVolumes()
function win.On.MyWin.Close(ev)
disp:ExitLoop()
end
function win.On.geturl.Clicked(ev)
url = tostring(itm.inputurl.Text)
dump(url)
lpath = tostring(mtdvol[1]).."/ytdl"
dump(lpath)
ytdlProgramPath = 'youtube-dl'
ytformatcmd=ytdlProgramPath.." -F "..url
formatproc=io.popen(ytformatcmd)
local foutput = formatproc:read('*all')
formatproc:close()
dump(foutput)
itm.formats.PlainText = foutput
ytcommand=ytdlProgramPath.." "..url
dump("Attempting to download ")
dump(ytcommand)
--propat=os.execute(ytcommand)
--mediastorage:AddItemListToMediaPool(fpath)
folder = mediapool:GetCurrentFolder()
end
function win.On.getvidf.Clicked(ev)
url = tostring(itm.inputurl.Text)
if itm.userformat.Text ~= "" then
uformat = tostring(itm.userformat.Text)
uwuformat = " -f "..uformat
dump(uwuformat)
else
uwuformat = " "
dump("Inentionally blank ")
end
pname = project:GetName()
ipath = mtdvol[1].."\\ytdl\\"..pname
iqpath = "\""..mtdvol[1].."\\ytdl\\"..pname.."\""
prelscomm = "dir \""..ipath.."\" /o-d /tc /b"
dump(prelscomm)
count = 0
--[[for line in noutput:lines() do
if count == 8 then
noutput:close()
preoutput = line
end
count = count+1
end
noutput:close()]]
ytdlcomm ="youtube-dl"..uwuformat.." "..url.." -o \""..ipath.."\\%(title)s.%(ext)s\" --restrict-filenames"
propat=os.execute(ytdlcomm)
prenameproc = assert(io.popen(prelscomm))
for line in prenameproc:lines() do
if count == 0 then
dump(line)
fname = line
end
count = count +1
end
prenameproc:close()
fpath = ipath.."\\"..fname
dump(fpath)
mediastorage:AddItemListToMediaPool(fpath)
end
win:Show()
disp:RunLoop()
win:Hide()