INTERACT FORUM

Please login or register.

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

Author Topic: A very special task ( for MrC? :-) )  (Read 22255 times)

Fred1

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 491
  • Change this by choosing profile
A very special task ( for MrC? :-) )
« on: April 15, 2013, 07:43:34 am »

I have a special problem, that could probably mastered by a little Perl Script.

I ripped a bunch of CDs lately, that i would like to tag with data from All Music Guide.
If you select the CD titles with the mouse and copy them to the clipboard and later drop them unformatted to a text editor, you get something like this:

.
.
.
2                              <- Track #                
Walk in My Shadows <- Name                    
                                <- Composer                
Joe Bonamassa         <- Performer (Album Artist)
3:27                         <- Duration                
                                <- Link 1                  
                                <- Link 2                  
                                <- Link 3                  
                                <- Empty Line              
3            <- Track #                
A New Day Yesterday<- Name                    
J. Anderson               <- Composer                
Joe Bonamassa         <- Performer (Album Artist)
4:45                         <- Duration                
                                <- Link 1                  
                                <- Link 2                  
                                <- Link 3                  
                                <- Empty Line              
4            <- Track #
.
.
.                

I would like to have it in that format, however ...

1 - Cradle Rock - Rory Gallagher - Joe Bonamassa
2 - Walk in My Shadows - - Joe Bonamassa
3 - A New Day Yesterday - J. Anderson - Joe Bonamassa
.
.
.

... to copy it via AppleScript (with MC Mac) into the MC database.
The number of empty lines may vary due to the links for the actual CD.
An AppleScript can call a Perl Script and use the result.

It would be nice to have such a transformation.
I assume MrC could be the right man for this :-).
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #1 on: April 15, 2013, 12:01:28 pm »

This isn't the best way to do this.  If one is going to write a script to pull the data, using the clipboard involves extra steps (select, copy, paste clip data into a file, parse the less-than-ideally structured file contents, etc...).

The better method is to connect to the URL and grab the key segments of the data, which is well-defined, and easy to do (esp. with the great Perl modules that parse HTML / XML data).

If I were to want this for myself, I'd pull the data from the URL, grab the important segments, and output that data as an MC MPL file that MC can consume directly.
Logged
The opinions I express represent my own folly.

Fred1

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 491
  • Change this by choosing profile
Re: A very special task ( for MrC? :-) )
« Reply #2 on: April 16, 2013, 01:27:19 am »

Hi MrC,

i'm sure, there are many better ways to solve my little "problem".
There is only one disadvantage with them: they demand a steep learning curve for me, because i'm not familiar with any of the methods you mentioned.

I thought, it would be a 2-liner Perl Script to parse this structure - but apparently i'm wrong.


A little example of an AppleScript calling a Perl Script, to demonstrate the principle:

Code: [Select]

set str to do shell script "perl -e '
    use Data::Dumper;
    print Dumper(\\%ENV);
'"

display dialog str buttons ["Ok"] default button 1


The clipboard -> AppleScript -> Perl Script -> AppleScript -> MC method has advantages, too, and it runs in memory only.
You can select one or two lines (titles) that are missing for you and paste them into MC with a keyboard shortcut very quickly.




Nevertheless, thank you for your attention to my problem.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #3 on: April 16, 2013, 01:46:36 am »

The script as you asked for it is easy.  I'll post one tomorrow, but will use Tab characters rather than dashes to separate the fields so that there is no need to escape any of these from fields that contain a dash.
Logged
The opinions I express represent my own folly.

Fred1

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 491
  • Change this by choosing profile
Re: A very special task ( for MrC? :-) )
« Reply #4 on: April 16, 2013, 01:51:56 am »

That's great, MrC!

Which separators are used is not the problem.
My problem is: i don't speak Perl - but i should learn.
It is a really elegant tool for parsing text.

Thank you.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #5 on: April 16, 2013, 03:20:16 pm »

Which browser are you using to copy the AMG data?  I'm finding that the formatting is different that you mention, and each browser copies the data differently.
Logged
The opinions I express represent my own folly.

Fred1

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 491
  • Change this by choosing profile
Re: A very special task ( for MrC? :-) )
« Reply #6 on: April 16, 2013, 03:41:31 pm »

I'm using Safari on a Mac.
But the comments (<- Track #, <- Name etc.) are not originally in the data.

Looks like this:

1   
Cradle Rock
Rory Gallagher
Joe Bonamassa
3:50   
2   
Walk in My Shadows
Joe Bonamassa
3:27   
3   
A New Day Yesterday
J. Anderson
Joe Bonamassa
4:45      

Pasting it here has removed the empty lines.

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #7 on: April 16, 2013, 03:51:52 pm »

Copy and Paste isn't going to work.  The fields are not consistent when copied, as missing fields are collapsed so it is impossible to determine which line belongs to which field.

The data will have to be parsed from the HTML.

Here's an example, where ^I are tabs and $ means end of line:
Code: [Select]
Sample ^I^ITitle/Composer ^IPerformer ^ITime$   
^I1 ^I$
Walk a Fine Line$
Paul Anka / Michael McDonald$
^I$
Paul Anka$
feat. George Benson, Michael McDonald, Frank Sinatra ^I5:32$
^I2 ^I$
Find My Way Back to Your Heart$
Paul Anka / Michael Thompson$
^I$
Paul Anka$
feat. Tita Hutchison ^I4:39$
^I3 ^I$
Do I Love You (Yes, In Every Way)$
Paul Anka / Alain Joseph Yves Le Govic / Michel Albert Louis Pelay / Maxime Piolot$
^I$
Paul Anka$
feat. Dolly Parton ^I4:53$
^I4 ^I$
This Is It$
Paul Anka / Michael Jackson$
^I$
Paul Anka$
feat. Michael Jackson ^I

Taken from: http://www.allmusic.com/album/duets-mw0002487037
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: A very special task ( for MrC? :-) )
« Reply #8 on: April 16, 2013, 11:18:14 pm »

Here's a script to try.  Unzip it, and locate it somewhere convenient.

Call it as follows:

   perl amg.pl URL

where URL is the AMG page URL you want parsed.  It will output tab-separated fields of:

Track #    Name    Composer    Artist     Featuring
Code: [Select]
$ perl  amg.pl http://www.allmusic.com/album/a-new-day-yesterday-mw0000104226
1       Cradle Rock     Rory Gallagher  Joe Bonamassa
2       Walk in My Shadows              Joe Bonamassa
3       A New Day Yesterday     J. Anderson     Joe Bonamassa
4       I Know Where I Belong   Joe Bonamassa   Joe Bonamassa
5       Miss You, Hate You      Joe Bonamassa   Joe Bonamassa
6       Nuthin' I Wouldn't Do (For a Woman Like You)    Al Kooper       Joe Bonamassa
7       Colour and Shape        Joe Bonamassa   Joe Bonamassa
8       Headaches to Heartbreaks        Joe Bonamassa   Joe Bonamassa
9       Trouble Waiting Joe Bonamassa; Stephanie Tyrell; Steve Tyrell   Joe Bonamassa
10      If Heartaches Were Nickels      W. Hayes        Joe Bonamassa
11      Current Situation       Joe Bonamassa   Joe Bonamassa
12      Don't Burn Down That Bridge             Joe Bonamassa
13      Miss You, Hate You      Joe Bonamassa   Joe Bonamassa

Code: [Select]
$ perl  amg.pl http://www.allmusic.com/album/duets-mw0002487037
1       Walk a Fine Line        Paul Anka; Michael McDonald     Paul Anka       George Benson, Michael McDonald, Frank Sinatra
2       Find My Way Back to Your Heart  Paul Anka; Michael Thompson     Paul Anka       Tita Hutchison
3       Do I Love You (Yes, In Every Way)       Paul Anka; Alain Joseph Yves Le Govic; Michel Albert Louis Pelay; Maxime Piolot Paul Anka    Dolly Parton
4       This Is It      Paul Anka; Michael Jackson      Paul Anka       Michael Jackson
5       I Really Miss You       Paul Anka       Paul Anka       Leon Russell
6       Think I'm in Love Again Paul Anka; Bob McDill   Paul Anka       Gloria Estefan
7       Pennies from Heaven     Johnny Burke; Arthur Johnston   Paul Anka       Michael BublC)
8       Crazy   Willie Nelson   Paul Anka       Willie Nelson
9       You Are My Destiny      Paul Anka       Paul Anka       Patti LaBelle
10      Les Filles de Paris     Paul Anka       Paul Anka       Chris Botti
11      It's Hard to Say Goodbye        Paul Anka; Mark Spiro; Jack White       Paul Anka       Celine Dion
12      She's a Lady    Paul Anka       Paul Anka       Tom Jones
13      Hold Me 'til the Morning Comes  Paul Anka; David Foster Paul Anka       Peter Cetera
14      My Way  Paul Anka; Claude FranC'ois; Jacques Revaux; Gilles Thibault    Paul Anka       Frank Sinatra

Its quick and dirty and might need some tune-ups.
Logged
The opinions I express represent my own folly.

Fred1

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 491
  • Change this by choosing profile
Re: A very special task ( for MrC? :-) )
« Reply #9 on: April 17, 2013, 01:21:58 am »

Wow, it works like a charm!
Thank you very, very much for your work.

The handling is very easy.
You can drag 'n' drop the URL to the open terminal window and press Return to let the script run.

I will have a hard time to fully understand what your script does exactly - but i will try.
I've purchased a Perl book yesterday and begin to study.

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #10 on: April 17, 2013, 01:28:52 am »

Great news.

If you make the script executable (and possibly place it somewhere in your path), you don't have to call perl directly:

   chmod a+x amg.pl

Execute it using any of the following (depending upon its location and your path):

   ./amg.pl URL
   path/to/amg.pl URL
   amg.pl URL
  
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: A very special task ( for MrC? :-) )
« Reply #11 on: July 24, 2013, 04:35:14 pm »

FYI.  I've rewritten this script to be more comprehensive.  It works like this:

1. You define a user field in MC called Allmusic URL, and enter the AMG URL for the album into the field for all the tracks.
2. You select all the tracks for the album (these must contain the AMG URL) and Ctrl-C to copy.  This places the track data on the clipboard.
3. You run the script, capturing the output into an MPL file.
4. You import the MPL file (File > Import Playlist) and the AMG data is imported.  Currently it imports Name, Composer, Artist, Date, Genre, Styles, Moods and Themes.  Styles, Moods and Themes need to be defined (and should be list fields) in MC to be imported.

The script works by pulling the track info from the clipboard, matching the track # from your list with the track # from AMG.  This is required, because to import the items and associate them with your existing MC entries, the Filename field must be grabbed and used.  Track # seems like the most reliable method to match tracks on the clipboard with pulled AMG tracks.  Obviously the Filename and Track # fields must be visible in the view.

Let me know if you want to test it out.  I'll provide more error and sanity checking later.

btw. I tried to post the data directly to the clipboard in an attempt to coerce MC to allow Paste Tags to work.  It didn't work - MC doesn't enable Paste Tags.  I'd have to load the clipboard with MC's special clipboard tokens, and I can't do that easily.  So, its the old MC MPL import method.
Logged
The opinions I express represent my own folly.

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772
Re: A very special task ( for MrC? :-) )
« Reply #12 on: July 25, 2013, 04:31:41 am »


Let me know if you want to test it out.  I'll provide more error and sanity checking later.

btw. I tried to post the data directly to the clipboard in an attempt to coerce MC to allow Paste Tags to work.  It didn't work - MC doesn't enable Paste Tags.  I'd have to load the clipboard with MC's special clipboard tokens, and I can't do that easily.  So, its the old MC MPL import method.
OMG I missed this. Leaving on vacation for 10 days but would LOVE to try this Mr. C. Great idea/work guys  8)

Sure do wish we could paste tags for multiple files/multiple fields, btw  I use chrome  ;)
Logged

darichman

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1363
Re: A very special task ( for MrC? :-) )
« Reply #13 on: July 25, 2013, 05:42:55 am »

This. Looks amazing.

Unfortunately I have no knowledge of Perl... how easy would it be to get this usable assuming zero knowledge of Perl? :)
Logged

Fred1

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 491
  • Change this by choosing profile
Re: A very special task ( for MrC? :-) )
« Reply #14 on: July 25, 2013, 07:02:31 am »

That's a great idea, MrC,
i'm looking forward to it!

btw. I tried to post the data directly to the clipboard in an attempt to coerce MC to allow Paste Tags to work.  It didn't work - MC doesn't enable Paste Tags.  I'd have to load the clipboard with MC's special clipboard tokens, and I can't do that easily.  So, its the old MC MPL import method.

This is an effect, i experienced in the Mac version already.
You can't paste from the clipboard to MC from an other application.
I tried Keyboard Maestro, Quicksilver and some others to do the job to no avail.
MC seems to be the only application, that doesn't accept this. Strange.
Perhaps a side effect from the self written libraries?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #15 on: July 25, 2013, 10:47:15 am »

At least one person wants to also capture the Credits page as well.  Anyone else think this is useful?

@darichman: No knowledge of Perl is required.

@Fred1: This works on a Mac too.

@Arindelle: Have a good vacation.
Logged
The opinions I express represent my own folly.

Fred1

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 491
  • Change this by choosing profile
Re: A very special task ( for MrC? :-) )
« Reply #16 on: July 25, 2013, 02:19:14 pm »

At least one person wants to also capture the Credits page as well.  Anyone else think this is useful?

Yes, this is highly appreciated!
Logged

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: A very special task ( for MrC? :-) )
« Reply #17 on: July 25, 2013, 04:01:42 pm »

At least one person wants to also capture the Credits page as well.  Anyone else think this is useful?

Yes, I would love to have that data. But how is this going to be handled in a sensible way in a non relational db like MC? That issue is what has been preventing me from adding this data (using another method that I am more familiar with),
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #18 on: July 25, 2013, 06:20:21 pm »

One question.  The AMG Rating values are 0 to 9, which allow representation of half-star increments.  I can cut those values in half, and round up or down.  Or would you prefer the actual AMG ratings?  Or both?  How should I handle this?

Yes, I would love to have that data. But how is this going to be handled in a sensible way in a non relational db like MC? That issue is what has been preventing me from adding this data (using another method that I am more familiar with),

I'm just making the data available in an MPL.  For relational fields, I believe MC will use one value (even though it is repeated verbatim / track in the MPL).  So if you define AMG Review to be an album-relational field, there's only 1 value for the album.  So I suppose if you're going to use the data, the fields should be per-album relational.

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: A very special task ( for MrC? :-) )
« Reply #19 on: July 25, 2013, 08:17:03 pm »

So here are the results (see attached).
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: A very special task ( for MrC? :-) )
« Reply #20 on: July 25, 2013, 11:45:35 pm »

I need to add a little code to handle multi-disc albums.  I'll do that shortly.

Just as soon as I get your feedback on how you want the AMG Rating to be handled (see questions above), I'll post the script and instructions.
Logged
The opinions I express represent my own folly.

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772
Re: A very special task ( for MrC? :-) )
« Reply #21 on: July 26, 2013, 02:40:15 am »

One question.  The AMG Rating values are 0 to 9, which allow representation of half-star increments.  I can cut those values in half, and round up or down.  Or would you prefer the actual AMG ratings?  Or both?  How should I handle this?

I'd rather have the ratings 0 to 9 if possible.

Would adding a soloist field be possible? - very nice for jazz -- lot of info I grab manually from the "credits" tab  (What/where is the "People" field being populated with?)

What happens when you pull from an album like this http://www.allmusic.com/album/high-fidelity-original-soundtrack-mw0000605666 do they use an "AlbumArtist" tag like Various Artists?
Logged

Fred1

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 491
  • Change this by choosing profile
Re: A very special task ( for MrC? :-) )
« Reply #22 on: July 26, 2013, 02:56:35 am »

One question.  The AMG Rating values are 0 to 9, which allow representation of half-star increments.  I can cut those values in half, and round up or down.  Or would you prefer the actual AMG ratings?  Or both?  How should I handle this?

0 to 9 would be great.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #23 on: July 26, 2013, 05:25:37 am »

OK, so the 0 to 9 rating seems good (and easy).

I'm grabbing all the Credits as they are.  There is nothing track-related.  The credits (People) look like this:

   David Angell [Violin]; Kai Blankenberg [Mastering]; BOY [Composer, Primary Artist]; ...

The Artist field is the value set from a scraped artist.  MC's Album Artist (auto) features will override these (if set).  Example tracks from the URL above:

Code: [Select]
$ perl amg.pl | egrep '"Track #"|"Artist"|"Composer"'
<Field Name="Track #">2</Field>
<Field Name="Composer">Ray Davies</Field>
<Field Name="Artist">The Kinks</Field>
<Field Name="Track #">13</Field>
<Field Name="Composer">Neil Michael Hagerty;Jennifer Herrema</Field>
<Field Name="Artist">Royal Trux</Field>
<Field Name="Track #">9</Field>
<Field Name="Composer">Elvis Costello;Clive Langer</Field>
<Field Name="Artist">Elvis Costello &amp; the Attractions</Field>
<Field Name="Track #">7</Field>
<Field Name="Composer">Sheila Nicholls</Field>
<Field Name="Artist">Sheila Nicholls</Field>

When an MPL is imported, all fields with values overwrite existing values.  So the program is going to have to know which fields you want written.  There are a several ways I can think of doing this:

   1. Populate only the fields that are in the clipboard (i.e. your view)
   2. Populate all fields except those specifically excluded via some special MC field
   3. Populate all fields except those specifically excluded via command line argument
   4. Ignore any fields pulled from the clipboard that have a value (i.e. fill empty cells)
   5. Overwrite all cells

Thoughts?
Logged
The opinions I express represent my own folly.

SkGe

  • Galactic Citizen
  • ****
  • Posts: 433
Re: A very special task ( for MrC? :-) )
« Reply #24 on: July 26, 2013, 07:47:36 am »

Dumb question?
How to run that script :)
Im a noob when come to this type of things.
And thanks MrC for the time spent on this :P
Logged

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: A very special task ( for MrC? :-) )
« Reply #25 on: July 26, 2013, 06:48:03 pm »

I'm just making the data available in an MPL.  For relational fields, I believe MC will use one value (even though it is repeated verbatim / track in the MPL).  So if you define AMG Review to be an album-relational field, there's only 1 value for the album.  So I suppose if you're going to use the data, the fields should be per-album relational.

How would I in MC in a structured way handle the relationship that guy X played Y on album Z by album artist Q? I could not figure that out. That is what I meant.

Before I settled for MC I looked at other music organisation software and some had a relational db that wold handle this very well, but MC was already then superior in its file tag reading and writing capabilities and that determined my choice. I do not regret that at all, but if you have a clever workaround I would be interested. (Perhaps I am spoiled by the Squeezebox MySql and then SqlLite db although I could never handle the queries in a professional manner of course.)
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #26 on: July 26, 2013, 06:55:33 pm »

I don't know of any way to do that.  Sorry.
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: A very special task ( for MrC? :-) )
« Reply #27 on: July 26, 2013, 08:54:54 pm »

Ok, here we go...

[edit: see next post for a new version and changes]

I'm sure there are errors below, and I'll correct them as you report them.

Attached is the script to scrape some data for the selected album tracks.  It works like this:

1. You supply an album's AMG URL either through an MC field of your choosing (default: AMG URL), or when you run the script.

2. You select all the tracks for an album and copy them to the clipboard (Ctrl-C).  This places the track data on the clipboard which will be used by the script.  The two key components are Track # and Filename, so those columns must be available in the file list.

3. You run the script, capturing the output into an MPL file.  If you have not defined an AMG URL field and filled it with a valid value, you can pass the URL on the command line.

4. You import the MPL file (File > Import Playlist) and the AMG data is imported.  Below is a list of the values available, and the default MC field names (which you can change to import to other fields).  Any fields not defined will be silently ignored (not imported).

The script works by pulling the track info from the clipboard, matching the Track # from your selected file list with the Track # from AMG.  Valid Track #'s are required, because to import the items and associate them with your existing MC entries, the track's Filename field must be used.  Track # seems like the most reliable method to match tracks on the clipboard with pulled AMG tracks.  Again, the Filename and Track # fields must be visible in the view.

Below is the list mapping the available AMG data to MC fields.  These are located at the top of the amg.pl script.  Search for %MCFieldMappings.  You may change the names in the MC Field Name column to match your data.  Some already match MC's default field names.  Other fields you must create, or MC will not import data for this field.  Review the comments in the script to learn more.

AMG data-->MC Field Name
url-->AMG URL
rating-->AMG Rating
pick-->AMG Track Pick
styles-->Styles
moods-->Moods
themes-->Themes
name-->Name
composer-->Composer
artist-->Artist
credits-->People
date-->Date
album-->Album
genre-->Genre
ratingmc-->Rating
tracknum-->Track #

Currently any item defined in the %MCFieldMappings table will be imported if the field exists in MC, and will overwrite any existing values.  If you do not want certain fields to be imported, you can comment out the line in the table with a # character.  This field will then be omitted from the MPL file.  Later I wlll add additional ways to disable certain fields (either by using the view's columns, or via command line).

So let's get started with

Installation and Setup:

1. Download and install ActivePerl for your version of Windows:

    http://www.activestate.com/activeperl/downloads

2. Download the attached amg_1.0.zip file and unzip it.  Place it somewhere convenient, like your Desktop.  Later you can move it once you become familiar with how to use it.

3. Open a Windows command shell (Start and type cmd in the Search box hit Enter) to install a required perl addon module, and enter:

    ppm install Win32-Clipboard

Keep this command shell open for later use.

4. Define any fields from above that don't already exist in MC if you want those fields imported.  If you want to change the field names, edit the amg.pl script and read the instructions at the top of and within the %MCFieldMappings table.  Take care to leave the quotes in place.  And don't rename 'Track #'.  You'll probably want to define a user field in MC called AMG URL so that the AMG URL will be retained for later use (make it Relational: Store one value for each album).

Usage:

1. In your browser, go to allmusic.com and search for and navigate to the album's page.  It will have the track listing, ratings, etc.  Copy this final URL.

2. In your still open Command Shell window, type:

    cd Desktop

and hit Enter.  Now partially enter the next command - don't hit Enter yet:

    perl amg.pl -u URL > import.mpl

replacing URL with the allmusic URL you copied in step 1.  You can paste the URL you copied by right-clicking in the Command Window anywhere, and use your left and right arrows to move around the command line.

3. Now go to MC, and select an album's tracks (you might want to use a scratch album for testing purposes).  Make sure the Filename and Track # columns are shown in the file list view.

4. Edit > Copy (or Ctrl-C on Windows, ⌘C on a Mac) to place the track data on the clipboard.

5. Now you can hit Enter in the Command Window to run the script.  It will output the results into the file import.mpl on your Desktop.  If there was an error, correct the problems as indicated by the error message.

6. In MC, File > Import Playlist and select the import.mpl file.

If all was successful, the album data should now be updated with the AMG data.

In Step 2, you passed the URL on the command line.  You can instead enter the URL into your AMG URL field in MC, and the script can use that instead.  This is useful if you want to re-scrape the data in the future (or to use as the target of an MC link).  The command would then just be:

    perl amg.pl > import.mpl

Current Limitations:
  - Works with only a single album at a time
  - Diacritics aren't functional yet
  - Doesn't yet handle multi-disc entries

Finally, I'm probably not going to extend the script to allow for scraping more than a single album at a time.  I think the reasons should be obvious.  Also note, as I was testing the script, AMG was changing their HTML, so the script might break at any time.  Watch for any error messages.
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: A very special task ( for MrC? :-) )
« Reply #28 on: July 28, 2013, 03:42:32 am »

[edit: see post 42 for the latest version and changes]

Here's a new version 1.1:

Changes:
  - Fixed: problem with pulling credits
  - New: supports Unicode
  - New: handles multi-disc albums
  - New: new include or exclude options to include or exclude a list of fields via command line
  - New: new sequence option to ignore Track # and Disc #, uses the track order in the view
  - New: Long or short options are supported (for example, -e or --exclude)
  - Change: credits are now mapped to AMG Credits (create your own AMG Field, type List, Album relational)
  - Change: output file goes to "import.mpl" on the Desktop by default, or use -o to specify an output file name
  - Improved: error detection, bad clipboard data, parsing problems, track-mismatches, etc.

Usage Examples

Note the new syntax - redirection into a mpl file is no longer required (or supported).  By default, import.mpl will be created on the Desktop, or use the -o option to specify an alternate file.

perl amg.pl
Runs using the AMG URL value from the copied tracks; outputs to import.mpl on the Destkop.

perl amg.pl -o my.mpl -u http://www.allmusic.com/album/revolver-mw0000189174
Runs using the specified URL, and outputs to my.mpl in the current directory.

perl amg.pl -e name,genre,moods
Runs like the first example, but excludes the Name, Genre, and Moods metadata.

perl amg.pl -i credits
Runs like the first example, but includes only credits (excludes all other metadata).  The -i option includes ONLY the specified items.

perl amg.pl -s
Runs like the first example, but ignores Track # and instead uses the sequence order of the file list.  This is useful for special issues, for example, AMG lists 12 tracks across 2 discs on the main page, but 13 tracks on the supplementary releases page.

It is a good idea to configure album-related fields such as Moods, AMG Rating, AMG Credits, etc. as Album-relational.  This way, any change to a single track in an album affects all tracks.  This is very useful when the number of track listed on AMG does not match your album (maybe due to special pressings).  By selecting and copying just one track to the clipboard, you can update the album-relational metadata for all tracks.
Logged
The opinions I express represent my own folly.

Fred1

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 491
  • Change this by choosing profile
Re: A very special task ( for MrC? :-) )
« Reply #29 on: July 28, 2013, 03:56:22 am »

Thanks for your work, MrC!

When i come home tonight, i will try your script.
Logged

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772
Re: A very special task ( for MrC? :-) )
« Reply #30 on: July 28, 2013, 04:05:37 am »

Looks great Mr C. Great! That you thought about commenting out certain fields, too.

Can't wait to give it a go when I get back from vacation.

Thanks much, very considerate!

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #31 on: July 28, 2013, 04:09:38 am »

Thanks.

You no longer have to comment out fields.  Just use the --exclude or --include options to pick the pieces you don't want, or just want.
Logged
The opinions I express represent my own folly.

Fred1

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 491
  • Change this by choosing profile
Re: A very special task ( for MrC? :-) )
« Reply #32 on: July 28, 2013, 04:54:05 am »

Question: Do i have to install additional libraries for Mac usage (for clipboard handling for example, as in Windows)?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #33 on: July 28, 2013, 06:20:08 am »

Mac::Pasteboard

You can use macports.
Logged
The opinions I express represent my own folly.

SkGe

  • Galactic Citizen
  • ****
  • Posts: 433
Re: A very special task ( for MrC? :-) )
« Reply #34 on: July 28, 2013, 05:13:36 pm »

Thx MrC for the time u put in this to help me and others, what a nice gentleman :)
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #35 on: July 28, 2013, 06:35:04 pm »

Anything for a guy named "sirgeo" - it just rolls off the tongue.  I feel like having some sangria and paella now.
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: A very special task ( for MrC? :-) )
« Reply #36 on: July 28, 2013, 09:03:53 pm »

I completed adding a new feature which I'll release with 1.2.  It is a new option, --fileregex which takes a regular expression as an argument, and matches it against the filename.  The regular expression should match the track number portion of the file name.  This is useful if you have no tags, but the files contain the track numbers, such as "1.mp3", "2.mp3", ... "10.mp3".  As long as your tracks are numbered, you can grab all track data by calling the script with an AMG url and a regular expression pattern:

   perl amg.pl --fileregex '^(\d+)' --url <amg url>

So now there are three ways to match your tracks against the AMG track list:

  1. Track # column values
  2. Sequence order with --sequence
  3. Regular expression captured track numbers from the file's name
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: A very special task ( for MrC? :-) )
« Reply #37 on: July 31, 2013, 05:30:37 pm »

AMG changed the way they are displaying their mood and theme data so my old way of manually copying the data is no longer working well. Would it be possible to change your method to collect (only) Style, Theme, Mood and AMG staff rating data?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #38 on: July 31, 2013, 05:51:27 pm »

It already does this.  Try:

   perl amg.pl -i moods,styles,themes,rating

You might need to change the field names to match yours, and either supply the URL or have the correct URL in the AMG URL field.
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: A very special task ( for MrC? :-) )
« Reply #39 on: August 01, 2013, 06:23:46 am »

Thanks!

I gave it a try. First, the script did not see the AMG URL field (it was in a visible column in the view I copied from). When I included the url in the command line I got a lot of errors and an empty mpl. I attach a file with the errors that the cmd window did not eat up.

Is there any chance of making the procedure easier to use, like having a file with the command line you use over and over to just double click while the track data are in the clipboard?

An additional issue I ran into was that the AMG page for my 2000 remaster of a 1970 album did not contain the mood data that the page for the 1970 album had, and the remaster of course had bonus tracks.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #40 on: August 01, 2013, 11:36:31 am »

I worried about your case.  I'm guessing its due to different locales and your use of commas and periods in data.

Can you send me the output of the view.

Select the files in question, and use File > Export Playlist.  Select:

   Format: Text File (CSV delimited)
   Included Fields: All Fields
   Output Range: Selection

Save it to the Desktop, zip it, and attach it in a reply here. 
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: A very special task ( for MrC? :-) )
« Reply #41 on: August 01, 2013, 11:48:31 am »

Do not put too much effort into this.

Here is the file.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #42 on: August 01, 2013, 01:03:26 pm »

[edit: see post 47 for the latest version and changes]

Attached is version 1.2.

Changes:
  - Fixed: problem handling missing Composer
  - Fixed: problem pulling Review section due to AMG html changes
  - New:  option --fileregex added, which allows pulling track numbers from filenames.  See thread above.

@vagskal - besides the fixes above, the main AMG page for the album you attached above describes the original release album, not yours which is a later, enhanced release including additional tracks.  So you'll have to use the -s option (sequence) to force using the main page despite track number mismatches.  Also, you have Disc # assigned to 1 for this single-disc album, and amg.pl currently assumes this would be for a multi-disc entry.  So the -s option also ignores the disc # data, and instead just uses the tracks sequence from amg.pl.  The command you would need is:

   perl  amg.pl  -s  -i moods,themes,styles,rating

Alternatively, you could also use the new --fileregex option to grab the track numbers and ignore the disc #:

   perl  -d amg.pl -f '^(\d+)'  -i moods,themes,styles,rating

Either way, this will only create MPL entries for the tracks listed in AMG.  The additional tracks won't be updated.  I suppose I could make an option to force updating data for all tracks when -s or -f is used, or just always assume this.  Your thoughts?

As to making the process easier, certainly you can make a Windows batch file to do this.  To just double-click an ActivePerl script and have it run requires updating some registry values, and I didn't want to get that aspect in the instructions above.  But, yes, this can be done.

The missing component is that there is no way with MC to ask it to import an MPL via command line!  You have to use the UI, so I've already put in a request to get a command line option to do this.  With that in place, you could then just double-click some script to have it pull pieces and do the import.  Still, since the parsing of data is fragile, there will be times when running it via command line will be required to diagnose when something fails.

See if the new script above, with the required options, works for you now.
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: A very special task ( for MrC? :-) )
« Reply #43 on: August 01, 2013, 01:47:47 pm »

Thanks!

I still could not get the script to recognize my AMG URL field.

Using the -u method and the first of your proposed command lines, data were collected with some error messages but they were not connected to the file copied to the clipboard so nothing was imported. I commented out the disc field in your script (and other fields but not the tracknum field).
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #44 on: August 01, 2013, 02:24:49 pm »

Can you provide me with one more thing?  Do the clipboard copy, and paste it into a Notepad document, and send that my way.  You can reply via email directly.
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: A very special task ( for MrC? :-) )
« Reply #45 on: August 01, 2013, 10:12:49 pm »

Would it be useful for anyone to have an option to populate non-track-specific values from AMG when there are more tracks in MC than the main AMG entry?

For example, some main entries have, say 10 tracks, but your edition of the album might have 14.  Currently, non-track-specific values (e.g. Genre, Moods, Review, etc.) won't be pushed out when you have more tracks than does AMG.
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: A very special task ( for MrC? :-) )
« Reply #46 on: August 02, 2013, 04:16:23 am »

Would it be useful for anyone to have an option to populate non-track-specific values from AMG when there are more tracks in MC than the main AMG entry?

Yes, I think I can handle such an option (which could be very destructive if by mistake tracks from different albums were selected).
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: A very special task ( for MrC? :-) )
« Reply #47 on: August 02, 2013, 02:43:12 pm »

[edit: see post 48 for the latest version and changes]

Attached is Version 1.3

Changes:
   - New: option --clipfile <file> allows using a file as a clipboard (for testing).
   - New: ability to send MPL to STDOUT (use - as the output file name with --outfile).
   - New: option --all allows populating non-track-specific values when selection has more tracks than AMG entry.  Useful for special album releases.
   - Change: add space after semicolons in list items.
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: A very special task ( for MrC? :-) )
« Reply #48 on: August 04, 2013, 11:44:48 am »

[edit: see post 52 for the latest version and changes]

Attached is Version 1.4.

Changes:
    - New: option --append will append to a possibly existing MPL file
    - New: option --help provides usage / options text
    - New: added descriptions for each option for help/usage text
    - Change: --all option shortcut letter is now -A (was -a).
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: A very special task ( for MrC? :-) )
« Reply #49 on: August 04, 2013, 12:47:47 pm »

Thank you, MrC! It works very well now.
Logged
Pages: [1] 2   Go Up