Username: Password:

Perl的程式:mkm3u
来源:linux宝库作者:linux宝库 发布时间:2007-09-30 00:00:00


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

  而编造的, 他能够将指定目录下面的任何mp3歌曲的路径表示成为

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

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

  #!/usr/bin/perl -w

  # print usage information if no argument offered by user.

  if ($#ARGV < 0)

  {

  print <
  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]");

  }

  }

  }

  }

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

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅