Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
AutoIt3 script to record individual Winamp presets as separate videos.
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.12.0
Author: Kawika (Ugotsta)
Script Function:
Automates recording of Winamp visualizations
#ce ----------------------------------------------------------------------------
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
CONST $video_recorder = "MSI Afterburner"
CONST $record_start = "{F12}"
CONST $record_stop = "{F12}"
CONST $preset_partial_path = 'Plugins\Milkdrop2\presets\'
CONST $record_path = 'C:\Games\Future Pinball\Videos'
CONST $record_length = 30000
; Set title match mode so that any occurrence within title will succeed
AutoItSetOption ( "WinTitleMatchMode", 2)
$Recorder = WinExists( $video_recorder )
; Check for video recorder
If $Recorder Then
; Recorder window exists
Else
MsgBox( $MB_SYSTEMMODAL, "", "Please ensure your video recorder is running." )
Exit
EndIf
$winamp = FindFile( "Please locate Winamp program (winamp.exe).", "Winamp (winamp.exe)" )
$music_file = FindFile( "Select music file to play.", "Audio (*.wav;*.mp3;)" )
; Get preset path
$winamp_path = StringTrimRight( $winamp, 10 )
$preset_path = $winamp_path & $preset_partial_path
; Allow user to select presets
$selected = GetFiles( "Hold down Ctrl or Shift to choose multiple files.", "Presets (*.milk)" )
$user_preset_path = $selected[0]
; --------------------------------------------------------
; LOOP start - begin looping through selected preset files
For $i = 0 To UBound( $selected ) - 1
if $i > 0 Then
; Delete all existing files in preset path
FileDelete( $preset_path & "*.milk")
; Copy our preset file to preset path
FileCopy( $user_preset_path & "\" & $selected[ $i ], $preset_path )
RecordPreset( $selected[ $i ] )
EndIf
Next
MsgBox( $MB_SYSTEMMODAL, "", "Recording completed." )
Func RecordPreset( $preset )
; Run WinAmp
Run ( $winamp & ' "' & $music_file & '"')
; Wait for Winamp to load
$title = "Winamp"
$Win = WinWait( $title, "", 5 )
WinActivate( $title )
; Minimize all windows
;Send("#{m}")
WinMinimizeAll ()
WinWaitActive( $title, "", 5 )
WinSetState ( $title, "", @SW_HIDE )
; Sleep a bit to let text disappear
Sleep ( 5000 )
; Record
Send( $record_start )
Sleep( $record_length )
Send( $record_stop )
; Close Winamp
WinSetState ( $title, "", @SW_SHOW )
WinClose( $title )
; Rename newest file in recording folder
$newest = _GetNewestFile( $record_path )
$ext = StringMid( $newest, StringInStr( $newest, ".", 2, -1 ) )
$adjusted = $record_path & "\" & StringTrimRight( $preset, 5 ) & $ext
$Win = WinWaitClose( $title, "", 5 )
FileMove( $newest, $adjusted)
EndFunc
Func FindFile( $msg, $wildcard )
; Create a constant variable in Local scope of the message to display in FileOpenDialog.
Local Const $sMessage = $msg
; Display an open dialog to select a file.
Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", $wildcard, $FD_FILEMUSTEXIST)
If @error Then
; Display the error message.
MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")
; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(@ScriptDir)
Else
; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(@ScriptDir)
; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog.
$sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
; Return selected file.
Return $sFileOpenDialog
EndIf
EndFunc
Func GetFiles( $msg, $wildcard )
; Display an open dialog to select a list of file(s).
Local $sFileOpenDialog = FileOpenDialog( $msg, @WindowsDir & "\", $wildcard, $FD_FILEMUSTEXIST + $FD_MULTISELECT )
If @error Then
MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.")
FileChangeDir(@ScriptDir)
Else
FileChangeDir(@ScriptDir)
; Split results into array.
Local $fileArray = StringSplit( $sFileOpenDialog, "|", 2 )
; Special handler when user selects just one file.
If UBound( $fileArray ) = 1 Then
Local $drive = "", $dir = "", $filename = "", $ext = ""
Local $path = _PathSplit( $sFileOpenDialog, $drive, $dir, $filename, $ext)
Local $file = $filename & $ext
$fileArray[0] = StringTrimRight( $sFileOpenDialog, StringLen( $file ) + 1 )
_ArrayAdd( $fileArray, $file )
EndIf
Return $fileArray
EndIf
EndFunc
; ---------------------------------------
;
; from here: https://www.autoitscript.com/forum/topic/98840-last-created-file-in-directory/
;
; Function _GetNewestFile()
; Call with: _GetNewestFile($DirPath [, $DateType [, $Recurse] [, $Oldest])
; Where: $DirPath is the directory to search
; $DateType (0ptional) is the type of date to use [from FileGetTime()]:
; 0 = Modified (default)
; 1 = Created
; 2 = Accessed
; $Recurse (Optional): If non-zero causes the search to be recursive.
; $Oldest (Optional): If non-zero find oldest file
; On success returns the full path to the newest file in the directory.
; On failure returns 0 and sets @error (see code below).
; ---------------------------------------
Func _GetNewestFile($DirPath, $DateType = 0, $Recurse = 0, $Oldest = 0)
Local $Found, $FoundRecurse, $FileTime
Local $avNewest[2] = [0, ""]; [0] = time, [1] = file
If StringRight($DirPath, 1) <> '\' Then $DirPath &= '\'
If Not FileExists($DirPath) Then Return SetError(1, 0, 0)
Local $First = FileFindFirstFile($DirPath & '*.*')
If $First = -1 Or @error Then Return SetError(2, @error, 0)
If $Oldest Then
$avNewest[0] = FileGetTime($DirPath & FileFindNextFile($First), $DateType, 1)
$avNewest[1] = $DirPath & FileFindNextFile($First)
EndIf
While 1
$Found = FileFindNextFile($First)
If @error Then ExitLoop
If StringInStr(FileGetAttrib($DirPath & $Found), 'D') Then
If $Recurse Then
$FoundRecurse = _GetNewestFile($DirPath & $Found, $DateType, 1, $Oldest)
If @error Then
ContinueLoop
Else
$Found = StringReplace($FoundRecurse, $DirPath, "")
EndIf
Else
ContinueLoop
EndIf
EndIf
$FileTime = FileGetTime($DirPath & $Found, $DateType, 1)
If $Oldest Then
If $FileTime < $avNewest[0] Then
$avNewest[0] = $FileTime
$avNewest[1] = $DirPath & $Found
EndIf
Else
If $FileTime > $avNewest[0] Then
$avNewest[0] = $FileTime
$avNewest[1] = $DirPath & $Found
EndIf
EndIf
WEnd
If $avNewest[0] = 0 Then
Return SetError(3, 0, 0)
Else
Return $avNewest[1]
EndIf
EndFunc ;==>_GetNewestFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment