「ありがとう浜村淳です」は毎日更新されるので、これこそ毎日サーバで自動的にダウンロードしたい。ところが Windows Media なので、便利ツールは大抵 Windows で手動取得である。なんとかFreeBSDでダウンロードできないだろうか。ということで探してみると mimms という大変便利なツールの有ることがわかった。早速導入。
portinstall multimedia/mimms
試しにPR音声を取得してみたい。使い方は? …
$ mimms --help
Usage: mimms [options] [filename]
mimms is an mms (e.g. mms://) stream downloader
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-c, --clobber automatically overwrite an existing file
-r, --resume attempt to resume a partially downloaded stream
-b BANDWIDTH, --bandwidth=BANDWIDTH
the desired bandwidth for stream selection in
BANDWIDTH bytes/s
-t TIME, --time=TIME stop downloading after TIME minutes
-v, --verbose print verbose debug messages to stderr
-q, --quiet don't print progress messages to stdout
実は元々、mms: って何?状態だった。知っているURIは http: で始まって asx で終わるのだ。そこで asx ファイルの中身を見てみると、XMLっぽいテキストファイル。この中に mms: で始まる URI 発見。なるほどそれでツールの名称にも mms が含まれるのだと納得。試しにその URI を指定して実行したら、時間はかかるけれどもファイルは取得できた。
mimms mms://mbs.sswmt1.smartstream.ne.jp/mbs/arigatou/ari_intro.wma
ディレクトリを掘ったりはしないらしい。
というわけで、この mimms を呼び出すスクリプトを、podcast用のを改造して書いてみた。
<?php
// 起動パラメータがなければ異常終了
if($argc <= 1) {
exit(1);
}
// 適当なUser-Agentを設定
ini_set("user_agent","Mozilla/2.0 (compatible; get-mbs.php)");
// 指定されたパラメーターをXMLだと思って開く
$file = simplexml_load_file($argv[1]);
// falseが返ってきたら異常終了。
if(!$file) {
exit(2);
}
// 直接欲しいエレメントを取ってくる。SimpleXMLは便利。
$result = $file->xpath('/ASX/Entry/Ref');
foreach($result as $elm) {
if(is_null($elm["href"])) {
continue;
}
// URIっぽいものを指定して mimms で取得
$cmd = "/usr/local/bin/mimms -r -q -b 131072 ";
//print $cmd . $elm["href"] . "\n";
exec($cmd . $elm["href"]);
}
exit(0);
?>
これでどうかな、と実行してみたら、やっぱり上手く行かない。がっくし。URIを直接指定して mimms 起動だと上手く行くのだが。