|
|
#1 |
|
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 |
|
|
|
|
|
#2 |
|
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)..
|
|
|
|
|
|
#3 |
|
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.
|
|
|
|
|
|
#4 |
|
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? |
|
|
|
|
|
#5 |
|
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){
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. |
|
|
|
|
|
#6 | |||||||||||||||||||
|
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;
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. |
|||||||||||||||||||
|
|
|
|
|
#7 |
|
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... |
|
|
|
|
|
#8 |
|
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 that's about the extent of my AppleScript knowledge... |
|
|
|
|
|
#9 |
|
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 |
|
|
|
|
|
#10 |
|
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." |
|
|
|
|
|
#11 |
|
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. |
|
|
|
|
|
#12 |
|
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 |
|
|
|
|
|
#13 |
|
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. |
|
|
|
|
|
#14 |
|
Triple-A Player
Join Date: May 2003
Posts: 233
|
Bump!!!!
__________________
Koala Surf Camp |
|
|
|
![]() |
|
|