3 import java.io.BufferedReader;
\r
5 import java.io.IOException;
\r
6 import java.io.InputStreamReader;
\r
7 import java.io.OutputStreamWriter;
\r
8 import java.io.UnsupportedEncodingException;
\r
9 import java.net.Authenticator;
\r
10 import java.net.DatagramPacket;
\r
11 import java.net.DatagramSocket;
\r
12 import java.net.HttpURLConnection;
\r
13 import java.net.InetSocketAddress;
\r
14 import java.net.PasswordAuthentication;
\r
15 import java.net.SocketException;
\r
16 import java.net.URL;
\r
17 import java.util.ArrayList;
\r
18 import java.util.Calendar;
\r
19 import java.util.Date;
\r
20 import java.util.GregorianCalendar;
\r
21 import java.util.HashMap;
\r
22 import java.util.Hashtable;
\r
23 import java.util.List;
\r
24 import java.util.Map;
\r
25 import java.util.regex.Matcher;
\r
26 import java.util.regex.Pattern;
\r
30 * {@link HDDRecorder}インタフェース をインプルメントしたレコーダプラグインのクラスで利用できる、共有部品の集合です。
\r
31 * @version 3.15.4β クラス名を RecorderUtils から HDDRecorderUtils に変更しました。
\r
33 public class HDDRecorderUtils implements HDDRecorder,Cloneable {
\r
35 /*******************************************************************************
\r
37 ******************************************************************************/
\r
39 public HDDRecorderUtils clone() {
\r
41 HDDRecorderUtils ru = (HDDRecorderUtils) super.clone();
\r
42 FieldUtils.deepCopy(ru, this); // ディープコピーするよ
\r
44 } catch (CloneNotSupportedException e) {
\r
45 throw new InternalError(e.toString());
\r
49 /*******************************************************************************
\r
51 ******************************************************************************/
\r
54 public boolean isReserveListSupported() { return true; }
\r
56 public boolean isThereAdditionalDetails() { return false; }
\r
58 public boolean isEditAutoReserveSupported() { return false; }
\r
60 public boolean isRecordedListSupported() { return false; }
\r
62 public boolean isRepeatReserveSupported() { return true; }
\r
64 public boolean isPursuesEditable() { return false; }
\r
66 public boolean isAutocompleteSupported() { return true; }
\r
68 public boolean isChangeChannelSupported() { return ChangeChannel(null); }
\r
70 public boolean isBackgroundOnly() { return false; }
\r
72 public boolean isChValueAvailable() { return false; }
\r
74 public boolean isChCodeNeeded() { return true; }
\r
76 public boolean isRecChNameNeeded() { return true; }
\r
78 public boolean isBroadcastTypeNeeded() { return false; }
\r
80 public boolean isAutoEncSelectEnabled() { return true; }
\r
82 public String getChDatHelp() { return ""; }
\r
84 // フリーテキストによるオプション指定
\r
86 public boolean setOptString(String s) { return true; } // ダミー
\r
88 public String getOptString() { return null; } // ダミー
\r
91 /*******************************************************************************
\r
93 ******************************************************************************/
\r
95 public static final String NULL_ENCODER = "■";
\r
98 private static final String MSGID = "[レコーダ共通] ";
\r
99 private static final String DBGID = "[DEBUG]"+MSGID;
\r
100 private static final String ERRID = "[ERROR]"+MSGID;
\r
103 /*******************************************************************************
\r
105 ******************************************************************************/
\r
108 public void setDebug(boolean b) { debug = b; }
\r
109 protected boolean getDebug() { return debug; }
\r
110 private boolean debug = false;
\r
112 // 終了時刻と開始時刻が重なる番組を重複扱いするか
\r
113 public void setAdjNotRep(boolean b) { adjnotrep = b; }
\r
114 private boolean getAdjNotRep() { return adjnotrep; }
\r
115 private boolean adjnotrep = false;
\r
118 public void setUseCalendar(boolean b) { usecalendar = b; }
\r
119 public boolean getUseCalendar() { return usecalendar; }
\r
120 private boolean usecalendar = true;
\r
123 public void setUseChChange(boolean b) { usechchange = b; }
\r
124 public boolean getUseChChange() { return usechchange; }
\r
125 private boolean usechchange = true;
\r
128 public void setRecordedCheckScope(int n) { recordedCheckScope = n; }
\r
129 protected int getRecordedCheckScope() { return recordedCheckScope; }
\r
130 private int recordedCheckScope = 14;
\r
133 public void setRecordedSaveScope(int n) { recordedSaveScope = n; }
\r
134 protected int getRecordedSaveScope() { return recordedSaveScope; }
\r
135 private int recordedSaveScope = 90;
\r
137 // HTTPアクセス時のUser-Agent
\r
138 public void setUserAgent(String s) { userAgent = s; }
\r
139 //public String getUserAgent() { return userAgent; }
\r
140 private String userAgent = "";
\r
143 /*******************************************************************************
\r
145 ******************************************************************************/
\r
147 public String Myself() { return(getIPAddr()+":"+getPortNo()+":"+getRecorderId()); }
\r
148 public boolean isMyself(String myself) { return Myself().equals(myself); }
\r
150 protected ArrayList<TextValueSet> vrate = new ArrayList<TextValueSet>();
\r
151 protected ArrayList<TextValueSet> arate = new ArrayList<TextValueSet>();
\r
152 protected ArrayList<TextValueSet> folder = new ArrayList<TextValueSet>();
\r
153 protected ArrayList<TextValueSet> encoder = new ArrayList<TextValueSet>();
\r
154 protected ArrayList<TextValueSet> dvdcompat = new ArrayList<TextValueSet>();
\r
155 protected ArrayList<TextValueSet> device = new ArrayList<TextValueSet>();
\r
156 protected ArrayList<TextValueSet> channel = new ArrayList<TextValueSet>();
\r
157 protected ArrayList<TextValueSet> xchapter = new ArrayList<TextValueSet>();
\r
158 protected ArrayList<TextValueSet> mschapter = new ArrayList<TextValueSet>();
\r
159 protected ArrayList<TextValueSet> mvchapter = new ArrayList<TextValueSet>();
\r
160 protected ArrayList<TextValueSet> chvalue = new ArrayList<TextValueSet>();
\r
161 protected ArrayList<TextValueSet> chtype = new ArrayList<TextValueSet>();
\r
162 protected ArrayList<TextValueSet> genre = new ArrayList<TextValueSet>();
\r
164 protected ArrayList<TextValueSet> aspect = new ArrayList<TextValueSet>();
\r
165 protected ArrayList<TextValueSet> bvperf = new ArrayList<TextValueSet>();
\r
166 protected ArrayList<TextValueSet> lvoice = new ArrayList<TextValueSet>();
\r
167 protected ArrayList<TextValueSet> autodel = new ArrayList<TextValueSet>();
\r
169 public ArrayList<TextValueSet> getVideoRateList() { return(vrate); }
\r
170 public ArrayList<TextValueSet> getAudioRateList() { return(arate); }
\r
171 public ArrayList<TextValueSet> getFolderList() { return(folder); }
\r
172 public ArrayList<TextValueSet> getEncoderList() { return(encoder); }
\r
173 public ArrayList<TextValueSet> getDVDCompatList() { return(dvdcompat); }
\r
174 public ArrayList<TextValueSet> getDeviceList() { return(device); }
\r
175 public ArrayList<TextValueSet> getXChapter() { return(xchapter); }
\r
176 public ArrayList<TextValueSet> getMsChapter() { return(mschapter); }
\r
177 public ArrayList<TextValueSet> getMvChapter() { return(mvchapter); }
\r
178 public ArrayList<TextValueSet> getChValue() { return(chvalue); }
\r
179 public ArrayList<TextValueSet> getChType() { return(chtype); }
\r
181 public ArrayList<TextValueSet> getAspect() { return(aspect); }
\r
182 public ArrayList<TextValueSet> getBVperf() { return(bvperf); }
\r
183 public ArrayList<TextValueSet> getLVoice() { return(lvoice); }
\r
184 public ArrayList<TextValueSet> getAutodel() { return(autodel); }
\r
186 public String getLabel_Videorate() { return null; }
\r
187 public String getLabel_Audiorate() { return null; }
\r
188 public String getLabel_Folder() { return null; }
\r
189 public String getLabel_Device() { return null; }
\r
190 public String getLabel_DVDCompat() { return null; }
\r
191 public String getLabel_XChapter() { return null; }
\r
192 public String getLabel_MsChapter() { return null; }
\r
193 public String getLabel_MvChapter() { return null; }
\r
194 public String getLabel_Aspect() { return null; }
\r
195 public String getLabel_BVperf() { return null; }
\r
196 public String getLabel_LVoice() { return null; }
\r
197 public String getLabel_Autodel() { return null; }
\r
199 /*******************************************************************************
\r
201 ******************************************************************************/
\r
203 public String getRecorderId() { return "THIS IS DUMMY METHOD"; }
\r
205 private String recorderIPAddr = "";
\r
206 private String recorderPortNo = "";
\r
207 private String recorderUser = "";
\r
208 private String recorderPasswd = "";
\r
209 private String recorderMacAddr = "";
\r
210 private String recorderBroadcast = "";
\r
211 private int recorderTunerNum = 0;
\r
213 public String getIPAddr() { return recorderIPAddr; }
\r
214 public void setIPAddr(String s) { recorderIPAddr = s; }
\r
215 public String getPortNo() { return recorderPortNo; }
\r
216 public void setPortNo(String s) { recorderPortNo = s; }
\r
217 public String getUser() { return recorderUser; }
\r
218 public void setUser(String s) { recorderUser = s; }
\r
219 public String getPasswd() { return recorderPasswd; }
\r
220 public void setPasswd(String s) { recorderPasswd = s; }
\r
221 public String getMacAddr() { return recorderMacAddr; }
\r
222 public void setMacAddr(String s) { recorderMacAddr = s; }
\r
223 public String getBroadcast() { return recorderBroadcast; }
\r
224 public void setBroadcast(String s) { recorderBroadcast = s; }
\r
225 public int getTunerNum() { return recorderTunerNum; }
\r
226 public void setTunerNum(int n) { recorderTunerNum = n; }
\r
229 public String getColor(String tuner) {
\r
231 if (tuner != null && tuner.length() != 0) {
\r
233 for (TextValueSet e : getEncoderList()) {
\r
234 if (tuner.equals(e.getText())) {
\r
235 if (recorderColorList.size() > idx) {
\r
236 return recorderColorList.get(idx);
\r
243 // 適当なエンコーダが見つからない場合は既定値
\r
244 return recorderColorList.get(0);
\r
247 // Envからもらってきたものを分解して保持する
\r
248 public void setColor(String s) {
\r
250 recorderColorList.clear();
\r
253 ma = Pattern.compile("^#......$").matcher(s);
\r
255 recorderColorList.add(s);
\r
258 ma = Pattern.compile("(#......);").matcher(s);
\r
259 while (ma.find()) {
\r
260 recorderColorList.add(ma.group(1));
\r
266 public ArrayList<String> getColors() { return recorderColorList; }
\r
268 private ArrayList<String> recorderColorList = new ArrayList<String>();
\r
273 public ReserveList getReserveList(String rsvId) {
\r
274 for ( ReserveList rsv : RESERVES ) {
\r
275 if ( rsv.getId() != null && rsv.getId().equals(rsvId) ) {
\r
283 * 持っている予約をすべて…吐き出させるっ…!
\r
285 public ArrayList<ReserveList> getReserves() { return RESERVES; }
\r
287 private ArrayList<ReserveList> RESERVES = new ArrayList<ReserveList>();
\r
292 public AutoReserveInfoList getAutoReserves() { return AUTORESERVES; }
\r
293 private AutoReserveInfoList AUTORESERVES = new AutoReserveInfoList(Env.envDir,null,"dummy","0.0.0.0","0");
\r
298 public ArrayList<RecordedInfo> getRecorded() { return RECORDED; }
\r
299 protected void setRecorded(ArrayList<RecordedInfo> r ) { RECORDED = r; }
\r
301 private ArrayList<RecordedInfo> RECORDED = new ArrayList<RecordedInfo>();
\r
303 /***************************************
\r
304 * 利用可能なエンコーダの絞り込み2種
\r
305 **************************************/
\r
311 public ArrayList<String> getFilteredEncoders(String webChName) {
\r
313 ArrayList<String> encs = new ArrayList<String>();
\r
315 if ( getEncoderList().size() == 0 ) {
\r
316 encs.add(NULL_ENCODER);
\r
320 // エンコーダーに地上波・BS/CSの区別のあるとき
\r
321 if ( isBroadcastTypeNeeded() ) {
\r
323 String code = getChCode().getCH_WEB2CODE(webChName);
\r
325 if ( code != null ) {
\r
326 for ( TextValueSet enc : getEncoderList() ) {
\r
328 (code.startsWith(BroadcastType.TERRA.getName()+":") && enc.getText().startsWith("地上")) ||
\r
329 ((code.startsWith(BroadcastType.BS.getName()+":")||code.startsWith(BroadcastType.CS.getName()+":")) && enc.getText().startsWith("BS")) ||
\r
330 (code.startsWith(BroadcastType.CAPTURE.getName()+":") && enc.getText().startsWith("キャプチャ")) ) {
\r
331 encs.add(enc.getText());
\r
335 if ( encs.size() > 0 ) {
\r
340 // エンコーダーに地上波・BS/CSの区別のないとき or フィルタ結果が0件のとき
\r
341 for ( TextValueSet enc : getEncoderList() ) {
\r
342 encs.add(enc.getText());
\r
348 public String getEmptyEncorder(String webChName, String startDateTime, String endDateTime, ReserveList myrsv, String vardiaVrate) {
\r
351 ArrayList<String> encs = getFilteredEncoders(webChName);
\r
353 // 旧RDデジ系かどうか確認する(R1/R2以外のRDかどうか調べる)
\r
356 for ( String enc : encs ) {
\r
357 if ( ! enc.matches("^R\\d$") ) {
\r
365 // 予約リストをなめて予約済みエンコーダーを探しつつ、裏番組リストも作る
\r
366 urabanlist = new ArrayList<ReserveList>();
\r
367 String rsvedTuner = null;
\r
368 for ( ReserveList r : getReserves() ) {
\r
369 if ( r == myrsv ) {
\r
370 // 自分自身は排除(予約一覧から開いたときとかに使う)
\r
373 if ( ! r.getExec() ) {
\r
379 ArrayList<String> starts = new ArrayList<String>();
\r
380 ArrayList<String> ends = new ArrayList<String>();
\r
381 CommonUtils.getStartEndList(starts, ends, r);
\r
382 for ( int i=0;i<starts.size(); i++ ) {
\r
385 starts.get(i).equals(startDateTime) &&
\r
386 ends.get(i).equals(endDateTime) &&
\r
387 webChName.equals(r.getCh_name())
\r
389 rsvedTuner = r.getTuner();
\r
394 if ( CommonUtils.isOverlap(startDateTime, endDateTime, starts.get(i), ends.get(i), getAdjNotRep()) ) {
\r
397 if ( ! urabanlist.contains(r) ) {
\r
401 // 予約時間が重なるものはエンコーダーの一覧から削除する
\r
402 HashMap<String,Boolean> removeitems = new HashMap<String,Boolean>();
\r
403 for ( String enc : encs ) {
\r
404 if ( enc.equals(r.getTuner()) ) {
\r
406 removeitems.put(enc, true);
\r
408 // ---- RDデジタルW録向け暫定コード ----
\r
409 if ( enc.equals("TS1") || enc.equals("DR1") ) {
\r
410 // TS1が埋まっていればREは使えない
\r
411 removeitems.put("RE", true);
\r
413 else if ( enc.equals("RE") ) {
\r
414 // REが埋まっていればTS1は使えない
\r
415 removeitems.put("TS1", true);
\r
416 removeitems.put("DR1", true);
\r
418 // ---- RDデジタルW録向け暫定コード ----
\r
423 for ( String key : removeitems.keySet() ) {
\r
430 if ( ! isAutoEncSelectEnabled() ) {
\r
436 if ( vardiaVrate != null ) {
\r
437 return getOldVARDIAEmpEnc(encs, vardiaVrate);
\r
441 if ( encs.size() == 0 ) {
\r
448 if ( rsvedTuner != null ) {
\r
452 if ( encs.size() > 0 ) {
\r
453 // エンコーダーが残っていればそれらの先頭を返す(裏番組がない場合は除く)
\r
454 return encs.get(0);
\r
462 public ArrayList<ReserveList> getUrabanList() {
\r
466 private ArrayList<ReserveList> urabanlist = null; // 裏番組の一覧
\r
469 /***************************************
\r
470 * R1/R2に統合されていない旧RDデジ系用の部品2種
\r
471 **************************************/
\r
474 * チューナーにあった画質を拾ってみる
\r
476 public String getPreferredVrate_VARDIA(String tuner) {
\r
478 if ( ! isOldVARDIA() ) {
\r
482 if ( tuner.startsWith("TS") ) {
\r
483 // TS1/2では画質に[TS]系列を選ぶ
\r
484 return getAppropriateVrate("[TS]",null);
\r
486 else if ( tuner.startsWith("DR") ) {
\r
487 // DR1/2では画質に[DR]を選ぶ
\r
488 return getAppropriateVrate("[DR]",null);
\r
490 else if ( tuner.startsWith("RE") ) {
\r
491 // REでは画質に[TSE]または[AVC]系列を選ぶ
\r
492 return getAppropriateVrate("[TSE] ","[AVC] ");
\r
498 private String getAppropriateVrate(String vrate1, String vrate2) {
\r
499 for ( TextValueSet tv : getVideoRateList() ) {
\r
500 String vrate = tv.getText();
\r
501 if ( vrate1 != null && vrate.startsWith(vrate1) ) {
\r
504 if ( vrate2 != null && vrate.startsWith(vrate2) ) {
\r
512 * 画質にあったチューナーだけ拾ってみる
\r
514 public ArrayList<TextValueSet> getPreferredTuners_VARDIA(String vrate) {
\r
516 if ( ! isOldVARDIA() ) {
\r
520 ArrayList<TextValueSet> encs = new ArrayList<TextValueSet>();
\r
522 for ( TextValueSet tv : getEncoderList() ) {
\r
523 String enc = tv.getText();
\r
524 if ( vrate.equals("[TS]") ) {
\r
525 if ( enc.startsWith("TS") ) {
\r
529 else if ( vrate.equals("[DR]") ) {
\r
530 if ( enc.startsWith("DR") ) {
\r
535 // TSE or AVC or VR
\r
536 if ( enc.equals("RE") || enc.equals("VR") ) {
\r
545 private String getOldVARDIAEmpEnc(ArrayList<String> encs, String vrate) {
\r
546 if ( vrate.equals("[TS]") ) {
\r
547 for ( String enc : encs ) {
\r
548 if ( enc.startsWith("TS") ) {
\r
553 else if ( vrate.equals("[DR]") ) {
\r
554 for ( String enc : encs ) {
\r
555 if ( enc.startsWith("DR") ) {
\r
561 // TSE or AVC or VR
\r
562 for ( String enc : encs ) {
\r
563 if ( enc.equals("RE") || enc.equals("VR") ) {
\r
572 * R1/R2に統合されていない古いRD(VARDIA・REGZA RD)かどうか調べるかどうか調べる
\r
574 public boolean isOldVARDIA() {
\r
575 return ( getRecorderId().startsWith("VARDIA RD-") || getRecorderId().startsWith("REGZA RD-") );
\r
581 public boolean isRD() {
\r
582 return ( getRecorderId().startsWith("RD-") || getRecorderId().startsWith("VARDIA RD-") || getRecorderId().startsWith("REGZA RD-") || getRecorderId().startsWith("REGZA DBR-Z") );
\r
586 /*******************************************************************************
\r
588 ******************************************************************************/
\r
590 // 素直にHashMapつかっておけばよかった
\r
592 public String text2value(ArrayList<TextValueSet> tvs, String text) {
\r
593 for ( TextValueSet t : tvs ) {
\r
594 if (t.getText().equals(text)) {
\r
595 return(t.getValue());
\r
601 public String value2text(ArrayList<TextValueSet> tvs, String value) {
\r
602 for ( TextValueSet t : tvs ) {
\r
603 if (t.getValue().equals(value)) {
\r
604 return(t.getText());
\r
611 public TextValueSet getDefaultSet(ArrayList<TextValueSet> tvs) {
\r
612 for ( TextValueSet t : tvs ) {
\r
613 if ( t.getDefval() ) {
\r
620 protected TextValueSet add2tvs(ArrayList<TextValueSet> tvs, String text, String value) {
\r
621 TextValueSet t = new TextValueSet();
\r
627 protected TextValueSet add2tvs(int n, ArrayList<TextValueSet> tvs, String text, String value) {
\r
628 TextValueSet t = new TextValueSet();
\r
635 // 予約日付をId化する(単日以外)
\r
636 protected int getRec_pattern_Id(String s) {
\r
638 for (; i<HDDRecorder.RPTPTN.length;i++) {
\r
639 //System.out.println(s + "->" + HDDRecorder.RPTPTN[i]);
\r
640 if (s.equals(HDDRecorder.RPTPTN[i])) {
\r
647 /* 予約IDが動的に変化するレコーダ向けの処理 */
\r
648 private int rsvcnt = 0;
\r
649 protected String getUniqId(String rsvId) { return (!rsvId.startsWith("U$"))?(String.format("U$%14s,%05d,%s",CommonUtils.getDateTimeYMD(0),(rsvcnt++)%100000,rsvId)):(rsvId); }
\r
650 protected String getRsvId(String uniqId) { return (uniqId.startsWith("U$"))?(uniqId.substring(23)):(uniqId); }
\r
654 public void getStartEndDateTime(ReserveList r) {
\r
656 GregorianCalendar c = CommonUtils.getCalendar(r.getRec_nextdate());
\r
658 // ★★★ MM/DDをYYYY/MM/DDに戻す? ★★★
\r
659 c.set(Calendar.MINUTE, Integer.valueOf(r.getAmm()));
\r
660 c.set(Calendar.HOUR_OF_DAY, Integer.valueOf(r.getAhh()));
\r
661 r.setStartDateTime(CommonUtils.getDateTime(c));
\r
663 c.add(Calendar.MINUTE, Integer.valueOf(r.getRec_min()));
\r
664 r.setEndDateTime(CommonUtils.getDateTime(c));
\r
669 public String[] _mmdd2yyyymmdd(String mm, String dd)
\r
671 GregorianCalendar c = new GregorianCalendar();
\r
672 c.setTime(new Date());
\r
673 if ( Integer.valueOf(mm) < c.get(Calendar.MONTH)+1 ) {
\r
674 c.add(Calendar.YEAR, 1);
\r
677 return (new String[] { String.format("%04d",c.get(Calendar.YEAR)), mm, dd });
\r
681 public String[] _hhmm2hhmm_min(String ahhmm, String zhhmm)
\r
688 Matcher ma = Pattern.compile("^(\\d+):(\\d+)").matcher(ahhmm);
\r
690 ahh = String.format("%02d",Integer.valueOf(ma.group(1)));
\r
691 amm = String.format("%02d",Integer.valueOf(ma.group(2)));
\r
694 ma = Pattern.compile("^(\\d+):(\\d+)").matcher(zhhmm);
\r
696 zhh = String.format("%02d",Integer.valueOf(ma.group(1)));
\r
697 zmm = String.format("%02d",Integer.valueOf(ma.group(2)));
\r
700 int min = Integer.valueOf(zhh)*60+Integer.valueOf(zmm) - (Integer.valueOf(ahh)*60+Integer.valueOf(amm));
\r
701 if ( min < 0 ) min += 24*60;
\r
703 return (new String[] {ahh, amm, zhh, zmm, Integer.toString(min)});
\r
706 // レコーダの設定情報をキャッシュする
\r
707 public ArrayList<TextValueSet> TVSload(String filename) {
\r
708 File f = new File(filename);
\r
709 if ( ! f.exists() ) {
\r
710 return new ArrayList<TextValueSet>();
\r
713 @SuppressWarnings("unchecked")
\r
714 ArrayList<TextValueSet> ar = (ArrayList<TextValueSet>) CommonUtils.readXML(filename);
\r
715 if ( ar == null ) {
\r
716 System.err.println("設定ファイルの読み込みに失敗しました: "+filename);
\r
717 return new ArrayList<TextValueSet>();
\r
722 public void TVSsave(ArrayList<TextValueSet> ar, String filename) {
\r
723 if ( ! CommonUtils.writeXML(filename, ar) ) {
\r
724 System.err.println("設定ファイルの保存に失敗しました: "+filename);
\r
729 * レコーダの予約リストをキャッシュする
\r
731 * @return nullは返さない!
\r
732 * @see #ReservesToFile(ArrayList, String)
\r
734 protected ArrayList<ReserveList> ReservesFromFile(String rsvedFile) {
\r
735 File f = new File(rsvedFile);
\r
736 if ( ! f.exists() ) {
\r
737 System.out.println("+予約キャッシュはありません: "+rsvedFile);
\r
738 return new ArrayList<ReserveList>();
\r
741 @SuppressWarnings("unchecked")
\r
742 ArrayList<ReserveList> tmp = (ArrayList<ReserveList>) CommonUtils.readXML(rsvedFile);
\r
743 if ( tmp == null ) {
\r
744 System.err.println("予約キャッシュの読み込みに失敗しました: "+rsvedFile);
\r
745 return new ArrayList<ReserveList>();
\r
750 for (ReserveList r : tmp) {
\r
751 if (r.getId() == null && r.getNo() > 0) {
\r
752 r.setId(String.valueOf(r.getNo()));
\r
757 System.out.println("+予約キャッシュを読み込みました("+tmp.size()+"): "+rsvedFile);
\r
764 * @see #ReservesFromFile(String)
\r
766 protected void ReservesToFile(ArrayList<ReserveList> reserves, String rsvedFile) {
\r
767 if ( ! CommonUtils.writeXML(rsvedFile, reserves) ) {
\r
768 System.err.println("予約キャッシュの保存に失敗しました: "+rsvedFile);
\r
773 * レコーダの録画結果リストをキャッシュする<BR>
\r
774 * ※キャッシュから取得したものはIDがnullでクリアされる
\r
776 * @return nullは返さない!
\r
777 * @see #RecordedToFile(ArrayList, String)
\r
779 protected ArrayList<RecordedInfo> RecordedFromFile(String recedFile) {
\r
781 File f = new File(recedFile);
\r
782 if ( ! f.exists() ) {
\r
783 System.out.println("+録画結果キャッシュはありません: "+recedFile);
\r
784 return new ArrayList<RecordedInfo>();
\r
787 @SuppressWarnings("unchecked")
\r
788 ArrayList<RecordedInfo> tmp = (ArrayList<RecordedInfo>) CommonUtils.readXML(recedFile);
\r
789 if ( tmp == null ) {
\r
790 System.err.println("録画結果キャッシュの読み込みに失敗しました: "+recedFile);
\r
791 return new ArrayList<RecordedInfo>();
\r
795 String critDate = CommonUtils.getDate(CommonUtils.getCalendar(-86400*getRecordedSaveScope()));
\r
796 String specialDate = CommonUtils.getDate(CommonUtils.getCalendar("1970/01/01"));
\r
797 for ( int i=tmp.size()-1; i>=0; i-- ) {
\r
798 if ( tmp.get(i).getDate().compareTo(critDate) < 0 && tmp.get(i).getDate().compareTo(specialDate) > 0) {
\r
800 if (debug) System.out.println("録画結果のキャッシュを削除しました: "+tmp.get(i).getDate()+" "+tmp.get(i).getTitle());
\r
809 for ( RecordedInfo ri : tmp ) {
\r
810 // キャッシュから読みだしたものはIDをクリアする
\r
813 if ( ri.getCh_orig() == null ) {
\r
814 ri.setCh_orig(ri.getCh_name());
\r
818 System.out.println("+録画結果キャッシュを読み込みました("+tmp.size()+"件): "+recedFile);
\r
825 * @see #RecordedToFile(ArrayList, String)
\r
827 protected void RecordedToFile(ArrayList<RecordedInfo> recorded, String recedFile) {
\r
828 if ( ! CommonUtils.writeXML(recedFile, recorded) ) {
\r
829 System.err.println("録画結果キャッシュの保存に失敗しました: "+recedFile);
\r
836 protected boolean matchReserveV1(ReserveList n, ReserveList o) {
\r
838 n.getTitle().equals(o.getTitle()) &&
\r
839 n.getChannel().equals(o.getChannel()) &&
\r
840 n.getRec_pattern().equals(o.getRec_pattern()) &&
\r
841 n.getAhh().equals(o.getAhh()) && n.getAmm().equals(o.getAmm())
\r
844 public void setReservesV1(ArrayList<ReserveList> r) {
\r
845 // ライン入力のチャンネル名を保持する
\r
846 //System.out.println(RESERVES.size()+","+r.size());
\r
847 for (ReserveList o : RESERVES) {
\r
848 for (ReserveList n : r) {
\r
849 if (matchReserveV1(n, o)) {
\r
851 if (o.getCh_name() != null && n.getCh_name() != null && n.getCh_name().startsWith("外部入力")) {
\r
852 System.out.println("外部入力を次の放送局で置き換えます: "+n.getCh_name()+"->"+o.getCh_name());
\r
853 n.setCh_name(o.getCh_name());
\r
857 n.setAutocomplete(o.getAutocomplete());
\r
859 n.setDetail(o.getDetail());
\r
860 n.setRec_genre(o.getRec_genre());
\r
861 n.setRec_device(o.getRec_device());
\r
862 n.setRec_folder(o.getRec_folder());
\r
863 n.setRec_dvdcompat(o.getRec_dvdcompat());
\r
864 n.setRec_xchapter(o.getRec_xchapter());
\r
865 n.setRec_mschapter(o.getRec_mschapter());
\r
866 n.setRec_mvchapter(o.getRec_mvchapter());
\r
868 n.setRec_aspect(o.getRec_aspect());
\r
869 n.setRec_bvperf(o.getRec_bvperf());
\r
870 n.setRec_lvoice(o.getRec_lvoice());
\r
871 n.setRec_autodel(o.getRec_autodel());
\r
878 removePassedReserves();
\r
880 public void setReserves(ArrayList<ReserveList> r) {
\r
881 // ライン入力のチャンネル名を保持する
\r
882 for (ReserveList o : RESERVES) {
\r
883 for (ReserveList n : r) {
\r
885 if (o.getCh_name() != null && n.getCh_name() != null && n.getCh_name().startsWith("外部入力")) {
\r
886 if (o.getId() == n.getId() && o.getChannel().equals(n.getChannel())) {
\r
887 System.out.println("外部入力を次の放送局で置き換えます: "+n.getCh_name()+"->"+o.getCh_name());
\r
888 n.setCh_name(o.getCh_name());
\r
895 if ( getTunerNum() >= 2 ) {
\r
899 ArrayList<ReserveList> s = new ArrayList<ReserveList>();
\r
900 for ( ReserveList o : r ) {
\r
902 for ( int i=0; i<s.size(); i++ ) {
\r
903 if ( o.getStartDateTime().compareTo(s.get(i).getStartDateTime()) < 0 ) {
\r
919 for ( int x=0; x<s.size(); x++ ) {
\r
921 ArrayList<String> tuns = new ArrayList<String>();
\r
922 for ( TextValueSet enc : encoder ) {
\r
923 tuns.add(enc.getText());
\r
925 // 残っているチューナーをリストアップする
\r
926 for ( int y=0; y<s.size() && tuns.size()>0; y++ ) {
\r
927 if ( x == y || s.get(y).getTuner().equals("") ) {
\r
928 // 自分自身と、チューナー番号が振られていない相手はスルー
\r
931 // 時間が重なっている予約が既に使用しているチューナーは除外する
\r
932 ArrayList<String> starts = new ArrayList<String>();
\r
933 ArrayList<String> ends = new ArrayList<String>();
\r
934 CommonUtils.getStartEndList(starts, ends, s.get(y));
\r
935 for ( int z=0; z<starts.size(); z++ ) {
\r
936 // 帯予約を正しく処理するために全予約日時をなめるようにする
\r
937 if ( CommonUtils.isOverlap(s.get(x).getStartDateTime(), s.get(x).getEndDateTime(), starts.get(z), ends.get(z), getAdjNotRep()) ) {
\r
938 tuns.remove(s.get(y).getTuner());
\r
944 if ( tuns.size() == 0 ) {
\r
946 s.get(x).setTuner(encoder.get(0).getText());
\r
949 // 余っているならそのうちの最初のものを使用
\r
950 s.get(x).setTuner(tuns.get(0));
\r
954 else if ( getTunerNum() == 1 ) {
\r
956 for ( int x=0; x<r.size(); x++ ) {
\r
957 r.get(x).setTuner("■");
\r
966 removePassedReserves();
\r
968 public void removePassedReserves() {
\r
970 String curDateTime = CommonUtils.getCritDateTime();
\r
972 for (int i=RESERVES.size()-1; i>=0; i--) {
\r
973 ReserveList r = RESERVES.get(i);
\r
974 if (r.getRec_pattern_id() == HDDRecorder.RPTPTN_ID_BYDATE) {
\r
976 if (r.getEndDateTime().compareTo(curDateTime) < 0) {
\r
978 RESERVES.remove(r);
\r
990 protected ArrayList<ReserveList> decodeReservedList(String response) {
\r
992 ArrayList<ReserveList> newReserveList = new ArrayList<ReserveList>();
\r
994 Matcher ma = Pattern.compile("(c1\\[\\d+?\\]=[\\s\\S]+?\";)\\n").matcher(response);
\r
995 while ( ma.find() ) {
\r
997 ReserveList entry = new ReserveList();
\r
1001 String[] d = new String[17];
\r
1002 mb = Pattern.compile("c\\d+?\\[\\d+?\\]=\"(.*?)\";").matcher(ma.group(1));
\r
1003 for (int i=0; i<d.length; i++) {
\r
1005 d[i] = mb.group(1);
\r
1007 //System.out.println(i+") "+d[i]);
\r
1011 if (d[1].equals("2")) {
\r
1012 entry.setExec(false);
\r
1016 //if (d[12].equals("0") || d[12].equals("4") || d[12].equals("3")) {
\r
1017 if (d[12].equals("4")) {
\r
1018 entry.setPursues(true);
\r
1022 entry.setRec_device(d[8]);
\r
1025 String title = CommonUtils.unEscape(d[2]).replaceAll("<BR>","");
\r
1028 entry.setId(d[0]);
\r
1031 entry.setRec_pattern(d[5]);
\r
1032 entry.setRec_pattern_id(getRec_pattern_Id(entry.getRec_pattern()));
\r
1033 mb = Pattern.compile("(\\d\\d):(\\d\\d).*?(\\d\\d):(\\d\\d)").matcher(d[6]+"-"+d[7]);
\r
1035 entry.setAhh(mb.group(1));
\r
1036 entry.setAmm(mb.group(2));
\r
1037 entry.setZhh(mb.group(3));
\r
1038 entry.setZmm(mb.group(4));
\r
1040 entry.setRec_nextdate(CommonUtils.getNextDate(entry));
\r
1041 //entry.setRec_nextdate(getNextDate(entry.getRec_pattern(), entry.getZhh()+":"+entry.getZmm()));
\r
1042 entry.setRec_min(CommonUtils.getRecMin(entry.getAhh(), entry.getAmm(), entry.getZhh(), entry.getZmm()));
\r
1043 getStartEndDateTime(entry);
\r
1046 if (d[3].equals("18") || d[3].equals("10") || d[3].equals("9")) {
\r
1047 entry.setTuner("TS2");
\r
1049 else if (d[3].equals("17") || d[3].equals("12") || d[3].equals("11")) {
\r
1050 entry.setTuner("TS1");
\r
1052 else if (d[3].equals("16") || d[3].equals("7")) {
\r
1053 entry.setTuner("RE");
\r
1056 entry.setTuner("--");
\r
1060 if (d[10].equals(" ")) {
\r
1061 if (d[9].equals("A1")) {
\r
1062 d[9] = "[TSE] AT 4.7GB";
\r
1064 else if (d[9].equals("A2")) {
\r
1065 d[9] = "[TSE] AT 9.4GB";
\r
1067 else if (d[9].equals("DL")) {
\r
1068 d[9] = "[TSE] AT 8.5GB";
\r
1071 Matcher mc = Pattern.compile("^MN").matcher(d[9]);
\r
1073 d[9] = mc.replaceFirst("[TSE] ");
\r
1078 if (d[9].equals("A1")) {
\r
1079 d[9] = "[VR] AT 4.7GB";
\r
1081 else if (d[9].equals("A2")) {
\r
1082 d[9] = "[VR] AT 9.4GB";
\r
1084 else if (d[9].equals("DL")) {
\r
1085 d[9] = "[VR] AT 8.5GB";
\r
1088 Matcher mc = Pattern.compile("^MN").matcher(d[9]);
\r
1090 d[9] = mc.replaceFirst("[VR] ");
\r
1092 else if ( d[9].startsWith("SP") || d[9].startsWith("LP")) {
\r
1093 d[9] = "[VR] "+d[9];
\r
1098 if (d[9].equals("TS")) {
\r
1099 entry.setRec_mode("[TS]");
\r
1102 entry.setRec_mode(d[9]);
\r
1105 entry.setTitle(title);
\r
1106 entry.setTitlePop(TraceProgram.replacePop(title));
\r
1107 //entry.setCh_name(getChCode().getCH_NO2NAME(d[4])); // 機種固有領域に移動
\r
1108 entry.setChannel(d[4]);
\r
1110 entry.setRec_audio(d[10]);
\r
1111 //entry.rec_folder = data.get(); // 予約一覧からはとれない
\r
1112 //entry.rec_genre = data.get(); // 予約一覧からはとれない
\r
1115 newReserveList.add(entry.clone());
\r
1117 return(newReserveList);
\r
1121 * レコーダーから取得できない情報は直接コピー(既存のリストから探して)
\r
1123 protected void copyAttributes(ReserveList to, ArrayList<ReserveList> fromlist) {
\r
1124 ReserveList olde = null;
\r
1125 for ( ReserveList from : fromlist ) {
\r
1126 if ( from.getId() != null && from.getId().equals(to.getId()) ) {
\r
1127 copyAttribute(to, olde = from);
\r
1132 // DIGAの終了時間"未定"対応だけど、別にDIGAかどうか確認したりはしない。
\r
1133 setAttributesDiga(to,olde);
\r
1137 * レコーダーから取得できない情報は直接コピー(既存エントリから直に)
\r
1139 protected void copyAttribute(ReserveList to, ReserveList from) {
\r
1141 to.setAutocomplete(from.getAutocomplete());
\r
1142 // 予約一覧からは取得できない情報
\r
1143 to.setDetail(from.getDetail());
\r
1144 to.setRec_genre(from.getRec_genre());
\r
1145 //n.setRec_device(o.getRec_device());
\r
1146 to.setRec_folder(from.getRec_folder());
\r
1147 to.setRec_dvdcompat(from.getRec_dvdcompat());
\r
1148 to.setRec_xchapter(from.getRec_xchapter());
\r
1149 to.setRec_mschapter(from.getRec_mschapter());
\r
1150 to.setRec_mvchapter(from.getRec_mvchapter());
\r
1152 to.setRec_aspect(from.getRec_aspect());
\r
1153 to.setRec_bvperf(from.getRec_bvperf());
\r
1154 to.setRec_lvoice(from.getRec_lvoice());
\r
1155 to.setRec_autodel(from.getRec_autodel());
\r
1156 // BZ700以降の取得一覧から取得できない画質の対応
\r
1157 if (to.getRec_mode().equals("")) {
\r
1158 to.setRec_mode(from.getRec_mode());
\r
1162 protected void setAttributesDiga(ReserveList to, ReserveList from) {
\r
1163 if ( to.getZhh() != null && to.getZmm() != null && to.getRec_min() != null ) {
\r
1168 if ( from != null && from.getZhh() != null ) {
\r
1170 to.setZhh(from.getZhh());
\r
1171 to.setZmm(from.getZmm());
\r
1172 to.setRec_min(from.getRec_min());
\r
1173 to.setRec_nextdate(CommonUtils.getNextDate(to));
\r
1174 getStartEndDateTime(to);
\r
1179 // 現在時刻から30分後か、開始時刻から1時間後の、どちらか短い方に強制設定する
\r
1180 String curTM = CommonUtils.getTime(30);
\r
1181 String endTM = String.format("%02d:%s", (Integer.valueOf(to.getAhh())+1)%24,to.getAmm());
\r
1182 if ( curTM.compareTo(endTM) > 0 ) {
\r
1185 to.setZhh(endTM.substring(0,2));
\r
1186 to.setZmm(endTM.substring(3,5));
\r
1187 to.setRec_min(CommonUtils.getRecMin(to.getAhh()+":"+to.getAmm(), endTM));
\r
1190 // 開始時刻から1時間後に強制設定する
\r
1191 to.setZhh(String.format("%02d", (Integer.valueOf(to.getAhh())+1)%24));
\r
1192 to.setZmm(to.getAmm());
\r
1193 to.setRec_min("60");
\r
1195 to.setRec_nextdate(CommonUtils.getNextDate(to));
\r
1196 getStartEndDateTime(to);
\r
1202 protected void setRecordedFlag() {
\r
1204 // 過去X日分までチェック(初期値は14日)
\r
1205 final String critDateTime = CommonUtils.getDateTimeW(-86400*getRecordedCheckScope());
\r
1207 for ( ReserveList reserved : RESERVES ) {
\r
1208 reserved.setRecorded(false);
\r
1211 for ( RecordedInfo recorded : RECORDED ) {
\r
1212 if ( critDateTime.compareTo(recorded.getDate()+" "+recorded.getAhh()+":"+recorded.getAmm()) > 0 ) {
\r
1215 String chktitle = recorded.getTitle().replaceFirst(TVProgram.titlePrefixRemoveExpr, "");
\r
1216 for ( ReserveList reserved : RESERVES ) {
\r
1217 if ( reserved.getRecorded() ) {
\r
1218 // 既にフラグが立ってるものはスルー
\r
1221 if ( reserved.getRec_pattern_id() != HDDRecorder.RPTPTN_ID_BYDATE ) {
\r
1225 String restitle = reserved.getTitle().replaceFirst(TVProgram.titlePrefixRemoveExpr, "");
\r
1226 boolean chchk = (recorded.getChannel() != null && recorded.getChannel().length() > 0) ? (recorded.getChannel().equals(reserved.getChannel())) : (true);
\r
1227 if ( recorded.getSucceeded() && recorded.getDrop_mpeg() == 0 && chchk && chktitle.equals(restitle) ) {
\r
1228 // 成功していて、放送局とタイトルが一致
\r
1229 reserved.setRecorded(true);
\r
1236 * 録画結果一覧は開始日時降順で保存
\r
1237 * @param newRecordedList
\r
1240 protected RecordedInfo addRecorded(ArrayList<RecordedInfo> newRecordedList, RecordedInfo entry) {
\r
1242 String endt = entry.getDate()+entry.getAhh()+entry.getAmm();
\r
1246 for ( ; n<newRecordedList.size(); n++ ) {
\r
1247 RecordedInfo ri = newRecordedList.get(n);
\r
1248 String ridt = ri.getDate()+ri.getAhh()+ri.getAmm();
\r
1249 int result = ridt.compareTo(endt);
\r
1250 if ( result == 0 ) {
\r
1252 // 開始時刻が同じ情報を発見したら、最終的にはそれの前に差し込みたいので、nを保存する
\r
1257 if ( ri.getId() == null ) {
\r
1258 // キャッシュから取得したものだった場合に重複チェックする
\r
1259 if ( ri.getTitle().equals(entry.getTitle()) && ri.getCh_orig().equals(entry.getCh_orig()) && ri.getLength() == entry.getLength()/* && ri.getDrop() == entry.getDrop()*/ ) {
\r
1261 System.out.println(MSGID+"録画結果はすでにキャッシュ上に存在していたようです: "+endt+" "+entry.getTitle());
\r
1265 if (getDebug()) System.out.println(DBGID+"よく似た録画結果です: "+endt+" "+entry.getTitle()+" <-> "+ridt+ri.getTitle());
\r
1269 else if ( result < 0 ) {
\r
1274 entry.setDrop_mpeg(entry.getDrop()-entry.getDrop_mpeg());
\r
1276 newRecordedList.add((dn!=-1)?(dn):(n),entry);
\r
1278 if (getDebug()) System.out.println(DBGID+"録画結果を追加しました: "+endt+" "+entry.getTitle());
\r
1285 * <P>chCode→chName変換もこの中でやる
\r
1287 protected void setAutoReserves(AutoReserveInfoList l) {
\r
1288 for ( AutoReserveInfo r : l ) {
\r
1290 for ( String chCode : r.getChCodes() ) {
\r
1291 String chName = getChCode().getCH_CODE2WEB(chCode);
\r
1292 r.addChName((chName!=null) ? chName : chCode);
\r
1298 /*******************************************************************************
\r
1300 ******************************************************************************/
\r
1302 private StatusWindow stw = null;
\r
1303 public void setProgressArea(StatusWindow o) { stw = o; }
\r
1304 protected void reportProgress(String msg) {
\r
1305 if (stw != null) {
\r
1308 System.out.println(msg);
\r
1312 protected String getNewId(String response) {
\r
1313 Matcher ma = null;
\r
1314 String newid = null;
\r
1315 ma = Pattern.compile("c1\\[\\d+?\\]=\"(\\d+?)\";").matcher(response);
\r
1316 while (ma.find()) {
\r
1318 String idtmp = ma.group(1);
\r
1320 boolean flag = true;
\r
1321 for (ReserveList rx : getReserves()) {
\r
1322 if (rx.getId().equals(idtmp)) {
\r
1327 if (flag == true) {
\r
1335 /*******************************************************************************
\r
1337 ******************************************************************************/
\r
1339 protected void ShowReserves(ArrayList<ReserveList> ress) {
\r
1341 System.out.println("---Reserved List Start---");
\r
1343 for ( ReserveList e : ress ) {
\r
1345 System.out.println(String.format("[%s] %s\t%s\t%s %s:%s-%s:%s\t%sm\t%s\t%s\t%s(%s)\t%s\t%s\t%s",
\r
1346 ++i, e.getId(), e.getRec_pattern(), e.getRec_nextdate(), e.getAhh(), e.getAmm(), e.getZhh(), e.getZmm(), e.getRec_min(), e.getContentId(), e.getRec_audio(), e.getTitle(), e.getTitlePop(), e.getChannel(), e.getCh_name(), e.getRecorded()));
\r
1348 System.out.println(" *** 以下略 ***");
\r
1352 System.out.println("---Reserved List End---");
\r
1356 protected void ShowRecorded(ArrayList<RecordedInfo> recs) {
\r
1358 System.out.println("---Recorded List Start---");
\r
1360 for ( RecordedInfo e : recs ) {
\r
1362 System.out.println(String.format("[%s] %s %s\t%s:%s-%s:%s\t%s(%s)\t%s",
\r
1363 ++i, e.getId(), e.getDate(), e.getAhh(), e.getAmm(), e.getZhh(), e.getZmm(), e.getTitle(), e.getCh_name(), e.getResult()));
\r
1365 System.out.println(" *** 以下略 ***");
\r
1369 System.out.println("---Recorded List End---");
\r
1373 /*******************************************************************************
\r
1375 ******************************************************************************/
\r
1377 private final DumpHttp dump = new DumpHttp();
\r
1380 public void wakeup() {
\r
1381 if ( ! getMacAddr().equals("") && ! getBroadcast().equals("")) {
\r
1383 byte[] magic = new byte[102];
\r
1385 for (; i<6; i++) {
\r
1386 magic[i] = (byte) 0xff;
\r
1388 for (int j=0; j<16; j++) {
\r
1389 for (int k=0; k<6; k++) {
\r
1390 short sv = Short.decode("0x"+getMacAddr().substring(k*2,k*2+2));
\r
1391 magic[i++] = (byte)sv;
\r
1397 InetSocketAddress remote = new InetSocketAddress(getBroadcast(), 1234);
\r
1398 DatagramPacket packet = new DatagramPacket(magic, magic.length, remote);
\r
1399 new DatagramSocket().send(packet);
\r
1400 } catch (SocketException e) {
\r
1401 e.printStackTrace();
\r
1402 } catch (IOException e) {
\r
1403 e.printStackTrace();
\r
1407 System.out.println("send magic packet to "+getBroadcast()+","+getMacAddr());
\r
1412 public void shutdown() {
\r
1414 Authenticator.setDefault(new MyAuthenticator(getUser(), getPasswd()));
\r
1416 reqGET("http://"+getIPAddr()+":"+getPortNo()+"/remote/remote.htm?key=12", null);
\r
1418 System.out.println("send shutdown request to "+getBroadcast()+","+getMacAddr());
\r
1422 public class MyAuthenticator extends Authenticator {
\r
1423 private String username;
\r
1424 private String password;
\r
1426 public MyAuthenticator(String username, String password) {
\r
1427 this.username = username;
\r
1428 this.password = password;
\r
1430 protected PasswordAuthentication getPasswordAuthentication() {
\r
1431 return new PasswordAuthentication(username, password.toCharArray());
\r
1436 public String[] reqGET(String uri, Hashtable<String, String>property) {
\r
1437 return reqGET(uri, property, "MS932");
\r
1439 public String[] reqGET(String uri, Hashtable<String, String>property, String encoding)
\r
1441 //CookieManager manager = new CookieManager();
\r
1442 //CookieHandler.setDefault(manager);
\r
1444 String header = "";
\r
1445 String response = "";
\r
1446 boolean getSuccess = false;
\r
1448 HttpURLConnection conn = null;
\r
1449 BufferedReader reader = null;
\r
1450 InputStreamReader sr = null;
\r
1453 System.out.println("# GET: "+uri);
\r
1454 dump.request("# GET: "+uri);
\r
1458 URL url = new URL(uri);
\r
1459 conn = (HttpURLConnection)url.openConnection();
\r
1460 conn.setRequestMethod("GET");
\r
1461 conn.setConnectTimeout(5*1000);
\r
1462 conn.setReadTimeout(15*1000);
\r
1463 conn.addRequestProperty("User-Agent", userAgent);
\r
1464 if (property != null) {
\r
1465 for (String key : property.keySet()) {
\r
1466 conn.setRequestProperty(key, property.get(key));
\r
1472 Map<String, List<String>> h = conn.getHeaderFields();
\r
1473 for ( String key : h.keySet() ) {
\r
1475 if (key == null) {
\r
1476 header += h.get(key).get(0)+"\n";
\r
1477 Matcher ma = Pattern.compile(" 200 ").matcher(h.get(key).get(0).toString());
\r
1479 getSuccess = true;
\r
1483 header += key+": "+h.get(key).get(0)+"\n";
\r
1487 System.out.println("# Header");
\r
1488 System.out.println(header);
\r
1489 dump.res_header("# Header\n"+header);
\r
1491 if (getSuccess == false) {
\r
1492 // コネクション切断はfinallyで
\r
1493 return(new String[] {header,null});
\r
1497 sr = new InputStreamReader(conn.getInputStream(),encoding);
\r
1498 reader = new BufferedReader(sr);
\r
1501 StringBuilder sb = new StringBuilder();
\r
1502 while ((s = reader.readLine()) != null) {
\r
1507 response = sb.toString();
\r
1509 // コネクション切断はfinallyで
\r
1512 //System.out.printf("# RESPONSE\n%s\n", response);
\r
1513 System.out.println("# DUMP TO FILE: "+dump.res_body("<!-- # RESPONSE -->\n"+response));
\r
1516 return(new String[] {header,response});
\r
1518 catch (UnsupportedEncodingException e) {
\r
1519 System.err.println("[ERROR] レコーダへのアクセスで問題が発生しました(GET): "+e.toString());
\r
1520 if (getSuccess == true) {
\r
1521 return(new String[] {header,null});
\r
1524 catch (IOException e) {
\r
1525 System.err.println("[ERROR] レコーダへのアクセスで問題が発生しました(GET): "+e.toString());
\r
1526 if (getSuccess == true) {
\r
1527 return(new String[] {header,null});
\r
1531 CommonUtils.closing(reader);
\r
1532 CommonUtils.closing(sr);
\r
1533 CommonUtils.closing(conn);
\r
1536 return(new String[] {null,null});
\r
1540 public String[] reqPOST(String uri, String pstr, Hashtable<String, String>property) {
\r
1541 return reqPOST(uri, pstr, property, "MS932");
\r
1543 public String[] reqPOST(String uri, String pstr, Hashtable<String, String>property, String encoding)
\r
1545 //CookieManager manager = new CookieManager();
\r
1546 //CookieHandler.setDefault(manager);
\r
1548 boolean postSuccess = false;
\r
1549 String header = "";
\r
1550 String response = "";
\r
1552 HttpURLConnection conn = null;
\r
1553 OutputStreamWriter writer = null;
\r
1554 BufferedReader reader = null;
\r
1555 InputStreamReader sr = null;
\r
1558 System.out.println("# POST: "+uri+"?"+pstr);
\r
1559 dump.request("# POST: "+uri+"?"+pstr);
\r
1562 URL url = new URL(uri);
\r
1563 conn = (HttpURLConnection)url.openConnection();
\r
1564 conn.setRequestMethod("POST");
\r
1565 conn.setConnectTimeout(5*1000);
\r
1566 conn.setReadTimeout(15*1000);
\r
1567 conn.setDoOutput(true);
\r
1568 conn.addRequestProperty("User-Agent", userAgent);
\r
1569 if (property != null) {
\r
1570 for (String key : property.keySet()) {
\r
1571 conn.setRequestProperty(key, property.get(key));
\r
1577 writer = new OutputStreamWriter(conn.getOutputStream(),encoding);
\r
1578 writer.write(pstr);
\r
1582 Map<String, List<String>> h = conn.getHeaderFields();
\r
1583 for ( String key : h.keySet() ) {
\r
1585 if (key == null) {
\r
1586 header += h.get(key).get(0)+"\n";
\r
1587 Matcher ma = Pattern.compile(" 200 ").matcher(h.get(key).get(0).toString());
\r
1589 postSuccess = true;
\r
1593 header += key+": "+h.get(key).get(0)+"\n";
\r
1597 System.out.println("# Header");
\r
1598 System.out.println(header);
\r
1599 dump.res_header("# Header\n"+header);
\r
1601 if (postSuccess == false) {
\r
1602 // コネクション切断はfinallyで
\r
1603 return(new String[] {header,null});
\r
1606 sr = new InputStreamReader(conn.getInputStream(),encoding);
\r
1607 reader = new BufferedReader(sr);
\r
1610 StringBuilder sb = new StringBuilder();
\r
1611 while ((s = reader.readLine()) != null) {
\r
1616 response = sb.toString();
\r
1618 // コネクション切断はfinallyで
\r
1621 //System.out.printf("# RESPONSE\n%s\n", response);
\r
1622 System.out.println("# DUMP TO FILE: "+dump.res_body("<!-- # RESPONSE -->\n"+response));
\r
1625 return(new String[] {header,response});
\r
1627 catch (UnsupportedEncodingException e) {
\r
1628 System.err.println("[ERROR] レコーダへのアクセスで問題が発生しました(POST): "+e.toString());
\r
1629 if (postSuccess == true) {
\r
1630 return(new String[] {header,null});
\r
1633 catch (IOException e) {
\r
1634 System.err.println("[ERROR] レコーダへのアクセスで問題が発生しました(POST): "+e.toString());
\r
1635 if (postSuccess == true) {
\r
1636 return(new String[] {header,null});
\r
1640 CommonUtils.closing(writer);
\r
1641 CommonUtils.closing(reader);
\r
1642 CommonUtils.closing(sr);
\r
1643 CommonUtils.closing(conn);
\r
1646 return(new String[] {null,null});
\r
1649 /*******************************************************************************
\r
1650 * ここから下は該当機能が無効なプラグイン用のダミー
\r
1651 ******************************************************************************/
\r
1654 public RecType getType() {
\r
1658 public ChannelCode getChCode() {
\r
1662 public boolean ChangeChannel(String Channel) {
\r
1666 public boolean GetRdSettings(boolean force) {
\r
1670 public boolean GetRdReserve(boolean force) {
\r
1674 public boolean GetRdAutoReserve(boolean force) {
\r
1679 public boolean GetRdReserveDetails() {
\r
1683 public boolean GetRdRecorded(boolean force) {
\r
1687 public boolean PostRdEntry(ReserveList r) {
\r
1691 public boolean UpdateRdEntry(ReserveList o, ReserveList r) {
\r
1695 public ReserveList RemoveRdEntry(String delno) {
\r
1699 public String getErrmsg() {
\r