Mercurial > epgrec.yaz
comparison Reservation.class.php @ 137:a18df712fc7e
merged with upstream
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Sun, 21 Mar 2010 03:15:00 +0900 |
| parents | b172a0b1ea48 9c5e597ef6c6 |
| children | 0ded1d3bd448 |
comparison
equal
deleted
inserted
replaced
| 119:b172a0b1ea48 | 137:a18df712fc7e |
|---|---|
| 1 <?php | 1 <?php |
| 2 include_once('config.php'); | 2 include_once('config.php'); |
| 3 include_once( INSTALL_PATH . "/DBRecord.class.php" ); | 3 include_once( INSTALL_PATH . "/DBRecord.class.php" ); |
| 4 include_once( INSTALL_PATH . "/reclib.php" ); | 4 include_once( INSTALL_PATH . "/reclib.php" ); |
| 5 include_once( INSTALL_PATH . "/Settings.class.php" ); | 5 include_once( INSTALL_PATH . "/Settings.class.php" ); |
| 6 include_once( INSTALL_PATH . "/recLog.inc.php" ); | |
| 6 | 7 |
| 7 | 8 |
| 8 // 予約クラス | 9 // 予約クラス |
| 9 | 10 |
| 10 class Reservation { | 11 class Reservation { |
| 75 } | 76 } |
| 76 | 77 |
| 77 $crec = new DBRecord( CHANNEL_TBL, "id", $channel_id ); | 78 $crec = new DBRecord( CHANNEL_TBL, "id", $channel_id ); |
| 78 | 79 |
| 79 // 既存予約数 = TUNER番号 | 80 // 既存予約数 = TUNER番号 |
| 80 $tuners = ($crec->type == "GR") ? $settings->gr_tuners : $settings->bs_tuners; | 81 $tuners = ($crec->type == "GR") ? (int)($settings->gr_tuners) : (int)($settings->bs_tuners); |
| 81 $type_str = ($crec->type == "GR") ? "type = 'GR' " : "(type = 'BS' OR type = 'CS') "; | 82 $type_str = ($crec->type == "GR") ? "type = 'GR' " : "(type = 'BS' OR type = 'CS') "; |
| 82 | 83 |
| 83 $battings = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ". | 84 $battings = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ". |
| 84 "AND ".$type_str. | 85 "AND ".$type_str. |
| 85 "AND starttime < '".toDatetime($end_time) ."' ". | 86 "AND starttime < '".toDatetime($end_time) ."' ". |
| 175 | 176 |
| 176 // 改めてdurationをチェックしなおす | 177 // 改めてdurationをチェックしなおす |
| 177 if( $duration < ($settings->former_time + 60) ) { // 60秒以下の番組は弾く | 178 if( $duration < ($settings->former_time + 60) ) { // 60秒以下の番組は弾く |
| 178 throw new Exception( "終わりつつある/終わっている番組です" ); | 179 throw new Exception( "終わりつつある/終わっている番組です" ); |
| 179 } | 180 } |
| 180 | 181 |
| 181 | |
| 182 // ここからファイル名生成 | 182 // ここからファイル名生成 |
| 183 /* | 183 /* |
| 184 %TITLE% 番組タイトル | 184 %TITLE% 番組タイトル |
| 185 %ST% 開始日時(ex.200907201830) | 185 %ST% 開始日時(ex.200907201830) |
| 186 %ET% 終了日時 | 186 %ET% 終了日時 |
| 201 $filename = $settings->filename_format; | 201 $filename = $settings->filename_format; |
| 202 // あると面倒くさそうな文字を全部_に | 202 // あると面倒くさそうな文字を全部_に |
| 203 $fn_title = mb_ereg_replace("[ \./\*:<>\?\\|()\'\"&]","_", trim($title) ); | 203 $fn_title = mb_ereg_replace("[ \./\*:<>\?\\|()\'\"&]","_", trim($title) ); |
| 204 | 204 |
| 205 // %TITLE% | 205 // %TITLE% |
| 206 $filename = str_replace("%TITLE%", $fn_title, $filename); | 206 $filename = mb_str_replace("%TITLE%", trim($title), $filename); |
| 207 // %ST% 開始日時 | 207 // %ST% 開始日時 |
| 208 $filename = str_replace("%ST%",date("YmdHis", $start_time), $filename ); | 208 $filename = str_replace("%ST%",date("YmdHis", $start_time), $filename ); |
| 209 // %ET% 終了日時 | 209 // %ET% 終了日時 |
| 210 $filename = str_replace("%ET%",date("YmdHis", $end_time), $filename ); | 210 $filename = str_replace("%ET%",date("YmdHis", $end_time), $filename ); |
| 211 // %TYPE% GR/BS | 211 // %TYPE% GR/BS |
| 227 // %MIN% 開始分 | 227 // %MIN% 開始分 |
| 228 $filename = str_replace("%MIN%",date("i", $start_time), $filename ); | 228 $filename = str_replace("%MIN%",date("i", $start_time), $filename ); |
| 229 // %SEC% 開始秒 | 229 // %SEC% 開始秒 |
| 230 $filename = str_replace("%SEC%",date("s", $start_time), $filename ); | 230 $filename = str_replace("%SEC%",date("s", $start_time), $filename ); |
| 231 // %DURATION% 録画時間(秒) | 231 // %DURATION% 録画時間(秒) |
| 232 $filename = str_replace("%DURATION%","".$duration, $filename ); | 232 $filename = mb_str_replace("%DURATION%","".$duration, $filename ); |
| 233 | 233 |
| 234 // あると面倒くさそうな文字を全部_に | |
| 235 $filename = preg_replace("/[ \.\/\*:<>\?\\|()\'\"&]/u","_", trim($filename) ); | |
| 236 | |
| 234 // 文字コード変換 | 237 // 文字コード変換 |
| 235 if( defined("FILESYSTEM_ENCODING") ) { | 238 if( defined("FILESYSTEM_ENCODING") ) { |
| 236 // $filename = mb_convert_encoding( $filename, FILESYSTEM_ENCODING, "UTF-8" ); | 239 // $filename = mb_convert_encoding( $filename, FILESYSTEM_ENCODING, "UTF-8" ); |
| 237 $filename = mb_convert_encoding( $filename, FILESYSTEM_ENCODING, "auto" ); | 240 $filename = mb_convert_encoding( $filename, FILESYSTEM_ENCODING, "auto" ); |
| 238 } | 241 } |
| 242 | |
| 239 $filename .= $RECORD_MODE["$mode"]['suffix']; | 243 $filename .= $RECORD_MODE["$mode"]['suffix']; |
| 240 $thumbname = $filename.".jpg"; | 244 $thumbname = $filename.".jpg"; |
| 241 | 245 |
| 242 // サムネール | 246 // サムネール |
| 243 $gen_thumbnail = INSTALL_PATH."/gen-thumbnail.sh"; | 247 $gen_thumbnail = INSTALL_PATH."/gen-thumbnail.sh"; |
| 297 fclose( $pipes[2] ); | 301 fclose( $pipes[2] ); |
| 298 proc_close( $process ); | 302 proc_close( $process ); |
| 299 } | 303 } |
| 300 else { | 304 else { |
| 301 $rrec->delete(); | 305 $rrec->delete(); |
| 306 reclog( "Reservation::custom atの実行に失敗した模様", E_ERROR); | |
| 302 throw new Exception("AT実行エラー"); | 307 throw new Exception("AT実行エラー"); |
| 303 } | 308 } |
| 304 // job番号を取り出す | 309 // job番号を取り出す |
| 305 $rarr = array(); | 310 $rarr = array(); |
| 306 $tok = strtok( $rstring, " \n" ); | 311 $tok = strtok( $rstring, " \n" ); |
| 310 } | 315 } |
| 311 $key = array_search("job", $rarr); | 316 $key = array_search("job", $rarr); |
| 312 if( $key !== false ) { | 317 if( $key !== false ) { |
| 313 if( is_numeric( $rarr[$key+1]) ) { | 318 if( is_numeric( $rarr[$key+1]) ) { |
| 314 $rrec->job = $rarr[$key+1]; | 319 $rrec->job = $rarr[$key+1]; |
| 320 reclog( "Reservation::custom ジョブ番号".$rrec->job."に録画ジョブを登録"); | |
| 315 return $rrec->job; // 成功 | 321 return $rrec->job; // 成功 |
| 316 } | 322 } |
| 317 } | 323 } |
| 318 // エラー | 324 // エラー |
| 319 $rrec->delete(); | 325 $rrec->delete(); |
| 326 reclog( "Reservation::custom job番号の取得に失敗",E_ERROR ); | |
| 320 throw new Exception( "job番号の取得に失敗" ); | 327 throw new Exception( "job番号の取得に失敗" ); |
| 321 } | 328 } |
| 322 catch( Exception $e ) { | 329 catch( Exception $e ) { |
| 323 if( $rrec != null ) { | 330 if( $rrec != null ) { |
| 324 if( $rrec->id ) { | 331 if( $rrec->id ) { |
| 346 if( $rec == null ) { | 353 if( $rec == null ) { |
| 347 throw new Exception("IDの指定が無効です"); | 354 throw new Exception("IDの指定が無効です"); |
| 348 } | 355 } |
| 349 if( ! $rec->complete ) { | 356 if( ! $rec->complete ) { |
| 350 // 未実行の予約である | 357 // 未実行の予約である |
| 351 if( toTimestamp($rec->starttime) < (time() + PADDING_TIME + $settings->former_time) ) | 358 if( toTimestamp($rec->starttime) < (time() + PADDING_TIME + $settings->former_time) ) { |
| 352 throw new Exception("過去の録画予約です"); | 359 reclog("Reservation::cancel 未実行の予約の取り消しが実行された", E_ERROR ); |
| 360 } | |
| 353 exec( $settings->atrm . " " . $rec->job ); | 361 exec( $settings->atrm . " " . $rec->job ); |
| 362 reclog("Reservation::cancel ジョブ番号".$rec->job."を削除"); | |
| 354 } | 363 } |
| 355 $rec->delete(); | 364 $rec->delete(); |
| 356 } | 365 } |
| 357 catch( Exception $e ) { | 366 catch( Exception $e ) { |
| 367 reclog("Reservation::cancel 予約キャンセルでDB接続またはアクセスに失敗した模様", E_ERROR ); | |
| 358 throw $e; | 368 throw $e; |
| 359 } | 369 } |
| 360 } | 370 } |
| 361 } | 371 } |
| 362 ?> | 372 ?> |
