#!/usr/bin/env perl # MP3 FreeRADIO numberic symbolic link maker, v1.2 ## Start user config # # config file $config = "/usr/local/etc/rc.mp3radio"; # location of remote count file $nfscount = "/nfs/.count"; # ## End user config use File::Copy; sub Config { open C, $config || warn "\nCouldn't open $config: $!\nUsing defaults\n\n"; while () { chomp; next if /^\#/; next if /^$/; next if (!m/(.*)=\s*(.*)/); @line = split/\s*\=\s*(\S+)/; push @{$conf{$line[0]}}, $line[1]; } } $conf = &Config; $conf{home}[0] = "/usr/local/lib/mp3radio" unless defined $conf{home}[0]; $conf{mp3dir}[0] = "/mp3/.mp3" unless defined $conf{mp3dir}[0]; $conf{list_plan}[0] = "/home/list/.plan" unless defined $conf{list_plan}[0]; $conf{songhtml}[0] = "/home/httpd/html/songlist.html" unless defined $conf{songhtml}[0]; $conf{songlist}[0] = "/home/httpd/html/songlist" unless defined $conf{songlist}[0]; $conf{mp3_link}[0] = "/mp3" unless defined $conf{mp3_link}[0]; $home = $conf{home}[0]; $list_plan = $conf{list_plan}[0]; $songhtml = $conf{songhtml}[0]; $songlist = $conf{songlist}[0]; $mp3_link = $conf{mp3_link}[0]; $mp3dir = $conf{mp3dir}[0]; $red = "\033[31m\033[1m"; $cyan = "\033[36m\033[1m"; $reset = "\033[0m"; ($sec, $min, $hour, $mday, $mon, $year) = gmtime; $hour = sprintf "%02.0f", $hour; $min = sprintf "%02.0f", $min; $sec = sprintf "%02.0f", $sec; $mon = sprintf "%02.0f", $mon + 1; $mday = sprintf "%02.0f", $mday; $year = sprintf "%02.0f", $year + 1900; unlink "$list_plan", "$songhtml", "$songlist"; # Start # print "\33[H\33[J"; print $red, ">>>> Starting the numeric MP3 linking process. (This may take". " awhile)\n", $reset; # Deletes old numeric symlinks # opendir D, $mp3_link || die "\nCan't open $mp3_link: $!\n\n"; @allfiles = grep !/^\.\.?$/, readdir D; closedir D; foreach (@allfiles) { unlink "$mp3_link/$_"; } # Make numeric symlinks # chdir $mp3dir; $count = 1; open M, "ls $mp3dir|" || die "\nCan't open $mp3dir: $!\n\n"; @mp3dir = ; close M; foreach (@mp3dir) { chomp; next if $_ !~ /.*.mp3$/i; symlink ".mp3/$_", "$mp3_link/$count"; $count++; } open C, ">$home/.count"; print C $count - 1; close C; copy "$home/.count", "$nfscount"; print $red, "\n\n>>>> Numeric MP3 linking done.\n". " Linked ", $reset; print $cyan, $count - 1; print $red, " MP3 files.\n\n". ">>>> Starting to build the MP3 songlists.\n", $reset; # Make songlist text file # open F, ">$list_plan"; print F "\nAs of $hour:$min:$sec $mon/$mday/$year GMT\n\n". "Song # Artist Song title\n"; print F "-" x 80, "\n\n"; open F, "/bin/ls -l $mp3_link|" || die "\nCan't open $mp3_link: $!\n\n"; while () { next if $_ !~ /.*.mp3$/i; ($i, $k) = (split)[8, 10]; $k =~ s/.mp3//g; $k =~ tr/[\/_]/ /; ($l, $m) = split '-', $k; push @array, "$i, $l, $m"; } open F, "|sort -n >> $list_plan" || die "\nCan not open sort: $!\n\n"; foreach (@array) { ($i, $l, $m) = split/,/; printf F "%-4s %-34s %-34s\n", $i, $l, $m; } # Make songlist html file # open F, ">>$songhtml"; print F "\n\n\n". "
\n";
		open F1, $list_plan || die "\nCan not open $list_plan: $!\n\n";
			while () {
				print F;
			}
		close F1;
	print F "
\n\n\n"; close F; copy "$list_plan", "$songlist"; print $red, "\n>>>> Building of MP3 songlists is complete.\n\n", $reset;