How do I pass complex arguments in BAT scripts?

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
inferusvir
Posts: 6
Joined: 10 Dec 2018, 21:02

How do I pass complex arguments in BAT scripts?

Post by inferusvir »

Right off the bat, here's my filebot system info

Code: Select all

C:\Windows\system32>filebot -script fn:sysinfo
FileBot 4.9.3 (r8338)
JNA Native: 6.1.0
MediaInfo: 20.09
7-Zip-JBinding: 16.02
Tools: fpcalc/1.5.0
Extended Attributes: OK
Unicode Filesystem: OK
Script Bundle: 2021-06-15 (r755)
Groovy: 3.0.7
JRE: OpenJDK Runtime Environment 15.0.2
JVM: 64-bit OpenJDK 64-Bit Server VM
CPU/MEM: 8 Core / 8 GB Max Memory / 22 MB Used Memory
OS: Windows 10 (amd64)
STORAGE: NTFS [(C:)] @ 307 GB | NTFS [Multimedia] @ 1.1 TB
DATA: C:\Users\sm\AppData\Roaming\FileBot
Package: MSI
License: FileBot License PX6356267 (Valid-Until: 2068-11-30)
Done ?(?????)?

C:\Windows\system32>
Gotta wonder what that "?(?????)?" means.

I've been using FileBot manually for a few years now, and am trying to implement some automation into the process.

To start, I wrote a DOS batch file that checks a couple directories for audio/video files, launches the appropriate converter to convert found applicable file(s) to either mp4, or mp3.
On completion it'll call the FileBot amc script and send to particular destinations depending on whether audio/video.

Code: Select all

@echo off

rem Filename:      BFC.bat
rem Name:           Batch File Conversion
rem Version:	   1.32
rem Description:   Batch convert video and/or audio files to either mp4(video) or mp3 (audio)
rem Purpose:	   file preparation for inclusion into Plex media library
rem Author:	   infernusvir
rem Date:		   July 2021


setlocal enabledelayedexpansion enableextensions

REM set variables
set aworkdir=D:\Audio
set vworkdir=D:\Video

:MP4
if exist %vworkdir%\*.mp4 ( echo send to filebot ) && ( goto VFileBot ) else ( echo no mp4 file to process )

:MP3
if exist %aworkdir%\*.mp3 ( echo send to filebot ) && ( goto AFileBot ) else ( echo no mp3 file to process )

:F2
if exist %vworkdir%\*.* ( echo convert video ) && ( goto Video ) else ( echo no video file to process )

:F1
if exist %aworkdir%\*.* ( echo convert audio ) && ( goto Audio ) else ( echo no audio file to process )

:VFileBot
rem filebot -script fn:amc --output "x:/media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%l" "ut_state=%s" "ut_title=%n" "ut_kind=%k" "ut_file=%f" "ut_dir=%d"
goto MP3

:AFileBot
rem filebot -script fn:amc --output "x:/media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%l" "ut_state=%s" "ut_title=%n" "ut_kind=%k" "ut_file=%f" "ut_dir=%d"
goto F1

:Video
start "convert" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\all-to-mp4.xml" || goto END
goto L2

:Audio
start "convert" "C:\Program Files (x86)\AVS4YOU\AVSAudioConverter\AVSAudioConverter.exe" -a "D:\Documents\Conversions\all-to-mp3.xml" || goto END
goto L1

:L1
tasklist | find /i "AVSAudioConverter" >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO C1
) ELSE (
  ECHO AudioConverter is still running
  Timeout /T 10 /Nobreak
  GOTO L1
)

:C1
move %aworkdir%\*.* %aworkdir%\Processed\
goto F2

:L2
tasklist | find /i "AVSVideoConverter" >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO C2
) ELSE (
  ECHO VideoConverter is still running
  Timeout /T 10 /Nobreak
  GOTO L2
)

:C2
move %vworkdir%\*.* %vworkdir%\Processed\
goto END

:END



Making some assumptions based on reading through a few threads, calling the amc script should be something like this, correct?:

Code: Select all

filebot -script fn:amc --output "/path/to/output" --action duplicate -non-strict "/path/to/input" --log-file amc.log 
--def 
music=y
subtitles=en
plex=host:token
movieDB=TheMovieDB
seriesDB=TheMovieDB::TV
musicDB=ID3
movieFormat="{
	['Y:', 'Z:']
	.collect{ it + '/' + plex[0..1] as File }
	.sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace }
	.last()
}/{plex.name}"
seriesFormat="{
	['Y:', 'Z:']
	.collect{ it + '/' + plex[0..1] as File }
	.sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace }
	.last()
}/Season {s}/{n} - {s00e00} - {t}"
musicFormat="{
	['Y:', 'Z:']
	.collect{ it + '/' + plex[0..1] as File }
	.sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace }
	.last()
}/{album+'/'}{pi.pad(2)+' - '} {t}"
unsorted=y
artwork=y
"ut_label=%l"
"ut_state=%s"
"ut_title=%n"
"ut_kind=%k"
"ut_file=%f"
"ut_dir=%d"
excludeList=amc.txt

[*]is just one --def then each argument correct syntax,, or is it necessary to enter a --def for each argument?
[*]The various format definitions are direct copies of the definitions I've been using manually. Is it necessary to remove the white space, carriage returns, etc or leave as is?
[*]for the "/path/to/output" &"/path/to/input" I really not sure what to enter since both arguments will be variable, depending on file type and sorting destination (ie: source directories will be either d:\audio or d:\video & output directories would be any of: y:\movies, y:\ music; y:\tv shows, z:\movies, z:\ music; z:\tv shows
[*]Is it possible to increase the granularity for where files are output based on label/tag? ie: animation, concerts, documentary movies into a different directory than movies? soundtracks into soundtrack directory instead of music directory?
[*]Is it possible once subtitle files are downloaded, to automatically strip them of various advertising lines (most notably opensubtitles.org & 'encoded by xxxx')?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: amc script variable arguments

Post by rednoah »

1.
--def can be used for 1 or more name=value pairs, e.g.

Code: Select all

--def a=1 b=2 c=3

2.
This is a generic question on how to write BAT scripts, unrelated to filebot specifically. Google will help. I'd use the @file syntax for reading complex command-line arguments from external text files to avoid BAT code as much as possible.


3.
You would use BAT variables, and the the BAT interpreter will then call filebot with the corresponding input / output values. Google will help.


4.
You can either use the {label} binding in your format, or pass a different formats on the command-line altogether depending on the situation.


5.
No, but you can use --def exec to run custom post-processing commands on newly processed subtitle files.
:idea: Please read the FAQ and How to Request Help.
Post Reply