INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Bug in Expressions Editor?  (Read 3671 times)

DanielBuus

  • Recent member
  • *
  • Posts: 30
Bug in Expressions Editor?
« on: July 21, 2009, 02:45:12 pm »

Hey hey :)

I'm trying (in MC13, build 171) to rename my files using some if constructs, to only include e.g. Date (Year) in a folder name if it exists (thus avoiding the "Unknown Year" thing). (And, btw, it really sucks that IsEmpty() doesn't work with file renaming).

Okay, so consider this directory rule:
[Name] If(IsEqual([Subtitle], Unknown Subtitle), , - [Subtitle]) If(IsEqual([Date (Year)], Unknown Year), , -[Date (Year)]-)

This produces (first one has no Subtitle but a Date (Year), second one has neither, third one has a Subtitle and a Date (Year)):
X:\Alien  -1979-\
X:\Hero\
X:\The Ring 0 - Birthday -2000-\

Now, the same rule, except () instead of -- around the year:
[Name] If(IsEqual([Subtitle], Unknown Subtitle), , - [Subtitle]) If(IsEqual([Date (Year)], Unknown Year), , ([Date (Year)]))

X:\Alien  (1979)\
X:\Hero )\
X:\The Ring 0 - Birthday (2000)\

So I read you can escape literals using a forward slash:
[Name] If(IsEqual([Subtitle], Unknown Subtitle), , - [Subtitle]) If(IsEqual([Date (Year)], Unknown Year), , /([Date (Year)]/))

X:\Alien  \(1979\)\
X:\Hero )\
X:\The Ring 0 - Birthday \(2000\)\

Am I missing something completely or is there something really wrong with the expressions editor? I think the idea of having an expressions editor is awesome (as are most other things in MC, it's just so  well constructed), but something's amiss. One thing is that I can't insert " - ([Date (Year))" and keep the preceding space because function arguments are not enclosed in apostrophes or quotes, another is the thing described above. Where does that stray closing parenthesis come from?

Please point me to some documentation if I'm just being daft, but reading http://wiki.jrmediacenter.com/index.php/Media_Center_expression_language didn't really help. It doesn't even note that you can't use IsEmpty() in the file renaming dialog (I tried doing IsEqual on dummy library fields of different types before finding a post on this forum that answered this question, hehe :D )
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Bug in Expressions Editor?
« Reply #1 on: July 21, 2009, 06:03:25 pm »

Same as my post here?:

[ Link removed ]
Logged
The opinions I express represent my own folly.

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9124
Re: Bug in Expressions Editor?
« Reply #2 on: July 22, 2009, 04:38:42 am »

Hmm, don't know. When following your link, I get:

An Error Has Occurred!
The topic or board you are looking for appears to be either missing or off limits to you.
MrC, you should consider removing the link in your post.

MrC Wrote:
Quote
It seems that quoting a parenthesis in the File Location->Folder Rule does not work properly.  The following expressions:

Code:

IsEqual([Album Artist (auto)], /(Multiple Artists/))
IsEqual([Album Artist (auto)], /(Multiple Artists/), 0)


return:

Code:

0)
0, 0)


respectively.

I seem to remember reporting this little problem a long long time ago, and dropped it after a while as I found a way around it...

MrC first.
You can avoid the problem altogether by using a case insensitive substring compare on [album artist (auto)] instead of a match, like so...
if(isequal([album artist (auto)],multiple,8),MULTIPLE,SINGLE)
By asking "Does [album artist (auto)] contain multiple?" you can bypass the entire parenthesis issue.

DanielBuus, good morning :)

The bug appears to be not the parenthesis, but that the expression engine is converting the forward slash 'escape' character into a directory path making backslash, which appears to be leaving the parenthesis exposed and interpreted by the expression engine.
The reason you're having problems with spaces is that after a comma, all spacing is ignored, so, in order to treat them literally, they need to be escaped, and as we've already ascertained, escaping is currently busted!! See the "Should work but doesn't" example for the escaped spaces and parenthesis.
This is definitely a bug, so, you can either hang fire and await a fix, or try one of the workaround strings provided below.
the long-winded workaround works because there are no spaces after any commas, and no parenthesis involved either.


Should Work but doesn't
[name]if(isequal([subtitle],unknown,8),,/ - [subtitle])if(isequal([year],unknown,8),,/ /([year]/))





Work around
if(isequal([subtitle],unknown,8),if(isequal([year],unknown,8),[name],[name] [[year]]),if(isequal([year],unknown,8),[name] - [subtitle],[name] - [subtitle] [[year]]))

or

if(isequal([subtitle],unknown,8),if(isequal([year],unknown,8),[name],[name] -[year]-),if(isequal([year],unknown,8),[name] - [subtitle],[name] - [subtitle] -[year]-))

-marko

DanielBuus

  • Recent member
  • *
  • Posts: 30
Re: Bug in Expressions Editor?
« Reply #3 on: July 22, 2009, 12:08:28 pm »

Hi Marko, thanks for your reply :)

Good to know that it is a known bug that'll be fixed :) In the meantime, thanks for the workaround - the brackets will have to do for now, and the clever (though extremely verbose!) nesting should also do for now to fix the spaces issue. I don't mind nesting anyway and I will just use Eclipse or something to help me not break syntax.

Gonna be fun to see what it'll expand to once I've got my entire expression written out! :D

Anyway, thanks for the help! Hope to see the bugfix in v14 once it's done? (Already have the beta installed, but I'm kinda hesitant to use it for massive organizing tasks like I'm doing ATM ;) )

Daniel
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Bug in Expressions Editor?
« Reply #4 on: July 22, 2009, 12:30:19 pm »

Thanks for the workaround Marko.

I'm still hoping the expression editor gets fixed.  It is hard enough testing each little modification to an expression, going through all the dialogs, but it is even more exasperating when tha expression parser is buggy.  Too much syntax-babying.
Logged
The opinions I express represent my own folly.

DanielBuus

  • Recent member
  • *
  • Posts: 30
Re: Bug in Expressions Editor?
« Reply #5 on: July 22, 2009, 12:46:15 pm »

Hey you guys, just thought of a different workaround where spaces and parentheses are available without too much hacking:

Create a new library field, e.g. [Generated Folder Name] (Options > Library & Folders > Manage Library Fields...), make it an expression field and create the unrestricted expression you'd wish you could've made in the file renaming dialog, and the just put in [Generated Folder Name] as the Rule!

This way you can have it just like you want, and the expression doesn't get extremely huge when you use a lot of "if empty"s - which, btw, are now available instead of having to use isequal to find out if a field is empty :D

Yay
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9124
Re: Bug in Expressions Editor?
« Reply #6 on: July 22, 2009, 12:55:57 pm »

Yup, works too. We've used that kind of shortcut quite regularly in the past.

You need to be mindful of one thing when using this approach though...

Don't be tempted to use more than one directory depth in each "generated folder name" field. Internally, MC will display the back slash correctly, but the file renamer will catch the back slashes as illegal characters and change them to underscores!!!

Work arounds shouldn't detract from the fact that the expression engine contains this bug. Expressions are hard enough work for beginners trying to learn, without chucking things like this into the mix.

-marko.

DanielBuus

  • Recent member
  • *
  • Posts: 30
Re: Bug in Expressions Editor?
« Reply #7 on: July 22, 2009, 01:15:32 pm »

LOL, just returned to write about the very same caveat! :D

Hm! Guess it's back to creating humongous workaround expression, then :P

Cheers
Logged

DanielBuus

  • Recent member
  • *
  • Posts: 30
Re: Bug in Expressions Editor?
« Reply #8 on: July 22, 2009, 01:25:05 pm »

Hahahaaaa! We don't give up that easy!

You CAN have full paths with subdirectories and all the trimmings! What you do is you create your custom expression field, make it create a complete path including drive etc., then instead of using the rename/copy files utility, you use the Library Tools -> Move / Copy Fields context menu entry.

Then, if you're trying to creating just a new path for the file (like me :) ), you can copy the value of your expression field to "Filename (path)" and whoosh, your file will be moved :)

Better make sure your expression is good, though ;)
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9124
Re: Bug in Expressions Editor?
« Reply #9 on: July 22, 2009, 01:29:05 pm »

Excellent!!
Nice bit of lateral thinking there. I didn't have that one in my toolbox before :)

Like you say though, potential for a wholesale disaster in the wrong hands  :o

DanielBuus

  • Recent member
  • *
  • Posts: 30
Re: Bug in Expressions Editor?
« Reply #10 on: July 22, 2009, 01:57:01 pm »

Thanks :D

I'm just gonna throw this one here, to show peeps what I'm doing if they wanna go the same way. Once you start nesting the IFs it can get really nasty, so you want to use tabs and newlines to keep your expression neat, but that screws the expression unless you use Replace(), so okay, here's where I'm at ATM, anyone interested can use it as a starting point, it's definitely a work in progress here (still typing away happily):

Code: [Select]
Replace(Replace(Replace(Replace(Replace(X:\[Media Type]\[Accessibility]\
If(IsEqual([Media Type],Video),
If(IsEmpty([Series]),
<VIDEO BUT NOT SERIES>
,
[Series]\If(IsEmpty([Season]),,S[Season])If(IsEmpty([Episode]),,E[Episode]) If(IsEmpty([Name]),,[Name])
)
,
<NOT VIDEO>
)
If(IsEmpty([Date]),,/ /([Date]/)) If(IsEmpty([Release Title]),,\[Release Title]\)
,/
),
/  ),/ ),/ \,\),\/ ,\)

Okay, so the stuff inside <>s are there as reminders to me - ATM I'm doing series, so I'm branching in that direction. Later I'm going back and taking the "video, but movie" branch, then later all the stuff that isn't video at all ;)

And the other thing to note is all the Replace()s - they're doing a couple of things:
1) They make sure you don't have to worry about double spaces inside your expression. Like when you want a space between your movie name and "(2006)" but nothing at all when there's no year specified.
2) They clean up spaces in front of, and after, backslashes. Pretty much same deal as before - if I have a series episode with no particular name, the expression would give me a space before the next backslash, so this is cleaned up too.
3) To be better able to edit and understand the expression, I put newlines and tabs in there to show nesting and keep things tidy. This is also cleaned up.

Basically the result is one long line without double spaces and tabs and spaces around backslashes, so you can basically take the first and the last line and replace the innards using all the spaces, newlines and tabs you want and still get a usable result. Only you can't move the "X:\[Media Type]\[Accessibility]\" part on the first line to a newline, but of course you can edit it :)

HTH someone :)

This was fun! :D

Oh, BTW: Some of these tags are my own, so don't get confused about the [Accessibility] and [Release Title] tags ;)
Logged

DanielBuus

  • Recent member
  • *
  • Posts: 30
Re: Bug in Expressions Editor?
« Reply #11 on: July 22, 2009, 01:59:19 pm »

Oh, sorry, you have to keep a bit more than the first and last line, there's an escaped newline there in the end to be replaced (the forward slash just before a newline) :)
Logged

DanielBuus

  • Recent member
  • *
  • Posts: 30
Re: Bug in Expressions Editor?
« Reply #12 on: July 22, 2009, 02:01:32 pm »

...that probably didn't make much sense...

Like this:
Code: [Select]
Replace(Replace(Replace(Replace(Replace(X:\[Media Type]\[Accessibility]\
If(IsEqual([Media Type],Video),
If(IsEmpty([Series]),
<VIDEO BUT NOT SERIES>
,
[Series]\If(IsEmpty([Season]),,S[Season])If(IsEmpty([Episode]),,E[Episode]) If(IsEmpty([Name]),,[Name])
)
,
<NOT VIDEO>
)
If(IsEmpty([Date]),,/ /([Date]/)) If(IsEmpty([Release Title]),,\[Release Title]\)
,/
),/  ),/ ),/ \,\),\/ ,\)

Then consider the first and the last two lines as wrappers for the expression, cleaning it up :)
Logged

DanielBuus

  • Recent member
  • *
  • Posts: 30
Re: Bug in Expressions Editor?
« Reply #13 on: July 22, 2009, 02:20:58 pm »

Hehe, okay, one small detail. The expressions I posted where created for an "added expression column" in a view, i.e. when you right-click the column headers and click "Add Expression Column". The editor here does not remove newlines, but it appears that the editor under the library settings does, that is, where you add columns you can later add to your views.

So, for that editor, you need to NOT replace newlines, or you'll end up replacing single spaces because the editor changes newlines to spaces. I.e. the same expression as posted above, only for when you create REAL new library fields:

Code: [Select]
Replace(Replace(Replace(Replace(Replace(X:\[Media Type]\[Accessibility]\
If(IsEqual([Media Type],Video),
If(IsEmpty([Series]),
<VIDEO BUT NOT SERIES>
,
[Series]\If(IsEmpty([Season]),,S[Season])If(IsEmpty([Episode]),,E[Episode]) If(IsEmpty([Name]),,[Name])
)
,
<NOT VIDEO>
)
If(IsEmpty([Date]),,/ /([Date]/)) If(IsEmpty([Release Title]),,\[Release Title]\)
,/ / ),/ ),/ \,\),\/ ,\),\\)

- this time you only need to consider the very first and very last lines as wrappers :)
Logged

DanielBuus

  • Recent member
  • *
  • Posts: 30
Re: Bug in Expressions Editor?
« Reply #14 on: July 22, 2009, 02:39:21 pm »

Yeah, okay, final one for awhile!  :-X With the real library field editor you're gonna end up with a space in the end of the path which might cause problems unless you move the last line up like this:

Code: [Select]
Replace(Replace(Replace(Replace(Replace(X:\Stores\Mother\[Media Type]\[Accessibility]\
If(IsEqual([Media Type],Video),
If(IsEmpty([Series]),
<VIDEO BUT NOT SERIES>
,
[Series]\If(IsEmpty([Season]),,S[Season])If(IsEmpty([Episode]),,E[Episode]) If(IsEmpty([Name]),,[Name]) If(IsEmpty([Subtitle]),, -/ [Subtitle])
)
,
<NOT VIDEO>
)
If(IsEmpty([Date]),,/ /([Date]/)) If(IsEmpty([Release Title]),,\[Release Title]),/ / ),/ ),/ \,\),\/ ,\),\\)

I'll just keep quiet for awhile now, and post my final expression if anyone wants it ;)
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42323
  • Shoes gone again!
Re: Bug in Expressions Editor?
« Reply #15 on: July 22, 2009, 02:45:00 pm »

This is definitely a bug, so, you can either hang fire and await a fix, or try one of the workaround strings provided below.
the long-winded workaround works because there are no spaces after any commas, and no parenthesis involved either.

In Media Center 14.0.38 and later (available in about a week):
Fixed: Renaming directory expressions that used slashes (the escape character) did not work correctly.

Thanks.
Logged
Matt Ashland, JRiver Media Center
Pages: [1]   Go Up