Jump to content

iso to avs


mikeytown2
 Share

Recommended Posts

Needed a way to automate ripping mutiple .iso DVDs and I came up with this. Uses VirtualCloneDrive to mount the iso file. Uses PgcDemux to do the actual ripping. Uses DGIndex to index the m2v. And finally writes a avs file for input into MeGUI.

Not perfect but gets the job done

#include <Array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>

Global $sINI = @ScriptDir & '\iso_to_avs.ini'

;add to array, list of files in a dir
Func FileListFromDir($dir, $filetype, ByRef $filelist)
    ;search for the first file with the correct file extenstion
    Local $file, $search = FileFindFirstFile($dir & "\" & $filetype)
    ; Check if the search was successful
    If $search = -1 Then
        $searchDIR = FileFindFirstFile($dir & "\*")
        While 1
            $file = FileFindNextFile($searchDIR)
            If @error Then
                ExitLoop
            EndIf
            If StringInStr(FileGetAttrib($dir & "\" & $file), "D") Then
                FileListFromDir($dir & "\" & $file, $filetype, $filelist)
            EndIf
        WEnd
        FileClose($searchDIR) ; Close the search handle
    EndIf

    ;add found files to array
    While 1
        $file = FileFindNextFile($search)
        If @error Then
            ExitLoop
        EndIf
        ;Add file to array
        _ArrayAdd($filelist, $dir & "\" & $file)
        $filelist[0] += 1
    WEnd
    FileClose($search) ; Close the search handle
EndFunc   ;==>FileListFromDir

;add from given array to Filelist
Func GetListOfFiles()
    Local $dirbit = 0
    Local $filetype = '*.iso'
    Local $filelist[1]
    $filelist[0] = 0

    ;Grab EXE Drag-n-Droped files/dir's
    If $CmdLine[0] > 0 Then
        For $x = 1 To $CmdLine[0] Step +1 ;run though all files droped and look for dir's
            If StringInStr(FileGetAttrib($CmdLine[$x]), "D") Then
                $dirbit += 1
                FileListFromDir($CmdLine[$x], $filetype, $filelist) ;parce dir looking for file of that extenstion
            Else ;add file to list
                _ArrayAdd($filelist, $CmdLine[$x])
                $filelist[0] += 1
            EndIf
        Next
    EndIf
    If $filelist[0] <= 0 Then
        ; Create a constant variable in Local scope of the message to display in FileOpenDialog.
        Local Const $sMessage = "Hold down Ctrl or Shift to choose multiple files."

        ; Display an open dialog to select a list of file(s).
        Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "ISO Files (*.iso)", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
        If @error Then
            ; Display the error message.
            MsgBox($MB_SYSTEMMODAL, "", "No file(s) were 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)

            If StringInStr($sFileOpenDialog, '|') Then
                $templist = StringSplit($sFileOpenDialog, '|')
                $dir = $templist[1]
                _ArrayDelete($templist, 1)
                $templist[0] -= 1
                While $templist[0] > 0
                    $newfile = $dir & '\' & $templist[1]
                    _ArrayDelete($templist, 1)
                    $templist[0] -= 1
                    _ArrayAdd($filelist, $newfile)
                    $filelist[0] += 1
                WEnd
            Else
                _ArrayAdd($filelist, $sFileOpenDialog)
                $filelist[0] += 1
            EndIf
        EndIf
    EndIf


    Return $filelist
EndFunc   ;==>ArrayToFileList

Func LoadISO($filename)
    Local $cmd = IniRead($sINI, 'FileLocations', 'vcdmount', @ProgramFilesDir & ' (x86)\Elaborate Bytes\VirtualCloneDrive\VCDMount.exe')
    RunWait(@ComSpec & " /c " & '"' & $cmd & '"' & ' /d=0 /u', "", @SW_HIDE)
    ShellExecuteWait($cmd, ' /d=0 ' & '"' & $filename & '"')
    Send("{SHIFTDOWN}")
    GUISetCursor(15)
    OutputStatus("Waiting for the DVD to load:" & @CRLF & $filename & @CRLF & "DO NOT PRESS THE SHIFT KEY")
    WinWait("AutoPlay","", 15)
    WinClose("AutoPlay")
    OutputStatus("")
    Send("{SHIFTUP}")
EndFunc


Func RipDVD($isoName)
    Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
    Local $aPathSplit = _PathSplit($isoName, $sDrive, $sDir, $sFilename, $sExtension)
    Local $dest = IniRead($sINI, 'FileLocations', 'destdir', 'D:\Users\admin\Videos\Rips\Auto\')  & $sFilename
    DirCreate($dest)

    Local $cmd = IniRead($sINI, 'FileLocations', 'pgcdemux', 'D:\Users\admin\Desktop\New folder\PgcDemuxMod.exe')
    Local $cddrive = IniRead($sINI, 'FileLocations', 'cddrive', 'G:\')
    Local $filelist[1]
    $filelist[0] = 0

    FileListFromDir($cddrive & 'VIDEO_TS', 'VTS*.IFO', $filelist)
    Local $counter = 1
    While $filelist[0] > 0
        $iPreviousFileSize = 0
        For $x = 1 To 99 Step +1
            OutputStatus('')
            If Not FileExists($dest & '\' & $counter & '-' & $x & '\VideoFile.m2v') Then
                DirCreate($dest & '\' & $counter & '-' & $x)
                Local $iPID = Run(@ComSpec & " /c " & '"' & $cmd & '"' & '  -pgc ' & $x & ' -m2v ' & $filelist[1] & ' ' & $dest & '\' & $counter & '-' & $x & '', "", @SW_HIDE)
                OutputStatus($counter & '-' & $x & ':m2v')
                ProcessWaitClose($iPID)
                Local $sOutput = StdoutRead($iPID)
                ; Remove dir if an error code was returned.
                If $sOutput <> 0 Then
                    DirRemove($dest & '\' & $counter & '-' & $x)
                    ExitLoop
                EndIf
                ; Remove dir if no video file was made.
                If Not FileExists($dest & '\' & $counter & '-' & $x & '\VideoFile.m2v') Then
                    DirRemove($dest & '\' & $counter & '-' & $x)
                    ExitLoop
                EndIf
            EndIf
            OutputStatus($counter & '-' & $x & ':checking')
            ; Remove dir if no audio file was made.
            If Not FileExists($dest & '\' & $counter & '-' & $x & '\AudioFile_80.ac3') Then
                DirRemove($dest & '\' & $counter & '-' & $x, 1)
            EndIf
            Local $iFileSize = FileGetSize($dest & '\' & $counter & '-' & $x & '\VideoFile.m2v')
            ; Remove dir if video file is smaller than 5MB.
            If $iFileSize < 5242880 Then
                DirRemove($dest & '\' & $counter & '-' & $x, 1)
            EndIf
            ; Remove dir if video file is the same as the last one.
            If $iPreviousFileSize == $iFileSize Then
                $this = _Crypt_HashFile($dest & '\' & $counter & '-' & $x & '\VideoFile.m2v', $CALG_MD5)
                $prev = _Crypt_HashFile($dest & '\' & $counter & '-' & ($x-1) & '\VideoFile.m2v', $CALG_MD5)
                ;MsgBox($MB_SYSTEMMODAL, "", StringCompare($this, $prev) & @CRLF & $this & @CRLF & $prev & @CRLF & $iPreviousFileSize & @CRLF & $iFileSize & @CRLF & $dest & '\' & $counter & '-' & $x & '\VideoFile.m2v' & @CRLF & $dest & '\' & $counter & '-' & ($x-1) & '\VideoFile.m2v')
                If StringCompare($this, $prev) == 0 Then
                    DirRemove($dest & '\' & $counter & '-' & $x, 1)
                EndIf
            EndIf
            $iPreviousFileSize = $iFileSize
            IndexVideo($dest & '\' & $counter & '-' & $x, $counter & '-' & $x)
            MakeAviSynthFile($dest, $counter & '-' & $x)
        Next
        OutputStatus('')
        $counter += 1
        _ArrayDelete($filelist, 1)
        $filelist[0] -= 1
    WEnd
EndFunc

Func IndexVideo($dir, $small_dir)
    If FileExists($dir & '\VideoFile.m2v') Then
        If Not FileExists($dir & '\VideoFile.d2v') Then
            Local $cmd = '"' & IniRead($sINI, 'FileLocations', 'dgindex', @ProgramFilesDir & ' (x86)\AviSynth 2.5\tools\dgmpegdec\DGIndex.exe') & '" -IF=[' & $dir & '\VideoFile.m2v] -OF=[' & $dir & '\VideoFile] -HIDE -EXIT'
            OutputStatus($small_dir & ':d2v')
            RunWait(@ComSpec & " /c " & $cmd, "", @SW_HIDE)
            OutputStatus('')
        EndIf
    EndIf
EndFunc

Func MakeAviSynthFile($dest, $small_dir)
    $sDestFile = $dest & '\' & $small_dir & '.avs'
    If Not FileExists($dest & '\' & $small_dir & '\VideoFile.d2v') Then
        If FileExists($sDestFile) Then
            FileDelete($sDestFile)
        EndIf
    ElseIf Not FileExists($sDestFile) Then
        Local $sFileContents = ''
        $sFileContents &= 'v = MPEG2Source("' & $small_dir & '\VideoFile.d2v", cpu=2)' & @CRLF
        $sFileContents &= 'a = NicAC3Source("' & $small_dir & '\AudioFile_80.ac3", 2)' & @CRLF
        $sFileContents &= 'audiodubex(v,  a)' & @CRLF
        $sFileContents &= '#QTGMC(Preset="draft",  NoisePreset="Slow")' & @CRLF
        $sFileContents &= 'QTGMC(Preset="Medium", NoisePreset="Slow")' & @CRLF
        $sFileContents &= 'SelectEven()' & @CRLF
        $sFileContents &= 'TDecimate()' & @CRLF
        FileWrite($sDestFile, $sFileContents)
    EndIf
EndFunc

Func OutputStatus($sMessage)
    Local $hWnd = WinGetHandle("")
    TrayTip('Status:', $sMessage, 30)
    TraySetToolTip($sMessage)
    WinActivate($hWnd)
EndFunc

$files = GetListOfFiles()
While $files[0] > 0
    LoadISO($files[1])
    RipDVD($files[1])
    _ArrayDelete($files, 1)
    $files[0] -= 1
WEnd
MsgBox($MB_SYSTEMMODAL, "", "Done")

Example INI file

 

[FileLocations]
dgindex=C:Program Files (x86)AviSynth 2.5toolsdgmpegdecDGIndex.exe
pgcdemux=D:UsersAdminDesktopNew folderPgcDemuxMod.exe
vcdmount=C:Program Files (x86)Elaborate BytesVirtualCloneDriveVCDMount.exe
cddrive=G:
destdir=D:UsersAdminVideosRipsAuto

Edited by mikeytown2
Link to comment
Share on other sites

avs to m4v script

#include <Array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>

;add to array, list of files in a dir
Func FileListFromDir($dir, $filetype, ByRef $filelist)
    ;search for the first file with the correct file extenstion
    Local $file, $search = FileFindFirstFile($dir & "\" & $filetype)
    ; Check if the search was successful
    If $search = -1 Then
        $searchDIR = FileFindFirstFile($dir & "\*")
        While 1
            $file = FileFindNextFile($searchDIR)
            If @error Then
                ExitLoop
            EndIf
            If StringInStr(FileGetAttrib($dir & "\" & $file), "D") Then
                FileListFromDir($dir & "\" & $file, $filetype, $filelist)
            EndIf
        WEnd
        FileClose($searchDIR) ; Close the search handle
    EndIf

    ;add found files to array
    While 1
        $file = FileFindNextFile($search)
        If @error Then
            ExitLoop
        EndIf
        ;Add file to array
        _ArrayAdd($filelist, $dir & "\" & $file)
        $filelist[0] += 1
    WEnd
    FileClose($search) ; Close the search handle
EndFunc   ;==>FileListFromDir

;add from given array to Filelist
Func GetListOfFiles()
    Local $dirbit = 0
    Local $filetype = '*.avs'
    Local $filelist[1]
    $filelist[0] = 0

    ;Grab EXE Drag-n-Droped files/dir's
    If $CmdLine[0] > 0 Then
        For $x = 1 To $CmdLine[0] Step +1 ;run though all files droped and look for dir's
            If StringInStr(FileGetAttrib($CmdLine[$x]), "D") Then
                $dirbit += 1
                FileListFromDir($CmdLine[$x], $filetype, $filelist) ;parce dir looking for file of that extenstion
            Else ;add file to list
                _ArrayAdd($filelist, $CmdLine[$x])
                $filelist[0] += 1
            EndIf
        Next
    EndIf
    If $filelist[0] <= 0 Then
        ; Create a constant variable in Local scope of the message to display in FileOpenDialog.
        Local Const $sMessage = "Hold down Ctrl or Shift to choose multiple files."

        ; Display an open dialog to select a list of file(s).
        Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "AVS Files (*.avs)", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
        If @error Then
            ; Display the error message.
            MsgBox($MB_SYSTEMMODAL, "", "No file(s) were 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)

            If StringInStr($sFileOpenDialog, '|') Then
                $templist = StringSplit($sFileOpenDialog, '|')
                $dir = $templist[1]
                _ArrayDelete($templist, 1)
                $templist[0] -= 1
                While $templist[0] > 0
                    $newfile = $dir & '\' & $templist[1]
                    _ArrayDelete($templist, 1)
                    $templist[0] -= 1
                    _ArrayAdd($filelist, $newfile)
                    $filelist[0] += 1
                WEnd
            Else
                _ArrayAdd($filelist, $sFileOpenDialog)
                $filelist[0] += 1
            EndIf
        EndIf
    EndIf


    Return $filelist
EndFunc   ;==>ArrayToFileList





Func QueueFile($sFileName)
    Opt("WinTitleMatchMode", 1)
    Local $hMeGUI = WinActivate("MeGUI ")
    BlockInput(1)
    Send("{CTRLDOWN}o{CTRLUP}")
    BlockInput(0)
    Local $hWnd = WinWaitActive("Select your input file")
    Sleep(500)
    Opt("SendKeyDelay", 0)
    BlockInput(1)
    ControlSend($hWnd, "", "Edit1", $sFileName & "{ENTER}")
    BlockInput(0)
    Opt("SendKeyDelay", 5)
    $hWnd = WinWaitActive("Current position:")
    Sleep(500)
    BlockInput(1)
    ControlSend($hWnd, "", "[NAME:showPAR]", "{SPACE}")
    BlockInput(0)
    Sleep(500)
    BlockInput(1)
    ControlSend($hWnd, "", "[NAME:dropDownButton]", "{SPACE}")
    Opt("SendKeyDelay", 50)
    Send("1{ENTER}")
    Opt("SendKeyDelay", 5)
    BlockInput(0)
    WinClose($hWnd)
    Sleep(500)
    WinWaitActive($hMeGUI)

        Local $aPos = MouseGetPos()
        Opt("MouseCoordMode", 0)
        BlockInput(1)
        MouseClick("left", 30, 50, 1, 0)
        BlockInput(0)
        Opt("MouseCoordMode", 1)
        MouseMove($aPos[0], $aPos[1], 0)

    Sleep(500)
    BlockInput(1)
    ControlClick($hMeGUI, "", "[NAME:autoEncodeButton]", "left", 1)
    BlockInput(0)
    Sleep(500)
    $hWnd = WinWaitActive("MeGUI - Automatic Encoding")
    Sleep(500)
    BlockInput(1)
    ControlClick($hWnd, "", "[NAME:addSubsNChapters]", "left", 1)
    BlockInput(0)
    Sleep(500)
    BlockInput(1)
    ControlClick($hWnd, "", "[NAME:queueButton]", "left", 1)
    BlockInput(0)
    Sleep(5000)
EndFunc


$files = GetListOfFiles()
While $files[0] > 0
    QueueFile($files[1])
    _ArrayDelete($files, 1)
    $files[0] -= 1
WEnd
MsgBox($MB_SYSTEMMODAL, "", "Done")
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...