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.