Difference between revisions of "Anri-chan/Source/anri.bat"

From SDA Knowledge Base

Jump to: navigation, search
(avi sample extractor)
(sample extractor - separatefields back in.)
Line 69: Line 69:
 
ECHO trim^(!trimval!,!trim2!^) >> sample.avs
 
ECHO trim^(!trimval!,!trim2!^) >> sample.avs
 
ECHO AssumeTFF >> sample.avs
 
ECHO AssumeTFF >> sample.avs
REM ECHO SeparateFields >> sample.avs
+
ECHO SeparateFields >> sample.avs
 
ECHO converttoyv12 >> sample.avs
 
ECHO converttoyv12 >> sample.avs
 
CALL :1pass sample.avs sample 128000 19 1
 
CALL :1pass sample.avs sample 128000 19 1
Line 77: Line 77:
 
ECHO Finished. You will find sample.mp4 on your desktop. Feel free to rename it to something more descriptive like nameofgame_sample.mp4.
 
ECHO Finished. You will find sample.mp4 on your desktop. Feel free to rename it to something more descriptive like nameofgame_sample.mp4.
 
ECHO.
 
ECHO.
REM ECHO ^^! READ ^^! You will see that the video has been resized vertically ^(it's slightly more complicated than that..^), this is normal and will make it easier for the techies to help you.
+
ECHO ^^! READ ^^! You will see that the video has been resized vertically ^(it's slightly more complicated than that..^), this is normal and will make it easier for the techies to help you.
 
ECHO.
 
ECHO.
 
pause
 
pause

Revision as of 22:03, 12 February 2008

@ECHO OFF

REM metroid 2002 speed demos archive anri-chan
REM http://www.metroid2002.com/
REM http://speeddemosarchive.com/
REM nathan jahnke <njahnke@gmail.com>
REM Ian Bennett
REM Philip "ballofsnow" Cornell

REM Restart anri-chan if not set to low priority
FOR %%G IN (%*) DO (
  IF %%G==anrilow (SET anrilow=y)
  IF %%G==samplemode (SET samplemode=y)
)
IF NOT DEFINED anrilow ( GOTO setanribat )

REM INITIALISATION
(SET in_anrichan=y)
(SET anri_dir=%~dp0)
(SET anri_path=%~dp0anri.bat)
(SET dgmpgdec_dir=dgmpgdec149)
(SET vdub=virtualdub-1.7.6)
REM Get AviSynth path, %avisynthdir%, C:\Program Files\AviSynth 2.5
CALL externalpaths.bat

REM log name
(SET log=log_%time%)
(SET log=%log::=%)
(SET log=%log: =%)
(SET log=%log:.=%.txt)

REM get the name of the desktop ... old method for safety, then new method
(SET DESKTOP=%HOMEPATH%\desktop)

XCOPY /Y /Q "%anri_dir%anridesktoploc.bat" "%appdata%"
REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /V "Desktop" | "%anri_dir%sed" -n s/.\+REG_SZ.\+\\\(.\+\)[^\\]*/\1/gp >> "%appdata%\anridesktoploc.bat"
CALL "%appdata%\anridesktoploc.bat"
SET DESKTOP=%HOMEPATH%\%DESKTOP%
DEL "%appdata%\anridesktoploc.bat"

CALL "%anri_dir%settings.bat"
REM SETTINGS
REM (SET vars_to_use=temp_files this_anriver done d f vhs onepixel nes twod statid statid1 statid2 statid3 driveletter projname gba gameboy dvdsource prog trim create_hq create_mq create_lq create_iq create_xm create_xl using_settings check_now avifiles avifolder deflicker twodtemp maxaudiobitrate hqq no_pause_before_indexing)
(SET anri_ver=2.1)


REM ------- SAMPLE EXTRACTION PROCEDURE -------
:proc_sample
IF NOT "%samplemode%"=="y" GOTO proc_main
SETLOCAL ENABLEDELAYEDEXPANSION
CD "%DESKTOP%"
SET projdirpath=%CD%
(SET no_pause_before_indexing=y)
(SET projname=sample)
CALL :out_cls
CALL :q_dvdsource
IF "%dvdsource%"=="y" (
  CALL :q_driveletter 0
  CALL :index_dvd
) ELSE CALL :q_avi
CALL :out_info This sample will be 300 frames long, pick the starting frame of a scene with action.
COPY /B "sample.avs" "sample_trimtemp.avs" 1> NUL
ECHO lanczos4resize^(320,240^) >> "sample_trimtemp.avs"
PAUSE
START "trimming vdub" "%anri_dir%%vdub%\virtualdub.exe" "sample_trimtemp.avs"
CALL :q_trimval Frame#:
SET /A trim2=!trimval! + 299
ECHO trim^(!trimval!,!trim2!^) >> sample.avs
ECHO AssumeTFF >> sample.avs
ECHO SeparateFields >> sample.avs
ECHO converttoyv12 >> sample.avs
CALL :1pass sample.avs sample 128000 19 1
DEL sample*.avs 2> NUL | DEL sample.bak 2> NUL | DEL sample*.d2v 2> NUL | DEL sampleVTS* 2> NUL | DEL log*.txt 2> NUL
ECHO.
ECHO.
ECHO Finished. You will find sample.mp4 on your desktop. Feel free to rename it to something more descriptive like nameofgame_sample.mp4.
ECHO.
ECHO ^^! READ ^^! You will see that the video has been resized vertically ^(it's slightly more complicated than that..^), this is normal and will make it easier for the techies to help you.
ECHO.
pause
@echo on
ENDLOCAL ENABLEDELAYEDEXPANSION
EXIT


REM ------- MAIN PROCEDURE -------
:proc_main
CALL :out_cls
IF "%main_anri_updated%"=="y" GOTO die
IF "%using_settings%"=="y" GOTO proc_check_settings
CALL :resetvars
CALL :out_cls
CALL :out_info ON HERMESUS LUC ARSUS ESTARIAS AUC ELTRAS LI CELES! Now, let's get to work!
CALL :out_section PROJECT SETUP
CALL :q_projname
CALL :make_projdir
CALL :find_existing_settings
IF "%using_settings%"=="y" GOTO proc_check_settings
CALL :out_cls_section MOVIE SOURCE
CALL :q_dvdsource
IF "%dvdsource%"=="y" (
  CALL :q_driveletter
  CALL :index_dvd
) ELSE CALL :q_avi

:proc_gameproperties
CALL :out_cls_section GAME PROPERTIES
CALL :q_dfnd
IF "%dfnd_set%"=="y" GOTO dfnd_is_set
CALL :q_d
CALL :q_f
IF NOT "%f%"=="1" (SET twod=n) ELSE (CALL :q_2d)
CALL :q_submit_dfnd
:dfnd_is_set
IF "%d%"=="4" SET hqq=17
IF "%d%"=="1" SET hqq=19

CALL :out_cls_section VIDEO PROPERTIES
CALL :q_prog
IF "%prog%"=="y" GOTO contprop
CALL :q_fieldorder
CALL :q_vhs
IF "%d%"=="1" GOTO contprop
IF NOT "%f%"=="2" CALL :q_onepixel
IF NOT "%dfnd_set%"=="y" CALL :q_nes
IF "%nes%"=="y" GOTO contprop
IF NOT "%dfnd_set%"=="y" CALL :q_gba
IF "%gba%"=="y" (
  SET deflicker=y
  GOTO contprop
)
IF NOT "%dfnd_set%"=="y" CALL :q_gameboy
IF "%gameboy%"=="y" (
  SET deflicker=y
  GOTO contprop
)
IF NOT "%f%"=="2" CALL :q_deflicker

:contprop
CALL :out_cls_section CONTENT PROPERTIES
CALL :q_trim
IF "%trim%"=="y" CALL :q_trimming
CALL :q_statid
IF "%statid%"=="y" CALL :q_statid_lines

:proc_check_settings
CD "%DESKTOP%\%PROJNAME%"
CALL :check_settings
IF "%settings_good%"=="y" (
  CALL :savesettings
  CALL :out_cls_section READY TO ENCODE
  CALL :out_info Your settings for this project have been saved to "%projname%_job.bat". To resume the project, double-click that file.
  CALL :q_encodenow
  GOTO :start_encode_test
) ELSE (
  REM CALL :wipe_projdir
  REM CALL :resetvars
  REM SET using_settings=
  REM GOTO proc_main
  FOR %%A IN (d f twod fieldorder vhs onepixel nes gba gameboy deflicker trimarray) DO (SET %%A=)
  GOTO proc_gameproperties
)

:proc_encode
CALL :script_buildfiles
CALL :out_cls_section ENCODING OPTIONS
CALL :select_qualities
REM IF "%not_encoding%"=="y" GOTO proc_close
REM see below comment for more about this
REM CALL :out_cls_info Now encoding.
CALL :encode_movies

:proc_close
ECHO All dun.
GOTO die



REM ------- QUESTIONS ABOUT MOVIE SOURCE -------

:q_dfnd
CALL :out_info The next few questions are about the game played in this video. SDA has a database of games we have seen in the past, which can answer some or all of the questions for you.
SET s=
SET /P s=Do you want to use Anri-chan's games database [Y] or enter the data yourself [N]? [y,n] 
CALL :set_var_bool dfnd q_dfnd
IF "%dfnd%"=="y" CALL :dfnd
GOTO :EOF

:q_dvdsource
SET s=
SET /P s=DVD source [y,n]: 
CALL :set_var_bool dvdsource q_dvdsource
GOTO :EOF

:q_driveletter
REM If a parameter of 0 is sent to this function, it will skip mplayer extraction.
ECHO.
CALL :out_info Tip: If you already have your DVD source files on your hard drive, move them into C:\VIDEO_TS\ and select C as your drive letter.
SET s=
SET /P s=DVD Drive Letter: 
CALL :set_var_letter driveletter q_driveletter
IF EXIST %driveletter%:\VIDEO_TS (
  SET dvdfolder=VIDEO_TS
  SET source=%driveletter%:\VIDEO_TS\VTS_01_1.VOB
  SET dginputmethod=-AIF
  CALL :log_dvdfolder
  IF EXIST %driveletter%:\VIDEO_TS\*.IFO IF NOT [%1]==[0] CALL :rip_dvd
) ELSE (
  IF EXIST %driveletter%:\DVD_RTAV (
    SET dvdfolder=DVD_RTAV
    SET dginputmethod=-IF
  ) ELSE (
    ECHO Neither VIDEO_TS or DVD_RTAV folder was found on %driveletter%:\. Anri-chan is displeased.
    goto :die
  )
)
GOTO :EOF


:q_projname
SET s=
SET /P s=Project name (no spaces allowed; if you enter the same name as an existing project then all of its files will be overwritten): 
CALL :set_var_nospace projname q_projname
GOTO :EOF


:q_avi
SET maxaudiobitrate=320000
CALL :out_cls_section AVI SOURCE
ECHO Enter the path to each avi file [i]ndividually or [a]utomatically. Note that if you choose automatic, anri-chan will load the files in an alphabetical manner. The files must have the same resolution and framerate to be joined together.
ECHO.
:q_avi_p2
SET s=
SET /P s=[i,a]: 
CALL :set_var_in avimethod q_avi_p2 ia
IF %avimethod%==i ( CALL :q_avi_i ) ELSE ( CALL :q_avi_a )
REM AVI files loaded, generate avs source lines.
ECHO import^("%anri_dir%nate.avs"^) > "%projname%.avs"
ECHO import^("%avisynthdir%\plugins\mvbob.avs"^) > "%projname%.avs"
SETLOCAL ENABLEDELAYEDEXPANSION
SET num=1
SET isTSCC=0
FOR %%G IN (%avifiles%) DO (
  IF NOT !num!==1 (
    ECHO \++directshowsource^("%avifolder%%%~G"^) >> "%projname%.avs"
  ) ELSE (
    ECHO directshowsource^("%avifolder%%%~G"^) >> "%projname%.avs"
  )
  SET /A num=!num!+1
  REM Check if source file is TSCC codec
  "%anri_dir%fourccc.exe" "%avifolder%%%~G" tscc > NUL
  SET /A isTSCC=!isTSCC! + !ERRORLEVEL!
)
IF !isTSCC! GTR 0 (
  ECHO.
  ECHO   Warning^^! The TSCC codec was detected in at least one avi file. This
  ECHO   codec has been known to cause audio desync. It is recommended to 
  ECHO   encode a new source with the Lagarith codec in YV12 mode and load
  ECHO   that instead.
  ECHO.
  ECHO   If you choose to continue using this codec, be sure to analyze the
  ECHO   final video for any possible audio desync.
  ECHO.
  ECHO   http://www.videohelp.com/tools/Lagarith_Lossless_Video_Codec
  ECHO   http://www.videohelp.com/tools/VirtualdubMOD
  ECHO.
  ECHO   Proceeding with the TSCC codec.
  ECHO.
  PAUSE
)
ENDLOCAL ENABLEDELAYEDEXPANSION
ECHO converttoyuy2^(^) >> "%projname%.avs"
COPY /Y "%projname%.avs" "%projname%.bak" > NUL
GOTO :EOF

:q_avi_i
SETLOCAL
ECHO.
ECHO Path to source video file e.g. c:\path to\video.avi without quotes.
ECHO  - Type n to quit -
ECHO.
SET avifiles=
SET counterA=0
SET counterB=1
:q_avi_i_p2
SET file=
SET /P file=avi#%counterB%: 
REM Validate
IF NOT "%file%"=="n" (
  IF NOT DEFINED file (
    CALL :out_error You must enter a path, or type n to quit.
    GOTO :q_avi_i_p2
  )
  IF NOT %file:~-4%==.avi (
    CALL :out_error Must be an avi file, try again.
    GOTO :q_avi_i_p2
  )
  IF NOT EXIST "%file%" (
    CALL :out_error File does not exist, try again.
    GOTO :q_avi_i_p2
  ) ELSE (
    (SET avifiles=%avifiles%"%file%" )
    SET /A counterA=%counterA% + 1
    SET /A counterB=%counterB% + 1
    GOTO :q_avi_i_p2
  )
) ELSE (
  IF %counterA%==0 (
    CALL :out_error You must load at least one avi file.
    GOTO :q_avi_i_p2
  )
)
ENDLOCAL & SET avifiles=%avifiles% & SET avifolder=
GOTO :EOF


:q_avi_a
ECHO.
ECHO Path to folder e.g. c:\my video folder\ without quotes.
SET avifolder=
SET /P avifolder=: 
REM Validate avifolder. Check for blank, then :\ for full path, then try DIR.
IF NOT DEFINED avifolder (
  CALL :out_error You must enter a path.
  GOTO :q_avi_a
)
IF NOT "%avifolder:~1,2%"==":\" (
  CALL :out_error Must be full path.
  GOTO :q_avi_a
)
dir "%avifolder%" > NUL 2>&1
IF %ERRORLEVEL%==1 (
  CALL :out_error Folder does not exist
  GOTO :q_avi_a
)
REM Add backslash in avifolder if missing.
IF NOT "%avifolder:~-1%"=="\" SET avifolder=%avifolder%\
REM avifolder good, change directory. (Avoid trouble with for loop because of spaces in path)
CD /D %avifolder%
:q_avi_a_p2
REM Make avi file array.
SET avifiles=
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%G IN (*.avi) DO (
  (SET avifiles=!avifiles!"%%G" )
  ECHO %%G
)
SET avifiles=!avifiles:~0,-1!
ENDLOCAL ENABLEDELAYEDEXPANSION & SET avifiles=%avifiles%
REM Ask user if the list is good.
SET s=
SET /P s=Continue [Y] or rescan [N]? [y,n] 
IF NOT DEFINED s GOTO :q_avi_a_p2
IF NOT %s%==y GOTO :q_avi_a_p2
CD /D %projdirpath%
GOTO :EOF

:q_d
ECHO.
ECHO "D" and "F" are letters used at SDA to refer to the video dimensions and framerate. D1 is full resolution and D4 is half resolution. F1 is full framerate, F2 is half framerate and F3 is 1/3 framerate.
ECHO.
ECHO   Find D and F for your game at this URL:
ECHO   http://speeddemosarchive.com/kb/index.php/DF
ECHO.
ECHO If you don't see your game listed there, you can use the Extract Sample utility to make a sample video to post in the SDA Tech Support Forum. Someone there will look at the video and let you know what D and F are.
ECHO.
:q_d_p2
SET s=
SET /P s=D [1,4]: 
CALL :set_var_in d q_d_p2 14
GOTO :EOF

:q_f
SET s=
(SET /P s=F [1,2,3]: )
CALL :set_var_in f q_f 12345
GOTO :EOF

:q_prog
SET s=
SET /P s=Progressive scan source? Answer n if you don't know [y,n]: 
CALL :set_var_bool prog q_prog
GOTO :EOF

:q_fieldorder
ECHO.
CALL :out_info Virtualdub will now open with a split screen of your video. Find a scene with movement and use the slider or play button to play through it to see which looks better. Enter t for top, or b for bottom. If both look good, enter t.
PAUSE
ECHO.
COPY /B "%projname%.avs" "%projname%_fieldordertemp.avs" 1> NUL
ECHO tff=last.AssumeTFF().SeparateFields().bilinearresize(320,240) >> "%projname%_fieldordertemp.avs"
ECHO bff=last.AssumeBFF().SeparateFields().bilinearresize(320,240) >> "%projname%_fieldordertemp.avs"
ECHO StackVertical(tff,bff) >> "%projname%_fieldordertemp.avs"
START "determine field order" "%anri_dir%%vdub%\virtualdub.exe" "%projname%_fieldordertemp.avs"
:q_fieldorder_p2
SET s=
SET /P s=[t,b]: 
CALL :set_var_in fieldorder q_fieldorder_p2 tb
ECHO You may now close the VirtualDub window.
ECHO.
GOTO :EOF

:q_vhs
SET s=
SET /P s=Originally VHS [y,n]: 
CALL :set_var_bool vhs q_vhs
GOTO :EOF

:q_onepixel
SET s=
SET /P s=1 pixel bob ... answer y if it's jumping up and down [y,n]: 
CALL :set_var_bool onepixel q_onepixel
GOTO :EOF

:q_nes
SET s=
SET /P s=NES [y,n]: 
CALL :set_var_bool nes q_nes
GOTO :EOF

:q_gba
SET s=
SET /P s=Game Boy Advance [y,n]: 
CALL :set_var_bool gba q_gba
GOTO :EOF

:q_gameboy
SET s=
SET /P s=Game Boy [y,n]: 
CALL :set_var_bool gameboy q_gameboy
GOTO :EOF

:q_deflicker
SET s=
SET /P s=Deflickered (rereleased old game e.g. Mega Man AC, Sonic Mega Collection, Wii Virtual Console) [y,n]: 
CALL :set_var_bool deflicker q_deflicker
GOTO :EOF

:q_2d
SET s=
SET /P s=2D game [y,n]: 
CALL :set_var_bool twod q_2d
GOTO :EOF

:q_trim
CALL :out_info Trimming lets you remove the start and end of the existing movie so you only keep the run itself.
:q_trim_p2
SET s=
SET /P s=Do you want to trim off unwanted content in this video? [y,n]: 
CALL :set_var_bool trim q_trim_p2
GOTO :EOF

:q_trimming
ECHO.
ECHO VirtualDub will now open with a low quality temporary version of the source video. Use the slider at the bottom of the VirtualDub window to locate the first and last frame numbers of the part of the video you WANT TO KEEP, then input them here. You can specify multiple ranges of frames. - Type n to quit -
PAUSE
ECHO.
CALL :sball
START "trimming vdub" "%anri_dir%%vdub%\virtualdub.exe" "%projname%_trimtemp.avs"
SET trimarray=
SET counterA=0
SET counterB=1
:trimloop
SET /A counterC=%counterA%/2+1
CALL :q_trimval Range#%counterC%/Frame#%counterB%:
IF NOT "%s%"=="n" (
  (SET trimarray=%trimarray%%trimval% )
  SET /A counterA=%counterA%+1
  SET /A counterB=%counterB%+1
  GOTO trimloop
) ELSE (
  IF %counterA%==0 (
    ECHO No values entered, cancelling trim.
    SET trim=n
    PAUSE
  ) ELSE (
    SETLOCAL ENABLEDELAYEDEXPANSION
    SET /A countermodulus="!counterA!%%2"
    IF !countermodulus!==1 (
      ECHO DETECTED ODD NUMBER OF FRAME INPUTS.
      ENDLOCAL ENABLEDELAYEDEXPANSION
      GOTO trimloop
    )
    ENDLOCAL ENABLEDELAYEDEXPANSION
  )
)
GOTO :EOF

:q_trimval
IF [%1]==[] ( (SET qframe=Frame#: ) ) ELSE ( (SET qframe=%1 ) )
SET s=
SET /P s=%qframe%
IF NOT "%s%"=="n" CALL :set_var_number trimval q_trimval
GOTO :EOF

:q_statid
CALL :out_cls_section Station ID
CALL :out_info Set the info shown on the Station ID (the clip at the start of an SDA movie). Run the Station ID Preview program for a preview.
SET statid1=
SET statid2=
SET statid3=
:q_statid_p2
SET s=
SET /P s=Do you want to append an SDA Station ID to the front and end of this video? [y,n]: 
CALL :set_var_bool statid q_statid_p2
GOTO :EOF

:q_statid_lines
CALL :out_info Line 1 is normally the runner's name. Line 2 (and Line 3 if necessary) normally include the game name, the type of run and the time to completion.
SET /P statid1=Station ID Line 1: 
SET /P statid2=Station ID Line 2: 
SET /P statid3=Station ID Line 3: 
IF NOT DEFINED statid1 (SET statid1= )
IF NOT DEFINED statid2 (SET statid2= )
IF NOT DEFINED statid3 (SET statid3= )
REM Replace quotes from user
(SET statid1=%statid1:"="+chr(34)+"%)
(SET statid2=%statid2:"="+chr(34)+"%)
(SET statid3=%statid3:"="+chr(34)+"%)
GOTO :EOF

:q_encodenow
SET s=
SET /P s="Do you want to start encoding now [Y] or save the job for a later date [N]? "
CALL :set_var_bool start_encode q_encodenow
GOTO :EOF

:q_update_anri
SET s=
SET /P s="Do you want to update Anri-chan's games database? [y,n] "
CALL :set_var_bool check_now q_update_anri
GOTO :EOF

:q_submit_dfnd
ECHO.
ECHO You didn't use the Anri-chan DFnD database. Does that mean that it didn't have your game? If so, we'd love it if you posted the "D", "F" and "2D Game" info you just entered here, into our DFnD updates topic on SDA, so we can add it to the next version of the database. You don't need to register to do so and it only takes a few seconds.
ECHO.
SET s=
SET /P s="Submit this game's DFnD data to SDA? [y,n] "
CALL :set_var_bool submit_dfnd q_submit_dfnd
IF "%submit_dfnd%"=="n" GOTO :EOF
START http://speeddemosarchive.com/yabb/YaBB.pl?board=other;action=post;num=1180412303;title=Post+reply;start=
CALL :out_info Thanks!
PAUSE
GOTO :EOF


REM ------- DFND SECTION -------

:dfnd
CALL :q_update_anri
IF "%check_now%"=="y" (
IF EXIST "dfnd_data_temp.bat" DEL "dfnd_data_temp.bat"
IF EXIST "dfnd_titles_temp.bat" DEL "dfnd_titles_temp.bat"
"%anri_dir%wget.exe" http://speeddemosarchive.com/anri-chan/dfnd_data_temp.bat
"%anri_dir%wget.exe" http://speeddemosarchive.com/anri-chan/dfnd_titles_temp.bat
REM can't write to the anri-chan dir in vista...
IF EXIST "dfnd_data_temp.bat" MOVE /Y "dfnd_data_temp.bat" "%appdata%\dfnd_data.bat"
IF EXIST "dfnd_titles_temp.bat" MOVE /Y "dfnd_titles_temp.bat" "%appdata%\dfnd_titles.bat"
CALL :out_info Anri-chan updated.
)

SET nodb=n
IF NOT EXIST "%anri_dir%dfnd_titles.bat" SET nodb=y
IF NOT EXIST "%anri_dir%dfnd_data.bat" SET nodb=y
IF "%nodb%"=="y" (
	CALL :out_error The DFnD database was not found in Anri-chan's data directory.
	GOTO :EOF
)

SET dfnd_titlesfile=dfnd_titles.bat
SET dfnd_titles="%appdata%\%dfnd_titlesfile%"
IF NOT EXIST "%appdata%\%dfnd_titlesfile%" SET dfnd_titles="%anri_dir%%dfnd_titlesfile%"

SET dfnd_datafile=dfnd_data.bat
SET dfnd_data="%appdata%\%dfnd_datafile%"
IF NOT EXIST "%appdata%\%dfnd_datafile%" SET dfnd_data="%anri_dir%%dfnd_datafile%"

CALL :out_info Ignore "The" in a game's title when answering this question: in the case of games from the "The Legend of Zelda" series, enter Z. For .hack games, enter D.
:dfnd_letter
SET s=
SET /P s="Enter the first letter of the game's title: "
CALL :set_var_letter dfnd_letter dfnd_letter
:dfnd_list
CALL %dfnd_titles% | MORE
PAUSE
ECHO.
:dfnd_code
CALL :out_info If your game was not shown, enter L to select another letter or X to enter details manually. Enter R to repeat the list of games.
SET s=
SET /P s="Enter the game's code (shown at the left, not including the colon): "
IF /I "%s%"=="l" GOTO dfnd_letter
IF /I "%s%"=="x" GOTO :EOF
IF /I "%s%"=="r" GOTO dfnd_list
CALL %dfnd_data%
IF NOT "%dfnd_set%"=="y" (
	CALL :out_error A game with code %s% was not found.
	GOTO :dfnd_code
)
CALL :out_info Set data successfully.
PAUSE
GOTO :EOF


REM ------- SUBROUTINES TO VALIDATE/SET VARIABLES -------

:set_var_bool
IF "%s%"=="y" (
	SET %1=y
	GOTO :EOF
)
IF "%s%"=="n" (
	SET %1=n
	GOTO :EOF
)
CALL :out_error Invalid value. Please enter Y (Yes) or N (No).
GOTO :%2

:set_var_letter
ECHO %s%|findStr /i "^[a-z]$">nul
IF %ERRORLEVEL%==0 (
	SET %1=%s%
	GOTO :EOF
) ELSE (
	CALL :out_error Invalid value. Please enter a single letter.
	GOTO :%2
)

:set_var_number
ECHO %s%|findStr "[^0-9]">nul
IF %ERRORLEVEL%==0 (
	CALL :out_error Invalid value. Please enter a number.
	GOTO :%2
)
IF "%3"=="" GOTO :napproved
IF %s% GTR %3% (
	CALL :out_error Invalid value. The maximum value is %3.
	GOTO :%2
)
:napproved
SET %1=%s%
GOTO :EOF

:set_var_nospace
ECHO %s%|findStr /c:" ">nul
IF %ERRORLEVEL%==0 (
	CALL :out_error Invalid value. You cannot have a space.
	GOTO :%2
) ELSE (
	SET %1=%s%
	GOTO :EOF
)

:set_var_notnull
IF NOT DEFINED s (
	CALL :out_error Invalid value. You must enter a value.
	GOTO :%2
) ELSE (
	SET %1=%s%
	GOTO :EOF
)

:set_var_in
ECHO %s%|findStr "^[%3]$">nul
IF %ERRORLEVEL%==0 (
	SET %1=%s%
	GOTO :EOF
) ELSE (
	CALL :out_error Invalid value. Please enter one of the suggested values only.
	GOTO :%2
)



REM ------- FILE HANDLING -------

:make_projdir
CD "%DESKTOP%"
IF NOT EXIST "%projname%" MD "%projname%"
CD "%projname%"
SET projdirpath=%CD%
SET in_projdir=y
CALL :log_anridir_desktop_projdir
GOTO :EOF

:wipe_projdir
IF NOT "%in_projdir%"=="y" CALL :make_projdir
IF EXIST "%projname%.avs" DEL *.avs *.d2v *.wav
IF EXIST "%projname%_job.bat" DEL %projname%_job.bat
GOTO :EOF

:wipe_avs
IF EXIST "%projname%.avs" DEL *.avs
COPY /B "%projname%.bak" "%projname%.avs" 1> NUL
GOTO :EOF


:rip_dvd
SETLOCAL ENABLEDELAYEDEXPANSION
echo.
CALL :out_info Anri-chan will now extract everything needed from the DVD. Make sure you have enough hard drive space (up to 4.3 GB). This may take some time.
echo.
PAUSE
REM Create pgclist.txt
SET ifolist=
FOR %%G IN (%driveletter%:\%dvdfolder%\VTS*.IFO) DO (
  (SET ifolist=!ifolist!%%~fG )
)
"%anri_dir%pgccount.exe" !ifolist!
REM Rip the titles with Mplayer using info from pgclist.txt
FOR /F "tokens=1,2 delims=," %%G IN (pgclist.txt) DO (
  SET str=%%~nH
  SET str=!str:~4,2!
  REM Add leading zeros to avoid sorting problems where 10 comes before 1.
  SET expandpgc=00000000000%%G
  SET expandpgc=!expandpgc:~-3!
  "%anri_dir%mplayer.exe" dvd://%%G -dvd-device %driveletter%:\%dvdfolder% -dumpstream -dumpfile I!str!_!expandpgc!.vob 2>> %log%
)
copy %driveletter%:\%dvdfolder%\*.IFO
copy %driveletter%:\%dvdfolder%\*.BUP
echo finished ripping
ENDLOCAL ENABLEDELAYEDEXPANSION
SET source=I*.VOB
SET dginputmethod=-IF
(SET no_pause_before_indexing=y)
CALL :log_rip_dvd
GOTO :EOF

:index_dvd
ECHO.
CALL :out_info Anri-chan will now open DGMPGDec to index your DVD movie files. Once it is finished, Anri-chan will continue.
IF NOT "%no_pause_before_indexing%"=="y" PAUSE
IF EXIST %projname%.avs DEL %projname%.avs
ECHO loadplugin("%anri_dir%%dgmpgdec_dir%\DGDecode.dll") > %projname%.avs
ECHO import("%anri_dir%nate.avs") >> %projname%.avs
ECHO import("%avisynthdir%\plugins\mvbob.avs") >> %projname%.avs
CALL :out_info Now indexing MPEG-2 ...
SETLOCAL ENABLEDELAYEDEXPANSION
SET num=1
REM If no IFO files are found, source is set to the dvd folder.
REM Otherwise, source is set to the VOB files created by Mplayer, named I*.VOB
IF EXIST %driveletter%:\%dvdfolder%\VR_MOVIE.VRO SET source=%driveletter%:\%dvdfolder%\VR_MOVIE.VRO
FOR %%G IN (!source!) DO (
  REM "%anri_dir%fieldorder.exe" %%G
  REM IF NOT !ERRORLEVEL!==-1 (
  IF %%~zG GTR 5000 (
    REM Run current vob through dgindex. Set to demux all tracks. Place vid,aud,delay info into temporary avs file.
    "%anri_dir%%dgmpgdec_dir%\dgindex.exe" %dginputmethod%=[%%G] -OM=2 -OF=[%projname%%%~nG] -AT=[%anri_dir%%dgmpgdec_dir%\infotemplate.avs] -exit
    REM If there's more than one file to be joined, they must be appended together.
    IF NOT !num!==1 echo \++\ >> %projname%.avs
    REM Detect audio type, set vid,aud,delay to parameters a, b and c, generate source line.
    IF EXIST *.ac3 (
      FOR /F "tokens=1,2,3 delims=," %%A IN (%projname%%%~nG.avs) DO (
        ECHO AC3source^(MPEG2source^("%%A"^,upConv=1^),"%%B"^).DelayAudio^(%%C^) >> %projname%.avs
      )
    ) ELSE (
      IF EXIST *.mpa (
        FOR /F "tokens=1,2,3 delims=," %%A IN (%projname%%%~nG.avs) DO (
          ECHO AudioDub^(MPEG2source^("%%A"^,upConv=1^),mpasource^("%%B"^)^).DelayAudio^(%%C^) >> %projname%.avs
        )
      ) ELSE (
        IF EXIST *.wav (
          FOR /F "tokens=1,2 delims=," %%A IN (%projname%%%~nG.avs) DO (
            ECHO AudioDub^(MPEG2source^("%%A"^,upConv=1^),wavsource^("%%B"^)^) >> %projname%.avs
          )
        )
      )
    )
    DEL %projname%%%~nG.avs
    SET /A num=!num!+1
  )  
)
ENDLOCAL ENABLEDELAYEDEXPANSION
ECHO. >> "%projname%.avs"
COPY /Y "%projname%.avs" "%projname%.bak"
REM Need to find a better way to get bitrate.
IF EXIST *.ac3 (
  FOR /f "tokens=4 delims= " %%a IN ('dir /b *.ac3') DO SET maxaudiobitrate=%%a
) ELSE (
  SET maxaudiobitrate=320
)
SET maxaudiobitrate=%maxaudiobitrate:~0,3%000
IF %maxaudiobitrate% GTR 320000 SET maxaudiobitrate=320000
GOTO :EOF

:sball
CALL :wipe_avs
SET temp_files=y
TYPE "%anri_dir%ntscpal.txt" >> "%projname%.avs"
IF "%d%"=="4" TYPE "%anri_dir%d4.txt" >> "%projname%_temp.avs"
IF "%d%"=="1" TYPE "%anri_dir%d1.txt" >> "%projname%_temp.avs"
TYPE "%anri_dir%f1.txt" >> "%projname%_temp_2.avs"
IF "%prog%"=="y" (
   TYPE "%anri_dir%deint_prog.txt" >> "%projname%_temp_2.avs"
   GOTO itsprog
)
IF "%fieldorder%"=="t" ECHO AssumeTFF^(^) >> "%projname%.avs"
IF "%fieldorder%"=="b" ECHO AssumeBFF^(^) >> "%projname%.avs"
IF "%vhs%"=="y" ECHO nate_vhs_head_change_erase >> "%projname%_temp_2.avs"
TYPE "%anri_dir%deint.txt" >> "%projname%_temp_2.avs"
IF "%onepixel%"=="y" ECHO nate_1_pixel_bob_fix >> "%projname%_temp_2.avs"
IF "%deflicker%"=="y" ECHO nate_retard_bob_2 >> "%projname%_temp_2.avs"
IF "%nes%"=="y" ECHO nate_nes >> "%projname%_temp_2.avs"
TYPE "%anri_dir%resize.txt" >> "%projname%_temp_2.avs"
IF "%gba%"=="y" ECHO nate_gba >> "%projname%_temp_2.avs"
IF "%gameboy%"=="y" ECHO nate_gb >> "%projname%_temp_2.avs"
:itsprog
REM IF "%prog%"=="y" type "%anri_dir%fwhatever.txt" >> "%projname%_temp_2.avs"
IF NOT "%prog%"=="y" ECHO changefps(f1/%f%) >> "%projname%_temp_2.avs"
REM TYPE "%anri_dir%firstf.txt" >> "%projname%_temp_2.avs"
ECHO run=converttoyv12 >> "%projname%_temp_2.avs"
COPY /B "%projname%.avs" "%projname%_trimtemp.avs" 1> NUL
ECHO bilinearresize(320,240) >> "%projname%_trimtemp.avs"
GOTO :EOF

:script_buildfiles
IF NOT "%temp_files%"=="y" CALL :sball
IF "%trim%"=="y" (
  SET trimarraycode=
  SETLOCAL ENABLEDELAYEDEXPANSION
  (SET counter=0)
  FOR %%G IN (!trimarray!) DO (
    SET /A counter=!counter!+1
    SET /A countermodulus="!counter!%%2"
    IF !countermodulus!==1 (
      SET trimarraycode=!trimarraycode!trim^(%%G,
    ) ELSE (
      SET trimarraycode=!trimarraycode!%%G^)++
    )
  )
  SET trimarraycode=!trimarraycode:~0,-2!
  echo !trimarraycode! >> "%projname%.avs"
  ENDLOCAL ENABLEDELAYEDEXPANSION
)
IF "%gba%"=="y" GOTO gbastatid
IF "%gameboy%"=="y" GOTO gbstatid
ECHO statid=nate_statid_d1(run,"%statid1%","%statid2%","%statid3%").Lanczos4Resize(run.width,run.height) >> "%projname%_temp_2.avs"
GOTO statidrefork
:gbastatid
ECHO statid=nate_statid_gba(run,"%statid1%","%statid2%","%statid3%").Lanczos4Resize(run.width,run.height) >> "%projname%_temp_2.avs"
GOTO statidrefork
:gbstatid
ECHO statid=nate_statid_gb(run,"%statid1%","%statid2%","%statid3%").Lanczos4Resize(run.width,run.height) >> "%projname%_temp_2.avs"
:statidrefork
IF "%statid%"=="y" ( ECHO statid++run++statid >> "%projname%_temp_2.avs" ) ELSE ( ECHO run >> "%projname%_temp_2.avs" )
ECHO changefps(last.framerate) >> "%projname%_temp_2.avs"
ECHO converttoyv12 >> "%projname%_temp_2.avs"
copy /B "%projname%.avs"+"%projname%_temp.avs"+"%projname%_temp_2.avs" "%projname%_HQ.avs" 1> NUL
TYPE "%anri_dir%d4.txt" >> "%projname%.avs"
REN "%projname%.avs" "%projname%_temp_f.avs"
COPY /B "%projname%_temp_f.avs"+"%projname%_temp_2.avs" "%projname%.avs" 1> NUL
DEL "%projname%_temp.avs" "%projname%_temp_2.avs" "%projname%_temp_f.avs" "%projname%_trimtemp.avs"
COPY /B "%projname%_HQ.avs" "%projname%_IQ.avs" 1> NUL
REM IF "%gba%"=="y" ECHO lanczos4resize(240,160) >> "%projname%.avs"
COPY /B "%projname%.avs" "%projname%_LQ.avs" 1> NUL
IF "%twod%"=="y" TYPE "%anri_dir%changef3.txt" >> "%projname%_LQ.avs"
IF "%twod%"=="n" (
  TYPE "%anri_dir%changef2.txt" >> "%projname%.avs"
  TYPE "%anri_dir%changef2.txt" >> "%projname%_LQ.avs"
)
copy /B "%projname%_LQ.avs" "%projname%_xvid.avs" 1> NUL
copy /B "%projname%_LQ.avs" "%projname%_LQ_xvid.avs" 1> NUL
GOTO :EOF


REM ------- SETTINGS MANAGER -------

:find_existing_settings
IF EXIST "%DESKTOP%\%projname%\%projname%_job.bat" (
	CALL "%DESKTOP%\%projname%\%projname%_job.bat"
	SET using_settings=y
)
GOTO :EOF

:check_settings
CALL :show_settings
:check_settings_p2
SET s=
SET /P s=Do you want to encode using these settings? If you choose No you will be prompted to enter them again. [y/n] 
CALL :set_var_bool settings_good check_settings_p2
GOTO :EOF

:show_settings
CALL :out_cls_section REVIEW SETTINGS
IF DEFINED this_anriver IF NOT "%this_anriver%"=="%anri_ver%" CALL :out_info NOTICE: Your settings for this project were created in an outdated version of Anri-chan. They may not work properly in this version. It is recommended that you discard these settings and re-enter them.
IF "%dvdsource%"=="y" ( CALL :out_info DVD Source: Yes ) ELSE (	CALL :out_info DVD Source: No )
IF "%dvdsource%"=="y" ( CALL :out_info DVD Drive Letter: %driveletter% )
CALL :out_info Project Name: %projname%
IF DEFINED avifolder CALL :out_info AVI folder: %avifolder%
IF DEFINED avifiles CALL :out_info Source Video Files: %avifiles%
IF NOT "%twod%"=="y" (SET twodtemp=3D) ELSE (SET twodtemp=2D)
IF DEFINED d IF DEFINED f CALL :out_info Video Format: D%d% F%f% %twodtemp%
IF "%vhs%"=="y" ( CALL :out_info From VHS Source ) ELSE ( CALL :out_info Not From VHS Source )
IF "%prog%"=="y" ( CALL :out_info Progressive ) ELSE ( CALL :out_info Interlaced )
IF "%fieldorder%"=="t" CALL :out_info Top field first
IF "%fieldorder%"=="b" CALL :out_info Bottom field first
IF "%onepixel%"=="y" CALL :out_info One-Pixel Bob
IF "%nes%"=="y" CALL :out_info From NES Console
IF "%gba%"=="y" CALL :out_info From Game Boy Advance
IF "%gameboy%"=="y" CALL :out_info From Game Boy
IF "%deflicker%"=="y" CALL :out_info Deflickered
IF "%trim%"=="y" CALL :out_info Trim frame ranges %trimarray%
IF "%statid%"=="y" CALL :out_info StatID: %statid1:"+chr(34)+"="% / %statid2:"+chr(34)+"="% / %statid3:"+chr(34)+"="%
GOTO :EOF

:savesettings
ECHO @ECHO OFF > "%projname%_job.bat"
ECHO ^(SET proj_anriver=%anri_ver%^) >> "%projname%_job.bat"
ECHO ^(SET using_settings=y^) >> "%projname%_job.bat"
ECHO ^(SET dvdsource=%dvdsource%^) >> "%projname%_job.bat"
ECHO ^(SET avifolder=%avifolder%^) >> "%projname%_job.bat"
ECHO ^(SET avifiles=%avifiles%^) >> "%projname%_job.bat"
ECHO ^(SET fieldorder=%fieldorder%^) >> "%projname%_job.bat"
ECHO ^(SET d=%d%^) >> "%projname%_job.bat"
ECHO ^(SET f=%f%^) >> "%projname%_job.bat"
ECHO ^(SET vhs=%vhs%^) >> "%projname%_job.bat"
ECHO ^(SET onepixel=%onepixel%^) >> "%projname%_job.bat"
ECHO ^(SET nes=%nes%^) >> "%projname%_job.bat"
ECHO ^(SET twod=%twod%^) >> "%projname%_job.bat"
ECHO ^(SET statid=%statid%^) >> "%projname%_job.bat"
ECHO ^(SET statid1=%statid1%^) >> "%projname%_job.bat"
ECHO ^(SET statid2=%statid2%^) >> "%projname%_job.bat"
ECHO ^(SET statid3=%statid3%^) >> "%projname%_job.bat"
ECHO ^(SET driveletter=%driveletter%^) >> "%projname%_job.bat"
ECHO ^(SET projname=%projname%^) >> "%projname%_job.bat"
ECHO ^(SET gba=%gba%^) >> "%projname%_job.bat"
ECHO ^(SET gb=%gameboy%^) >> "%projname%_job.bat"
ECHO ^(SET dvdsource=%dvdsource%^) >> "%projname%_job.bat"
ECHO ^(SET prog=%prog%^) >> "%projname%_job.bat"
ECHO ^(SET trim=%trim%^) >> "%projname%_job.bat"
ECHO ^(SET trimarray=%trimarray%^) >> "%projname%_job.bat"
ECHO ^(SET maxaudiobitrate=%maxaudiobitrate%^) >> "%projname%_job.bat"
ECHO ^(SET hqq=%hqq%^) >> "%projname%_job.bat"
ECHO IF NOT "%%in_anrichan%%"=="y" call "%anri_path%" >> "%projname%_job.bat"
GOTO :EOF

:createjob
CALL :savesettings
PAUSE
GOTO die


REM ------- QUALITIES SELECTION -------

:selectquality
SET s=
SET /P s="Create %1 (%2Kbps) movie? "
IF "%s%"=="y" (
	SET create_%3=y
	GOTO :EOF
)
IF "%s%"=="n" (
	SET create_%3=n
	GOTO :EOF
)
CALL :out_error Invalid value. Please enter Y (Yes) or N (No).
GOTO :selectquality %1 %2 %3

:select_qualities
CALL :savesettings
CALL :selectquality Low-Quality 192 lq
CALL :selectquality Normal-Quality 576 mq
CALL :selectquality High-Quality 2176 hq
IF NOT "%d%"=="1" SET create_iq=n
IF NOT "%f%"=="1" SET create_iq=n
IF "%gba%"=="y" SET create_iq=n
IF "%gameboy%"=="y" SET create_iq=n
IF NOT "%create_iq%"=="n" CALL :selectquality Insane-Quality 5320 iq
CALL :selectquality XviD-Low-Quality 192 xl
CALL :selectquality XviD-Normal-Quality 576 xm
GOTO :EOF

REM ------- ENCODING -------

:encode_movies
CALL :out_section encoding %projname%

REM thanks snow!
IF "%create_lq%"=="y" (
CALL :out_section encoding %projname% LQ MP4
CALL :2pass %projname%_LQ.avs %projname%_LQ       128  64000  17 1 1
)
IF "%create_mq%"=="y" (
CALL :out_section encoding %projname% MQ MP4
CALL :ipod %projname%.avs    %projname%          512  64000  17 1 1
)
IF "%create_hq%"=="y" (
CALL :out_section encoding %projname% HQ MP4
CALL :2pass %projname%_HQ.avs %projname%_HQ      2048 128000 %hqq% 1 1
)
IF "%create_iq%"=="y" (
CALL :out_section encoding %projname% IQ MP4
CALL :2pass %projname%_IQ.avs %projname%_IQ      5000 %maxaudiobitrate% 19 1 1
)

REM back to nate's work (based on snow's though!)
IF "%create_xl%"=="y" (
CALL :out_section encoding %projname% LQ AVI
CALL :xvid %projname%_LQ_xvid.avs %projname%_LQ   128     64   1 1
)
IF "%create_xm%"=="y" (
CALL :out_section encoding %projname% MQ AVI
CALL :xvid %projname%_xvid.avs %projname%         512     64   1 1
)

GOTO :EOF


:2pass
"%anri_dir%x264.exe" --pass 1 --bitrate %3 --stats "%2.stats" --bframes 16 --analyse none --qpmin %5 --threads auto --thread-input --progress --no-psnr --no-ssim --output NUL %1
"%anri_dir%x264.exe" --pass 2 --bitrate %3 --stats "%2.stats" --direct auto --ref 8 --mixed-refs --no-fast-pskip --bframes 16 --b-rdo --bime --weightb --subme 7 --trellis 2 --analyse all --qpmin %5 --me umh --threads auto --thread-input --progress --no-psnr --output "%2_video.mp4" %1
"%anri_dir%%vdub%\vdub.exe" %1 /i "%anri_dir%audioout.vcf" "%2_temp.wav"
"%anri_dir%neroAacEnc.exe" -br %4 -lc -if "%2_temp.wav" -of "%2_audio.mp4"
"%anri_dir%MP4Box.exe" -tmp . -new -add "%2_video.mp4" -add "%2_audio.mp4" "%2.mp4"
IF "%6" == "1" del %2.stats
IF "%7" == "1" del %2_video.mp4 | del %2_temp.wav | del %2_audio.mp4
GOTO :EOF

:1pass
"%anri_dir%x264.exe" --qp %4 --ref 8 --mixed-refs --no-fast-pskip --bframes 5 --b-rdo --bime --weightb --nf --direct auto --subme 7 --analyse p8x8,b8x8,i4x4,p4x4 --threads auto --thread-input --progress --no-psnr --no-ssim --output "%2_video.mp4" %1
"%anri_dir%%vdub%\vdub.exe" %1 /i "%anri_dir%audioout.vcf" "%2_temp.wav"
"%anri_dir%neroAacEnc.exe" -br %3 -lc -if "%2_temp.wav" -of "%2_audio.mp4"
"%anri_dir%MP4Box.exe" -tmp . -new -add "%2_video.mp4" -add "%2_audio.mp4" "%2.mp4"
IF "%5" == "1" del %2_video.mp4 | del %2_temp.wav | del %2_audio.mp4
GOTO :EOF

:ipod
"%anri_dir%x264.exe" --pass 1 --bitrate %3 --vbv-maxrate 768 --stats "%2.stats" --level 1.3 --no-cabac --analyse none --qpmin %5 --threads auto --thread-input --progress --no-psnr --no-ssim --output NUL %1
"%anri_dir%x264.exe" --pass 2 --bitrate %3 --vbv-maxrate 768 --stats "%2.stats" --level 1.3 --no-cabac --direct auto --mixed-refs --no-fast-pskip --b-rdo --bime --weightb --subme 7 --trellis 2 --analyse all --qpmin %5 --me umh --threads auto --thread-input --progress --no-psnr --output "%2_video.mp4" %1
"%anri_dir%%vdub%\vdub.exe" %1 /i "%anri_dir%audioout.vcf" "%2_temp.wav"
"%anri_dir%neroAacEnc.exe" -br %4 -lc -if "%2_temp.wav" -of "%2_audio.mp4"
"%anri_dir%MP4Box.exe" -tmp . -new -add "%2_video.mp4" -add "%2_audio.mp4" "%2.mp4"
IF "%6" == "1" del %2.stats
IF "%7" == "1" del %2_video.mp4 | del %2_temp.wav | del %2_audio.mp4
GOTO :EOF

:xvid
"%anri_dir%xvid_encraw.exe" -i %1 -bitrate %3 -pass1 "%2.stats"
"%anri_dir%xvid_encraw.exe" -i %1 -bitrate %3 -pass2 "%2.stats" -avi "%2v.avi"
"%anri_dir%ffmpeg.exe" -b %4 -ac 2 -acodec mp3 -y -i "%2v.avi" -vcodec copy -i %1 "%2.avi"
IF "%5" == "1" del "%2.stats"
IF "%6" == "1" del "%2v.avi"
GOTO :EOF


REM ------- OUTPUT -------

:out_cls
CLS
ECHO.
ECHO ===============================================================================
ECHO.                 metroid 2002 speed demos archive anri-chan %anri_ver%
ECHO.        http://www.metroid2002.com/     http://speeddemosarchive.com/
ECHO ===============================================================================
ECHO.
GOTO :EOF

:out_info
ECHO %*
REM ECHO.
GOTO :EOF

:out_error
ECHO [!]
ECHO [!] %*
ECHO [!]
ECHO.
GOTO :EOF

:out_section
TITLE Anri-chan %anri_ver% - %*
ECHO -------------------------
ECHO. %*
ECHO -------------------------
ECHO.
GOTO :EOF

:out_cls_section
CALL :out_cls
CALL :out_section %*
GOTO :EOF

:out_cls_info
CALL :out_cls
CALL :out_info %*
GOTO :EOF


REM ------- LOGGING -------

:log_anridir_desktop_projdir
REM anrichan directory contents, desktop path, poject name
DIR "%anri_dir%" >> %log%
ECHO desktop path: %DESKTOP% >> %log%
ECHO project name: %projname% >> %log%
GOTO :EOF

:log_dvdfolder
REM DVD folder contents
DIR "%driveletter%:\%dvdfolder%" >> %log%
GOTO :EOF

:log_rip_dvd
REM verify mplayer rip
SETLOCAL ENABLEDELAYEDEXPANSION
(SET totaldvdsize=0)
(SET totalripsize=0)
FOR %%F IN (*.VOB) DO (
  SET /A totalripsize=!totalripsize! + %%~zF
)
FOR %%F IN (%driveletter%:\%dvdfolder%\*.V*) DO (
  SET /A totaldvdsize=!totaldvdsize! + %%~zF
)
SET /A fileratio=!totalripsize! / (!totaldvdsize! / 100)
ECHO DVD VOB/VRO file size = !totaldvdsize! bytes >> %log%
ECHO RIP VOB/VRO file size = !totalripsize! bytes >> %log%
ECHO File ratio = !fileratio!%% >> %log%
ENDLOCAL ENABLEDELAYEDEXPANSION
GOTO :EOF


REM ------- OTHER -------

:start_encode_test
IF "%start_encode%"=="y" GOTO proc_encode
IF NOT "%start_encode%"=="y" GOTO proc_close

:resetvars
FOR %%A IN (%vars_to_use%) DO (SET %%A=)
GOTO :EOF

:die
CALL :resetvars
(SET in_anrichan=)
CD "%DESKTOP%"
TITLE Anri-chan dun ^^_^^
PAUSE
EXIT

:setanribat
CD %~dp0
START /LOW /B anri.bat anrilow
EXIT
Personal tools