下载百度排行榜音乐的程序(Perl)
发布时间:2020-12-15 21:04:49 所属栏目:大数据 来源:网络整理
导读:下载百度排行榜音乐的程序(Perl) #!/usr/bin/perluse 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_
下载百度排行榜音乐的程序(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_cmdn"; 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(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |