OSDN Git Service

d6bcccd82e4d69b8621169e70d32cad119fd3965
[coroid/inqubus.git] / frontend / src / saccubus / ConvertingSetting.java
1 package saccubus;
2
3 import java.util.Properties;
4 import java.io.IOException;
5 import java.io.FileOutputStream;
6 import java.io.FileInputStream;
7 import java.io.File;
8
9 /**
10  * <p>
11  * \83^\83C\83g\83\8b\82³\82«\82ã\82Î\82·
12  * </p>
13  * 
14  * <p>
15  * \90à\96¾: \83j\83R\83j\83R\93®\89æ\82Ì\93®\89æ\82ð\83R\83\81\83\93\83g\82Â\82«\82Å\95Û\91
16  * </p>
17  * 
18  * <p>
19  * \92\98\8dì\8c : Copyright (c) 2007 PSI
20  * </p>
21  * 
22  * <p>
23  * \89ï\8eÐ\96¼:
24  * </p>
25  * 
26  * @author \96¢\93ü\97Í
27  * @version 1.0
28  */
29 public class ConvertingSetting {
30         public static final String[] ShadowKindArray = {
31                 "00:\82È\82µ",
32                 "01:\83j\83R\83j\83R\93®\89æ\95\97",
33                 "02:\89E\89º",
34                 "03:\88Í\82¢\8d\9e\82Ý"
35                 };
36
37         private String MailAddress;
38
39         private String Password;
40
41         private VideoSaveKind saveVideo;
42
43         private File VideoFile;
44
45         private boolean SaveComment;
46
47         private File CommentFile;
48
49         private boolean SaveConverted;
50
51         private File ConvertedVideoFile;
52
53         private String FFmpegPath;
54
55         private String VhookPath;
56
57         private String CmdLineOptionExt;
58
59         private String CmdLineOptionIn;
60
61         private String CmdLineOptionOut;
62
63         private String CmdLineOptionMain;
64
65         private String FontPath;
66
67         private int FontIndex;
68
69         private String BackComment;
70
71         private boolean Vhook_ShowConvertingVideo;
72
73         private int VideoShowNum;
74
75         private boolean DeleteVideoAfterConverting;
76
77         private boolean VideoFixFileName;
78
79         private File VideoFixFileNameFolder;
80
81         private boolean DeleteCommentAfterConverting;
82
83         private boolean CommentFixFileName;
84
85         private File CommentFixFileNameFolder;
86
87         private boolean ConvFixFileName;
88
89         private File ConvFixFileNameFolder;
90
91         private String NG_Word;
92
93         private String NG_ID;
94
95         private boolean UseProxy;
96
97         private String Proxy;
98
99         private int ProxyPort;
100
101         private boolean FixFontSize;
102
103         private boolean FixCommentNum;
104
105         private boolean OpaqueComment;
106
107         private boolean NotAddVideoID_Conv;
108
109         private boolean UseOptionFile;
110
111         private File OptionFile;
112
113         private boolean DisableVhook;
114         
115         private int ShadowIndex;
116
117         public ConvertingSetting(String mailaddress, String password,
118                         VideoSaveKind savevideo, String videofile, boolean savecomment,
119                         String commentfile, boolean saveconverted, String convvideofile,
120                         String videoshownum, String ffmpegpath, String vhookpath,
121                         String cmdlineoption_ext, String cmdlineoption_main,
122                         String cmdlineoption_in, String cmdlineoption_out,
123                         String backcomment, String fontpath, int font_index,
124                         boolean showconvvideo, boolean delete_video_after_conv,
125                         boolean video_fix_file_name, String video_fix_file_name_folder,
126                         boolean delete_comment_after_conv, boolean comment_fix_file_name,
127                         String comment_fix_file_name_folder, boolean not_add_videoid_conv,
128                         boolean conv_fix_file_name, String conv_fix_file_name_folder,
129                         String ngword, String ngid, boolean use_proxy, String proxy,
130                         int proxy_port, boolean fix_font_size, boolean fix_comment_num,
131                         boolean opaque_comment, File option_file, boolean disable_vhook,
132                         int shadow_index) {
133                 MailAddress = mailaddress;
134                 Password = password;
135         this.saveVideo = savevideo;
136                 if (videofile.lastIndexOf(".") < videofile.lastIndexOf("\\")) {
137                         videofile += ".flv";
138                 }
139                 VideoFile = new File(videofile);
140                 SaveComment = savecomment;
141                 if (commentfile.lastIndexOf(".") < commentfile.lastIndexOf("\\")) {
142                         commentfile += ".xml";
143                 }
144                 CommentFile = new File(commentfile);
145                 SaveConverted = saveconverted;
146                 if (convvideofile.lastIndexOf(".") < convvideofile.lastIndexOf("\\")) {
147                         convvideofile += ".avi";
148                 }
149                 ConvertedVideoFile = new File(convvideofile);
150                 try {
151                         VideoShowNum = Integer.parseInt(videoshownum);
152                 } catch (NumberFormatException ex) {
153                         VideoShowNum = 30;
154                 }
155                 FFmpegPath = ffmpegpath;
156                 VhookPath = vhookpath;
157                 CmdLineOptionExt = cmdlineoption_ext;
158                 CmdLineOptionMain = cmdlineoption_main;
159                 CmdLineOptionIn = cmdlineoption_in;
160                 CmdLineOptionOut = cmdlineoption_out;
161                 BackComment = backcomment;
162                 FontPath = fontpath;
163                 FontIndex = font_index;
164                 Vhook_ShowConvertingVideo = showconvvideo;
165                 DeleteVideoAfterConverting = delete_video_after_conv;
166                 VideoFixFileName = video_fix_file_name;
167                 VideoFixFileNameFolder = new File(video_fix_file_name_folder, "");
168                 DeleteCommentAfterConverting = delete_comment_after_conv;
169                 CommentFixFileName = comment_fix_file_name;
170                 CommentFixFileNameFolder = new File(comment_fix_file_name_folder, "");
171                 NotAddVideoID_Conv = not_add_videoid_conv;
172                 ConvFixFileName = conv_fix_file_name;
173                 ConvFixFileNameFolder = new File(conv_fix_file_name_folder, "");
174                 NG_Word = ngword;
175                 NG_ID = ngid;
176                 UseProxy = use_proxy;
177                 Proxy = proxy;
178                 ProxyPort = proxy_port;
179                 FixFontSize = fix_font_size;
180                 FixCommentNum = fix_comment_num;
181                 OpaqueComment = opaque_comment;
182                 OptionFile = option_file;
183                 DisableVhook = disable_vhook;
184                 ShadowIndex = shadow_index;
185         }
186
187         public File getVideoFile() {
188                 return VideoFile;
189         }
190
191         public File getCommentFile() {
192                 return CommentFile;
193         }
194
195         public File getConvertedVideoFile() {
196                 return ConvertedVideoFile;
197         }
198
199         public String getFFmpegPath() {
200                 return FFmpegPath;
201         }
202
203         public String getVhookPath() {
204                 return VhookPath;
205         }
206
207         public String getCmdLineOptionIn() {
208                 return CmdLineOptionIn;
209         }
210
211         public String getFontPath() {
212                 return FontPath;
213         }
214
215         public String getFontIndex() {
216                 return Integer.toString(FontIndex);
217         }
218
219         public boolean isVhook_ShowConvertingVideo() {
220                 return Vhook_ShowConvertingVideo;
221         }
222
223         public String getMailAddress() {
224                 return MailAddress;
225         }
226
227         public String getPassword() {
228                 return Password;
229         }
230
231         public VideoSaveKind getVideoSaveKind() {
232                 return saveVideo;
233         }
234
235         public boolean isSaveComment() {
236                 return SaveComment;
237         }
238
239     /** @return \81u\83R\83\81\83\93\83g\95t\82«\93®\89æ\82É\95Ï\8a·\82·\82é\81v\82È\82çtrue. */
240         public boolean isSaveConverted() {
241                 return SaveConverted;
242         }
243
244         public String getCmdLineOptionOut() {
245                 return CmdLineOptionOut;
246         }
247
248         public String getBackComment() {
249                 return BackComment;
250         }
251
252         public String getVideoShowNum() {
253                 return Integer.toString(VideoShowNum);
254         }
255
256         public String getCmdLineOptionExt() {
257                 return CmdLineOptionExt;
258         }
259
260         public String getCmdLineOptionMain() {
261                 return CmdLineOptionMain;
262         }
263
264     /**
265      * @return \93®\89æ\95Û\91\90Ý\92è\82Å\81u\95Û\91\82·\82é\83t\83H\83\8b\83_\82ð\8ew\92è\82µ\81A\83t\83@\83C\83\8b\96¼\82Í\8e©\93®\82Å\8c\88\92è\82·\82é\81v\82Ì\82Å\82 \82ê\82Îtrue.
266      * \81u\95Û\91\82·\82é\83t\83@\83C\83\8b\96¼\82ð\8ew\92è\82·\82é\81v\82Ì\82Å\82 \82ê\82Îfalse.
267      */
268         public boolean isVideoFixFileName() {
269                 return VideoFixFileName;
270         }
271
272         public boolean isDeleteVideoAfterConverting() {
273                 return DeleteVideoAfterConverting;
274         }
275
276         public File getVideoFixFileNameFolder() {
277                 return VideoFixFileNameFolder;
278         }
279
280         public boolean isCommentFixFileName() {
281                 return CommentFixFileName;
282         }
283
284         public boolean isDeleteCommentAfterConverting() {
285                 return DeleteCommentAfterConverting;
286         }
287
288         public File getCommentFixFileNameFolder() {
289                 return CommentFixFileNameFolder;
290         }
291
292         public boolean isNotAddVideoID_Conv() {
293                 return NotAddVideoID_Conv;
294         }
295
296         public boolean isConvFixFileName() {
297                 return ConvFixFileName;
298         }
299
300         public File getConvFixFileNameFolder() {
301                 return ConvFixFileNameFolder;
302         }
303
304         public String getNG_Word() {
305                 return NG_Word;
306         }
307
308         public String getNG_ID() {
309                 return NG_ID;
310         }
311
312         public boolean useProxy() {
313                 return UseProxy;
314         }
315
316         public String getProxy() {
317                 return Proxy;
318         }
319
320         public int getProxyPort() {
321                 return ProxyPort;
322         }
323
324         public boolean isFixFontSize() {
325                 return FixFontSize;
326         }
327
328         public boolean isFixCommentNum() {
329                 return FixCommentNum;
330         }
331
332         public boolean isOpaqueComment() {
333                 return OpaqueComment;
334         }
335
336         public boolean useOptionFile() {
337                 return UseOptionFile;
338         }
339
340         public File getOptionFile() {
341                 return OptionFile;
342         }
343
344         public boolean isVhookDisabled() {
345                 return DisableVhook;
346         }
347         public int getShadowIndex(){
348                 return ShadowIndex;
349         }
350
351         private static final String PROP_FILE = "./saccubus.xml";
352
353         private static final String PROP_MAILADDR = "MailAddress";
354         private static final String PROP_PASSWORD = "Password";
355
356         private static final String PROP_SAVE_VIDEO = "SaveVideoFile";
357
358         private static final String PROP_VIDEO_FILE = "VideoFile";
359
360         private static final String PROP_SAVE_COMMENT = "SaveCommentFile";
361
362         private static final String PROP_COMMENT_FILE = "CommentFile";
363
364         private static final String PROP_SAVE_CONVERTED = "SaveConvertedFile";
365
366         private static final String PROP_CONVERTED_FILE = "ConvertedFile";
367
368         private static final String PROP_FFMPEG_PATH = "FFnpegPath";
369
370         private static final String PROP_VHOOK_PATH = "VhookPath";
371
372         private static final String PROP_FONT_PATH = "FontPath";
373
374         private static final String PROP_FONT_INDEX = "FontIndex";
375
376         private static final String PROP_CMDLINE_EXT = "CMD_EXT";
377
378         private static final String PROP_CMDLINE_MAIN = "CMD_MAIN";
379
380         private static final String PROP_CMDLINE_IN = "CMD_IN";
381
382         private static final String PROP_CMDLINE_OUT = "CMD_OUT";
383
384         private static final String PROP_BACK_COMMENT = "BackComment";
385
386         private static final String PROP_SHOW_VIDEO = "ShowVideo";
387
388         private static final String PROP_SHOW_COMMENT = "ShowCommentNum";
389
390         private static final String PROP_VIDEO_FIX_FILE_NAME = "VideoFixFileName";
391
392         private static final String PROP_DEL_VIDEO_AFTER_CONV = "DeleteVideoAfterConv";
393
394         private static final String PROP_VIDEO_FIX_FILE_NAME_FOLDER = "VideoFixFileNameFolder";
395
396         private static final String PROP_DEL_COMMENT_AFTER_CONV = "DeleteCommentAfterConv";
397
398         private static final String PROP_COMMENT_FIX_FILE_NAME = "CommentFixFileName";
399
400         private static final String PROP_COMMENT_FIX_FILE_NAME_FOLDER = "CommentFixFileNameFolder";
401
402         private static final String PROP_NOT_ADD_VIDEOID_CONV = "NotAddVideoIDtoConverted";
403
404         private static final String PROP_CONV_FIX_FILE_NAME = "ConvFixFileName";
405
406         private static final String PROP_CONV_FIX_FILE_NAME_FOLDER = "ConvFixFileNameFolder";
407
408         private static final String PROP_NG_WORD = "NG_Word";
409
410         private static final String PROP_NG_ID = "NG_ID";
411
412         private static final String PROP_USE_PROXY = "UseProxy";
413
414         private static final String PROP_PROXY = "Proxy";
415
416         private static final String PROP_PROXY_PORT = "ProxyPort";
417
418         private static final String PROP_FIX_FONT_SIZE = "FixFontSize";
419
420         private static final String PROP_FIX_COMMENT_NUM = "FixCommentSize";
421
422         private static final String PROP_OPAQUE_COMMENT = "OpaqueComment";
423
424         private static final String PROP_OPTION_FILE = "OptionFile";
425
426         private static final String PROP_DISABLE_VHOOK = "VhookDisabled";
427         
428         private static final String PROP_SHADOW_INDEX = "ShadowIndex";
429
430         public static void saveSetting(ConvertingSetting setting) {
431                 Properties prop = new Properties();
432                 prop.setProperty(PROP_MAILADDR, setting.getMailAddress());
433                 prop.setProperty(PROP_PASSWORD, setting.getPassword());
434         prop.setProperty(PROP_SAVE_VIDEO, setting.getVideoSaveKind().toString());
435                 prop.setProperty(PROP_VIDEO_FILE, setting.getVideoFile().getPath());
436                 prop.setProperty(PROP_SAVE_COMMENT, Boolean.toString(setting
437                                 .isSaveComment()));
438                 prop.setProperty(PROP_COMMENT_FILE, setting.getCommentFile().getPath());
439                 prop.setProperty(PROP_SAVE_CONVERTED, Boolean.toString(setting
440                                 .isSaveConverted()));
441                 prop.setProperty(PROP_SHOW_COMMENT, setting.getVideoShowNum());
442                 prop.setProperty(PROP_CONVERTED_FILE, setting.getConvertedVideoFile()
443                                 .getPath());
444                 prop.setProperty(PROP_FFMPEG_PATH, setting.getFFmpegPath());
445                 prop.setProperty(PROP_VHOOK_PATH, setting.getVhookPath());
446                 prop.setProperty(PROP_FONT_PATH, setting.getFontPath());
447                 prop.setProperty(PROP_FONT_INDEX, setting.getFontIndex());
448                 prop.setProperty(PROP_CMDLINE_EXT, setting.getCmdLineOptionExt());
449                 prop.setProperty(PROP_CMDLINE_MAIN, setting.getCmdLineOptionMain());
450                 prop.setProperty(PROP_CMDLINE_IN, setting.getCmdLineOptionIn());
451                 prop.setProperty(PROP_CMDLINE_OUT, setting.getCmdLineOptionOut());
452                 prop.setProperty(PROP_BACK_COMMENT, setting.getBackComment());
453                 prop.setProperty(PROP_SHOW_VIDEO, Boolean.toString((setting
454                                 .isVhook_ShowConvertingVideo())));
455                 prop.setProperty(PROP_DEL_VIDEO_AFTER_CONV, Boolean.toString(setting
456                                 .isDeleteVideoAfterConverting()));
457                 prop.setProperty(PROP_VIDEO_FIX_FILE_NAME, Boolean.toString(setting
458                                 .isVideoFixFileName()));
459                 prop.setProperty(PROP_VIDEO_FIX_FILE_NAME_FOLDER, setting
460                                 .getVideoFixFileNameFolder().getPath());
461                 prop.setProperty(PROP_DEL_COMMENT_AFTER_CONV, Boolean.toString(setting
462                                 .isDeleteCommentAfterConverting()));
463                 prop.setProperty(PROP_COMMENT_FIX_FILE_NAME, Boolean.toString(setting
464                                 .isCommentFixFileName()));
465                 prop.setProperty(PROP_COMMENT_FIX_FILE_NAME_FOLDER, setting
466                                 .getCommentFixFileNameFolder().getPath());
467
468                 prop.setProperty(PROP_NOT_ADD_VIDEOID_CONV, Boolean.toString(setting
469                                 .isNotAddVideoID_Conv()));
470
471                 prop.setProperty(PROP_CONV_FIX_FILE_NAME, (new Boolean(setting
472                                 .isConvFixFileName())).toString());
473                 prop.setProperty(PROP_CONV_FIX_FILE_NAME_FOLDER, setting
474                                 .getConvFixFileNameFolder().getPath());
475
476                 prop.setProperty(PROP_NG_WORD, setting.getNG_Word());
477                 prop.setProperty(PROP_NG_ID, setting.getNG_ID());
478                 prop.setProperty(PROP_USE_PROXY, Boolean.toString(setting.useProxy()));
479                 prop.setProperty(PROP_PROXY, setting.getProxy());
480                 prop.setProperty(PROP_PROXY_PORT, Integer.toString(setting
481                                 .getProxyPort()));
482                 prop.setProperty(PROP_FIX_FONT_SIZE, Boolean.toString(setting
483                                 .isFixFontSize()));
484                 prop.setProperty(PROP_FIX_COMMENT_NUM, Boolean.toString(setting
485                                 .isFixCommentNum()));
486                 prop.setProperty(PROP_OPAQUE_COMMENT, Boolean.toString(setting
487                                 .isOpaqueComment()));
488                 if (setting.getOptionFile() != null) {
489                         prop.setProperty(PROP_OPTION_FILE, setting.getOptionFile()
490                                         .getPath());
491                 }
492                 prop.setProperty(PROP_DISABLE_VHOOK, Boolean.toString(setting
493                                 .isVhookDisabled()));
494                 prop.setProperty(PROP_SHADOW_INDEX, Integer.toString(setting.getShadowIndex()));
495                 try {
496                         prop.storeToXML(new FileOutputStream(PROP_FILE), "settings");
497                 } catch (IOException ex) {
498                         ex.printStackTrace();
499                 }
500         }
501
502     /** \96{\89Æ\82³\82«\82ã\82Î\82·\82Å\95Û\91\82µ\82Ä\82¢\82½\8fê\8d\87\81APROP_SAVE_VIDEO\82Ítrue/false\82È\82Ì\82Å\95Ï\8a·\82·\82é. */
503     private static VideoSaveKind convertVideoSaveKind(Properties prop) {
504         VideoSaveKind kind;
505         String saveVideo = prop.getProperty(PROP_SAVE_VIDEO);
506         if (Boolean.toString(true).equals(saveVideo) || saveVideo == null) {
507             kind = VideoSaveKind.SAVE;
508         } else if (Boolean.toString(false).equals(saveVideo)) {
509             kind = VideoSaveKind.NO_SAVE;
510         } else {
511             kind = VideoSaveKind.valueOf(saveVideo);
512         }
513         return kind;
514     }
515
516         public static ConvertingSetting loadSetting(String user, String password) {
517                 Properties prop = new Properties();
518                 try {
519                         prop.loadFromXML(new FileInputStream(PROP_FILE));
520                 } catch (IOException ex) {
521                         ex.printStackTrace();
522                 }
523                 if (user == null) {
524                         user = prop.getProperty(PROP_MAILADDR, "");
525                 }
526                 if (password == null) {
527                         password = prop.getProperty(PROP_PASSWORD, "");
528                 }
529                 String option_file_name = prop.getProperty(PROP_OPTION_FILE, null);
530                 File option_file = null;
531                 if (option_file_name != null) {
532                         option_file = new File(option_file_name);
533                 }
534                 String win_dir = System.getenv("windir");
535                 if(!win_dir.endsWith("\\")){
536                         win_dir = win_dir+"\\";
537                 }
538
539         final VideoSaveKind kind = convertVideoSaveKind(prop);
540                 return new ConvertingSetting(user, password,
541                 kind,
542                                 prop.getProperty(PROP_VIDEO_FILE, ".\\video.flv"),
543                                  Boolean.parseBoolean(prop.getProperty(PROP_SAVE_COMMENT, "true")),
544                                  prop.getProperty(PROP_COMMENT_FILE, ".\\comment.xml"),
545                                  Boolean.parseBoolean(prop.getProperty(PROP_SAVE_CONVERTED, "true")),
546                                  prop.getProperty(PROP_CONVERTED_FILE, ".\\video.avi"),
547                                  prop.getProperty(PROP_SHOW_COMMENT, "30"),
548                                  prop.getProperty(PROP_FFMPEG_PATH,".\\bin\\ffmpeg.exe"),
549                                  prop.getProperty(PROP_VHOOK_PATH,".\\bin\\nicovideo.dll"),
550                                  prop.getProperty(PROP_CMDLINE_EXT, "avi"),
551                                  prop.getProperty(PROP_CMDLINE_MAIN,""),
552                                  prop.getProperty(PROP_CMDLINE_IN, ""),
553                                  prop.getProperty(PROP_CMDLINE_OUT,"-s 512x384 -acodec libmp3lame -ab 128k -ar 44100 -ac 2 -vcodec libxvid -qscale 3 -async 1"),
554                                  prop.getProperty(PROP_BACK_COMMENT, "500"),
555                                  prop.getProperty(PROP_FONT_PATH, win_dir+"Fonts\\msgothic.ttc"),
556                                  Integer.parseInt(prop.getProperty(PROP_FONT_INDEX, "1")),
557                                  Boolean.parseBoolean(prop.getProperty(PROP_SHOW_VIDEO, "true")),
558                                 Boolean.parseBoolean(prop.getProperty(PROP_DEL_VIDEO_AFTER_CONV, "false")),
559                                  Boolean.parseBoolean(prop.getProperty(PROP_VIDEO_FIX_FILE_NAME, "true")),
560                                  prop.getProperty(PROP_VIDEO_FIX_FILE_NAME_FOLDER,".\\[out]video\\"),
561                                  Boolean.parseBoolean(prop.getProperty(PROP_DEL_COMMENT_AFTER_CONV, "false")),
562                                 Boolean.parseBoolean(prop.getProperty(PROP_COMMENT_FIX_FILE_NAME, "true")),
563                                  prop.getProperty(PROP_COMMENT_FIX_FILE_NAME_FOLDER, ".\\[out]comment\\"),
564                                 Boolean.parseBoolean(prop.getProperty(PROP_NOT_ADD_VIDEOID_CONV, "false")),
565                                  Boolean.parseBoolean(prop.getProperty(PROP_CONV_FIX_FILE_NAME,"true")),
566                                  prop.getProperty(PROP_CONV_FIX_FILE_NAME_FOLDER, ".\\[out]converted\\"),
567                                  prop.getProperty(PROP_NG_WORD, ""),
568                                  prop.getProperty(PROP_NG_ID, ""),
569                                  Boolean.parseBoolean(prop.getProperty(PROP_USE_PROXY, "false")),
570                                  prop.getProperty(PROP_PROXY,""),
571                                  Integer.parseInt(prop.getProperty(PROP_PROXY_PORT,"-1")),
572                                  Boolean.parseBoolean(prop.getProperty(PROP_FIX_FONT_SIZE, "true")),
573                                  Boolean.parseBoolean(prop.getProperty(PROP_FIX_COMMENT_NUM, "true")),
574                                  Boolean.parseBoolean(prop.getProperty(PROP_OPAQUE_COMMENT,"false")),
575                                  option_file, Boolean.parseBoolean(prop.getProperty(PROP_DISABLE_VHOOK,"false")),
576                                 Integer.parseInt(prop.getProperty(PROP_SHADOW_INDEX,"1"),
577                                  10)
578                 );
579         }
580
581 }