AudioConvert script

Discuss and share scripts and script files...
Post Reply
highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

AudioConvert script

Post by highend »

Again, I was asked if I can share it ;)

Nothing spectacular, just the one that I use to convert audio files to .mp3 (cbr), different bitrates can be selected.

Btw, I was too lazy to use a function call for the mp3gain things ;(

Code: Select all

// 26.06.2011, use sox to convert audio files to .mp3
// setting('BackgroundFileOps', 0);

/*
Sox parameters:
-S = Show progress | --multi-threaded = More threads
-C 192.2 = 192kbit, 2 channel (joint stero)
rate -v 44100 = 44,1khz samplerate

MP3Gain parameters:
/r = Track gain | /a = Album gain
/k = Avoid clipping | /t = Use temp files
/p = Preserve timestamps | /c = Ignore clipping warning
/s i = Use ID3v2 Tag, not APE
*/

"Convert audio files to...|<xypath>\.Icons\AudioConvert.ico|1"
	;

"... 128kbit cbr"
	sub "_Initialize";

	global $OutputPath, $FileExtNew, $gopts, $effopt, $fopts;

	$OutputPath = "<curpath>\.ConvertedTo_128kbit";
	$FileExtNew = "mp3";
	$gopts = "-S --multi-threaded";
	$effopt ="rate -v 44100";
	$fopts = "-C 128.2";
	
	sub "_WriteBatchFile";

"... 160kbit cbr"
	sub "_Initialize";

	global $OutputPath, $FileExtNew, $gopts, $effopt, $fopts;

	$OutputPath = "<curpath>\.ConvertedTo_160kbit";
	$FileExtNew = "mp3";
	$gopts = "-S --multi-threaded";
	$effopt ="rate -v 44100";
	$fopts = "-C 160.2";

	sub "_WriteBatchFile";

"... 192kbit cbr"
	sub "_Initialize";

	global $OutputPath, $FileExtNew, $gopts, $effopt, $fopts;

	$OutputPath = "<curpath>\.ConvertedTo_192kbit";
	$FileExtNew = "mp3";
	$gopts = "-S --multi-threaded";
	$effopt ="rate -v 44100";
	$fopts = "-C 192.2";

	sub "_WriteBatchFile";

-
"MP3Gain (Track)"
	$TempFile = "%temp%\~mp3gain.bat";
	$MP3gain_Cmd = quote("<xydrive>\Tools\MP3Gain_CLI\mp3gain.exe");
	$gopts = "/r /k /t /p /c /s i";
	$SelectedItems = quote(get("SelectedItemsPathNames", """ """));

	writefile($TempFile, "@Echo off".<crlf>, o, ta);
	writefile($TempFile, "setlocal enabledelayedexpansion".<crlf>, a, ta);
	writefile($TempFile, <crlf>, a, ta);
	writefile($TempFile, CALL $MP3gain_Cmd $gopts $SelectedItems.<crlf>, a, ta);
	writefile($TempFile, pause.<crlf>, a, ta);
	writefile($TempFile, <crlf>, a, ta);

	open "$TempFile";

"MP3Gain (Album)"
	$TempFile = "%temp%\~mp3gain.bat";
	$MP3gain_Cmd = quote("<xydrive>\Tools\MP3Gain_CLI\mp3gain.exe");
	$gopts = "/a /k /t /p /c /s i";
	$SelectedItems = quote(get("SelectedItemsPathNames", """ """));

	writefile($TempFile, "@Echo off".<crlf>, o, ta);
	writefile($TempFile, "setlocal enabledelayedexpansion".<crlf>, a, ta);
	writefile($TempFile, <crlf>, a, ta);
	writefile($TempFile, CALL $MP3gain_Cmd $gopts $SelectedItems.<crlf>, a, ta);
	writefile($TempFile, pause.<crlf>, a, ta);
	writefile($TempFile, <crlf>, a, ta);

	open "$TempFile";

/*
Functions
*/

"_Initialize"
	global $TempFile, $Sox_Cmd, $InputPath, $SelectedItems;

	$TempFile = "%temp%\~sox.bat";
	$Sox_Cmd = quote("<xydrive>\Tools\Sox_CLI\sox.exe");
	$InputPath = "<curpath>";
	$SelectedItems = report("{Basename}?{Ext}|",1);
	$SelectedItems = substr($SelectedItems, 0, -1);


"_WriteBatchFile"
	global $TempFile, $Sox_Cmd, $InputPath, $SelectedItems;
	global $OutputPath, $FileExtNew, $gopts, $effopt, $fopts;

	$WavPlayer = quote("<xypath>\.Tools\.Wav_Player\sWavPlayer.exe");
	$SoundFinished = quote("<xypath>\.Tools\.Wav_Player\Sync_Complete.wav");

	writefile($TempFile, "@Echo off".<crlf>, o, ta);
	writefile($TempFile, "setlocal enabledelayedexpansion".<crlf>, a, ta);
	writefile($TempFile, <crlf>, a, ta);

	$ReturnCode = exists("$OutputPath");
	if($ReturnCode == 0) {	new("$OutputPath", "dir"); }

	foreach($Token, $SelectedItems, "|") {
		$FileBase = gettoken($Token,1,"?");
		$FileExtOld = gettoken($Token,2,"?");
		$FileNameOld = "$FileBase.$FileExtOld";
		$FileNameNew = "$FileBase.$FileExtNew";
		$InputFile = "$InputPath\$FileNameOld";
		$OutputFile = "$OutputPath\$FileNameNew";

		$ReturnCode = exists("$OutputFile");
		if($ReturnCode == 1) {
			delete 1, 0, "$OutputFile";
		}
		if($FileExtNew == "") {
			writefile($TempFile, CALL $Sox_Cmd $gopts "$InputFile".<crlf>, a, ta);
			writefile($TempFile, pause.<crlf>, a, ta);
		}
		else {
			writefile($TempFile, CALL $Sox_Cmd $gopts "$InputFile" $fopts "$OutputFile" $effopt.<crlf>, a, ta);
		}
	}

	writefile($TempFile, <crlf>, a, ta);
	writefile($TempFile, $WavPlayer $SoundFinished.<crlf>, a, ta);
	writefile($TempFile, <crlf>, a, ta);

	open "$TempFile";

-

"Cancel"

-
"Edit this &script : edit"
	self $ScriptFile, file;
	openwith "<xydrive>\Tools\EditPlus\editplus.exe", ,$ScriptFile;
One of my scripts helped you out? Please donate via Paypal

Post Reply