Esempio n. 1
0
         // $last_time より遅く終わる番組
         if (toTimestamp($prg['endtime']) > $last_time) {
             $height = ($last_time - toTimestamp($prg['starttime'])) * $settings->height_per_hour / 3600;
         }
         // プログラムを埋める
         $cat = new DBRecord(CATEGORY_TBL, "id", $prg['category_id']);
         $programs[$st]['list'][$num]['category_name'] = $cat->name_en;
         $programs[$st]['list'][$num]['height'] = $height;
         $programs[$st]['list'][$num]['title'] = $prg['title'];
         $programs[$st]['list'][$num]['starttime'] = date("H:i", $start) . "";
         $programs[$st]['list'][$num]['description'] = $prg['description'];
         $programs[$st]['list'][$num]['prg_start'] = str_replace("-", "/", $prg['starttime']);
         $programs[$st]['list'][$num]['duration'] = "" . (toTimestamp($prg['endtime']) - toTimestamp($prg['starttime']));
         $programs[$st]['list'][$num]['channel'] = ($prg['type'] == "GR" ? "地上D" : "BS") . ":" . $prg['channel'] . "ch";
         $programs[$st]['list'][$num]['id'] = "" . $prg['id'];
         $programs[$st]['list'][$num]['rec'] = DBRecord::countRecords(RESERVE_TBL, "WHERE complete = '0' AND program_id = '" . $prg['id'] . "'");
         $num++;
     }
 } catch (exception $e) {
     //		exit( $e->getMessage() );
     //		何もしない
 }
 // 空きを埋める
 if ($last_time - $prev_end > 0) {
     $height = ($last_time - $prev_end) * $settings->height_per_hour / 3600;
     $height = $height;
     $programs[$st]['list'][$num]['category_name'] = "none";
     $programs[$st]['list'][$num]['height'] = $height;
     $programs[$st]['list'][$num]['title'] = "";
     $programs[$st]['list'][$num]['starttime'] = "";
     $programs[$st]['list'][$num]['description'] = "";
Esempio n. 2
0
 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;
     }
 }
Esempio n. 3
0
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());
        }
    }
}
Esempio n. 4
0
try {
    $precs = DBRecord::createRecords(PROGRAM_TBL, $options);
    $programs = array();
    foreach ($precs as $p) {
        $ch = new DBRecord(CHANNEL_TBL, "id", $p->channel_id);
        $cat = new DBRecord(CATEGORY_TBL, "id", $p->category_id);
        $arr = array();
        $arr['type'] = $p->type;
        $arr['station_name'] = $ch->name;
        $arr['starttime'] = $p->starttime;
        $arr['endtime'] = $p->endtime;
        $arr['title'] = $p->title;
        $arr['description'] = $p->description;
        $arr['id'] = $p->id;
        $arr['cat'] = $cat->name_en;
        $arr['rec'] = DBRecord::countRecords(RESERVE_TBL, "WHERE program_id='" . $p->id . "'");
        array_push($programs, $arr);
    }
    $k_category_name = "";
    $crecs = DBRecord::createRecords(CATEGORY_TBL);
    $cats = array();
    $cats[0]['id'] = 0;
    $cats[0]['name'] = "すべて";
    $cats[0]['selected'] = $category_id == 0 ? "selected" : "";
    foreach ($crecs as $c) {
        $arr = array();
        $arr['id'] = $c->id;
        $arr['name'] = $c->name_jp;
        $arr['selected'] = $c->id == $category_id ? "selected" : "";
        if ($c->id == $category_id) {
            $k_category_name = $c->name_jp;
Esempio n. 5
0
        if ($num == 0 && check_file($temp_xml_cs2)) {
            $cmdline = "CHANNEL=" . CS2_EPG_CHANNEL . " DURATION=120 TYPE=CS TUNER=0 MODE=0 OUTPUT=" . $settings->temp_data . " " . DO_RECORD . " >/dev/null 2>&1";
            exec($cmdline);
            $cmdline = $settings->epgdump . " /CS " . $settings->temp_data . " " . $temp_xml_cs2;
            exec($cmdline);
            $cmdline = INSTALL_PATH . "/storeProgram.php CS " . $temp_xml_cs2 . " >/dev/null 2>&1 &";
            exec($cmdline);
            if (file_exists($settings->temp_data)) {
                @unlink($settings->temp_data);
            }
        }
    }
}
// 地上波を処理する
if ($settings->gr_tuners != 0) {
    foreach ($GR_CHANNEL_MAP as $key => $value) {
        // 録画重複チェック
        $num = DBRecord::countRecords(RESERVE_TBL, "WHERE complete = '0' AND type = 'GR' AND endtime > now() AND starttime < addtime( now(), '00:01:10')");
        if ($num == 0 && check_file($temp_xml_gr . $value . "")) {
            $cmdline = "CHANNEL=" . $value . " DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=" . $settings->temp_data . " " . DO_RECORD . " >/dev/null 2>&1";
            exec($cmdline);
            $cmdline = $settings->epgdump . " " . $key . " " . $settings->temp_data . " " . $temp_xml_gr . $value . "";
            exec($cmdline);
            $cmdline = INSTALL_PATH . "/storeProgram.php GR " . $temp_xml_gr . $value . " >/dev/null 2>&1 &";
            exec($cmdline);
            if (file_exists($settings->temp_data)) {
                @unlink($settings->temp_data);
            }
        }
    }
}