Mercurial > epgrec.yaz
annotate 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 |
| rev | line source |
|---|---|
| 1 | 1 <?php |
| 2 include_once('config.php'); | |
| 3 include_once( INSTALL_PATH . "/DBRecord.class.php" ); | |
| 4 include_once( INSTALL_PATH . "/reclib.php" ); | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
5 include_once( INSTALL_PATH . "/Settings.class.php" ); |
|
135
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
134
diff
changeset
|
6 include_once( INSTALL_PATH . "/recLog.inc.php" ); |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
7 |
| 1 | 8 |
| 9 // 予約クラス | |
| 10 | |
| 11 class Reservation { | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
12 |
| 1 | 13 public static function simple( $program_id , $autorec = 0, $mode = 0) { |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
14 $settings = Settings::factory(); |
| 1 | 15 $rval = 0; |
| 16 try { | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
17 $prec = new DBRecord( PROGRAM_TBL, "id", $program_id ); |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
18 |
| 1 | 19 $rval = self::custom( |
| 20 $prec->starttime, | |
| 21 $prec->endtime, | |
| 22 $prec->channel_id, | |
| 23 $prec->title, | |
| 24 $prec->description, | |
| 25 $prec->category_id, | |
| 26 $program_id, | |
| 27 $autorec, | |
| 28 $mode ); | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
29 |
| 1 | 30 } |
| 31 catch( Exception $e ) { | |
| 32 throw $e; | |
| 33 } | |
| 34 return $rval; | |
| 35 } | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
36 |
| 1 | 37 public static function custom( |
| 38 $starttime, // 開始時間Datetime型 | |
| 39 $endtime, // 終了時間Datetime型 | |
| 40 $channel_id, // チャンネルID | |
| 41 $title = "none", // タイトル | |
| 42 $description = "none", // 概要 | |
| 43 $category_id = 0, // カテゴリID | |
| 44 $program_id = 0, // 番組ID | |
| 45 $autorec = 0, // 自動録画 | |
| 46 $mode = 0 // 録画モード | |
| 47 ) { | |
| 48 global $RECORD_MODE; | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
49 $settings = Settings::factory(); |
|
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
50 |
| 1 | 51 // 時間を計算 |
| 52 $start_time = toTimestamp( $starttime ); | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
53 $end_time = toTimestamp( $endtime ) + $settings->extra_time; |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
54 |
| 1 | 55 if( $start_time < (time() + PADDING_TIME + 10) ) { // 現在時刻より3分先より小さい=すでに開始されている番組 |
| 56 $start_time = time() + PADDING_TIME + 10; // 録画開始時間を3分10秒先に設定する | |
| 57 } | |
| 58 $at_start = $start_time - PADDING_TIME; | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
59 $sleep_time = PADDING_TIME - $settings->former_time; |
|
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
60 $rec_start = $start_time - $settings->former_time; |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
61 |
| 1 | 62 // durationを計算しておく |
| 63 $duration = $end_time - $rec_start; | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
64 if( $duration < ($settings->former_time + 60) ) { // 60秒以下の番組は弾く |
| 1 | 65 throw new Exception( "終わりつつある/終わっている番組です" ); |
| 66 } | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
67 |
| 1 | 68 $rrec = null; |
| 69 try { | |
| 70 // 同一番組予約チェック | |
| 71 if( $program_id ) { | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
72 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE program_id = '".$program_id."'" ); |
| 1 | 73 if( $num ) { |
| 74 throw new Exception("同一の番組が録画予約されています"); | |
| 75 } | |
| 76 } | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
77 |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
78 $crec = new DBRecord( CHANNEL_TBL, "id", $channel_id ); |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
79 |
| 1 | 80 // 既存予約数 = TUNER番号 |
| 120 | 81 $tuners = ($crec->type == "GR") ? (int)($settings->gr_tuners) : (int)($settings->bs_tuners); |
|
91
f6b909678e51
fix: CS?BS???????????????????????????????
Sushi-k <epgrec@park.mda.or.jp>
parents:
79
diff
changeset
|
82 $type_str = ($crec->type == "GR") ? "type = 'GR' " : "(type = 'BS' OR type = 'CS') "; |
|
102
49145003e6a3
fix whitespace and new line code
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
92
diff
changeset
|
83 |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
84 $battings = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ". |
|
91
f6b909678e51
fix: CS?BS???????????????????????????????
Sushi-k <epgrec@park.mda.or.jp>
parents:
79
diff
changeset
|
85 "AND ".$type_str. |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
86 "AND starttime < '".toDatetime($end_time) ."' ". |
|
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
87 "AND endtime > '".toDatetime($rec_start)."'" |
| 1 | 88 ); |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
89 |
| 1 | 90 if( $battings >= $tuners ) { |
| 91 // 重複を発見した | |
| 40 | 92 if( $settings->force_cont_rec == 1 ) { |
| 1 | 93 // 解消可能な重複かどうかを調べる |
| 94 // 前後の予約数 | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
95 $nexts = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ". |
|
91
f6b909678e51
fix: CS?BS???????????????????????????????
Sushi-k <epgrec@park.mda.or.jp>
parents:
79
diff
changeset
|
96 "AND ".$type_str. |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
97 "AND starttime = '".toDatetime($end_time - $settings->former_time)."'"); |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
98 |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
99 $prevs = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ". |
|
91
f6b909678e51
fix: CS?BS???????????????????????????????
Sushi-k <epgrec@park.mda.or.jp>
parents:
79
diff
changeset
|
100 "AND ".$type_str. |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
101 "AND endtime = '".$starttime."'" ); |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
102 |
| 1 | 103 // 前後を引いてもチューナー数と同数以上なら重複の解消は無理 |
| 104 if( ($battings - $nexts - $prevs) >= $tuners ) | |
| 105 throw new Exception( "重複予約を解消できません" ); | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
106 |
| 1 | 107 // 直後の番組はあるか? |
| 108 if( $nexts ) { | |
| 109 // この番組の終わりをちょっとだけ早める | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
110 $end_time = $end_time - $settings->former_time - $settings->rec_switch_time; |
| 1 | 111 $duration = $end_time - $rec_start; // durationを計算しなおす |
| 112 } | |
| 113 $battings -= $nexts; | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
114 |
| 1 | 115 // 直前の録画予約を見付ける |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
116 $trecs = DBRecord::createRecords(RESERVE_TBL, "WHERE complete = '0' ". |
|
91
f6b909678e51
fix: CS?BS???????????????????????????????
Sushi-k <epgrec@park.mda.or.jp>
parents:
79
diff
changeset
|
117 "AND ".$type_str. |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
118 "AND endtime = '".$starttime."'" ); |
| 1 | 119 // 直前の番組をずらす |
| 120 for( $i = 0; $i < count($trecs) ; $i++ ) { | |
| 121 if( $battings < $tuners ) break; // 解消終了のハズ? | |
| 122 // 予約修正に必要な情報を取り出す | |
| 123 $prev_id = $trecs[$i]->id; | |
| 124 $prev_program_id = $trecs[$i]->program_id; | |
| 125 $prev_channel_id = $trecs[$i]->channel_id; | |
| 126 $prev_title = $trecs[$i]->title; | |
| 127 $prev_description = $trecs[$i]->description; | |
| 128 $prev_category_id = $trecs[$i]->category_id; | |
| 129 $prev_starttime = $trecs[$i]->starttime; | |
| 130 $prev_endtime = $trecs[$i]->endtime; | |
| 131 $prev_autorec = $trecs[$i]->autorec; | |
| 132 $prev_mode = $trecs[$i]->mode; | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
133 |
| 1 | 134 $prev_start_time = toTimestamp($prev_starttime); |
| 135 // 始まっていない予約? | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
136 if( $prev_start_time > (time() + PADDING_TIME + $settings->former_time) ) { |
| 1 | 137 // 開始時刻を元に戻す |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
138 $prev_starttime = toDatetime( $prev_start_time + $settings->former_time ); |
| 1 | 139 // 終わりをちょっとだけずらす |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
140 $prev_endtime = toDatetime( toTimestamp($prev_endtime) - $settings->former_time - $settings->rec_switch_time ); |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
141 |
| 1 | 142 // tryのネスト |
| 143 try { | |
| 144 // いったん予約取り消し | |
| 145 self::cancel( $prev_id ); | |
| 146 // 再予約 | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
147 self::custom( |
| 1 | 148 $prev_starttime, // 開始時間Datetime型 |
| 149 $prev_endtime, // 終了時間Datetime型 | |
| 150 $prev_channel_id, // チャンネルID | |
| 151 $prev_title, // タイトル | |
| 152 $prev_description, // 概要 | |
| 153 $prev_category_id, // カテゴリID | |
| 154 $prev_program_id, // 番組ID | |
| 155 $prev_autorec, // 自動録画 | |
| 156 $prev_mode ); | |
| 157 } | |
| 158 catch( Exception $e ) { | |
| 159 throw new Exception( "重複予約を解消できません" ); | |
| 160 } | |
| 161 } | |
| 162 else { | |
| 163 throw new Exception( "重複予約を解消できません" ); | |
| 164 } | |
| 165 $battings--; | |
| 166 } | |
| 167 if( $battings < 0 ) $battings = 0; | |
| 168 // これで重複解消したはず | |
| 169 } | |
| 170 else { | |
| 171 throw new Exception( "重複予約があります" ); | |
| 172 } | |
| 173 } | |
| 174 // チューナー番号 | |
| 175 $tuner = $battings; | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
176 |
| 1 | 177 // 改めてdurationをチェックしなおす |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
178 if( $duration < ($settings->former_time + 60) ) { // 60秒以下の番組は弾く |
| 1 | 179 throw new Exception( "終わりつつある/終わっている番組です" ); |
| 180 } | |
| 181 | |
|
15
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
182 // ここからファイル名生成 |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
183 /* |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
184 %TITLE% 番組タイトル |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
185 %ST% 開始日時(ex.200907201830) |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
186 %ET% 終了日時 |
|
91
f6b909678e51
fix: CS?BS???????????????????????????????
Sushi-k <epgrec@park.mda.or.jp>
parents:
79
diff
changeset
|
187 %TYPE% GR/BS/CS |
|
15
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
188 %CH% チャンネル番号 |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
189 %DOW% 曜日(Sun-Mon) |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
190 %DOWJ% 曜日(日-土) |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
191 %YEAR% 開始年 |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
192 %MONTH% 開始月 |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
193 %DAY% 開始日 |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
194 %HOUR% 開始時 |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
195 %MIN% 開始分 |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
196 %SEC% 開始秒 |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
197 %DURATION% 録画時間(秒) |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
198 */ |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
199 |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
200 $day_of_week = array( "日","月","火","水","木","金","土" ); |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
201 $filename = $settings->filename_format; |
|
15
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
202 // あると面倒くさそうな文字を全部_に |
|
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
203 $fn_title = mb_ereg_replace("[ \./\*:<>\?\\|()\'\"&]","_", trim($title) ); |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
204 |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
205 // %TITLE% |
| 133 | 206 $filename = mb_str_replace("%TITLE%", trim($title), $filename); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
207 // %ST% 開始日時 |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
208 $filename = str_replace("%ST%",date("YmdHis", $start_time), $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
209 // %ET% 終了日時 |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
210 $filename = str_replace("%ET%",date("YmdHis", $end_time), $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
211 // %TYPE% GR/BS |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
212 $filename = str_replace("%TYPE%",$crec->type, $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
213 // %CH% チャンネル番号 |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
214 $filename = str_replace("%CH%","".$crec->channel, $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
215 // %DOW% 曜日(Sun-Mon) |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
216 $filename = str_replace("%DOW%",date("D", $start_time), $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
217 // %DOWJ% 曜日(日-土) |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
218 $filename = str_replace("%DOWJ%",$day_of_week[(int)date("w", $start_time)], $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
219 // %YEAR% 開始年 |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
220 $filename = str_replace("%YEAR%",date("Y", $start_time), $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
221 // %MONTH% 開始月 |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
222 $filename = str_replace("%MONTH%",date("m", $start_time), $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
223 // %DAY% 開始日 |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
224 $filename = str_replace("%DAY%",date("d", $start_time), $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
225 // %HOUR% 開始時 |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
226 $filename = str_replace("%HOUR%",date("H", $start_time), $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
227 // %MIN% 開始分 |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
228 $filename = str_replace("%MIN%",date("i", $start_time), $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
229 // %SEC% 開始秒 |
|
119
b172a0b1ea48
revoke mb_str_replace for now
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
117
diff
changeset
|
230 $filename = str_replace("%SEC%",date("s", $start_time), $filename ); |
|
116
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
231 // %DURATION% 録画時間(秒) |
|
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
232 $filename = mb_str_replace("%DURATION%","".$duration, $filename ); |
|
f268d7d10590
fix: ??????mb_str_replace?????????????
yoneda <epgrec@park.mda.or.jp>
parents:
91
diff
changeset
|
233 |
| 133 | 234 // あると面倒くさそうな文字を全部_に |
|
134
58791b90221b
mod: mb_ereg_replace -> preg_replace
yoneda <epgrec@park.mda.or.jp>
parents:
133
diff
changeset
|
235 $filename = preg_replace("/[ \.\/\*:<>\?\\|()\'\"&]/u","_", trim($filename) ); |
| 133 | 236 |
|
15
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
237 // 文字コード変換 |
|
76
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
56
diff
changeset
|
238 if( defined("FILESYSTEM_ENCODING") ) { |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
239 // $filename = mb_convert_encoding( $filename, FILESYSTEM_ENCODING, "UTF-8" ); |
|
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
240 $filename = mb_convert_encoding( $filename, FILESYSTEM_ENCODING, "auto" ); |
|
15
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
241 } |
| 133 | 242 |
|
76
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
56
diff
changeset
|
243 $filename .= $RECORD_MODE["$mode"]['suffix']; |
| 47 | 244 $thumbname = $filename.".jpg"; |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
245 |
|
56
be9e4520cfec
change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents:
48
diff
changeset
|
246 // サムネール |
|
be9e4520cfec
change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents:
48
diff
changeset
|
247 $gen_thumbnail = INSTALL_PATH."/gen-thumbnail.sh"; |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
248 if( defined("GEN_THUMBNAIL") ) |
|
56
be9e4520cfec
change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents:
48
diff
changeset
|
249 $gen_thumbnail = GEN_THUMBNAIL; |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
250 |
|
15
cbbddf99d1cd
added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents:
8
diff
changeset
|
251 // ファイル名生成終了 |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
252 |
| 1 | 253 // 予約レコードを埋める |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
254 $rrec = new DBRecord( RESERVE_TBL ); |
| 1 | 255 $rrec->channel_disc = $crec->channel_disc; |
| 256 $rrec->channel_id = $crec->id; | |
| 257 $rrec->program_id = $program_id; | |
| 258 $rrec->type = $crec->type; | |
| 259 $rrec->channel = $crec->channel; | |
| 260 $rrec->title = $title; | |
| 261 $rrec->description = $description; | |
| 262 $rrec->category_id = $category_id; | |
| 263 $rrec->starttime = toDatetime( $rec_start ); | |
| 264 $rrec->endtime = toDatetime( $end_time ); | |
| 265 $rrec->path = $filename; | |
| 266 $rrec->autorec = $autorec; | |
| 267 $rrec->mode = $mode; | |
| 268 $rrec->reserve_disc = md5( $crec->channel_disc . toDatetime( $start_time ). toDatetime( $end_time ) ); | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
269 |
| 1 | 270 // 予約実行 |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
271 $cmdline = $settings->at." ".date("H:i m/d/Y", $at_start); |
| 1 | 272 $descriptor = array( 0 => array( "pipe", "r" ), |
| 273 1 => array( "pipe", "w" ), | |
| 274 2 => array( "pipe", "w" ), | |
| 275 ); | |
| 276 $env = array( "CHANNEL" => $crec->channel, | |
| 277 "DURATION" => $duration, | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
278 "OUTPUT" => INSTALL_PATH.$settings->spool."/".$filename, |
| 1 | 279 "TYPE" => $crec->type, |
| 280 "TUNER" => $tuner, | |
| 281 "MODE" => $mode, | |
| 47 | 282 "THUMB" => INSTALL_PATH.$settings->thumbs."/".$thumbname, |
| 283 "FORMER" => "".$settings->former_time, | |
| 284 "FFMPEG" => "".$settings->ffmpeg, | |
|
79
6eabffb0ccac
add SID: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
76
diff
changeset
|
285 "SID" => $crec->sid, |
| 1 | 286 ); |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
287 |
| 1 | 288 // ATで予約する |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
289 $process = proc_open( $cmdline , $descriptor, $pipes, INSTALL_PATH.$settings->spool, $env ); |
| 1 | 290 if( is_resource( $process ) ) { |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
291 fwrite($pipes[0], $settings->sleep." ".$sleep_time."\n" ); |
| 1 | 292 fwrite($pipes[0], DO_RECORD . "\n" ); |
| 293 fwrite($pipes[0], COMPLETE_CMD." ".$rrec->id."\n" ); | |
| 48 | 294 if( $settings->use_thumbs == 1 ) { |
|
56
be9e4520cfec
change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents:
48
diff
changeset
|
295 fwrite($pipes[0], $gen_thumbnail."\n" ); |
| 1 | 296 } |
| 297 fclose($pipes[0]); | |
| 298 // 標準エラーを取る | |
| 299 $rstring = stream_get_contents( $pipes[2]); | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
300 |
| 1 | 301 fclose( $pipes[2] ); |
| 302 proc_close( $process ); | |
| 303 } | |
| 304 else { | |
| 305 $rrec->delete(); | |
|
135
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
134
diff
changeset
|
306 reclog( "Reservation::custom atの実行に失敗した模様", E_ERROR); |
| 1 | 307 throw new Exception("AT実行エラー"); |
| 308 } | |
| 309 // job番号を取り出す | |
| 310 $rarr = array(); | |
| 311 $tok = strtok( $rstring, " \n" ); | |
| 312 while( $tok !== false ) { | |
| 313 array_push( $rarr, $tok ); | |
| 314 $tok = strtok( " \n" ); | |
| 315 } | |
| 316 $key = array_search("job", $rarr); | |
| 317 if( $key !== false ) { | |
| 318 if( is_numeric( $rarr[$key+1]) ) { | |
| 319 $rrec->job = $rarr[$key+1]; | |
|
135
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
134
diff
changeset
|
320 reclog( "Reservation::custom ジョブ番号".$rrec->job."に録画ジョブを登録"); |
| 1 | 321 return $rrec->job; // 成功 |
| 322 } | |
| 323 } | |
| 324 // エラー | |
| 325 $rrec->delete(); | |
|
135
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
134
diff
changeset
|
326 reclog( "Reservation::custom job番号の取得に失敗",E_ERROR ); |
| 1 | 327 throw new Exception( "job番号の取得に失敗" ); |
| 328 } | |
| 329 catch( Exception $e ) { | |
| 330 if( $rrec != null ) { | |
| 331 if( $rrec->id ) { | |
| 332 // 予約を取り消す | |
| 333 $rrec->delete(); | |
| 334 } | |
| 335 } | |
| 336 throw $e; | |
| 337 } | |
| 338 } | |
| 339 // custom 終了 | |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
340 |
| 1 | 341 // 取り消し |
| 342 public static function cancel( $reserve_id = 0, $program_id = 0 ) { | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
343 $settings = Settings::factory(); |
| 1 | 344 $rec = null; |
|
75
11f63ae04a96
delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
71
diff
changeset
|
345 |
| 1 | 346 try { |
| 347 if( $reserve_id ) { | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
348 $rec = new DBRecord( RESERVE_TBL, "id" , $reserve_id ); |
| 1 | 349 } |
| 350 else if( $program_id ) { | |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
351 $rec = new DBRecord( RESERVE_TBL, "program_id" , $program_id ); |
| 1 | 352 } |
| 353 if( $rec == null ) { | |
| 354 throw new Exception("IDの指定が無効です"); | |
| 355 } | |
| 356 if( ! $rec->complete ) { | |
| 357 // 未実行の予約である | |
|
135
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
134
diff
changeset
|
358 if( toTimestamp($rec->starttime) < (time() + PADDING_TIME + $settings->former_time) ) { |
|
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
134
diff
changeset
|
359 reclog("Reservation::cancel 未実行の予約の取り消しが実行された", E_ERROR ); |
|
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
134
diff
changeset
|
360 } |
|
39
8965ef108821
change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents:
15
diff
changeset
|
361 exec( $settings->atrm . " " . $rec->job ); |
|
135
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
134
diff
changeset
|
362 reclog("Reservation::cancel ジョブ番号".$rec->job."を削除"); |
| 1 | 363 } |
| 364 $rec->delete(); | |
| 365 } | |
| 366 catch( Exception $e ) { | |
|
135
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
134
diff
changeset
|
367 reclog("Reservation::cancel 予約キャンセルでDB接続またはアクセスに失敗した模様", E_ERROR ); |
| 1 | 368 throw $e; |
| 369 } | |
| 370 } | |
| 371 } | |
| 48 | 372 ?> |
