Code: Select all
; V.002
#SingleInstance force
#NoEnv
#Persistent
FileEncoding, UTF-8
SetBatchLines, -1
SetTitleMatchMode, 2
SetKeyDelay 20
; #noTrayIcon
SoundPlayMediaFilesToMp3 := true
DetectHiddenWindows, On
loop, 100
{
Process, Exist, FFmpeg.exe
PID := Errorlevel
Process, Close, %PID%
}
thisFFmpeg = D:\ffmpeg-win-2.2.2\ffmpeg.exe
; loop, files, D:\s88 content\MEDIA all\Media 12.08.2023\*.*, R
; loop, files, D:\# AHK Projekte\ahk s88pro speicher\Neuer Ordner\*.*, R
loop, files, D:\# AHK Projekte\# tmp\*.*, R
if a_loopFileEXT not contains exe,com,jpg,jpeg,gif,csv,txt,pdf,ahk,dok,doc,xlsm,xls,nomedia,mp3
DateiListe .= A_LoopFileLongPath "`n"
Sort DateiListe ; , N D, ; Numerisch sortieren und Komma als Trennzeichen verwenden.
DateiListeArr := strSplit(DateiListe,["`n","`r"])
for all, thisFile in DateiListeArr {
DateiListeArrLength := DateiListeArr.length()
if !thisFile
continue
ALoopFileALL := getSourceFileDetails()
; MsgBox % thisLoopFileSize
thisSourceFile = "%ALoopFileLongPath%"
thisDestFile = "%ALoopFileLongPath%.mp3"
thisX = %ALoopFileLongPath%.mp3
if FileExist(thisX)
{
; msgBox,,% a_lineNumber, % thisX,1
thisFileCounter++
toolTip % a_tab "# " thisFileCounter "\" (DateiListeArrLength-1) "`tthisContinue`text:`t" ALoopFileExt "`t" ALoopFileName
sleep, 200
thisSourceFile := ""
thisDestFile := ""
continue
}
if (ALoopFileExt = "opus") ; 18k
{
thisFileCounter++
toolTip % a_tab "# " thisFileCounter "\" (DateiListeArrLength-1) "`text:`t" ALoopFileExt "`t" ALoopFileName
res := RunCMD(A_Comspec
. " /c "
. thisFFmpeg
. " -i "
. thisSourceFile
. " -ab 18k -map_metadata 0:s:a:0 -id3v2_version 3 "
. thisDestFile
, A_ScriptDir
,"UTF-8")
} else if (ALoopFileExt = "") ; 75k
{
thisFileCounter++
toolTip % a_tab "# " thisFileCounter "\" (DateiListeArrLength-1) "`text:`tEmpty`t" ALoopFileName
res := RunCMD(A_Comspec
. " /c "
. thisFFmpeg
. " -i "
. thisSourceFile
. " -ab 75k -map_metadata 0:s:a:0 -id3v2_version 3 "
. thisDestFile
, A_ScriptDir
,"UTF-8")
} else { ; 128k
thisFileCounter++
toolTip % a_tab "# " thisFileCounter "\" (DateiListeArrLength-1) "`text:`t" ALoopFileExt "`t" ALoopFileName
res := RunCMD(A_Comspec
. " /c "
. thisFFmpeg
. " -i "
. thisSourceFile
. " -ab 128k -map_metadata 0:s:a:0 -id3v2_version 3 "
. thisDestFile
, A_ScriptDir
,"UTF-8")
}
; loop % thisX
; if (A_LoopFileSize=0)
; FileGetSize, thisFileSize ,% thisX
; if (thisFileSize=0)
if (getMP3FileSize()="Empty")
FileDelete,% thisX
toolTip
if res contains Conversion failed,No such file or directory
continue
FileAppend,% ALoopFileALL "`nMP3FileSize:`t" getMP3FileSize() "`n" res "`n",% (ALoopFileLongPath . ".txt")
if SoundPlayMediaFilesToMp3
soundplay,% ALoopFileLongPath ".mp3", WAIT
}
toolTip
; try run,% a_scriptDir "\sOutput.txt"
msgBox,,,% res "`ndone"
exitapp
getMP3FileSize() {
global thisX
loop,% thisX
{
ALoopFileSize := A_LoopFileSize
ALoopFileSizeKB := A_LoopFileSizeKB
ALoopFileSizeMB := A_LoopFileSizeMB
}
Return thisMP3FileSize := ALoopFileSizeMB ? ALoopFileSizeMB " MB"
: ALoopFileSizeKB ? ALoopFileSizeKB " KB"
: ALoopFileSize ? ALoopFileSize " Byte"
: "Empty"
}
getSourceFileDetails() {
global
loop,% thisFile
{
ALoopFileName := A_LoopFileName
ALoopFileExt := A_LoopFileExt
ALoopFileLongPath := A_LoopFileLongPath
ALoopFileDir := A_LoopFileDir
ALoopFileTimeModified := A_LoopFileTimeModified
ALoopFileTimeCreated := A_LoopFileTimeCreated
ALoopFileTimeAccessed := A_LoopFileTimeAccessed
ALoopFileAttrib := A_LoopFileAttrib
ALoopFileSize := A_LoopFileSize
ALoopFileSizeKB := A_LoopFileSizeKB
ALoopFileSizeMB := A_LoopFileSizeMB
}
thisFileSize := ALoopFileSizeMB ? ALoopFileSizeMB " MB"
: ALoopFileSizeKB ? ALoopFileSizeKB " KB"
: ALoopFileSize ? ALoopFileSize " Byte"
: "Empty"
Return ALoopFileALL := "A_LoopFileName:`t" ALoopFileName "`n"
. "A_LoopFileExt:`t" ALoopFileExt "`n"
. "A_LoopFileLongPath:`t" ALoopFileLongPath "`n"
. "A_LoopFileDir:`t" ALoopFileDir "`n"
. "A_LoopFileTimeModified:`t" ALoopFileTimeModified "`n"
. "A_LoopFileTimeCreated:`t" ALoopFileTimeCreated "`n"
. "A_LoopFileTimeAccessed:`t" ALoopFileTimeAccessed "`n"
. "A_LoopFileAttrib:`t" ALoopFileAttrib "`n"
. "A_LoopFileSize:`t" ALoopFileSize "`n"
. "A_LoopFileSizeKB:`t" ALoopFileSizeKB "`n"
. "A_LoopFileSizeMB:`t" ALoopFileSizeMB "`n"
. "thisFileSize:`t" thisFileSize
}
;RunCMD v0.97 Erfassen Sie die Standardausgabe in der Variablen. Nicht blockierende Version. Einzelne Zeilen vorverarbeitenweglassen. AutoHotkeyCommunity und 2 weitere Seiten Persönlich Microsoft Edge
;https://www.autohotkey.com/boards/viewtopic.php?f=6&t=74647&hilit=runcmd
RunCMD(CmdLine, WorkingDir:="", Codepage:="CP0", Fn:="RunCMD_Output", Slow:=1) { ; RunCMD v0.97
Local ; RunCMD v0.97 by SKAN on D34E/D67E @ autohotkey.com/boards/viewtopic.php?t=74647
Global A_Args ; Based on StdOutToVar.ahk by Sean @ autohotkey.com/board/topic/15455-stdouttovar
Slow := !! Slow
, Fn := IsFunc(Fn) ? Func(Fn) : 0
, DllCall("CreatePipe", "PtrP",hPipeR:=0, "PtrP",hPipeW:=0, "Ptr",0, "Int",0)
, DllCall("SetHandleInformation", "Ptr",hPipeW, "Int",1, "Int",1)
, DllCall("SetNamedPipeHandleState","Ptr",hPipeR, "UIntP",PIPE_NOWAIT:=1, "Ptr",0, "Ptr",0)
, P8 := (A_PtrSize=8)
, VarSetCapacity(SI, P8 ? 104 : 68, 0) ; STARTUPINFO structure
, NumPut(P8 ? 104 : 68, SI) ; size of STARTUPINFO
, NumPut(STARTF_USESTDHANDLES:=0x100, SI, P8 ? 60 : 44,"UInt") ; dwFlags
, NumPut(hPipeW, SI, P8 ? 88 : 60) ; hStdOutput
, NumPut(hPipeW, SI, P8 ? 96 : 64) ; hStdError
, VarSetCapacity(PI, P8 ? 24 : 16) ; PROCESS_INFORMATION structure
If not DllCall("CreateProcess", "Ptr",0, "Str",CmdLine, "Ptr",0, "Int",0, "Int",True
,"Int",0x08000000 | DllCall("GetPriorityClass", "Ptr",-1, "UInt"), "Int",0
,"Ptr",WorkingDir ? &WorkingDir : 0, "Ptr",&SI, "Ptr",&PI)
Return Format("{1:}", "", ErrorLevel := -1
,DllCall("CloseHandle", "Ptr",hPipeW), DllCall("CloseHandle", "Ptr",hPipeR))
DllCall("CloseHandle", "Ptr",hPipeW)
, A_Args.RunCMD := { "PID": NumGet(PI, P8? 16 : 8, "UInt") }
, File := FileOpen(hPipeR, "h", Codepage)
, LineNum := 1, sOutput := ""
While ( A_Args.RunCMD.PID | DllCall("Sleep", "Int",Slow) )
and DllCall("PeekNamedPipe", "Ptr",hPipeR, "Ptr",0, "Int",0, "Ptr",0, "Ptr",0, "Ptr",0)
While A_Args.RunCMD.PID and StrLen(Line := File.ReadLine())
sOutput .= Fn ? Fn.Call(Line, LineNum++) : Line
A_Args.RunCMD.PID := 0
, hProcess := NumGet(PI, 0)
, hThread := NumGet(PI, A_PtrSize)
, DllCall("GetExitCodeProcess", "Ptr",hProcess, "PtrP",ExitCode:=0)
, DllCall("CloseHandle", "Ptr",hProcess)
, DllCall("CloseHandle", "Ptr",hThread)
, DllCall("CloseHandle", "Ptr",hPipeR)
, ErrorLevel := ExitCode
Return sOutput
}