Jump to content

Automate DVD Shrink


Recommended Posts

Hello All

I am not a full noob when it comes to programming but i'm definatelly not an elite programmer. I can create a hack here and a solution there but there is so much I don't understand and would love to. I'm getting there but I have to teach myself.

I have a program here that I created for my HTPC system for my girlfriend. It is an automation script for DVDShrink 3.2 and is designed for true 1 touch ripping and burning.

I needed a way I could insert a DVD, use a remote control to rip to HDD without the need for a mouse or keyboard. I also wanted options to be able to simply rip to HDD without burning so I could do that later.

Here is the script I created over time to do this:

#cs ----------------------------------------------------------------------------
 Title: AutoDVDShrink
 Version: 3.2.10.0
 Author: JesterMgee

 Script Function: Automate DVDShrink with no user intervention. 
    
1 click DVD backup. Choose (in config file) to archive rips to HDD and/or burn DVD.
Designed with HTPC applications in mind where you insert a DVD, press copy then go 
back to what it was you were doing.

#ce ----------------------------------------------------------------------------

; 
#include "Misc.au3" ;Includes a check to see if process is already running and terminates process.
if _Singleton("AutoDVDShrink",1) = 0 Then
    ProcessClose("AutoDVDShrink.exe")
EndIf
;Create Config.ini file if it doesn't exsist
If Not FileExists("Config.ini") Then
    IniWrite("Config.ini", "OPTIONS", "DVDLETTER", "F:")
    IniWrite("Config.ini", "OPTIONS", "DEFAULTDIR", "D:\DVDRip")
    IniWrite("Config.ini", "OPTIONS", "KEEPCOPY", "YES")
    IniWrite("Config.ini", "OPTIONS", "BURNCOPY", "YES")
    MsgBox(48,"No Configuration File Found", "No configuration file detected. A Configuration file has been created. Please set the options are reload AutoDVDShrink.")
    Exit
EndIf
;subroutine to continously check for DVDShrink. If not detected the script will exit with a failure message. Routine is activated by AdlibEnable.
Func processquit()
    If Not ProcessExists("DVD Shrink 3.2.exe") Then
        MsgBox(16,"Problem - DVD Shrink Not Detected", "DVD Shrink was not detected or has terminated. The process has not finished successfully and must quit.",60)
        CDTray(""&$DVDLETTER&"", "open")
        Exit
    EndIf
    EndFunc

;Load in values fron config.ini
$DVDLETTER = IniRead("Config.ini", "OPTIONS", "DVDLETTER", "F:")
$DEFAULTDIR = IniRead("Config.ini", "OPTIONS", "DEFAULTDIR", "D:\DVDRip")
$KEEPCOPY = IniRead("Config.ini", "OPTIONS", "KEEPCOPY", "YES")
$BURNCOPY = IniRead("Config.ini", "OPTIONS", "BURNCOPY", "YES")
DirRemove(""&$DEFAULTDIR&"\TEMP")

While 1
If FileExists(""&$DVDLETTER&"\VIDEO_TS") Then ;Check Drive Tray
Run("C:\Program Files\DVD Shrink\DVD Shrink 3.2.exe") ;Launch DVDShrink
WinWait("DVD Shrink 3.2", "", 10) ;Open DVD Shrink
AdlibEnable("processquit", 1000) ;Enable the routine to check for DVD Shrink.
IF @error = 1 Then
    Exit
EndIf
sleep(100)
Send("{ALT}") ;Open Menu
sleep(100)
Send("{DOWN}") ;Drop down menu
Send("{D}") ;Select "Open Disc"
Send("{ENTER}") ;Select DVD in rom drive on pop-up menu
sleep(1000)
; Send("{ENTER}")
WinWait("DVD Shrink 3.2 - "&$DVDLETTER&"", "", 900) ;wait for options window (wait for analyzing to finish)
IF @error = 1 Then
    WinClose("DVD Shrink 3.2")
    Exit
EndIf
sleep(100)
Send("^b") ;Send CTRL+B for "Backup"
sleep(1000)
IF $BURNCOPY = ("YES") Then ;Routine to select to either burn to disk or just save to HDD
    Send("{HOME}")
Else
    Send("{END}")
EndIf
sleep(200)
Send("{TAB}")
IF $KEEPCOPY = ("YES") Then
    $var = DriveGetLabel( ""&$DVDLETTER&"" )
    Send(""&$DEFAULTDIR&"\"&$var&"", 1)
Else
    Send(""&$DEFAULTDIR&"\TEMP", 1)
EndIf
WinWait("Backup DVD", "", 20) ;Backup dialog window
sleep(100)
Send("{ENTER}") ;Confirm backup to HDD
sleep(100)
If WinExists("DVD Shrink 3.2", "Delete the files now") Then ;If files exist in directory then delete
    Send("y")
Endif
Opt("WinTitleMatchMode", 2) ;Sets match mode for detecting the window to "any" to find the word "encoding"
WinWait("Encoding", "", 20) ;waits for the encoding window then switches control back to Meedio
sleep(500)
send("!{TAB}") ;Switches back to background application
WinWait("Backup Complete", "", 2400) ;Wait for the backup complete window then close DVD Shrink.
sleep(500)
AdlibDisable()
$var = WinClose("DVD Shrink 3.2") ;Close program after DVD copy complete
If $var = 1 Then
    MsgBox(64,"Completed", "The ripping process has completed. Please check to make sure it worked and have a good day",60)
Else
    MsgBox(16,"Problem", "DVDShrink was not closed by AutoDVD Shrink. The disk may not have ripped successfully.",60)
EndIf
CDTray(""&$DVDLETTER&"", "open")
Exit
Else ;Displays message if no DVD detected in drive
    CDTray(""&$DVDLETTER&"", "open")
    $var = MsgBox(1,"No DVD Detected..."&$DVDLETTER&"", "Insert a DVD Video Disk First. Auto Continue In 15 Sec.",15)
    CDTray(""&$DVDLETTER&"", "close")
    If $var = 2 Then Exit
    EndIf
    
WEnd

The code simply emulates keyboard presses to automate the copying process and I have helpful tags in there to show what everything does.

I'd like to clean it up a bit using routines and such but haven't mastered that yet. The code isn't perfect but if you have DVDShrink then you should be able to compile this code and test it out. You need DVDShrink 3.2 and it needs to be installed in the default dir (or need to change some of the code).

Because i'm no expert, there are some cases that if you do manually stop the copying process or there is some kind of failure, the script doesn't terminate. That is where I have timeouts where i'd like to have more of a reliable method since on some slower machines the timeout may expire before the ripping is done.

I'm open to suggestions to help me curb bad coding habbits. I have created many, many a batch script which I am quite good at but as many people here would agree, batch scripts tend to be sloppy on a good day and lead to bad habbits in coding.

Cheers :D

EDIT: Had to make a change to one timeout that was way too short.

Edited by jestermgee
Link to comment
Share on other sites

I am trying to improve this code now I have most of it working. I have made some additional timing changes and also created a check to see if my script successfully closed the program.

What I would like to do is get rid of the winwait timeouts if at all possible.

I need to wait while DVDShrink rips the disk but I also need a way to exit the script should something go wrong and the process never finishes. I am using this script as a learning tool so any pointers would be great.

QUESTION: Is there an easy way I can simply check to see if DVD Shrink is still running WHILE waiting for a particular process to finish?

Where I have the following code:

WinWait("Backup Complete", "", 2400)

I'd like to do a continous check to see if the DVDShrink.exe process is still running and if it is not then exit the script with an error. Ideally i'd like to continously check throughout the entire script for the existance of the running process and terminate at any time the process is not found. How can I create a continous subroutine to do this?

Link to comment
Share on other sites

Create your own little function using ProcessExists(), and then use AdlibEnable() to run your function at a regular interval.

That's exactly what I needed :D

Works a treat now and I have now updated my first post with the modified code.

Thanks.

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...