-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_to_mp3.ahk
More file actions
62 lines (51 loc) · 1.7 KB
/
Copy pathconvert_to_mp3.ahk
File metadata and controls
62 lines (51 loc) · 1.7 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
^!c:: ; Ctrl + Alt + C
logFile := A_ScriptDir . "\conversion_log.txt"
; keep only the current session in the log
if FileExist(logFile)
FileDelete, %logFile%
FileAppend, [%A_Now%] Conversion started.`n, %logFile%
selectedFiles := GetSelectedFiles()
if (selectedFiles = "")
{
FileAppend, [%A_Now%] No files selected.`n, %logFile%
return
}
Loop, Parse, selectedFiles, `n
{
file := A_LoopField
if (file = "")
continue
SplitPath, file, name, dir, ext, name_no_ext
ext := "." . ext
if (ext ~= "i)\.(mp4|mp3|webm|mkv|avi|mov|flv|wav|aac|wma|ts|3gp)")
{
outputFile := dir . "\" . name_no_ext . "_converted.mp3"
; always start fresh
if FileExist(outputFile)
FileDelete, %outputFile%
command := "ffmpeg -y -hwaccel cuvid -i """ file """ -vn -ar 44100 -ac 1 -b:a 64k """ outputFile """"
RunWait, %ComSpec% /c %command%, , Hide, exitCode
if (exitCode = 0)
FileAppend, [%A_Now%] SUCCESS: %file% converted to %outputFile%`n, %logFile%
else
FileAppend, [%A_Now%] ERROR: Failed to convert %file% (Exit Code: %exitCode%)`n, %logFile%
}
else
{
FileAppend, [%A_Now%] SKIPPED: %file% (unsupported format)`n, %logFile%
}
}
FileAppend, [%A_Now%] Conversion finished.`n, %logFile%
return
GetSelectedFiles() {
selected := ""
for window in ComObjCreate("Shell.Application").Windows
{
try {
if (InStr(window.Document.FocusedItem.Path, ":\"))
for item in window.Document.SelectedItems
selected .= item.Path "`n"
}
}
return RTrim(selected, "`n")
}