Perl的程序:mkm3u

王朝perl·作者佚名  2008-05-18
宽屏版  字体: |||超大  

这个程序是为在服务器端提供在线听mp3歌曲的人减轻制作.m3u文件负担

而编造的, 它可以将指定目录下面的所有mp3歌曲的路径表示成为

合法的URL并保存成all.m3u文件

----------------------------------------------------------------------------

#!/usr/bin/perl -w

# print usage information if no argument offered by user.

if ($#ARGV < 0)

{

print <<END_USAGE

Usage: mkm3u top-URL dir-of-your-public-html dir-you-want-to-search

For example,

$ mkm3u http://mp3.your.net/~yourID/ /home/yourID/public-html/ mp3-directory

And the result will be saved as all.m3u in your home directory.

END_USAGE

;

die("End of usage\n");

}

# if the directory offered by user is not an absolute one, make it be.

if( $ARGV[2] !~ /^\// )

{

$pwd = `pwd`;

chop($pwd);

$ARGV[2] = $pwd."/".$ARGV[2];

}

# get the home dir of the user

$home=$ENV{"HOME"};

print "The home dir of yours is: $home\n";

open(M3U, ">>${home}\/all.m3u");

&process_dir("$ARGV[2]");

print "The result is kept as $home/all.m3u\n";

close(M3U);

sub process_dir

{

my($pwd,@subs,$count,$i);

$pwd = $_[0];

print "The present directory is $pwd\n";

@subs=<$pwd/*>;

$count=@subs;

for($i=0;$i<$count;$i++)

{

if($subs[$i] !~ /\/\.?$/)

{

if( -f $subs[$i] && $subs[$i] =~ /\.mp3$/i)

{

$subs[$i] =~ s/$ARGV[1]/$ARGV[0]/e;

print M3U "$subs[$i]\n";

}

elsif( -d $subs[$i] )

{

&process_dir("$subs[$i]");

}

}

}

}

----------------------------------------------------------------------

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有