[Solved] Having a DOS batch problem. Working Handbrank XML Batch file Creater

travisray2004

Senior member
Jul 6, 2005
922
0
0
My goal is to locate files over 750mb and convert them with handbrake to mkv. Handbrake has a Import option for xml file. In my code its going to movie.queue. Currently using toconvert.bat to convert one by one; but this option takes forever.

This is what I have so far.
Code:
@ECHO off
setLocal EnableDelayedExpansion
SET WorkingPath=%CD%
SET filesize=750000000
SET J=1
SET FileExt=*.avi
SET "PathToHandbrake=C:\Program Files (x86)\Handbrake\HandBrakeCLI.exe"
SET "HandbrakeArgs=-f mkv --strict-anamorphic  -e x264 -S 700 -a 1 -E faac -6 dpl2 -R 48 -B 160 -D 0.0 --subtitle scan -x ref=2:bframes=2:subq=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0 -C 2  -v 1"
ECHO %time% - Batch Converter Started > toconvert.txt
ECHO %time% - Batch Converter Started > toremove.txt
echo "<?xml version="1.0"?>" > movie.queue
echo "	<ArrayOfJob xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">" >> movie.queue
FOR /R "%WorkingPath%" %%a IN (%FileExt%) DO (
IF %%~za GTR %filesize% (
ECHO "%PathToHandbrake%" -i "%%~dpa%%~nxa" -t 1 -c 1 -o"%%~dpa%%~na.mkv" %HandbrakeArgs% >> toconvert.bat
ECHO REN "%%~dpa%%~nxa" "%%~dpa%%~na.delete" >> toremove.txt
echo "	<Job>" >> movie.queue
echo "		<Id>!J!</Id>" >> movie.queue
echo "		<Query>-i "%%~dpa%%~nxa" -t 1 -c 1 -o "%%~dpa%%~na.mkv" %HandbrakeArgs% </Query>" >> movie.queue
echo "		<CustomQuery>false</CustomQuery>" >> movie.queue
echo "		<Source>"%%~dpa%%~nxa"</Source>" >> movie.queue
echo "		<Destination>"%%~dpa%%~na.mkv"</Destination>" >> movie.queue
echo "	</Job>" >> movie.queue
SET /A J+=1
)
)
echo "</ArrayofJob>" >> movie.queue
ECHO %time% - Batch Converter Ended >> toconvert.txt
ECHO %time% - Batch Converter Ended >> toremove.txt

PAUSE

Have a problem with the xml file its including the double quotes. And will not run the script with out the quotes. Thanks for any input.

See [post=30717285]post[/post] for resolved batch file.
 
Last edited:

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,624
4,546
75
Can you "call toconvert.bat" from this batch file, instead of writing an XML file?
 

MerlinRML

Senior member
Sep 9, 2005
207
0
71
Not sure if I totally understand the problem as I've never used handbrake.

So let me sum it up what I think you're saying isn't working and see if I've got it. You're building the xml file named movie.queue. To do that, you're using code like this:

Code:
echo "      <stuff>"

The problem is that you get the leading and trailing double quotes in the movie.queue file. So you want to be able to echo what you have, but not have the leading and trailing quotes. Am I on the right track?

Try removing the double quotes from the line and escaping (^) the angled brackets (<>) like this:


Code:
echo      ^<stuff^>

That should keep preserve your leading spaces, prevent the angled brackets from redirecting incorrectly and create the xml file without the double quotes. Unless I've totally misunderstood the problem, in which case .... maybe try and explain better for us slowpokes?
 

travisray2004

Senior member
Jul 6, 2005
922
0
0
Sorry for the delayed feedback. Merlin I will give that a try. You have understood me correctly. I am trying to have the whitespace in the file, but do not want to have the double quotes in it. I will try your method and report back the results. ;)
 

travisray2004

Senior member
Jul 6, 2005
922
0
0
Can you "call toconvert.bat" from this batch file, instead of writing an XML file?

It did create this file. and you can run the bat file and it will process the movies in order, but its a non-common way of doing it. Trying to stay GUIe with it.
 

travisray2004

Senior member
Jul 6, 2005
922
0
0
Thanks, I have gotten it to work. Minor Directory issues tho.

Code:
@ECHO off
setLocal EnableDelayedExpansion
SET WorkingPath=%CD%
SET filesize=750000000
SET J=1
SET FileExt=*.avi
SET "PathToHandbrake=C:\Program Files (x86)\Handbrake\HandBrakeCLI.exe"
SET "HandbrakeArgs=-f mkv --strict-anamorphic  -e x264 -S 700 -a 1 -E faac -6 dpl2 -R 48 -B 160 -D 0.0 --subtitle scan -x ref=2:bframes=2:subq=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0 -C 2  -v 1"
ECHO %time% - Batch Converter Started > toconvert.txt
ECHO %time% - Batch Converter Started > toremove.txt
echo ^<?xml version="1.0"?^> > movie.queue
echo ^<ArrayOfJob xmlns:xsi=^"http://www.w3.org/2001/XMLSchema-instance^" xmlns:xsd=^"http://www.w3.org/2001/XMLSchema^"^> >> movie.queue
FOR /R "%WorkingPath%" %%a IN (%FileExt%) DO (
IF %%~za GTR %filesize% (

ECHO REN "%%~dpa%%~nxa" "%%~dpa%%~na.delete" >> toremove.txt
echo   ^<Job^> >> movie.queue
echo     ^<Id^>!J!^</Id^> >> movie.queue
echo     ^<Query^> -i "%%~dpa%%~nxa" -t 1 -c 1 -o "%%~dpa%%~na.mkv" %HandbrakeArgs% ^</Query^> >> movie.queue
echo     ^<CustomQuery^>false^</CustomQuery^> >> movie.queue
echo     ^<Source^>"%%~dpa%%~nxa"^</Source^> >> movie.queue
echo     ^<Destination^>"%%~dpa%%~na.mkv"^</Destination^> >> movie.queue
echo   ^</Job^> >> movie.queue
SET /A J+=1
)
)
echo ^</ArrayOfJob^> >> movie.queue
ECHO %time% - Batch Converter Ended >> toconvert.txt
ECHO %time% - Batch Converter Ended >> toremove.txt

PAUSE