use Net::FTP; # This script is provided as-is by John Toomey. # Use it however you like, but remember: it's not MY fault. # Caveat emptor, and all that jazz. # ----- STUFF YOU'LL HAVE TO CHANGE (PROBABLY) ----- # Where should I put the output files to be sent? $datadir = "C:\\Ticker"; # Where should I scan for MP3s? # This is pretty much a default for W2K: $songsdir = "C:\\Docume~1\\username\\MyDocu~1\\MyMP3s~1"; # Where should I FTP the files to? $host = "ftp.mydomain.com"; $port = 21; # Where should I go on the FTP server? $remdir = "/destdir/musicdata"; # What's my login data? $uname = "username"; $passwd = "passwd"; # ----- STUFF YOU WON'T HAVE TO CHANGE (PROBABLY) ----- # Should I do all the extra stuff that generates the album # and complete song lists on YARK? If so, set this guy to 1. $doextras = 0; # Where should I scan for album playlists? $discdir = "C:\\Docume~1\\username\\MyDocu~1\\MyMP3s~1\\Albums"; # Colors to alternate in the table. $color1 = "ebffe7"; $color2 = "e7ebff"; # What's the filename Music Ticker writes out in the $datadir? $tickerfile = "songdata.htm"; # What should I name the What's Playing output file? $playfile = "songdata.txt"; # What should I name the sorted by artist output file? $artistlist = "songlist.txt"; # What should I name the sorted by time output file? $timelist = "songtime.txt"; # What should I name the album output file? $disclist = "disclist.txt"; #---------------------------------------- open INF, "${datadir}\\${tickerfile}"; @data = ; close INF; $data = join "", @data; @data = split "\", $data; for (@data) { last if /The server is currently off-line./; next unless (/\(.*?)\<\/TD\>/ || /\(.*?)\<\/TD\>/); push @tunes, $1; } open OUTF, ">${datadir}\\${playfile}"; if (scalar(@tunes) != 0) { for (@tunes) { next unless /=2\>(.*?)\<\/FONT/; $thisl = $1; $thisl =~ s/^\s*//; $thisl =~ s/\s*$//; $thisl =~ s/\s+\-\s+/ - /g; push @outl, $thisl; } print OUTF "\n"; @when = ("Now", "Then", "Pre-Then", "Even Earlier", "Way Back When"); for (0 .. $#outl) { print OUTF "\n"; } print OUTF "
"; print OUTF "" if $_ == 0; print OUTF $when[$_]; print OUTF "" if $_ == 0; print OUTF "    "; print OUTF "" if $_ == 0; print OUTF $outl[$_]; print OUTF "" if $_ == 0; print OUTF "
"; } else { print OUTF "Nothing, compadre.
WinAmp is currently off-line.
"; } close OUTF; # This is written for Windows... you'll have to use some ls variant for UNIX. # Do we need to update the extras? if ( $doextras == 1 ) { system("dir /b $songsdir > $datadir\\dirnew.txt"); $ck = system("fc $datadir\\dirold.txt $datadir\\dirnew.txt"); } else { $ck = 0; } if ($ck != 0) { # Save the new list as the old list. system("move $datadir\\dirnew.txt $datadir\\dirold.txt"); $dirlist = `dir $songsdir`; @fnames = split(/\n/, $dirlist); foreach (@fnames) { # I name my mp3s like so: "Title (Artist).mp3" /^(\d+\/\d+\/\d+\s+\d+:\d+\S)\s+\S+\s+(.*\S)\s+\((.*)\)\.mp3/ or next; ($a, $b, $c) = ($1, $2, $3); # If you use the more traditional: "Artist - Title.mp3" # comment out the above 2 lines and uncomment the following 2: # /^(\d+\/\d+\/\d+\s+\d+:\d+\S)\s+\S+\s+(.*\S)\s+\-\s+(.*)\.mp3/ or next; # ($a, $b, $c) = ($1, $3, $2); # Note the inherent ambiguity in this style... how can you tell where # the artist ends and the title begins on this: # Foo - Bar - Baz.mp3 # Is the band Foo - Bar? Or is the title Bar - Baz? # Ah well, I'm going to assume the former. # Set up the artist sort list. # $counter++; # push(@banddata, "$c$b"); push(@banddata, "$c$b"); # Set up the time sort list. $a =~ /(\d+)\/(\d+)\/(\d+)\s+(\d+):(\d+)(.)/; $t = $3 . "/" . $1 . "/" . $2 . " " . $6 . (($4 == 12) ? "00" : $4) . ":" . $5; push(@timedata, "$t$c$b"); } @bandsort = sort @banddata; unshift(@bandsort, "ArtistTitle"); unshift(@bandsort, ""); push(@bandsort, "
"); open OUTN, ">${datadir}\\${artistlist}"; foreach (@bandsort) { $bgcolor = ((((++$i) % 2) == 1) ? $color1 : $color2); $_ =~ s/TR/TR BGCOLOR=\"$bgcolor\"/; print OUTN "$_\n"; } close OUTN; @timesort = reverse sort @timedata; unshift(@timesort, "DateArtistTitle"); unshift(@timesort, ""); push(@timesort, "
"); open OUTD, ">${datadir}\\${timelist}"; foreach (@timesort) { $bgcolor = ((((++$i) % 2) == 1) ? $color1 : $color2); # Only leave the date in place, not the time. # We only needed the time there for sort purposes. $_ =~ s/(.)(..):(..)//; $_ =~ s/TR/TR BGCOLOR=\"$bgcolor\"/; print OUTD "$_\n"; } close OUTD; $discraw = `dir $discdir`; @fnames = split(/\n/, $discraw); foreach (@fnames) { # I name my album playlists like so: "Album Title (Artist).m3u" # As of right now, I'm not using the time field. What a waste. /^(\d+\/\d+\/\d+\s+\d+:\d+\S)\s+\S+\s+(.*\S)\s+\((.*)\)\.m3u/ or next; ($a, $b, $c) = ($1, $2, $3); # Set up the album list. push(@discdata, "$c$b"); } @discsort = sort @discdata; unshift(@discsort, "ArtistAlbum Title"); unshift(@discsort, ""); push(@discsort, "
"); open OUTF, ">${datadir}\\${disclist}"; foreach (@discsort) { $bgcolor = ((((++$i) % 2) == 1) ? $color1 : $color2); $_ =~ s/TR/TR BGCOLOR=\"$bgcolor\"/; print OUTF "$_\n"; } close OUTF; } # Send the data. $myftp = Net::FTP->new($host, "Port" => $port); $myftp->login($uname, $passwd); $myftp->type("ascii"); $myftp->cwd($remdir); $myftp->put("${datadir}\\${playfile}"); if ( $ck != 0 ) { $myftp->put("${datadir}\\${artistlist}"); $myftp->put("${datadir}\\${timelist}"); $myftp->put("${datadir}\\${disclist}"); } $myftp->quit;