require_once APP_PATH . 'util/db.php';
require_once APP_PATH . 'util/Collect.class.php';
$collect_size = 100;
// 采集数量
$con = get_con();
$collect = new Collect();
// manual_collect表示手动再次采集该歌手的专辑,比如想要更新歌手的新专辑就可以设置该字段为1
// 如果想重新采集某歌手的专辑设置manual_collect为1并设置shield_collect为0
$result = mysql_query("select id from {DBPREFIX}artist where (manual_collect=1 or id not in (select distinct artist_id from {DBPREFIX}album)) and shield_collect=0 order by manual_collect desc limit {$collect_size}", $con);
$artistIdArr = array();
while (!!($row = mysql_fetch_array($result))) {
    $artistIdArr[] = $row['id'];
}
// print_r($artistIdArr);die;
if (!empty($artistIdArr)) {
    $albumArr = $collect->albumList($artistIdArr);
    // print_r($albumArr);die;
    if (!empty($albumArr)) {
        foreach ($artistIdArr as $artistId) {
            $data['artist_id'] = $artistId;
            //  有些歌手没有专辑只有歌曲,把没有专辑的歌手的shield_collect设为1,防止下次还采集它。如果想再采集该歌手设置manual_collect为1。
            if (!empty($albumArr[$artistId])) {
                // 该歌手有专辑
                foreach ($albumArr[$artistId] as $album) {
                    $data['album_id'] = $album['album_id'];
                    $result = mysql_query("select id from " . DBPREFIX . "album where album_id={$data['album_id']}", $con);
                    if (!($row = mysql_fetch_array($result))) {
                        // 数据库不存在该专辑 -> insert
                        $sql = "insert into\n                                            " . DBPREFIX . "album\n                                           (album_id,\n                                            artist_id)\n                                     values\n                                           ({$data['album_id']},\n                                            {$data['artist_id']})";
                    }
                    // echo $sql;die;