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