<?php
/**
用于列出声波网某个分类下的所有节目的下载地址
修改 url 可以下载其他分类的节目
将url 中/p/后面的数字去掉,因为那是页码
另外填入需要获取的页数,修改 $maxpage 变量
所有节目的地址获取完毕后,会在当前目录下生成名为‘sl.bat’的批处理文件
双击‘sl.bat’即可开始下载
需要说明的是:需要‘wget.exe’的支持
将‘wget.exe’放到跟‘sl.bat’同目录下
*/

$url = 'http://shengbo.org/index.php/Index/ucenter/uid/531/p/';
$maxpage = 10;
$sc = 0;
$str = 'echo off';
for($i = 1; $i <=$maxpage; $i++) {
    echo gbk("开始处理第 $i 页\r\n");
    $s = file_get_contents($url . $i);
    preg_match_all('#<a href="/index.php/Index/play/playid/(.*?)" title="(.*?)" class="title"#i', $s, $rs);
    $cnt = count($rs[1]);
    $sc += $cnt;
    for($j = 0; $j < $cnt; $j++) {
        $d = file_get_contents('http://www.shengbo.org/index.php/Index/play/playid/'. $rs[1][$j]);
        preg_match('#<div class="ui360 ui360-vis" style="background-image: none;"><a href="(.*)" title="暂停/播放"></a></div></div></div><div#is', $d, $r);
        $str .= ' & wget -c "' . $r[1] . '" -O "' . $rs[2][$j] . '.' . substr($r[1], -3) . '"';
    }
    echo gbk("第 $i 页处理完成。\r\n");
}
$str .= ' & pause';
file_put_contents('sl.bat', gbk($str));
echo gbk("所有页面都处理完成。\r\n总计获取到: $sc 手歌曲。\r\n请运行“sl.bat”开始下载吧。");

function gbk($s) {
    return mb_convert_encoding($s,"gbk", "UTF-8");
}

标签: 批处理, php

添加新评论