Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 2.00 average. Display Modes
Old 11-22-2004, 09:23 AM   #1
david-bo
Triple-A Player
 
Join Date: May 2003
Posts: 233
Perlscript for Allmusic and iTunes

I just tried the perl script to update my iTunes library with Allmusic's 'tones' posted at http://www.macosxhints.com/article.p...40514091905395. Unfortunately it didn't work (I had to change which perl to use to /usr/bin/perl), I got the following messages and then the script just quitted:

v-strings are deprecated at /Library/Perl/5.8.1/Mac/AppleScript/Glue.pm line 234.
v-string in use/require non-portable at /Library/Perl/5.8.1/Mac/AppleScript/Glue.pm line 234.

Any suggestions?

Mac OS X 10.3.6

Btw, if someone can modify the script to use the 'grouping' field rather than the comment field for the tones it would be icing on the cake:-)

Thanks.

Last edited by hayne; 11-22-2004 at 12:44 PM. Reason: make link clickable
david-bo is offline   Reply With Quote
Old 11-28-2004, 04:02 AM   #2
david-bo
Triple-A Player
 
Join Date: May 2003
Posts: 233
No one knows anything about this? It looks rather basic for anyone that knows perl (which I don't)..
david-bo is offline   Reply With Quote
Old 11-28-2004, 12:37 PM   #3
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
Since the problem seems (from the error message) to be inside the Glue.pm module, it would require someone to understand the code of that module and then to fix it. Perhaps easy, perhaps not. Maybe best to contact the author of that module and ask if he/she knows of the problem.
hayne is offline   Reply With Quote
Old 11-28-2004, 01:18 PM   #4
david-bo
Triple-A Player
 
Join Date: May 2003
Posts: 233
That is odd because this is line 234 in Glue.pm:

require 5.6.0;


The section in Glue.pm is

=item *

The AppleScript interpreter seems somewhat lenient on the exact syntax
of the language. This makes it possible to write AppleScript
statements that work even though they look weird.

=back

=cut

use strict;
use warnings;

require 5.6.0;

######################################################################

use base qw(Exporter);

our ($VERSION, $AUTOLOAD, @EXPORT, @EXPORT_OK);

$VERSION = '0.03';


Do you really think it is a problem with Glue.pm?
david-bo is offline   Reply With Quote
Old 11-28-2004, 01:31 PM   #5
nkuvu
MVP
 
Join Date: Jun 2002
Location: Tucson, Arizona
Posts: 1,236
I played around with this a bit when you first posted. I commented out the require line, and got no error message. I also got no results.

I added a line in the original script:
Code:
my $mech = WWW::Mechanize->new();
my $controller = new Mac::AppleScript::Glue::Application('iTunes');
my $tracks = $controller->selection;
my %cache;

# Added by nkuvu:
die "No tracks found\n" if not @$tracks;

foreach my $track (@$tracks){
It dies every time. So it's not getting any tracks from iTunes, so of course it won't modify the tracks (won't even enter the foreach loop, actually).

The syntax all looks like it should work, but then again I know next to no AppleScript. I looked at the dictionary for iTunes in the AppleScript editor, and it said that selection uses a reference. But I don't know what that would be.

That's about as far as I got -- so if someone who knows AppleScript could look at this and provide the proper syntax for getting the selected tracks in iTunes then maybe we'd get somewhere.

Oh and if I'm reading this right, the above snippet of Perl says something like
Code:
tell application "iTunes"
	set tracks to selection
end tell

Last edited by nkuvu; 11-28-2004 at 01:33 PM.
nkuvu is offline   Reply With Quote
Old 11-28-2004, 01:40 PM   #6
nkuvu
MVP
 
Join Date: Jun 2002
Location: Tucson, Arizona
Posts: 1,236
I was having some syntax issues (I rarely if ever use references in Perl). But I'm better now.

I added code to the script (in place of the line I had above):
Code:
use Data::Dumper;
print "Controller selection: ", Dumper($controller->selection);
my @list = qw(foo bar baz); # To show how Dumper should work
print "List: ", Dumper(@list);
die;
What the Data::Dumper module does is show everything that's in a particular variable:
Quote:
Controller selection: $VAR1 = [];
List: $VAR1 = "foo";
$VAR2 = "bar";
$VAR3 = "baz";
Died at iTunesAMG.pl line 16.

Notice that $controller->selection is totally empty. So that fits what I said earlier -- glue.pm isn't returning the right information. (The problem is that my die statement wasn't working properly when I tested it in another script, that's the syntax problem I referred to)

So now I'm going to go drink more coffee so I don't have to edit my posts so darn many times...

Last edited by nkuvu; 11-28-2004 at 02:11 PM.
nkuvu is offline   Reply With Quote
Old 11-28-2004, 02:49 PM   #7
david-bo
Triple-A Player
 
Join Date: May 2003
Posts: 233
I think it is quite easy to set the value of any field in a track in iTunes. something like

set name to "some track name"

However, I am no AppleScript-guru...
david-bo is offline   Reply With Quote
Old 11-28-2004, 03:22 PM   #8
nkuvu
MVP
 
Join Date: Jun 2002
Location: Tucson, Arizona
Posts: 1,236
What I tried in AppleScript was
Code:
tell application "iTunes"
	set songName to selection
end tell

display dialog songName
and AppleScript gave me the error "Can't make {} into a string."

And that's about the extent of my AppleScript knowledge...
nkuvu is offline   Reply With Quote
Old 11-28-2004, 03:33 PM   #9
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
Maybe looking at Doug's AppleScripts for iTunes will give ideas on how to do it:
http://www.malcolmadams.com/itunes/s...s01.php?page=2
hayne is offline   Reply With Quote
Old 11-28-2004, 04:02 PM   #10
david-bo
Triple-A Player
 
Join Date: May 2003
Posts: 233
Just what I was doing. Here are some code snippets I found:

set these_tracks to the selection of browser window 1
if these_tracks is {} then error "No tracks are selected in the front window."
david-bo is offline   Reply With Quote
Old 06-10-2005, 05:40 PM   #11
david-bo
Triple-A Player
 
Join Date: May 2003
Posts: 233
Finally I have upgraded my perl-installation and tried this hint again but still without success. I therefore installed perlshell (psh) to step through the script, line by line, and quite soon found a problem:

eval error (Can't call method "selection" on an undefined value at (eval 27) line 1, <FIN> line 7.)!

The problematic line is just in the beginning of the script:

my $mech = WWW::Mechanize->new();
my $controller = new Mac::AppleScript::Glue::Application('iTunes');
my $tracks = $controller->selection;

Does anyone who speaks perl and applescript have any ideas what is wrong? To me as a non-perl speaker, it seems as the pointer to iTunes somehow fails, but I have no idea why.
david-bo is offline   Reply With Quote
Old 06-10-2005, 07:01 PM   #12
mark hunte
MVP
 
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
to get details of a track in iTunes you use something like this.

Code:
tell application "iTunes"
	
	set album_name to album of selection
	set Artist_name to artist of selection
	set song_name to name of selection
	
end tell
mark hunte is offline   Reply With Quote
Old 09-11-2005, 08:28 AM   #13
david-bo
Triple-A Player
 
Join Date: May 2003
Posts: 233
I have found the (first) culprit. I still don't speak perl but by accident I found out how to use the perl debugger (start the program with perl -d allmusic, then step one line at the time with 'n' untl it crashes) and the crash occur on line 51:

$mech->form_name('d');

This is line 50-52:

$mech->get($url);
$mech->form_name('d');
$mech->field('sql',$artist);


The crash log:

There is no form named "d" at bin/allmusic line 51
at /sw/lib/perl5/site_perl/5.8.6/WWW/Mechanize.pm line 2105
WWW::Mechanize::_warn(' There is no form named "d"') called at /sw/lib/perl5/site_perl/5.8.6/WWW/Mechanize.pm line 2083
WWW::Mechanize::warn('WWW::Mechanize=HASH(0x19e8448)', ' There is no form named "d"') called at /sw/lib/perl5/site_perl/5.8.6/WWW/Mechanize.pm line 1000
WWW::Mechanize::form_name('WWW::Mechanize=HASH(0x19e8448)', 'd') called at bin/allmusic line 51
main::getTones('myArtist', 'myAlbum', 'WWW::Mechanize=HASH(0x19e8448)') called at bin/allmusic line 19
Can't call method "value" on an undefined value at /sw/lib/perl5/site_perl/5.8.6/WWW/Mechanize.pm line 1030.
at /sw/lib/perl5/site_perl/5.8.6/WWW/Mechanize.pm line 1030
WWW::Mechanize::field('WWW::Mechanize=HASH(0x19e8448)', 'sql', 'myArtist') called at bin/allmusic line 52
main::getTones('myArtist', 'myAlbum', 'WWW::Mechanize=HASH(0x19e8448)') called at bin/allmusic line 19
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<1>

Last edited by david-bo; 09-11-2005 at 10:25 AM.
david-bo is offline   Reply With Quote
Old 10-29-2012, 01:27 PM   #14
david-bo
Triple-A Player
 
Join Date: May 2003
Posts: 233
Bump!!!!
__________________
Koala Surf Camp
david-bo is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 08:59 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.