Format rewrites to automate processes

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

Format rewrites to automate processes

Post by inferusvir »

I've gotten the following processes semi automated, and need help getting this as fully automated as possible:

1. Select a torrent
2. Assign a category to the download (animations, animated series, concerts, documentaries, documentary series, movies, music, shows)
3. On download completion, a batch file runs to check & convert any non-mp4 incoming files to mp4 format

What i need now is to b able to automatically send those files thru filebot, rename into plex format, acquire appropriate subtitle files, then transfer to 1 of 2 NAS drives, then update the plex libraries (which i'm still doing manually).

Here are the Filebot formats I'm currently using manually:

Animated Series
---------------

Code: Select all

{ ['Y:', 'Z:'] .collect{ it + '/Animated Series/' as File } .sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace } .last() }/{plex.tail}
Animations
----------

Code: Select all

{ ['Y:', 'Z:'] .collect{ it + '/Animations/' as File } .sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace } .last() }/{plex.name}/{plex.name}
Concerts
--------

Code: Select all

{ ['Y:', 'Z:'] .collect{ it + '/Concerts/' as File } .sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace } .last() }/{plex.name}/{plex.name}
Documentaries
-------------

Code: Select all

{ ['Y:', 'Z:'] .collect{ it + '/Documentaries/' as File } .sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace } .last() }/{plex.name}/{plex.name}
Documentary Series
------------------

Code: Select all

{ ['Y:', 'Z:'] .collect{ it + '/Documentary Series/' as File } .sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace } .last() }/{plex.tail}
Movies
------

Code: Select all

{ ['Y:', 'Z:'] .collect{ it + '/' + plex[0..1] as File } .sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace } .last() }/{plex.name}  { fn.matchAll(/Donner Cut|Redux|DC|Director's Cut|Extended Edition|Producer's Cut|Ultimate Uncut|Special Edition/) }
TV Shows
--------

Code: Select all

{ ['Y:', 'Z:'] .collect{ it + '/TV Shows/' as File } .sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace } .last() }/{plex.tail}

Here's the current batch file iteration I'm using for the file conversion process:

Code: Select all

@echo off
    set "rem[=rem/||(" & set "]rem=)"
	
%rem[%
	batch file for handling downloaded movies and tv episodes.
	name and category variables assigned by qbittorrent on download completion.
	videoconverter file location calls and write destinations based on category variable.
	converted files forwarded to filebot for renaming & upload to category-based directories within plex library.
%]rem%

set "logfile=d:\documents\torrent\conversionprogressreport.txt"
set "name=%1"
set "cat=%2"
set "folder=%3"
set "file=%4"
set "conv=d:\media\filebot"
set "dest=%conv%\%cat%\%name%"


%rem[%
	set config_output=%userprofile%/media - this is rem'd awaiting multi-drive config info.

	imported variables
	%1 = filename    -- %n in qbittorrent
	%2 = category    -- %l in qbittorrent
	%3 = root path    - %r in qbittorrent
	%4 = content path - %f in qbittorrent
%]rem%

echo ****************************** >> %logfile%
echo %date% at %time% : conversion/deletion test. >> %logfile%
echo %date% at %time% : load video converter for %name% in %cat%. >> %logfile%


:convert

start /b /wait "video converter" c:\"program files (x86)"\avs4you\avsvideoconverter\avsvideoconverter.exe -a "d:\documents\conversions\%cat%.xml"

findstr "succeeded" c:\users\sm\appdata\roaming\avs4you\avsvideoconverter\avsvideoconverter.rpt
if %errorlevel%==0 (
	echo %date% at %time% : video converter terminated successfully. >> %logfile%
	goto filecheck
) else (
	goto exit
)
goto exit

	
:filecheck

%rem[%
	if converted file is found, delete old file.
	if converted file not found, check old file.
	if old file is corrupt, delete & replace.
	if old file is not corrupt, recall converter
%]rem%

	if exist %dest%.mp4
	(
		echo %date% at %time% : %dest%.mp4 file found; move (delete once this batch file is debugged) source. >> %logfile%
		move /y %folder%.mkv d:\
		echo %date% at %time% : source .mkv file moved(deleted). >> %logfile%
		goto filebot
	) else (
		echo %date% at %time% : %dest%.mp4 file not found; restart converter. >> %logfile%
		goto convert
	)


:filebot

%rem[%
	echo "run filebot"
	filebot -script fn:amc --output %config_output% --action duplicate --conflict skip -non-strict --log-file amc.log --def skip extract=y unsorted=y music=y artwork=y clean=y plex=host:token:fbe9ujuypfyhktx1bwfu excludelist=excludes.txt subtitle=en ut_label=%cat% ut_title=%name% ut_file=%file% ut_dir=%folder%
%]rem%


:exit
Apparently, what i need now is to rewrite those 7 formats into one to a) select by genre and/or tag, and b) select destination drive & folder, then force an update w/ plex. I also need to work on error checking in that batch file & improve on it. (I'm *not* a programmer etc which is large part of why this has been on my to-do list for way too long lol)
Any assistance appreciated :)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Format rewrites to automate processes

Post by rednoah »

:idea: FileBot can't do much about (1) add torrent and (2) categorize files. There may be tools that take can care of (1) and (2) at the same time. If you take care of (1) then FileBot may be able to take care of (2) based on Movie / Series information to some degree of accuracy.


Your *.bat script already looks fairly complete, and seems to be already calling filebot which then does the normal Movie mode or Episode mode processing using default custom formats.


--def ut_label=%cat% is good if %cat% is TV or Movie but will do nothing for "Concerts" or "Documentaries". You'll want to set --def ut_label to either TV or Movie to force one or the other depending on the files at hand, and your "Concerts" or "Documentaries" modes presumably are just Movie mode with a different output folder.


e.g. You can pass custom script parameters on the command-line, and then use them in your custom format code to do anything:

Code: Select all

--def my_category="Animated Series"

Code: Select all

{
	['Y:', 'Z:']
	.collect{ it / defines.my_category  }
	.sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace }
	.last()
}
e.g. Use "movie folders" for Documentaries but "flat movie files" structure for other movies:

Code: Select all

{
	defines.my_category == /Documentaries/ ? plex.tail : plex.name
}

:idea: Use the @file syntax for reading command-line arguments from external text files:

Code: Select all

--def movieFormat=@/path/to/MovieFormat.groovy
:idea: Please read the FAQ and How to Request Help.
Post Reply