CSV File questions.

All about user-defined episode / movie / file name format expressions
Post Reply
DevXen
Power User
Posts: 164
Joined: 12 Oct 2014, 21:15

CSV File questions.

Post by DevXen »

So i'm trying to add a fairly large snipplet i found on the forums to my script to add the different codecs like TrueHD, Etc to the filenames.

and apparently there is a limit in the gui for how long it can be. and its about 2,000 characters over that.

so i have a couple questions to try to make it smaller.

Can i move def mappings to a CSV File?

For Exmaple:

Code: Select all

	def codecList =
	[
	'MPEG Audio' : 'MP2',
	'MP3' : 'MP3',
	'PCM' : 'PCM',
	'FLAC' : 'FLAC',
	]
Can i move that to a csv file:
MPEG AUDIO:MP2
MP3:MP3
PCM:PCM
FLAC:FLAC

and just call the CSV file to add it to an array? - I tried several ways and was unable to get it to work.

(this is the link to the full audio codec script i stumbled across and trying to adapt it to work in my script: viewtopic.php?p=56178#p56178)

the second question, i have my script calling several CSV Files for additional info. Based on book, banned films, Mockumentary, Time Travel, Post Credit Scenes, etc.
I did it that way as one movie may match several. vs only one it would match if it was all in one CSV File.

So my question with that is can I add those CSV Files to a single CSV or Text file and have it use them like it does in the script looking for a match from each?
cause that would help cut down the size a bit.

Edit: Ooo an even better question, can i move full scripts to separate files then call them to run from the gui? that would be nice too.

thanks,
-Dev
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: CSV File questions.

Post by rednoah »

FileBot provides the csv(path) built-in helper functions for reading *.csv files into Map objects.

e.g.

Code: Select all

def codecList = csv('/path/to/file.csv')
:idea: Passing a simple tab-separated values file is generally recommended. FileBot will try different column separators (i.e. TAB and SEMICOLON) but COLON : is notably not among them at this time.


i.e. your *.csv file should look like this:

Code: Select all

A	1
B	2
C	3
D	4
:idea: Note that the separator space in the snippet above is a single TAB character, and not multiple SPACE characters.



:arrow: Alternatively, you can also split your format into multiple external text files. Please read [DOCS] Split code into external *.groovy script files for details.
:idea: Please read the FAQ and How to Request Help.
DevXen
Power User
Posts: 164
Joined: 12 Oct 2014, 21:15

Re: CSV File questions.

Post by DevXen »

Awesome, I'll try both. Though i have a couple questions with the splitting the format into multiple external files. i didn't see them answered on your docs page for it.

1. I noticed the examples have the .groovy extension. Will my format work as is, or will i need to change/convert it to groovy to work? (I ask cause i have little to no actual experience with groovy)
2. Will it still what the files will be renamed too on the right side? (I use that to test and check things quite a bit.) and Will it still tell me script errors at the top?
3. Can I mix it with my current expression. or do i have to move it all to external files?

also as i noticed its taking quite a bit of space in my script. is there a way to match info from the filepath: /extended|director's.cut|unrated/ etc to an external csv/text file? that would save quite a bit of space.

I was thinking about the COLON not being used as a column separator. that's probably a good call since many tv shows use a colon in their name.

Thanks,
-Dev
Last edited by DevXen on 14 Apr 2022, 20:09, edited 1 time in total.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: CSV File questions.

Post by rednoah »

There is no magic. FileBot will simply replace the @file.groovy lines with the text content of the file. No more. No less.

e.g. have FileBot put the pieces together:

Code: Select all

@A.groovy
@B.groovy
@C.groovy
e.g. have your own shell script put the piece together ahead of time:

Code: Select all

cat A.groovy B.groovy C.groovy > format.groovy

Therefore:
1. The @file.groovy pattern is required. You are already using Groovy. FileBot Format Code is Groovy code. Just copy & paste your format from the Format Editor into a newly created text file named file.groovy and it'll work.
2. FileBot does not differentiate between code read from a GUI text field or code read from an external text file. Reading custom format code from an external text file does not change how the GUI works.
3. Yes, you can mix @file.groovy lines with lines of in-line code. FileBot will not substitute non @file.groovy patterns.

DevXen wrote: 14 Apr 2022, 18:41 also as i noticed its taking quite a bit of space in my script
You could have a million lines of code in your script and it would still mean nothing to modern hardware.
:idea: Please read the FAQ and How to Request Help.
Post Reply