返回列表 回复 发帖

[转帖]提供在线听mp3

这个程序是为在服务器端提供在线听mp3歌曲的人减轻制作.m3u文件负担
而编造的, 它可以将指定目录下面的所有mp3歌曲的路径表示成为
合法的URL并保存成all.m3u文件
作者 callmedear.bbs@smth.org
  1. #!/usr/bin/perl -w
  2. # print usage information if no argument offered by user.
  3. if ($#ARGV < 0)
  4. {
  5.   print <<END_USAGE
  6. Usage: mkm3u top-URL dir-of-your-public-html dir-you-want-to-search
  7. For example,
  8. $ mkm3u http://mp3.your.net/~yourID/ /home/yourID/public-html/ mp3-directory
  9. And the result will be saved as all.m3u in your home directory.
  10. END_USAGE
  11. ;
  12. die("End of usage\n");
  13. }
  14. # if the directory offered by user is not an absolute one, make it be.
  15. if( $ARGV[2] !~ /^\// )
  16. {
  17.   $pwd = `pwd`;
  18.   chop($pwd);
  19.   $ARGV[2] = $pwd."/".$ARGV[2];
  20. }
  21. # get the home dir of the user
  22. $home=$ENV{"HOME"};
  23. print "The home dir of yours is: $home\n";
  24. open(M3U, ">>${home}\/all.m3u");
  25. &process_dir("$ARGV[2]");
  26. print "The result is kept as $home/all.m3u\n";
  27. close(M3U);
  28. sub process_dir
  29. {
  30.   my($pwd,@subs,$count,$i);
  31.   $pwd = $_[0];
  32.   print "The present directory is $pwd\n";
  33.   @subs=<$pwd/*>;
  34.   $count=@subs;
  35.   for($i=0;$i<$count;$i++)
  36.         {
  37.           if($subs[$i] !~ /\/\.?$/)
  38.           {
  39.              if( -f $subs[$i] && $subs[$i] =~ /\.mp3$/i)
  40.              {
  41.               $subs[$i] =~ s/$ARGV[1]/$ARGV[0]/e;
  42.               print M3U "$subs[$i]\n";
  43.              }
  44.              elsif( -d $subs[$i] )
  45.              {
  46.               &process_dir("$subs[$i]");
  47.              }
  48.            }
  49.          }
  50. }
复制代码
返回列表