Return multiple results from a single CSV File?

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

Return multiple results from a single CSV File?

Post by DevXen »

Is there a way to return multiple results from the same CSV File, instead of just the first result?

for example, i have several csv file lists of specific movies, like: Mockumentaries, Direct To Video, Banned Films, Remakes, Based on True Stories, and several more.

And I want to check them if the movie name matches to add that additional info to the file name when applicable. but the only way I know how is to check each one separately.
But if I could add them all into 1 CSV File. and return each result when each one is found. (Surrounded by Brackets for each one) that would be great, and seems it'd be easier to maintain. I just don't know if it is possible.

Example:
I'd like it to return: [DTV] [Banned in US] [Remake] (When all 3 are in the same CSV File)
moviename;DTV
moviename;Banned in US
moviename;Remake


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

Re: Return multiple results from a single CSV File?

Post by rednoah »

Yes, the csv(...) function will give you a Map so you just grab the data you need from there.

@see http://groovy.codehaus.org/groovy-jdk/j ... g.Closure)
:idea: Please read the FAQ and How to Request Help.
DevXen
Power User
Posts: 132
Joined: 12 Oct 2014, 21:15

Re: Return multiple results from a single CSV File?

Post by DevXen »

I'm not so familiar with Groovy. But thanks for pointing me in the right direction, i'll see if I can get it working.
DevXen
Power User
Posts: 132
Joined: 12 Oct 2014, 21:15

Re: Return multiple results from a single CSV File?

Post by DevXen »

You know it took me over and hour to finally get the map to display with:

Code: Select all

{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv')}
as i kept working on variations of the .get()

But when I finally did get the map to show, it only showed the first and the last record in the csv file. not the ones in the middle. (I tested with 3 and 4 rows in the csv file)

then I tried:

Code: Select all

{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv').findResults(n)}
it is only showing 2 results (not 4 that are in the csv file), and both show as the movie name, not the value they should be.

Though if i do this:

Code: Select all

{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv').findResults{ k, v -> k == n ? "$v" : null }}
it shows the correct value, but only the last one.

if i do:

Code: Select all

{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv').findResults{ k, v -> k =~ n ? "$v" : null }}
it shows the values, but still only the first one, and the last one. not the second or third one. and if i add a 5th, it'll show that one, and not the 4th one.


The link you posted says that findResults():

"Iterates through the map transforming items using the supplied closure and collecting any non-null results."


I dunno, am I doing something wrong?
User avatar
rednoah
The Source
Posts: 19133
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Return multiple results from a single CSV File?

Post by rednoah »

The I assume the first and last entry match k =~ n and thus return v while the others return null and get ignored (since only non-null results are collected).

Maybe this little exercise will help:

Code: Select all

{[0:'a',1:'b',2:'c'].findResults{ k, v -> v =~ /a|b/ ? k : null}}
Result: [0, 1]

Keep in mind that your k =~ n assumes that n is a regular expression, which it isn't. You probably want k.contains(n) if you want to check if k contains n.
:idea: Please read the FAQ and How to Request Help.
DevXen
Power User
Posts: 132
Joined: 12 Oct 2014, 21:15

Re: Return multiple results from a single CSV File?

Post by DevXen »

I tried:

Code: Select all

{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv').findResults{ k, v -> k.contains(n) ? "$v" : null }}
and it still came up with the first and last result:

here is the csv file for testing (on all of the examples)

Code: Select all

Mortal Kombat;Super Natural
Mortal Kombat;Based on Video Game
Mortal Kombat;New Line Studios
Mortal Kombat;True Story
... it's only returning: [Super Natural, True Story]


The problem, i would assume. appears to be: The csv(...) is creating the map of only the first and last result.

When I try this:

Code: Select all

{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv')}
it only returns: {Mortal Kombat=Super Natural, Mortal Kombat=True Story}

now i can add/change as many lines i want. even by copy/paste and it'll still only show the first and last result.
User avatar
rednoah
The Source
Posts: 19133
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Return multiple results from a single CSV File?

Post by rednoah »

Alright, the csv(...) function will give you a Map, and a Map cannot contain the same key more than once.

e.g.

Code: Select all

Key1;Value
Key2;Value
Key3;Value
I guess you could just swap key<->value in your csv file.
:idea: Please read the FAQ and How to Request Help.
DevXen
Power User
Posts: 132
Joined: 12 Oct 2014, 21:15

Re: Return multiple results from a single CSV File?

Post by DevXen »

that's odd, cause it still showed 2. but by swapping the key in the csv file. that worked. Thank you. I never would have thought of that.
Post Reply