Page 1 of 1

Is there A Way to match multiple items against a csv file?

Posted: 02 Feb 2015, 19:15
by DevXen
I thought I saw something here on the forums last week that would do this.

I have a couple things like this, i'd like to simplify:

{if (file.path.matchAll(/monstervision/))('[MonsterVision]/')}{if (file.path.matchAll(/rifftrax/))('[RiffTrax]/')}{if (file.path.matchAll(/fan.edit|fanedit/))('[FanEdits]/')}}

Instead of doing a file.path.matchALL() 3 separate times. is there a way to loop through all the items i'm looking for and just do it once?

Something like:
file.path.matchALL(/monstervision|rifftrax|fanedit/) {(csv('C:/extras.csv').get($1))}


extras.csv:
monstervision;[Monstervision]/
riffrax;[RiffTrax]/
fanedit;[FanEdit]/




I was thinking something like:
{def map=[(csv('C:/FileBot Settings/Movies/GenreTest.csv'))]; genres.findResults{ map[it] }.sort{ map.values().toList().indexOf(it) }.first()}

But that's not working so well.

Re: Is there A Way to match multiple items against a csv fil

Posted: 03 Feb 2015, 01:18
by DavidRTurner
I "think" you mean this post, where I needed to find if a list item existed, in a specific order:
http://www.filebot.net/forums/viewtopic ... 263#p13498
Maybe you can use that as a baseline...

Re: Is there A Way to match multiple items against a csv fil

Posted: 03 Feb 2015, 04:07
by DevXen
DavidRTurner wrote:I "think" you mean this post, where I needed to find if a list item existed, in a specific order:
http://www.filebot.net/forums/viewtopic ... 263#p13498
Maybe you can use that as a baseline...
yeah that's the one i got the example i posted, and the base I was working with.
and i could do it like that. but that wouldn't really make it any shorter than the way i have it now.
but if i could have it check every genre in {genres} against a csv file, looking for a match, then use that result from the csv file. that would make it efficient. smaller, and easier to change/update as needed over time.

Re: Is there A Way to match multiple items against a csv fil

Posted: 05 Feb 2015, 21:51
by DevXen
The issue i'm having now is:
Using mapping (to correctly label 3D movies) i'm having issues, matching 'hou' but not also matching 'house'



the map= as far as I can tell, really doesn't like regex, which is too bad, cause it'd be much easier to do: /hsbs|halfsbs|h?sbs/: 'Half-SBS' but I wasn't able to get that to work either, so i've had to type them all separately.


here's the code:

Code: Select all

{def map=['3d':'3D','hsbs':'Half-SBS','halfsbs':'Half-SBS','fsbs':'Full-SBS','fullsbs':'Full-SBS','sbs':'SBS',/hou/:'Half-OU','halfou':'Half-OU','fou':'Full-OU','fullou':'Full-OU','ou':'OU']; "("+ ((file.path.lower().contains(/3d/)) ? '' : '3D ')+ file.path.lower().replaceAll(/[\W]/, "").matchAll(/3d|hsbs|halfsbs|fsbs|fullsbs|sbs|hou|halfou|fou|fullou|uo/).findResults{ map[it].replaceAll("\\[|\\]", "") }.sort().join(' ')+')'}
if the file name is like: House on haunted Hill 3D HOU
it returns as: House on Haunted Hill (3D Half-OU Half-OU)

which isn't what i want.
i've searched all over the net for regex examples to include the space \S and \W and tried a thousand examples, but haven't been able to get any of it to work.
it either shows Half-OU twice, or it fails completely.



Edit:
It's not elegant but I got it working:

Code: Select all

{def map=['3d':'3D','hsbs':'Half-SBS','halfsbs':'Half-SBS','fsbs':'Full-SBS','fullsbs':'Full-SBS','sbs':'SBS','halfou':'Half-OU','fullou':'Full-OU','overunder':'Over-Under']; "("+ ((file.path.lower().contains(/3d/)) ? '' : '3D ')+ file.path.lower().replaceAll(/(\W|^)hou(\W|$)/,'halfou').replaceAll(/(\W|^)fou(\W|$)/,'halfou').replaceAll(/(\W|^)ou(\W|$)/,'overunder').replaceAll(/[\W]/, "").matchAll(/3d|hsbs|halfsbs|fsbs|fullsbs|sbs|halfou|fullou|overunder/).findResults{ map[it]}.sort().join(' ')+')'}
still would be nice if i could make it smaller. or even save the data in a csv but the map= is pretty picky i've found. and as said above, doesn't appear to like regex to add multiple strings to check for.

Re: Is there A Way to match multiple items against a csv fil

Posted: 06 Feb 2015, 01:27
by DavidRTurner
DevXen wrote:The issue i'm having now is:
Using mapping (to correctly label 3D movies) i'm having issues, matching 'hou' but not also matching 'house'

the map= as far as I can tell, really doesn't like regex, which is too bad, cause it'd be much easier to do:
Correct - a map is a literal translation of X to Y - a short-form of "If X, then Y".
There must be regex ways to do this, but it might not be shorter.
It's not elegant but I got it working:

Code: Select all

{def map=['3d':'3D','hsbs':'Half-SBS','halfsbs':'Half-SBS','fsbs':'Full-SBS','fullsbs':'Full-SBS','sbs':'SBS','halfou':'Half-OU','fullou':'Full-OU','overunder':'Over-Under']; "("+ ((file.path.lower().contains(/3d/)) ? '' : '3D ')+ file.path.lower().replaceAll(/(\W|^)hou(\W|$)/,'halfou').replaceAll(/(\W|^)fou(\W|$)/,'halfou').replaceAll(/(\W|^)ou(\W|$)/,'overunder').replaceAll(/[\W]/, "").matchAll(/3d|hsbs|halfsbs|fsbs|fullsbs|sbs|halfou|fullou|overunder/).findResults{ map[it]}.sort().join(' ')+')'}
still would be nice if i could make it smaller. or even save the data in a csv but the map= is pretty picky i've found. and as said above, doesn't appear to like regex to add multiple strings to check for.
My own maps are for replacement phrases ('Home & Garden' to 'Home') for example.
My regexes are for punctuation & the like - to make '&' into 'and'; or an accented letter into a plain, non-accented letter; or to replace multiple possible items that would require several items in a map.

Sorry, I have no brainstorms on streamlining this one - I would be tempted, though, to look at doing more direct .replaceAll's and skip the map, if that's all it the items in it. Not shorter, but simpler.
.replaceAll(/(?i:hsbs|halfsbs)/, "Half-SBS")
.replaceAll(/(?i:fsbs|fullsbs)/, "Full-SBS")
.replaceAll(/(?i:sbs)/, "SBS")
...

Re: Is there A Way to match multiple items against a csv fil

Posted: 06 Feb 2015, 23:47
by DevXen
DavidRTurner wrote: Sorry, I have no brainstorms on streamlining this one - I would be tempted, though, to look at doing more direct .replaceAll's and skip the map, if that's all it the items in it. Not shorter, but simpler.
.replaceAll(/(?i:hsbs|halfsbs)/, "Half-SBS")
.replaceAll(/(?i:fsbs|fullsbs)/, "Full-SBS")
.replaceAll(/(?i:sbs)/, "SBS")
...

thanks for the advice, that was kinda how i had it before. Just thought i'd make it more streamlined.

I posted it in the naming scheme and everything it does if you want to take a look.

Though I just found another issue, literally on the first real movie i tried to rename too! what luck, huh?

You see my movies are in a folder: [3D Movies]\blah\whatever. then the folder of the movie also says 3D.SBS or whatever to say it's in 3D. then the file name says the same

So the match is matching every occcurance of 3D, and SBS (or the other things i have it checking for.)
so the one i'm testing on is returning (3D 3D Half-SBS 3D Half-SBS)

I haven't found a way to have it stop at the first match and move to the next item to look for.


You can see it if you try:
{"3D HSBS 3D HSBS 3D HSBS".replaceAll(/3d/hsbs/)}
will return: 3D, HSBS, 3D, HSBS, 3D, HSBS.

I tried the .replace(). but that stops after just the 3D, and doesn't match the sbs. (or anything else in the list)
i've looked for ways to stop it after the first match, nothing has been successful. grr.

Re: Is there A Way to match multiple items against a csv fil

Posted: 07 Feb 2015, 16:55
by DevXen
Wahoo I got it working with: 3d(?!.*?3d)|fhbs(?!.*?hsbs), etc

.. Main Script updated to reflect this in the naming scheme post as well.