
パブリックドメイン・クラシック
数日出遅れていますが、日本での著作権保護期間が終了し、パブリックドメインとなったクラシック音源を約4200曲も公開しているスゴイサイトが話題になっています。MP3形式で全て無料でダウンロードできるということで、クラシックとか良く分からないオイラなんかも気軽に聞くことができて嬉しいです。
で、せっかく全部ダンロードしてよいと言っていくので、PHPを使ってありがたく全部ダウンロードさせてもらおうかなと(え
こんなバッチファイルを書いて、
・public_classic_mp3.php
<?php
$url = 'http://public-domain-archive.com/classic/search.php?keyword=%25';
$limit = 10;
$max = 4293;
$save_dir = '';
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1\r\n"
)
);
$context = stream_context_create($opts);
for ( $i=1; $i<=(($max/$limit)+1); $i++ ) {
$page = '&tmn='.$max.'&page=' . $i;
echo $url . $page . "\n"; // debug
$html = file_get_contents($url . $page, false, $context);
$regex
= '<a href="download.php\?album_no=[0-9]+">(.+?) - (.+?)<br>'
. '(.+?)<\/a><br>'
. '(.+?) - (.+?) \([0-9:]+\)<br>'
. '<a href="(.+?)" class="dl">.+?<\/a><br><br>';
if ( preg_match_all('/'.$regex.'/',$html,$matches) ) {
//var_dump($matches);
$artists = $matches[1];
$albums = $matches[2];
$songs = $matches[5];
$mp3s = $matches[6];
for ( $j=0; $j<count($matches[0]); $j++ ) {
if ( strpos($mp3s[$j],'file') === 0 ) {
$dl = 'http://public-domain-archive.com/classic/'.$mp3s[$j];
} else {
$dl = $mp3s[$j];
}
echo $dl."\n"; // debug
preg_match('/([0-9]+)\.mp3$/',$dl,$match);
$id = $match[1];
if ( !is_dir($save_dir.rep($artists[$j])) ) {
mkdir($save_dir.rep($artists[$j]),0777);
}
if ( !is_dir($save_dir.rep($artists[$j]).'/'.rep($albums[$j])) ) {
mkdir($save_dir.rep($artists[$j]).'/'.rep($albums[$j]),0777);
}
$save_file = $save_dir.rep($artists[$j]).'/'.rep($albums[$j]).'/'.$id.'_'.rep($songs[$j]).'.mp3';
echo '-> ' . $save_file . "\n"; // debug
if ( !file_exists($save_file) ) {
$mp3 = file_get_contents($dl, false, $context);
file_put_contents($save_file,$mp3);
}
}
}
}
function rep($str) {
$from = array(" ","\\","/",";",":","*","?",'"',"<",">","|");
$to = array("_","¥","/",";",":","*","?",'"',"<",">","|");
$str = str_replace($from,$to,$str);
return $str;
}
こんな風に起動すればいいかな、
$ php -f public_classic_mp3.php
1ファイルずつ落としていくので、急激な負荷はかからないと思いますが、たくさんの人がこれやっちゃうとサーバ大変だと思うので、これ以上の説明はあえてしませんw
まとめ
えーと、誰かに怒られたらエントリー削除する可能性もありますw
とりあえず、のだめ以外はクラシックとか全く関わりがなかったので色々聞いてみたいと思います。癒されるかも!
▼ベスト・クラシック100 プレミアム
▼のだめカンタービレ 最終楽章 前編&後編
▼チャイコフスキー:ピアノ協奏曲第1番
↑この人、今日の特ダネで小倉さんが紹介してた美人さんだ。