INTERACT FORUM

More => Old Versions => Media Center 17 => Topic started by: rjm on March 30, 2012, 11:15:28 pm

Title: how to detect filename errors? (need expression expert)
Post by: rjm on March 30, 2012, 11:15:28 pm
For single artist audio music albums I try to rename the files [Track #] - [Name].

I want a filter to detect names that do not conform to this convention.

So far I have created the expression:

[=IsEqual(filename(,0),PadNumber([Track #],2) - [Name],0)]=0

which works except for those [Names] that have special characters like :?\ which are converted to _ by the file rename function.

How should the expression be modified to handle these special characters?
Title: Re: how to detect filename errors? (need expression expert)
Post by: MrC on March 31, 2012, 12:38:30 am
Here's a method.  Put it together how you want.  I tend to use Panes views to test and build.

Special chars /\:*?"<>| get converted to underbar (_) during Rename.

The Clean() function in mode 3 will clean file system special chars from a name.  Unfortunately, it cleans to use dash (-) rather than underbar (_), but you can correct for that in your expression.  The idea is to Clean() the name, and compare against filename with underbar replaced by dash (and you have to convert the underbar to dash in the filename() since converting dash to underbar in Name will also convert valid dash's in Name).

To test, I create one pane:

   Name: Contains FS Illegal char
   Expression: FormatBoolean(regex([Name], /#[\\/:*?"<>|]#/), Contains Illegal, Legal)

From there, a second column:

  Name: Name -> Cleaned
  Expression: [Name] -> Clean([Name], 3)

and finally a third:

  Name: Needs Update?
  Expression: If(IsEqual(PadNumber([Track #],2) - clean([Name],3), replace(filename(,0),_,-)), / **Path OK, [Name])

Title: Re: how to detect filename errors? (need expression expert)
Post by: rjm on March 31, 2012, 01:44:01 am
Thanks for pointing the way. I got it to work as a search list with the expression:

[=IsEqual(Replace(filename(,0),_,-),PadNumber([Track #],2) - Clean([Name],3),0)]=0
Title: Re: how to detect filename errors? (need expression expert)
Post by: MrC on March 31, 2012, 10:35:53 am
Great, good to hear.

It might be worth requesting a new mode to Clean(), perhaps 4, which changes the replacement character from dash (-) to underbar (_) so that this job is easier and matches Rename's functionality.

Name:                    Foo "Bar" Jones
Clean([Name], 3) => Foo -Bar- Jones
Clean([Name], 4) => Foo _Bar_ Jones
Title: Re: how to detect filename errors? (need expression expert)
Post by: rjm on March 31, 2012, 12:59:32 pm
Yes, that would be a nice enhancement.

Even better would an "expand to full artist" smartlist option.

Maybe Matt is eavesdropping.
Title: Re: how to detect filename errors? (need expression expert)
Post by: rjm on March 31, 2012, 02:50:22 pm
I just figured out that it is possible to use the "expand to full album" option for artist related applications provided you do not need info associated with (Multiple Artist) albums. An "expand to full artist" option would be nice to cover all possibilities.
Title: Re: how to detect filename errors? (need expression expert)
Post by: glynor on June 14, 2012, 09:41:49 pm
I need to do the same thing but have it apply to an entire expression that I already have.  So, to be specific, I have this the custom expression field [iTunesFileKey] which is:

M:\iTunes_cache\[Handheld Audio Path]\if(regex([Filename (name)],/#\.(mp3|mp4|m4a|m4v|m4p|m4b|m4r|jpg)$#/),[Filename (name)],Filename(,0).mp3)

[Handheld Audio Path] is, itself an expression:

Audio\If(IsEmpty([Media Sub Type]),Music,[Media Sub Type])\If(IsEmpty([Artist]),Unknown,[Artist])\If(IsEmpty([Album]),Unknown,[Album])If(IsEmpty([Disc #],1),,\[Disc #])

I need to check that whole thing for invalid filename characters and have them converted to _ as MC will do when it syncs the handheld.  But, obviously, I need the colon after M to stay as it is.  I've also noticed that MC seems to be converting ampersand characters to &amp; in my expression, but these come through in the actual filename as ampersands.  (On second thought, this might just be the logging in MCiS that is doing that.)

A "Filename Friendly" mode for Clean() would be so much simpler, and would be fantastic.  But, barring that, can anyone help?  I'm hopelessly lost as to how this would apply to my need.
Title: Re: how to detect filename errors? (need expression expert)
Post by: glynor on July 23, 2012, 04:19:24 pm
Anyone?  Bueller?

Also, to reiterate, a nice new feature would be a Clean() mode that matches the output of MC's Filename logic.
Title: Re: how to detect filename errors? (need expression expert)
Post by: MrC on July 23, 2012, 07:34:47 pm
See this post (http://yabb.jriver.com/interact/index.php?topic=72146.msg488144#msg488144) and replies.
Title: Re: how to detect filename errors? (need expression expert)
Post by: glynor on July 23, 2012, 08:11:22 pm
Awesomesauce.