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