private function getPrograms() { if ($this->id == 0) { return false; } // ちょっと先を検索する $options = " WHERE starttime > '" . date("Y-m-d H:i:s", time() + $this->settings->padding_time + 120) . "'"; if ($this->keyword != "") { if ($this->use_regexp) { $options .= " AND CONCAT(title,description) REGEXP '" . mysql_real_escape_string($this->keyword) . "'"; } else { $options .= " AND CONCAT(title,description) like '%" . mysql_real_escape_string($this->keyword) . "%'"; } } if ($this->type != "*") { $options .= " AND type = '" . $this->type . "'"; } if ($this->category_id != 0) { $options .= " AND category_id = '" . $this->category_id . "'"; } if ($this->channel_id != 0) { $options .= " AND channel_id = '" . $this->channel_id . "'"; } if ($this->weekofday != 7) { $options .= " AND WEEKDAY(starttime) = '" . $this->weekofday . "'"; } $options .= " ORDER BY starttime ASC"; $recs = array(); try { $recs = DBRecord::createRecords(PROGRAM_TBL, $options); } catch (Exception $e) { throw $e; } return $recs; }
$programs[$st]['list'][$num]['starttime'] = ""; $programs[$st]['list'][$num]['description'] = ""; $num++; } $st++; } $prec = null; // 局の幅 $ch_set_width = $settings->ch_set_width; // 全体の幅 $chs_width = $ch_set_width * count($channel_map); // GETパラメタ $get_param = $_SERVER['SCRIPT_NAME'] . "?type=" . $type . "&length=" . $program_length . ""; $smarty = new Smarty(); // カテゴリ一覧 $crec = DBRecord::createRecords(CATEGORY_TBL); $cats = array(); $num = 0; foreach ($crec as $val) { $cats[$num]['name_en'] = $val->name_en; $cats[$num]['name_jp'] = $val->name_jp; $num++; } $smarty->assign("cats", $cats); // タイプ選択 $types = array(); $i = 0; if ($settings->bs_tuners != 0) { $types[$i]['selected'] = $type == "BS" ? 'class="selected"' : ""; $types[$i]['link'] = $_SERVER['SCRIPT_NAME'] . "?type=BS&length=" . $program_length . "&time=" . date("YmdH", $top_time); $types[$i]['name'] = "BS";
public static function custom($starttime, $endtime, $channel_id, $title = "none", $description = "none", $category_id = 0, $program_id = 0, $autorec = 0, $mode = 0) { global $RECORD_MODE; $settings = Settings::factory(); // 時間を計算 $start_time = strtotime($starttime); $end_time = strtotime($endtime) + $settings->extra_time; if ($start_time < time() + PADDING_TIME + 10) { // 現在時刻より3分先より小さい=すでに開始されている番組 $start_time = time() + PADDING_TIME + 10; // 録画開始時間を3分10秒先に設定する } $at_start = $start_time - PADDING_TIME; $sleep_time = PADDING_TIME - $settings->former_time; $rec_start = $start_time - $settings->former_time; // durationを計算しておく $duration = $end_time - $rec_start; if ($duration < $settings->former_time + 60) { // 60秒以下の番組は弾く throw new Exception("終わりつつある/終わっている番組です"); } $rrec = null; try { // 同一番組予約チェック if ($program_id) { $num = DBRecord::countRecords(RESERVE_TBL, "WHERE program_id = '" . $program_id . "'"); if ($num) { throw new Exception("同一の番組が録画予約されています"); } } $crec = new DBRecord(CHANNEL_TBL, "id", $channel_id); // 既存予約数 = TUNER番号 $tuners = $crec->type == "GR" ? $settings->gr_tuners : $settings->bs_tuners; $battings = DBRecord::countRecords(RESERVE_TBL, "WHERE complete = '0' " . "AND type = '" . $crec->type . "' " . "AND starttime < '" . date('Y-m-d H:i:s', $end_time) . "' " . "AND endtime > '" . date('Y-m-d H:i:s', $rec_start) . "'"); if ($battings >= $tuners) { // 重複を発見した if ($settings->force_cont_rec == 1) { // 解消可能な重複かどうかを調べる // 前後の予約数 $nexts = DBRecord::countRecords(RESERVE_TBL, "WHERE complete = '0' " . "AND type = '" . $crec->type . "' " . "AND starttime = '" . date('Y-m-d H:i:s', $end_time - $settings->former_time) . "'"); $prevs = DBRecord::countRecords(RESERVE_TBL, "WHERE complete = '0' " . "AND type = '" . $crec->type . "' " . "AND endtime = '" . $starttime . "'"); // 前後を引いてもチューナー数と同数以上なら重複の解消は無理 if ($battings - $nexts - $prevs >= $tuners) { throw new Exception("重複予約を解消できません"); } // 直後の番組はあるか? if ($nexts) { // この番組の終わりをちょっとだけ早める $end_time = $end_time - $settings->former_time - $settings->rec_switch_time; $duration = $end_time - $rec_start; // durationを計算しなおす } $battings -= $nexts; // 直前の録画予約を見付ける $trecs = DBRecord::createRecords(RESERVE_TBL, "WHERE complete = '0' " . "AND type = '" . $crec->type . "' " . "AND endtime = '" . $starttime . "'"); // 直前の番組をずらす for ($i = 0; $i < count($trecs); $i++) { if ($battings < $tuners) { break; } // 解消終了のハズ? // 予約修正に必要な情報を取り出す $prev_id = $trecs[$i]->id; $prev_program_id = $trecs[$i]->program_id; $prev_channel_id = $trecs[$i]->channel_id; $prev_title = $trecs[$i]->title; $prev_description = $trecs[$i]->description; $prev_category_id = $trecs[$i]->category_id; $prev_starttime = $trecs[$i]->starttime; $prev_endtime = $trecs[$i]->endtime; $prev_autorec = $trecs[$i]->autorec; $prev_mode = $trecs[$i]->mode; $prev_start_time = strtotime($prev_starttime); // 始まっていない予約? if ($prev_start_time > time() + PADDING_TIME + $settings->former_time) { // 開始時刻を元に戻す $prev_starttime = date('Y-m-d H:i:s', $prev_start_time + $settings->former_time); // 終わりをちょっとだけずらす $prev_endtime = date('Y-m-d H:i:s', strtotime($prev_endtime) - $settings->former_time - $settings->rec_switch_time); // tryのネスト try { // いったん予約取り消し self::cancel($prev_id); // 再予約 self::custom($prev_starttime, $prev_endtime, $prev_channel_id, $prev_title, $prev_description, $prev_category_id, $prev_program_id, $prev_autorec, $prev_mode); } catch (Exception $e) { throw new Exception("重複予約を解消できません"); } } else { throw new Exception("重複予約を解消できません"); } $battings--; } if ($battings < 0) { $battings = 0; } // これで重複解消したはず } else { throw new Exception("重複予約があります"); } } // チューナー番号 $tuner = $battings; // 改めてdurationをチェックしなおす if ($duration < $settings->former_time + 60) { // 60秒以下の番組は弾く throw new Exception("終わりつつある/終わっている番組です"); } // ここからファイル名生成 /* %TITLE% 番組タイトル %ST% 開始日時(ex.200907201830) %ET% 終了日時 %TYPE% GR/BS %CH% チャンネル番号 %DOW% 曜日(Sun-Mon) %DOWJ% 曜日(日-土) %YEAR% 開始年 %MONTH% 開始月 %DAY% 開始日 %HOUR% 開始時 %MIN% 開始分 %SEC% 開始秒 %DURATION% 録画時間(秒) */ $day_of_week = array("日", "月", "火", "水", "木", "金", "土"); $filename = $settings->filename_format; // あると面倒くさそうな文字を全部_に $fn_title = mb_ereg_replace("[ \\./\\*:<>\\?\\|()\\'\"&]", "_", trim($title)); // %TITLE% $filename = str_replace("%TITLE%", $fn_title, $filename); // %ST% 開始日時 $filename = str_replace("%ST%", date("YmdHis", $start_time), $filename); // %ET% 終了日時 $filename = str_replace("%ET%", date("YmdHis", $end_time), $filename); // %TYPE% GR/BS $filename = str_replace("%TYPE%", $crec->type, $filename); // %CH% チャンネル番号 $filename = str_replace("%CH%", "" . $crec->channel, $filename); // %DOW% 曜日(Sun-Mon) $filename = str_replace("%DOW%", date("D", $start_time), $filename); // %DOWJ% 曜日(日-土) $filename = str_replace("%DOWJ%", $day_of_week[(int) date("w", $start_time)], $filename); // %YEAR% 開始年 $filename = str_replace("%YEAR%", date("Y", $start_time), $filename); // %MONTH% 開始月 $filename = str_replace("%MONTH%", date("m", $start_time), $filename); // %DAY% 開始日 $filename = str_replace("%DAY%", date("d", $start_time), $filename); // %HOUR% 開始時 $filename = str_replace("%HOUR%", date("H", $start_time), $filename); // %MIN% 開始分 $filename = str_replace("%MIN%", date("i", $start_time), $filename); // %SEC% 開始秒 $filename = str_replace("%SEC%", date("s", $start_time), $filename); // %DURATION% 録画時間(秒) $filename = str_replace("%DURATION%", "" . $duration, $filename); // 文字コード変換 if (defined("FILESYSTEM_ENCODING")) { $filename = mb_convert_encoding($filename, FILESYSTEM_ENCODING, "UTF-8"); } $filename .= $RECORD_MODE["{$mode}"]['suffix']; $thumbname = $filename . ".jpg"; // サムネール $gen_thumbnail = INSTALL_PATH . "/gen-thumbnail.sh"; if (defined("GEN_THUMBNAIL")) { $gen_thumbnail = GEN_THUMBNAIL; } // ファイル名生成終了 // 予約レコードを埋める $rrec = new DBRecord(RESERVE_TBL); $rrec->channel_disc = $crec->channel_disc; $rrec->channel_id = $crec->id; $rrec->program_id = $program_id; $rrec->type = $crec->type; $rrec->channel = $crec->channel; $rrec->title = $title; $rrec->description = $description; $rrec->category_id = $category_id; $rrec->starttime = date('Y-m-d H:i:s', $rec_start); $rrec->endtime = date('Y-m-d H:i:s', $end_time); $rrec->path = $filename; $rrec->autorec = $autorec; $rrec->mode = $mode; $rrec->reserve_disc = md5($crec->channel_disc . date('Y-m-d H:i:s', $start_time) . date('Y-m-d H:i:s', $end_time)); // 予約実行 $cmdline = $settings->at . " " . date("H:i m/d/Y", $at_start); $descriptor = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $env = array("CHANNEL" => $crec->channel, "DURATION" => $duration, "OUTPUT" => INSTALL_PATH . $settings->spool . "/" . $filename, "TYPE" => $crec->type, "TUNER" => $tuner, "MODE" => $mode, "THUMB" => INSTALL_PATH . $settings->thumbs . "/" . $thumbname, "FORMER" => "" . $settings->former_time, "FFMPEG" => "" . $settings->ffmpeg, "SID" => $crec->sid); // ATで予約する $process = proc_open($cmdline, $descriptor, $pipes, INSTALL_PATH . $settings->spool, $env); if (is_resource($process)) { fwrite($pipes[0], $settings->sleep . " " . $sleep_time . "\n"); fwrite($pipes[0], DO_RECORD . "\n"); fwrite($pipes[0], COMPLETE_CMD . " " . $rrec->id . "\n"); if ($settings->use_thumbs == 1) { fwrite($pipes[0], $gen_thumbnail . "\n"); } fclose($pipes[0]); // 標準エラーを取る $rstring = stream_get_contents($pipes[2]); fclose($pipes[2]); proc_close($process); } else { $rrec->delete(); throw new Exception("AT実行エラー"); } // job番号を取り出す $rarr = array(); $tok = strtok($rstring, " \n"); while ($tok !== false) { array_push($rarr, $tok); $tok = strtok(" \n"); } $key = array_search("job", $rarr); if ($key !== false) { if (is_numeric($rarr[$key + 1])) { $rrec->job = $rarr[$key + 1]; return $rrec->job; // 成功 } } // エラー $rrec->delete(); throw new Exception("job番号の取得に失敗"); } catch (Exception $e) { if ($rrec != null) { if ($rrec->id) { // 予約を取り消す $rrec->delete(); } } throw $e; } }
$arr = array(); $arr['name'] = "BS"; $arr['value'] = "BS"; $arr['selected'] = $type == "BS" ? "selected" : ""; array_push($types, $arr); // CS if ($settings->cs_rec_flg != 0) { $arr = array(); $arr['name'] = "CS"; $arr['value'] = "CS"; $arr['selected'] = $type == "CS" ? "selected" : ""; array_push($types, $arr); } } $k_station_name = ""; $crecs = DBRecord::createRecords(CHANNEL_TBL); $stations = array(); $stations[0]['id'] = 0; $stations[0]['name'] = "すべて"; $stations[0]['selected'] = !$station ? "selected" : ""; foreach ($crecs as $c) { $arr = array(); $arr['id'] = $c->id; $arr['name'] = $c->name; $arr['selected'] = $station == $c->id ? "selected" : ""; if ($station == $c->id) { $k_station_name = $c->name; } array_push($stations, $arr); } $weekofdays["{$weekofday}"]["selected"] = "selected";
function storeProgram($type, $xmlfile) { global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP; // チャンネルマップファイルの準備 $map = array(); if ($type == "BS") { $map = $BS_CHANNEL_MAP; } else { if ($type == "GR") { $map = $GR_CHANNEL_MAP; } else { if ($type == "CS") { $map = $CS_CHANNEL_MAP; } } } // XML parse $xml = @simplexml_load_file($xmlfile); if ($xml === false) { return; // XMLが読み取れないなら何もしない } // channel抽出 foreach ($xml->channel as $ch) { $disc = $ch['id']; try { // チャンネルデータを探す $num = DBRecord::countRecords(CHANNEL_TBL, "WHERE channel_disc = '" . $disc . "'"); if ($num == 0) { // チャンネルデータがないなら新規作成 $rec = new DBRecord(CHANNEL_TBL); $rec->type = $type; $rec->channel = $map["{$disc}"]; $rec->channel_disc = $disc; $rec->name = $ch->{'display-name'}; } else { // 存在した場合も、とりあえずチャンネル名は更新する $rec = new DBRecord(CHANNEL_TBL, "channel_disc", $disc); $rec->name = $ch->{'display-name'}; } } catch (Exception $e) { // 無視 } } // channel 終了 // programme 取得 foreach ($xml->programme as $program) { $channel_disc = $program['channel']; $channel = $map["{$channel_disc}"]; $starttime = str_replace(" +0900", '', $program['start']); $endtime = str_replace(" +0900", '', $program['stop']); $title = $program->title; $desc = $program->desc; $cat_ja = ""; $cat_en = ""; foreach ($program->category as $cat) { if ($cat['lang'] == "ja_JP") { $cat_ja = $cat; } if ($cat['lang'] == "en") { $cat_en = $cat; } } $program_disc = md5($channel_disc . $starttime . $endtime); // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja ); try { // カテゴリを処理する $category_disc = md5($cat_ja . $cat_en); $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '" . $category_disc . "'"); $cat_rec = null; if ($num == 0) { // 新規カテゴリの追加 $cat_rec = new DBRecord(CATEGORY_TBL); $cat_rec->name_jp = $cat_ja; $cat_rec->name_en = $cat_en; $cat_rec->category_disc = $category_disc; } else { $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc", $category_disc); } // $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", $channel_disc); $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '" . $program_disc . "'"); if ($num == 0) { // 新規番組 // 重複チェック 同時間帯にある番組 $options = "WHERE channel_disc = '" . $channel_disc . "' " . "AND starttime < '" . $endtime . "' AND endtime > '" . $starttime . "'"; $battings = DBRecord::countRecords(PROGRAM_TBL, $options); if ($battings > 0) { // 重複発生=おそらく放映時間の変更 $records = DBRecord::createRecords(PROGRAM_TBL, $options); foreach ($records as $rec) { // 自動録画予約された番組は放映時間変更と同時にいったん削除する try { $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id); if ($reserve->autorec) { Reservation::cancel($reserve->id); } } catch (Exception $e) { //無視 } // 番組削除 $rec->delete(); } } // // $rec = new DBRecord(PROGRAM_TBL); $rec->channel_disc = $channel_disc; $rec->channel_id = $channel_rec->id; $rec->type = $type; $rec->channel = $channel_rec->channel; $rec->title = $title; $rec->description = $desc; $rec->category_id = $cat_rec->id; $rec->starttime = $starttime; $rec->endtime = $endtime; $rec->program_disc = $program_disc; } else { // 番組内容更新 $rec = new DBRecord(PROGRAM_TBL, "program_disc", $program_disc); $rec->title = $title; $rec->description = $desc; $rec->category_id = $cat_rec->id; } } catch (Exception $e) { exit($e->getMessage()); } } }
public function reservationForm() { require_once INSTALL_PATH . '/DBRecord.class.php'; if (!isset($_GET['program_id'])) { exit('Error: 番組IDが指定されていません'); } $program_id = $_GET['program_id']; try { $prec = new DBRecord(PROGRAM_TBL, "id", $program_id); sscanf($prec->starttime, "%4d-%2d-%2d %2d:%2d:%2d", $syear, $smonth, $sday, $shour, $smin, $ssec); sscanf($prec->endtime, "%4d-%2d-%2d %2d:%2d:%2d", $eyear, $emonth, $eday, $ehour, $emin, $esec); $crecs = DBRecord::createRecords(CATEGORY_TBL); $cats = array(); foreach ($crecs as $crec) { $cat = array(); $cat['id'] = $crec->id; $cat['name'] = $crec->name_jp; $cat['selected'] = $prec->category_id == $cat['id'] ? "selected" : ""; array_push($cats, $cat); } $smarty = new Smarty(); $smarty->template_dir = dirname(dirname(__FILE__)) . '/templates/'; $smarty->compile_dir = dirname(dirname(__FILE__)) . '/templates_c/'; $smarty->assign("syear", $syear); $smarty->assign("smonth", $smonth); $smarty->assign("sday", $sday); $smarty->assign("shour", $shour); $smarty->assign("smin", $smin); $smarty->assign("eyear", $eyear); $smarty->assign("emonth", $emonth); $smarty->assign("eday", $eday); $smarty->assign("ehour", $ehour); $smarty->assign("emin", $emin); $smarty->assign("type", $prec->type); $smarty->assign("channel", $prec->channel); $smarty->assign("channel_id", $prec->channel_id); $smarty->assign("record_mode", $RECORD_MODE); $smarty->assign("title", $prec->title); $smarty->assign("description", $prec->description); $smarty->assign("cats", $cats); $smarty->assign("program_id", $prec->id); $smarty->display("reservationform.html"); } catch (Exception $e) { exit("Error:" . $e->getMessage()); } }
#!/usr/bin/php <?php include_once 'config.php'; include_once INSTALL_PATH . '/DBRecord.class.php'; include_once INSTALL_PATH . '/reclib.php'; include_once INSTALL_PATH . '/Settings.class.php'; $settings = Settings::factory(); try { $recs = DBRecord::createRecords(RESERVE_TBL); // DB接続 $dbh = mysql_connect($settings->db_host, $settings->db_user, $settings->db_pass); if ($dbh === false) { exit("mysql connection fail"); } $sqlstr = "use " . $settings->db_name; mysql_query($sqlstr); $sqlstr = "set NAME utf8"; mysql_query($sqlstr); foreach ($recs as $rec) { $title = mysql_real_escape_string($rec->title) . "(" . date("Y/m/d", toTimestamp($rec->starttime)) . ")"; $sqlstr = "update mt_cds_object set metadata='dc:description=" . mysql_real_escape_string($rec->description) . "&epgrec:id=" . $rec->id . "' where dc_title='" . $rec->path . "'"; mysql_query($sqlstr); $sqlstr = "update mt_cds_object set dc_title='" . $title . "' where dc_title='" . $rec->path . "'"; mysql_query($sqlstr); } } catch (Exception $e) { exit($e->getMessage()); }
<?php include_once 'config.php'; include_once INSTALL_PATH . '/DBRecord.class.php'; include_once INSTALL_PATH . '/Smarty/Smarty.class.php'; try { $rvs = DBRecord::createRecords(RESERVE_TBL, "WHERE complete='0' ORDER BY starttime ASC"); $reservations = array(); foreach ($rvs as $r) { $cat = new DBRecord(CATEGORY_TBL, "id", $r->category_id); $arr = array(); $arr['id'] = $r->id; $arr['type'] = $r->type; $arr['channel'] = $r->channel; $arr['starttime'] = $r->starttime; $arr['endtime'] = $r->endtime; $arr['mode'] = $RECORD_MODE[$r->mode]['name']; $arr['title'] = $r->title; $arr['description'] = $r->description; $arr['cat'] = $cat->name_en; $arr['autorec'] = $r->autorec; array_push($reservations, $arr); } $smarty = new Smarty(); $smarty->assign("sitetitle", "録画予約一覧"); $smarty->assign("reservations", $reservations); $smarty->display("reservationTable.html"); } catch (exception $e) { exit($e->getMessage()); }