-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscorder.ahk
More file actions
140 lines (112 loc) · 3.41 KB
/
Discorder.ahk
File metadata and controls
140 lines (112 loc) · 3.41 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
134
135
136
137
138
139
140
#SingleInstance Force
KeyHistory 0
#Requires AutoHotkey v2.0
SetWorkingDir A_ScriptDir ; Ensures a consistent starting directory.
; TraySetIcon("C:\Users\rocket\_util\_Custom_Icon\Skull_Boi\Skull5.ico", 1, freeze := true)
MyGui := Gui(, "Discorder")
MyGui.SetFont("s32")
MyGui.Opt("+AlwaysOnTop +ToolWindow -SysMenu +Owner") ; +Owner avoids a taskbar button.
MyGui.MenuBar := ""
w := A_ScreenWidth * 0.3
h := A_ScreenHeight * 0.3
x := A_ScreenWidth - w - 50
y := A_ScreenHeight - h - 100
guictrl := MyGui.Add("ListBox", "r6 x0 w600 vChoice", ["Drop Video Here"])
MyGui.OnEvent("DropFiles", Gui_DropFiles , 1)
MyGui.Show("NoActivate") ; NoActivate avoids deactivating the currently active window.
MyGui.Move(x, y, w, h)
ih := InputHook("L1", "{Space}{Enter}")
ih.Start()
ih.Wait()
guiData := MyGui.Submit()
if(ih.EndKey != "Space" and ih.EndKey != "Enter"){
return
}
Gui_DropFiles(GuiObj, GuiCtrlObj, FileArray, X, Y) {
guiData := MyGui.Submit()
ih.Stop()
ffprobePath := A_WorkingDir "/bin/path_ffprobe.md"
Loop Read, ffprobePath
{
ffprobe := a_LoopReadLine
break
}
for i, DroppedFilePath in FileArray
try
{
cmd := Format( '"{1}" -i "{2}" -show_entries format=duration -v quiet -of csv="p=0"', ffprobe, DroppedFilePath )
shell := ComObject("WScript.Shell")
fullCmd := A_ComSpec " /C " "`"" cmd "`""
exec := shell.Exec(fullCmd)
cmdOutput := exec.StdOut.ReadAll()
size := FileGetSize(DroppedFilePath, 'M')
if(size <= 9){
desiredSize := size
secNum := size
}else{
desiredSize := 10.0 - ((size/10) * 0.2) ; minus small buffer (0.2 mb) to further accomodate any potential inaccuracies
}
powerOf2ByBits := 8192
withOverhead := 1.024
if(InStr(cmdOutput,".")){
strArray := StrSplit(cmdOutput,'.')
secNum:= strArray[1]
}else{
secNum:= cmdOutput
}
if isInteger(secNum){
totalSeconds:= Integer(secNum)
audioBitRate := 128
result := (desiredSize * powerOf2ByBits) / (totalSeconds * withOverhead) - audioBitRate ;Calculate total bitrate → Subtract audio bitrate
strArray := StrSplit(result,'.')
result := Integer(strArray[1])
ReEncode(DroppedFilePath, result, size)
}
}
catch Error as e{
MsgBox(e.Message)
}
}
ReEncode(inputPath, bitrate, size) {
try{
handbrakePath := A_WorkingDir "/bin/path_HandBrakeCLI.md"
Loop Read, handbrakePath
{
cliPath := a_LoopReadLine
break
}
if(size <= 9){
presetPath := A_WorkingDir "/bin/slowpreset.json"
}else{
presetPath := A_WorkingDir "/bin/preset.json"
}
strArray := StrSplit(inputPath,'.')
outputPath := strArray[1] "+.mp4"
; outputPath := strArray[1] "+." strArray[2]
cmd := Format('"{1}" -i "{2}" -o "{3}" --preset-import-file "{4}" -b {5}', cliPath, inputPath, outputPath, presetPath, bitrate)
consolePath := A_WorkingDir "/bin/encode.ps1"
file := FileOpen(consolePath, "w")
{
if !IsObject(file)
{
MsgBox "Can't open" consolePath "for writing."
return
}
script .= "& " cmd "`n"
file.Write(script)
}
file.Close()
runcmd := Format('powershell.exe -ExecutionPolicy Unrestricted -File {1}', consolePath)
RunWait(runcmd)
}
catch Error as e{
MsgBox(e.Message)
}
}
; todo: sanitize filenames
; todo: add logging
; todo: detect audio bitrate
; todo: allow size choice
; todo: ignore files under sizechoice - overhead
; todo: make bg transparent ~~and move to one side~~
; todo: allow forcing slowpreset for better results