#!/usr/bin/php xpath('//station') as $ch){ $ch_xml = simplexml_load_string($ch->asXml()); foreach($ch_xml->xpath("//prog[contains(title, \"" . $keyword[$j] . "\")]") as $prog_xml){ $ch_name = $ch_xml['id']; $title = $prog_xml->title; $artist = $prog_xml->pfm; $start1 = date('Y-m-d H:i', strtotime('-1min', strtotime($prog_xml['ft']))); $start2 = date('H:i m/d/Y', strtotime('-1min', strtotime($prog_xml['ft']))); $dur = $prog_xml['dur'] + 40; $filename = $title . " " . date('Y年m月d日H時i分', strtotime($prog_xml['ft'])); /* 番組が終わっていないか確認 */ if(strtotime($prog_xml['ft']) > mktime()){ /* 時間が変更されていないか確認 */ $check = "for i in `atq | awk '{print $1}'`\n"; $check .= "do\n"; $check .= " if at -c \$i | grep -c \"" . $filename . "\" >/dev/null 2>&1; then\n"; $check .= " if [ \"`atq | grep \$i | awk '{print $2\\\" \\\"$3}'`\" = \"" . $start1 . "\" ]; then\n"; $check .= " echo 1\n"; $check .= " else\n"; $check .= " at -d \$i\n"; $check .= " fi\n"; $check .= " fi\n"; $check .= "done"; $check_handle = popen($check, "r"); $change = fgets($check_handle); pclose($check_handle); /* 予約されていないor時間が変更されていれば予約 */ if(!$change){ $at = "at " . $start2; $at_arg = "sleep 55s\n"; $at_arg .= $radiko_dir . "radiko_rec.sh " . $ch_name . " \"" . $filename . "\" " . $dur . " \"" . $artist . "\" >/dev/null 2>&1"; echo "[" . date('Y/m/d H:i:s') . "] Reserved: " . $ch_name . " \"" . $filename . "\" " . $dur . " \"" . $artist . "\" "; $at_handle = popen($at, "w"); fwrite($at_handle, $at_arg); pclose($at_handle); } } } } } } } ?>