{"id":477,"date":"2000-01-01T03:00:00","date_gmt":"2000-01-01T03:00:00","guid":{"rendered":"http:\/\/adam.rosi-kessel.org\/weblog\/free_software\/code\/fetchemusic.html"},"modified":"-0001-11-30T00:00:00","modified_gmt":"1970-01-01T05:00:00","slug":"fetchemusic","status":"publish","type":"post","link":"https:\/\/adam.rosi-kessel.org\/weblog\/2000\/01\/01\/fetchemusic","title":{"rendered":"fetchemusic"},"content":{"rendered":"<p> Unfortunately, this script no longer works. EMusic has switched to an encrypted RMP format. I&#8217;m leaving this script here in case it is ever useful for another project. <\/p>\n<p> Update 10\/1\/03: Someone has written a very nice perl script that works with the new encrypted EMP file format, called <a href=\"http:\/\/www.wannabehacker.com\/src\/decrypt-emp.pl\">decrypt-emp<\/a>. Get it now! <\/p>\n<pre> <font color=\"#444444\">#!\/usr\/bin\/perl # fetchrmp.pl - a quick-n-dirty script for parsing EMusic RMP data and # fetching entire albums. Requires an EMusic.com subscription. :-) # AUTHOR: Doran Barton <fozz@iodynamics.com> # Modifications: Adam Kessel <adam@bostoncoop.net> # VERSION 0.9 # Copyright (c) 2002 Doran Barton. All rights reserved. # Copyright (c) 2003 Adam Kessel. All rights reserved. # This program is free software; you can distribute it and\/or modify it # under the same terms as Perl itself. <\/font><strong>my<\/strong> <font color=\"#2040a0\">$VERSION<\/font> = 0.91; <strong>use<\/strong> strict; <strong>use<\/strong> XML::EasyOBJ; <strong>use<\/strong> LWP::Simple; <strong>use<\/strong> Getopt::Long; <strong>use<\/strong> File::Path; <strong>use<\/strong> File::Copy; Getopt::Long::config<font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#008000\">\"no_ignore_case\"<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <strong>my<\/strong> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$opt_help<\/font>, <font color=\"#2040a0\">$opt_destdir<\/font>, <font color=\"#2040a0\">$opt_rmpfile<\/font>, <font color=\"#2040a0\">$opt_folders<\/font>, <font color=\"#2040a0\">$opt_play<\/font>, <font color=\"#2040a0\">$opt_art<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <strong>my<\/strong> <font color=\"#2040a0\">$error<\/font> = &GetOptions<font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#008000\">'help'<\/font> => \\<font color=\"#2040a0\">$opt_help<\/font>, <font color=\"#008000\">'destdir:s'<\/font> => \\<font color=\"#2040a0\">$opt_destdir<\/font>, <font color=\"#008000\">'rmpfile:s'<\/font> => \\<font color=\"#2040a0\">$opt_rmpfile<\/font>, <font color=\"#008000\">'folders'<\/font> => \\<font color=\"#2040a0\">$opt_folders<\/font>, <font color=\"#008000\">'art'<\/font> => \\<font color=\"#2040a0\">$opt_art<\/font>, <font color=\"#008000\">'play:s'<\/font> => \\<font color=\"#2040a0\">$opt_play<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <strong>if<\/strong><font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$opt_help<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <strong>exit<\/strong> _usage<font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <font color=\"4444FF\"><strong>}<\/strong><\/font> <strong>if<\/strong><font color=\"4444FF\"><strong>(<\/strong><\/font>!<font color=\"#2040a0\">$opt_rmpfile<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <font color=\"a52a2a\"><strong>print<\/strong><\/font> STDERR <font color=\"#008000\">\"ERROR: An RMP data file is required (with the --rmpfile parameter)<font color=\"#77dd77\">\\n<\/font><font color=\"#77dd77\">\\n<\/font>\"<\/font>; <strong>exit<\/strong> _usage<font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <font color=\"4444FF\"><strong>}<\/strong><\/font> <strong>if<\/strong><font color=\"4444FF\"><strong>(<\/strong><\/font>!<font color=\"#2040a0\">$opt_destdir<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <font color=\"#2040a0\">$opt_destdir<\/font> = <font color=\"#008000\">\".\"<\/font>; <font color=\"4444FF\"><strong>}<\/strong><\/font> <strong>if<\/strong><font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"a52a2a\"><strong>defined<\/strong><\/font> <font color=\"#2040a0\">$opt_play<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <strong>unless<\/strong> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$opt_play<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <font color=\"#2040a0\">$opt_play<\/font> = <font color=\"#008000\">'mpg321 -o oss'<\/font>; <font color=\"4444FF\"><strong>}<\/strong><\/font> <font color=\"4444FF\"><strong>}<\/strong><\/font> <font color=\"#2040a0\">$opt_destdir<\/font> =~ s<<font color=\"b000d0\">\/$><>; # Trim any trailing \/<\/font>'s from destination dir <strong>my<\/strong> <font color=\"#2040a0\">$doc<\/font> = <strong>new<\/strong> XML::EasyOBJ<font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$opt_rmpfile<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <strong>my<\/strong> <font color=\"#2040a0\">$server<\/font> = <font color=\"#2040a0\">$doc<\/font>->SERVER<font color=\"4444FF\"><strong>(<\/strong><\/font>0<font color=\"4444FF\"><strong>)<\/strong><\/font>->NETNAME<font color=\"4444FF\"><strong>(<\/strong><\/font>0<font color=\"4444FF\"><strong>)<\/strong><\/font>->getString; <strong>my<\/strong> <font color=\"#2040a0\">@elements<\/font> = <font color=\"#2040a0\">$doc<\/font>->TRACKLIST<font color=\"4444FF\"><strong>(<\/strong><\/font>0<font color=\"4444FF\"><strong>)<\/strong><\/font>->TRACK; <strong>my<\/strong> <font color=\"#2040a0\">$track_num<\/font> = 1; <strong>my<\/strong> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$track<\/font>, <font color=\"#2040a0\">$url<\/font>, <font color=\"#2040a0\">$track_number<\/font>, <font color=\"#2040a0\">$genre<\/font>, <font color=\"#2040a0\">$artist<\/font>, <font color=\"#2040a0\">$album<\/font>, <font color=\"#2040a0\">$current_track<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <strong>my<\/strong> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$album_art<\/font>, <font color=\"#2040a0\">$lowergenre<\/font>, <font color=\"#2040a0\">$lowerartist<\/font>, <font color=\"#2040a0\">$loweralbum<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <strong>foreach<\/strong> <font color=\"#2040a0\">$track<\/font> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">@elements<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <font color=\"#2040a0\">$url<\/font> = <font color=\"a52a2a\"><strong>sprintf<\/strong><\/font><font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#008000\">\"http:\/\/<font color=\"#2040a0\">%s<\/font>\/<font color=\"#2040a0\">%s<\/font>\/<font color=\"#2040a0\">%s<\/font>\"<\/font>, <font color=\"#2040a0\">$server<\/font>, <font color=\"#2040a0\">$track<\/font>->TRACKID->getString, <font color=\"#2040a0\">$track<\/font>->FILENAME->getString<font color=\"4444FF\"><strong>)<\/strong><\/font>; <font color=\"#2040a0\">$current_track<\/font> = <font color=\"#2040a0\">$track<\/font>->FILENAME->getString; <font color=\"#2040a0\">$current_track<\/font> =~<font color=\"b000d0\"> tr\/A-Z \/a-z_\/<\/font>; <font color=\"#2040a0\">$current_track<\/font> =~<font color=\"b000d0\"> s\/[^a-z0-9_\\-\\.]\/\/g<\/font>; <font color=\"a52a2a\"><strong>print<\/strong><\/font> STDERR <font color=\"#008000\">\"Getting \"<\/font>, <font color=\"#2040a0\">$current_track<\/font>, <font color=\"#008000\">\"... \"<\/font>; <strong>if<\/strong> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$opt_folders<\/font> <strong>or<\/strong> <font color=\"#2040a0\">$opt_art<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <font color=\"#2040a0\">$genre<\/font> = <font color=\"#2040a0\">$track<\/font>->GENRE->getString || <font color=\"#008000\">\"\"<\/font>; <font color=\"#2040a0\">$artist<\/font> = <font color=\"#2040a0\">$track<\/font>->ARTIST->getString || <font color=\"#008000\">\"\"<\/font>; <font color=\"#2040a0\">$album<\/font> = <font color=\"#2040a0\">$track<\/font>->ALBUM->getString || <font color=\"#008000\">\"\"<\/font>; <font color=\"#2040a0\">$album_art<\/font> = <font color=\"#2040a0\">$track<\/font>->ALBUMART->getString || <font color=\"#008000\">\"\"<\/font>; <font color=\"#2040a0\">$loweralbum<\/font> = <font color=\"#2040a0\">$album<\/font>; <font color=\"#2040a0\">$loweralbum<\/font> =~<font color=\"b000d0\"> tr\/A-Z \/a-z_\/<\/font>; <font color=\"#2040a0\">$loweralbum<\/font> =~<font color=\"b000d0\"> s\/[^a-z0-9_\\-]\/\/g<\/font>; <font color=\"#2040a0\">$album<\/font> =~<font color=\"b000d0\"> tr\/ \/_\/<\/font>; <font color=\"#2040a0\">$album<\/font> =~<font color=\"b000d0\"> s\/[^A-Za-z0-9_\\-]\/\/g<\/font>; <font color=\"#2040a0\">$lowergenre<\/font> = <font color=\"#2040a0\">$genre<\/font>; <font color=\"#2040a0\">$lowergenre<\/font> =~<font color=\"b000d0\"> tr\/A-Z \/a-z_\/<\/font>; <font color=\"#2040a0\">$lowergenre<\/font> =~<font color=\"b000d0\"> s\/:.*\/\/<\/font>; <font color=\"#2040a0\">$lowergenre<\/font> =~<font color=\"b000d0\"> s\/[^a-z0-9_\\-]\/\/g<\/font>; <font color=\"#2040a0\">$lowerartist<\/font> = <font color=\"#2040a0\">$artist<\/font>; <font color=\"#2040a0\">$lowerartist<\/font> =~<font color=\"b000d0\"> tr\/A-Z \/a-z_\/<\/font>; <font color=\"#2040a0\">$lowerartist<\/font> =~<font color=\"b000d0\"> s\/[^a-z0-9_\\-]\/\/g<\/font>; <font color=\"#2040a0\">$artist<\/font> =~<font color=\"b000d0\"> tr\/ \/_\/<\/font>; <font color=\"#2040a0\">$artist<\/font> =~<font color=\"b000d0\"> s\/[^A-Za-z0-9_\\-]\/\/g<\/font>; <font color=\"#2040a0\">$track_number<\/font> = <font color=\"#2040a0\">$track_num<\/font>++; <font color=\"#2040a0\">$track_number<\/font> =~<font color=\"b000d0\"> s\/^(\\d)$\/0$1\/<\/font>; <font color=\"4444FF\"><strong>}<\/strong><\/font> <strong>my<\/strong> <font color=\"#2040a0\">$rv<\/font> = getstore<font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$url<\/font>, <font color=\"#2040a0\">$current_track<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <strong>if<\/strong><font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$rv<\/font> == 200<font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <font color=\"a52a2a\"><strong>print<\/strong><\/font> STDERR <font color=\"#008000\">\"OK<font color=\"#77dd77\">\\n<\/font>\"<\/font>; <strong>if<\/strong> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$opt_folders<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> mkpath<font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#008000\">\"<font color=\"#2040a0\">$opt_destdir<\/font>\/<font color=\"#2040a0\">$lowergenre<\/font>\/<font color=\"#2040a0\">$lowerartist<\/font>\/<font color=\"#2040a0\">$loweralbum<\/font>\"<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; move<font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$current_track<\/font>,<font color=\"#008000\">\"<font color=\"#2040a0\">$opt_destdir<\/font>\/<font color=\"#2040a0\">$lowergenre<\/font>\/<font color=\"#2040a0\">$lowerartist<\/font>\/<font color=\"#2040a0\">$loweralbum<\/font>\/<font color=\"#2040a0\">$artist<\/font>---<font color=\"#2040a0\">$album<\/font>---<font color=\"#2040a0\">$track_number<\/font>---<font color=\"#2040a0\">$current_track<\/font>\"<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <font color=\"4444FF\"><strong>}<\/strong><\/font> <font color=\"4444FF\"><strong>}<\/strong><\/font> <strong>else<\/strong> <font color=\"4444FF\"><strong>{<\/strong><\/font> <font color=\"a52a2a\"><strong>print<\/strong><\/font> STDERR <font color=\"#008000\">\"FAILED<font color=\"#77dd77\">\\n<\/font>\"<\/font>; <font color=\"4444FF\"><strong>}<\/strong><\/font> <font color=\"4444FF\"><strong>}<\/strong><\/font> <strong>if<\/strong> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$opt_art<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <strong>if<\/strong> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$album_art<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <strong>my<\/strong> <font color=\"#2040a0\">$rv<\/font> = getstore<font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$album_art<\/font>,<font color=\"#008000\">\"<font color=\"#2040a0\">$loweralbum<\/font>.jpg\"<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <strong>if<\/strong><font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$rv<\/font> == 200<font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <font color=\"a52a2a\"><strong>print<\/strong><\/font> STDERR <font color=\"#008000\">\"Art download OK<font color=\"#77dd77\">\\n<\/font>\"<\/font>; <strong>if<\/strong> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$opt_folders<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> move<font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#008000\">\"<font color=\"#2040a0\">$loweralbum<\/font>.jpg\"<\/font>,<font color=\"#008000\">\"<font color=\"#2040a0\">$opt_destdir<\/font>\/<font color=\"#2040a0\">$lowergenre<\/font>\/<font color=\"#2040a0\">$lowerartist<\/font>\/<font color=\"#2040a0\">$loweralbum<\/font>\"<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font>; <font color=\"4444FF\"><strong>}<\/strong><\/font> <font color=\"4444FF\"><strong>}<\/strong><\/font> <strong>else<\/strong> <font color=\"4444FF\"><strong>{<\/strong><\/font> <font color=\"a52a2a\"><strong>print<\/strong><\/font> STDERR <font color=\"#008000\">\"Art download failed<font color=\"#77dd77\">\\n<\/font>\"<\/font>; <font color=\"4444FF\"><strong>}<\/strong><\/font> <font color=\"4444FF\"><strong>}<\/strong><\/font> <font color=\"4444FF\"><strong>}<\/strong><\/font> <strong>if<\/strong> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$opt_play<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <strong>if<\/strong> <font color=\"4444FF\"><strong>(<\/strong><\/font><font color=\"#2040a0\">$opt_folders<\/font><font color=\"4444FF\"><strong>)<\/strong><\/font> <font color=\"4444FF\"><strong>{<\/strong><\/font> <font color=\"a52a2a\"><strong>chdir<\/strong><\/font> <font color=\"#008000\">\"<font color=\"#2040a0\">$opt_destdir<\/font>\/<font color=\"#2040a0\">$lowergenre<\/font>\/<font color=\"#2040a0\">$lowerartist<\/font>\/<font color=\"#2040a0\">$loweralbum<\/font>\"<\/font>; <font color=\"4444FF\"><strong>}<\/strong><\/font> `<font color=\"#2040a0\">$opt_play<\/font> *mp3`; <font color=\"4444FF\"><strong>}<\/strong><\/font> <strong>sub<font color=\"ff0000\"> _usage<\/font> {<\/strong> <font color=\"a52a2a\"><strong>print<\/strong><\/font> STDERR <font color=\"#008000\">\"This is <font color=\"#2040a0\">$0<\/font> version <font color=\"#2040a0\">$VERSION<\/font><font color=\"#77dd77\">\\n<\/font>\"<\/font>, <font color=\"#008000\">\"Usage: <font color=\"#2040a0\">$0<\/font> --help <font color=\"#77dd77\">\\n<\/font>\"<\/font>, <font color=\"#008000\">\" or: <font color=\"#2040a0\">$0<\/font> [--destdir DIR] --rmpfile FILE [--folders] [--play [mpeg player]] [--art]<font color=\"#77dd77\">\\n<\/font><font color=\"#77dd77\">\\n<\/font>\"<\/font>, <font color=\"#008000\">\"--folders puts track in folder hierarchy based on genre, album, and artist under destdir (or current directory if not specified)<font color=\"#77dd77\">\\n<\/font>\"<\/font>, <font color=\"#008000\">\"--play plays music when done downloading with specified command line (or mpg321 -o oss if not specified)<font color=\"#77dd77\">\\n<\/font>\"<\/font>, <font color=\"#008000\">\"--art downloads the album art if available and places it with the music<font color=\"#77dd77\">\\n<\/font><font color=\"#77dd77\">\\n<\/font>\"<\/font>, <font color=\"#008000\">\"Copyright (c) 2002 Doran Barton. All rights reserved. Modifications copyright (c) 2003 Adam Kessel.<font color=\"#77dd77\">\\n<\/font>\"<\/font>, <font color=\"#008000\">\"This program is free software; you can distribute it and\/or modify it<font color=\"#77dd77\">\\n<\/font>\"<\/font>, <font color=\"#008000\">\"under the same terms as Perl itself.<font color=\"#77dd77\">\\n<\/font>\"<\/font>; <strong>return<\/strong> 1; <font color=\"4444FF\"><strong>}<\/strong><\/font> <\/pre>\n<hr \/>\n<p> syntax highlighted by <a href=\"http:\/\/www.palfrader.org\/code2html\">Code2HTML<\/a>, v. 0.9.1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unfortunately, this script no longer works. EMusic has switched to an encrypted RMP format. I&#8217;m leaving this script here in case it is ever useful for another project. Update 10\/1\/03: Someone has written a very nice perl script that works with the new encrypted EMP file format, called decrypt-emp. Get it now! #!\/usr\/bin\/perl # fetchrmp.pl [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/posts\/477"}],"collection":[{"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/comments?post=477"}],"version-history":[{"count":0,"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/posts\/477\/revisions"}],"wp:attachment":[{"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/media?parent=477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/categories?post=477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/tags?post=477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}