How do I use Plain File Mode on the command-line and pass a complex custom format?

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
Retrorat1
Posts: 7
Joined: 24 Feb 2021, 07:23

How do I use Plain File Mode on the command-line and pass a complex custom format?

Post by Retrorat1 »

Hi
For the past 6 months have been using this code

Code: Select all

{fn.replaceAll(/(\w+).((?:19|20)\d{2}).(.+.vs.\w+).(\d{2}).(\d{2}).(\d{3}p)(.+)/, '$1 $2-$4-$5 $3').replace('EPL','English Premier League').space('.')}
given to me from here viewtopic.php?f=8&t=13173&p=57529&hilit=Sports#p57529 in filebot windows to rename my files but was hoping someone can give me direct instructions how to make this run on a remote Debian system with a watch folder.

so I download files to

Code: Select all

/home/terrymasu/torrents/rtorrent/Sports/football
I want it to use the script to rename and make a symlinks here

Code: Select all

/home/terrymasu/Plex/Sports/English Premier League/2022-2023
so I can still seed to original without a problem but then due to the naming it will show up on my plex with all the posters and write up automatically from SportsDB.
Thanks

P.S I have tried to read scripting and searching for videos on the process but nothing really helps as I cant understand where to even start.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Headless on Debian

Post by rednoah »

You can copy & paste from the Plain File Mode examples:
Image



e.g.

Code: Select all

filebot @/path/to/args.txt
/path/to/args.txt

Code: Select all

-rename
-r
/home/terrymasu/Plex/Sports/English Premier League/2022-2023
--db
file
--action
symlink
--format
{fn.replaceAll(/(\w+).((?:19|20)\d{2}).(.+.vs.\w+).(\d{2}).(\d{2}).(\d{3}p)(.+)/, '$1 $2-$4-$5 $3').replace('EPL','English Premier League').space('.')}
:idea: I use @file syntax for reading command-line arguments from external text files, because your format contains lots of ' and " and $ and so passing that on the command-line would be somewhat tricky and thus best avoided altogether.
:idea: Please read the FAQ and How to Request Help.
Retrorat1
Posts: 7
Joined: 24 Feb 2021, 07:23

Re: How do I use Plain File Mode on the command-line and pass a complex custom format?

Post by Retrorat1 »

@rednoah
Thank you so much for bearing with me and putting this up , sorry for the delay in responding but I was trying to get it working correctly for me before I come back on here and ppl go "He's Back" LoL.

This works like its meant to be but I had to figure out few things as the naming using the SportsDB has to be exact for it to pick up so first was the date the month and day needed to be switched over which I could figure out as it was the only format with a - in it lol,
So $2-$4-$5 became $2-$5-$4.
The next I couldn't figure out but I bet its as simple as the date.

The naming was working for some but not others and even though they looked exactly the same it didn't work, like this

Code: Select all

EPL 2012 Arsenal vs Newcastle Utd 29 12 720pEN60fps USA.mkv
English.Premier.League.2012.Arsenal.vs.Newcastle.Utd.29.12.720pEN60fps.USA
whereas this

Code: Select all

EPL 2013 Newcastle Utd vs Arsenal 19 05 720pEN60fps USA.mkv
English.Premier.League.2013-05-19.Newcastle.Utd.vs.Arsenal
I tried switching things around and everything but nothing worked, then I figured out it was because the second team and 2 names it was not picking up(still don't know how to fix that)
so Newcastle Utd vs Arsenal it worked as expected but
Arsenal vs Newcastle Utd it didn't because of the Utd in the second name
also noticed an extra space between the name and the date didn't get the right outcome as well

Code: Select all

EPL 2013 Newcastle Utd vs Arsenal  19 05 720pEN60fps USA.mkv
English.Premier.League.2013.Newcastle.Utd.vs.Arsenal.19.05.720pEN60fps.USA
The extra space after Arsenal did factor in after all.

Once again thank you for all the help.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How do I use Plain File Mode on the command-line and pass a complex custom format?

Post by rednoah »

If the regex pattern doesn't match your files:

Code: Select all

(\w+).((?:19|20)\d{2}).(.+.vs.\w+).(\d{2}).(\d{2}).(\d{3}p)(.+)
Then replaceAll does not replace anything, and the rest of your format just does simple replacements:

Code: Select all

{ fn.replace('EPL','English Premier League').space('.') }



:idea: If you test your code like this, then it'll be more easy to understand which capturing group captured with character sequence:

Code: Select all

{ fn.replaceAll(/(\w+).((?:19|20)\d{2}).(.+.vs.[\w\s]+).(\d{2}).(\d{2}).(\d{3}p)(.+)/, '($1) ($2)-($4)-($5) ($3)') }

Code: Select all

(EPL) (2012)-(29)-(12) (Arsenal vs Newcastle Utd)
:idea: \w matches word characters, i.e. letters and numbers, but not spaces. [\w\s] matches word or space characters. Note that this may introduce some ambiguousness because [\w\s]+ matches both Newcastle Utd and Arsenal vs Newcastle Utd 19 05 720pEN60fps USA. It happens to work for the test case above though.
:idea: Please read the FAQ and How to Request Help.
Retrorat1
Posts: 7
Joined: 24 Feb 2021, 07:23

Re: How do I use Plain File Mode on the command-line and pass a complex custom format?

Post by Retrorat1 »

@rednoah
Wow yes that made it work.
Thanks again for this going to try it on my formula 1 collection now lol.
Its understanding what needs to be picked up and what to be left out is where I don't understand at all, as some of it being left out is still in my eyes alpha or numerical characters.
opening the regex help page again to see if I can figure it out myself .
Thanks
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How do I use Plain File Mode on the command-line and pass a complex custom format?

Post by rednoah »

You can use regexr to test your regex on your sample file names:
https://regexr.com/

You can find detailed technical documentation and a list of available character classes here:
https://docs.oracle.com/en/java/javase/ ... ttern.html
:idea: Please read the FAQ and How to Request Help.
Post Reply