Chinaunix首页 | 论坛 | 博客
  • 博客访问: 119466
  • 博文数量: 32
  • 博客积分: 2067
  • 博客等级: 大尉
  • 技术积分: 383
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-08 07:47
文章分类

全部博文(32)

文章存档

2011年(1)

2010年(14)

2009年(17)

我的朋友

分类: LINUX

2010-03-08 20:20:52

前面写过一个shell脚本:
http://blog.chinaunix.net/u3/96229/showart.php?id=2120174

不过由于ST的网页更新,原shell脚本失效,新学了perl,正好处理这些文本内容
使用方法和原先一样(需要wget和mplayer):

试听: stmusic.pl l
下载: stmusic.pl d
注意修改开头的{my $dir = "/home/stesen/music";}这行

#!/usr/bin/perl -w
use strict;
use LWP::Simple;

my $dir = "/home/stesen/music";

my $url = $ARGV[0];
my $act = $ARGV[1];
unless ($url =~ m#^) {
  print "Wrong URL!\n";
}
unless ($act =~ /^(d|l)$/) {
  print "Download OR Listen?\n";
}
my $page = get ($url);
my $name_begin = "border=\"0\" alt=\"";
my $name_end = "\"> Listen Now";
my $link_begin = "javascript:playmedia1\(";
my $link_end = "\);ListenLog";
$page =~ m/$link_begin(.*)$link_end/is;
my $unclean_link = $1;
  $unclean_link =~ s/ //g;
  $unclean_link =~ s/\(//g;
  $unclean_link =~ s/\)//g;
  $unclean_link =~ s/\'//g;
my @misc = split /\,/, $unclean_link;
my $link = $misc[6].$misc[2].".mp3";
print $link;

if ($act eq 'd') {
  $page =~ m/$name_begin(.*)$name_end/is;
  my $name = $1;
    $name =~ s/ //g;
    $name =~ s/\(//g;
    $name =~ s/\)//g;
    $name =~ s/\[//g;
    $name =~ s/\《//g;
    $name =~ s/\&//g;
    $name =~ s/\@//g;
    $name =~ s/\”//g;
    $name =~ s/\"//g;
    $name =~ s/\“//g;
    $name =~ s/\`//g;
    $name =~ s/\'//g;
    $name =~ s/\\//g;
    $name =~ s/\///g;
    $name =~ s/\#//g;
    $name =~ s/\!//g;
    $name =~ s/\*//g;
    $name =~ s/\、//g;
    $name =~ s/\[//g;
    $name =~ s/\]//g;
    $name =~ s/\{//g;
    $name =~ s/\}//g;
    $name =~ s/\;//g;
    $name =~ s/\://g;
    $name =~ s/\$//g;

  exec "wget -c $link -O ${dir}/${name}.mp3";
}
elsif ($act eq 'l') {
  exec "mplayer $link";
}
阅读(808) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~