INTERACT FORUM

Please login or register.

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

Author Topic: Parse Existing Field Into Other Fields?  (Read 1741 times)

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Parse Existing Field Into Other Fields?
« on: October 26, 2012, 01:06:47 pm »

So, I was doing some much-needed Library cleanup last night (for hours and hours), and I came across a situation that I'm not sure how to fix easily, and wondered if anyone had any tips.  I think there's a clever way to do this, but I can't remember how...

If I have a bunch of files that have the [Name] field filled like this:

Track # - Song Title

The actual [Track #] field is blank, and I don't want that extra information in the [Name] field (I want to remove everything at the beginning, after copying the number over to the appropriate field).  The problem is that, in the cases I was hitting regularly last night:

1. These were audiobooks, so the track number part of the [Name] field actually went to three digits, but didn't start out as three digits.  They looked like "1 - Some section title" at the beginning, and "386 - Some section title" at the end of the list of files.

2. The actual filenames weren't easily parse-able, so it wasn't easy to use the Fill Properties from Filename tool without hosing a bunch of existing data in the files.  The data in the [Name] field came from ID3 tags in the files, not from auto-parsing the filenames.

3. The files were out of order.  I suppose I could have sorted the order, and then just done =Counter() in the [Track #] field, but the problem with that is that it doesn't let me make sure I don't have any duplicates or missing tracks.  When you have 300+ files, it isn't easy to just verify this visually.

I want to parse the [Name] field and extract the [Track #], remove the " - ", and leave only the "Song Title" in the [Name] field.

This turned out to be annoyingly difficult.  This is how I did it:

1. Use =ListItem() in the [Track #] field, looking at list item 1 in the [Name] field, to fill the track numbers properly.  This filled [Track #] and left [Name] untouched.
2. Use =ListItem() in the [Name] field, looking for the second list item.  This removed the track numbers from the [Name] field properly, but it left a leading space for each one (since it wasn't possible to use " - " as the delimiter, since spaces are ignored in Expressions).
3. Use =Clean() on the [Name] field to nix that leading space.
4. A side-order of =FixCase() most of the time.

This was annoyingly difficult, though certainly not impossible.  It took 3-4 "steps" to fix it each time, and inevitably once or twice I'd forget to type the = sign, and would overwrite all of the tracks in that particular field (requiring Control-Z try again).

It isn't the end of the world, but the whole time I felt like there should be some sort of Split The Existing Field ala Fill Properties from Filename function.  I'm sure if I was a smarter man, I could use a RegEx to do it, but I'm not a smarter man.

Is there some existing function that would have done this better?  I searched through the Wiki and did a few forum searches, but then gave up after finding nothing and knowing how to solve it myself via the clunky 4 step process above.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Parse Existing Field Into Other Fields?
« Reply #1 on: October 26, 2012, 01:13:55 pm »

Another case that came up regularly was when the [Album] tag was set like this:

Some Album Title, Disc 1
Some Album Title, Disc 2
etc...

And I want them all to be:
[Album] = Some Album Title
[Disc #] = 1-infinity

Again, if the Filename is easy to parse, I'll just grab it from there.  But such is not always the case.  Sometimes the ID3 tags are better than the filenames (but still obnoxious).  It would be nice to be able to, somehow, split those using ", Disc " as the delimiter.  I could do it using the method described above, but it took a bunch of steps to clean up.

Not a big deal when there are only two discs, but with some of these Audiobooks ripped from CD, there are 15 discs and 4-hundred-million 2-minute-long tracks (okay, that's an exaggeration, but it feels that way, I had some that were close to 1000 tracks).

If this is not currently possible:

It would be handy if the existing Fill Properties From Filename tool could be extended to be able to use an existing Library Field as the "source" instead of the Filename only.  That would do exactly what I wanted in an easy-to-use manner.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1971
Re: Parse Existing Field Into Other Fields?
« Reply #2 on: October 26, 2012, 01:27:20 pm »

In similar situations I have first used rename from properties [Name]
and then used fill properties from filename [track#] - [Name]
OR
rename using [album] and then [album], disc [disc #]


But of course it woud be great to be able to parse properties from properties 
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Parse Existing Field Into Other Fields?
« Reply #3 on: October 26, 2012, 01:30:06 pm »

The pattern:

   Track # - Song Title

is parsed with the Regex below, to grab both the Track # if it exists, and the Song Title.  The final param as 1 outputs the Track #, and as 2 gives you the Song Title:

   Regex([Name], /#^(?:(\d+) - )?(.+)$#/, 1)

You can do likewise with:

   Some Album Title, Disc 1

using:

   if(Regex([Album], /#^(.+), Disc (\d+)$#/), [R1], [Album])

using [R1] when you want the Album portion, and [R2] when you want the Disc number.
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Parse Existing Field Into Other Fields?
« Reply #4 on: October 26, 2012, 01:35:11 pm »

... since it wasn't possible to use " - " as the delimiter, since spaces are ignored in Expressions

Just escape them with forward slash:

    listitem([Album], 1, / -/ )
Logged
The opinions I express represent my own folly.

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Parse Existing Field Into Other Fields?
« Reply #5 on: October 26, 2012, 01:38:23 pm »

Thanks.

I almost posted a "Help Me, MrC" thread last night but I didn't know if you'd be online at the time.

My problem with RegEx isn't that I can't figure out how to do it... It is that to get that RegEx you just whipped up in a minute or two, would have taken me 25 minutes with four browser tabs open to RegEx man pages and guides.  And I'd probably typo it once or twice and spend another 25 minutes trying to figure out why it didn't work, when in the end it was because I transposed a ^ and a # sign.

And, at that point, my way is faster over all.

Of course, if I studied it and used it more, I'd become much more proficient.  That, or I need you on speed dial.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Parse Existing Field Into Other Fields?
« Reply #6 on: October 26, 2012, 01:39:34 pm »

Just escape them with forward slash:

    listitem([Album], 1, / -/ )

I did think of this after.  ::)

Of course, I don't know if any of those existing [Name] fields had trailing spaces either, so =Clean() isn't a bad idea in any case.  That isn't such a big deal because I can select huge swaths of files and do that at once (which is what I was doing last night).

I was just hoping there was an undocumented =Split([Field to Parse],[Pattern to Fill]) like expression that worked like the Fill Properties from Filename tool.  Apparently not, or you'd probably know about it.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Parse Existing Field Into Other Fields?
« Reply #7 on: October 26, 2012, 01:40:41 pm »

There is an investment in learning the language, to be sure.  But it does pay off.

Feel free to just say, "Help Me, MrC!", with a PM to ping if its urgent, or I don't notice the post.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up