下载百度排行榜音乐的程序(Perl)
2012-09-23 11:21
309 查看
下载百度排行榜音乐的程序(Perl)
#!/usr/bin/perl use FindBin '$Bin'; use URI::Escape; use lib $Bin; use lib "$Bin/../conf/"; use Conf; my %g_conf = ( task => { top100 => { list => "/data/share/code/trunk/perl/get_baidu_mp3/conf/top100_xml.txt", store_path => "/data/share/code/trunk/perl/get_baidu_mp3/music/top100/", }, top500 => { list => "/data/share/code/trunk/perl/get_baidu_mp3/conf/top500_xml.txt", store_path => "/data/share/code/trunk/perl/get_baidu_mp3/music/top500/", }, }, download_thread_cnt => 20, ); sub init { foreach my $key (keys %{$g_conf{'task'}}) { my $store_path = $g_conf{'task'}{$key}{'store_path'}; `mkdir -p $store_path`; } } sub main { init(); foreach my $key (keys %{$g_conf{'task'}}) { #step 1: get list my $html = $g_conf{'task'}{$key}{'list'}; open FV,$html; my @line_arr = <FV>; my $contents = join ("\n", @line_arr); my @idx; my $title; while ($contents =~ /\<data\>\<id\>(\d+)\<\/id\>\<name\>(\S+)\<\/name\>/g ) { push @idx, $1; push @title, $2; } #step 2: download my $download_thread_cnt = $g_conf{'download_thread_cnt'}; my @download_cmd = (); foreach my $i (1 .. scalar(@idx)) { my $index = $idx[$i]; my $title = $title[$i]; my $down_url; my $down_name; my ($song,$art); if ($title =~ /(\S+)\$\$(\S+)\$\$\$\$/) { $song = $1; $art = $2; } $down_name = $g_conf{'task'}{$key}{'store_path'} . $art . "_" . $song . ".mp3"; my $url = "http://box.zhangmen.baidu.com/x?op=12&count=1&mtype=1&title=$song\\\$\\\$$art\\\$\\\$\\\$\\\$&url="; my $xml = `curl "$url"`; if ($xml =~ /\<p2p\><hash>(\w+)<\/hash\>\<url\>\<\!\[CDATA\[(\S+)\]\]\>/) { $down_url = $2; if (length($down_url) < 10) { next; } #print "$download_cmd\n"; push @download_cmd, "wget -nv \"$down_url\" -O \"$down_name\""; } if ($i % $download_thread_cnt == 0 or $i == scalar(@idx)) { my $real_proc_cnt = scalar(@download_cmd); foreach my $do_key (@download_cmd) { my $pid = fork(); if ($pid == 0) { system($do_key); #print $do_key, "\n"; exit 0; } } while ($real_proc_cnt >0) { wait(); $real_proc_cnt --; } @download_cmd = (); } } } } main();
相关文章推荐
- 写个perl程序自动下载《南方周末》(2005年12月最后一期,38版,值得一看)
- WinRAR 简体中文版下载地址(有3721, CNNIC, 百度, 新浪免疫程序)
- ASP实现小偷程序的原理和示例(新闻小偷,音乐小偷,下载小偷)
- 一个利用python从中科大音乐网站下载mp3的程序
- 简易下载baidu音乐排行榜音乐
- 微信小程序使用audio组件播放音乐功能示例【附源码下载】
- 下载百度歌曲排行榜前500的脚本
- 火端搜索2.1源码,百度+好搜版免费下载小偷程序
- Perl实现下载百度Top100歌曲
- 为什么下载音乐要优先选择去google音乐下载,找不到之后再选择其它如:酷狗,百度?
- 为什么下载音乐要优先选择去google音乐下载,找不到之后再选择其它如:酷狗,百度?
- 程序中得到百度的搜索结果
- 调试笔记之 Flash Magic 下载程序 遇到的一些问题
- 【百度】写一个字符串逆序的程序,时间复杂度和空间复杂度最低,效率越高越好
- Window下怎么运行Perl程序?
- 原创:微信小程序源码解说:石头剪刀布(附源码下载)
- 用J-LINK的SWD模式下载程序
- 程序语言流行度最新排行榜 ,C和C++正在衰落
- ActiveState Perl Dev Kit Pro v8.2.0 七大平台版本下载(附注册授权文件)
- IOS6.0 应用内直接下载程序 不需跳转AppStore