OSDN Git Service

d2084c650aadf36a055461f64095486883459225
[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 boolean 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                         boolean 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                 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 boolean isSaveVideo() {
232                 return SaveVideo;
233         }
234
235         public boolean isSaveComment() {
236                 return SaveComment;
237         }
238
239         public boolean isSaveConverted() {
240                 return SaveConverted;
241         }
242
243         public String getCmdLineOptionOut() {
244                 return CmdLineOptionOut;
245         }
246
247         public String getBackComment() {
248                 return BackComment;
249         }
250
251         public String getVideoShowNum() {
252                 return Integer.toString(VideoShowNum);
253         }
254
255         public String getCmdLineOptionExt() {
256                 return CmdLineOptionExt;
257         }
258
259         public String getCmdLineOptionMain() {
260                 return CmdLineOptionMain;
261         }
262
263         public boolean isVideoFixFileName() {
264                 return VideoFixFileName;
265         }
266
267         public boolean isDeleteVideoAfterConverting() {
268                 return DeleteVideoAfterConverting;
269         }
270
271         public File getVideoFixFileNameFolder() {
272                 return VideoFixFileNameFolder;
273         }
274
275         public boolean isCommentFixFileName() {
276                 return CommentFixFileName;
277         }
278
279         public boolean isDeleteCommentAfterConverting() {
280                 return DeleteCommentAfterConverting;
281         }
282
283         public File getCommentFixFileNameFolder() {
284                 return CommentFixFileNameFolder;
285         }
286
287         public boolean isNotAddVideoID_Conv() {
288                 return NotAddVideoID_Conv;
289         }
290
291         public boolean isConvFixFileName() {
292                 return ConvFixFileName;
293         }
294
295         public File getConvFixFileNameFolder() {
296                 return ConvFixFileNameFolder;
297         }
298
299         public String getNG_Word() {
300                 return NG_Word;
301         }
302
303         public String getNG_ID() {
304                 return NG_ID;
305         }
306
307         public boolean useProxy() {
308                 return UseProxy;
309         }
310
311         public String getProxy() {
312                 return Proxy;
313         }
314
315         public int getProxyPort() {
316                 return ProxyPort;
317         }
318
319         public boolean isFixFontSize() {
320                 return FixFontSize;
321         }
322
323         public boolean isFixCommentNum() {
324                 return FixCommentNum;
325         }
326
327         public boolean isOpaqueComment() {
328                 return OpaqueComment;
329         }
330
331         public boolean useOptionFile() {
332                 return UseOptionFile;
333         }
334
335         public File getOptionFile() {
336                 return OptionFile;
337         }
338
339         public boolean isVhookDisabled() {
340                 return DisableVhook;
341         }
342         public int getShadowIndex(){
343                 return ShadowIndex;
344         }
345
346         private static final String PROP_FILE = "./saccubus.xml";
347
348         private static final String PROP_MAILADDR = "MailAddress";
349         private static final String PROP_PASSWORD = "Password";
350
351         private static final String PROP_SAVE_VIDEO = "SaveVideoFile";
352
353         private static final String PROP_VIDEO_FILE = "VideoFile";
354
355         private static final String PROP_SAVE_COMMENT = "SaveCommentFile";
356
357         private static final String PROP_COMMENT_FILE = "CommentFile";
358
359         private static final String PROP_SAVE_CONVERTED = "SaveConvertedFile";
360
361         private static final String PROP_CONVERTED_FILE = "ConvertedFile";
362
363         private static final String PROP_FFMPEG_PATH = "FFnpegPath";
364
365         private static final String PROP_VHOOK_PATH = "VhookPath";
366
367         private static final String PROP_FONT_PATH = "FontPath";
368
369         private static final String PROP_FONT_INDEX = "FontIndex";
370
371         private static final String PROP_CMDLINE_EXT = "CMD_EXT";
372
373         private static final String PROP_CMDLINE_MAIN = "CMD_MAIN";
374
375         private static final String PROP_CMDLINE_IN = "CMD_IN";
376
377         private static final String PROP_CMDLINE_OUT = "CMD_OUT";
378
379         private static final String PROP_BACK_COMMENT = "BackComment";
380
381         private static final String PROP_SHOW_VIDEO = "ShowVideo";
382
383         private static final String PROP_SHOW_COMMENT = "ShowCommentNum";
384
385         private static final String PROP_VIDEO_FIX_FILE_NAME = "VideoFixFileName";
386
387         private static final String PROP_DEL_VIDEO_AFTER_CONV = "DeleteVideoAfterConv";
388
389         private static final String PROP_VIDEO_FIX_FILE_NAME_FOLDER = "VideoFixFileNameFolder";
390
391         private static final String PROP_DEL_COMMENT_AFTER_CONV = "DeleteCommentAfterConv";
392
393         private static final String PROP_COMMENT_FIX_FILE_NAME = "CommentFixFileName";
394
395         private static final String PROP_COMMENT_FIX_FILE_NAME_FOLDER = "CommentFixFileNameFolder";
396
397         private static final String PROP_NOT_ADD_VIDEOID_CONV = "NotAddVideoIDtoConverted";
398
399         private static final String PROP_CONV_FIX_FILE_NAME = "ConvFixFileName";
400
401         private static final String PROP_CONV_FIX_FILE_NAME_FOLDER = "ConvFixFileNameFolder";
402
403         private static final String PROP_NG_WORD = "NG_Word";
404
405         private static final String PROP_NG_ID = "NG_ID";
406
407         private static final String PROP_USE_PROXY = "UseProxy";
408
409         private static final String PROP_PROXY = "Proxy";
410
411         private static final String PROP_PROXY_PORT = "ProxyPort";
412
413         private static final String PROP_FIX_FONT_SIZE = "FixFontSize";
414
415         private static final String PROP_FIX_COMMENT_NUM = "FixCommentSize";
416
417         private static final String PROP_OPAQUE_COMMENT = "OpaqueComment";
418
419         private static final String PROP_OPTION_FILE = "OptionFile";
420
421         private static final String PROP_DISABLE_VHOOK = "VhookDisabled";
422         
423         private static final String PROP_SHADOW_INDEX = "ShadowIndex";
424
425         public static void saveSetting(ConvertingSetting setting) {
426                 Properties prop = new Properties();
427                 prop.setProperty(PROP_MAILADDR, setting.getMailAddress());
428                 prop.setProperty(PROP_PASSWORD, setting.getPassword());
429                 prop.setProperty(PROP_SAVE_VIDEO, Boolean.toString(setting
430                                 .isSaveVideo()));
431                 prop.setProperty(PROP_VIDEO_FILE, setting.getVideoFile().getPath());
432                 prop.setProperty(PROP_SAVE_COMMENT, Boolean.toString(setting
433                                 .isSaveComment()));
434                 prop.setProperty(PROP_COMMENT_FILE, setting.getCommentFile().getPath());
435                 prop.setProperty(PROP_SAVE_CONVERTED, Boolean.toString(setting
436                                 .isSaveConverted()));
437                 prop.setProperty(PROP_SHOW_COMMENT, setting.getVideoShowNum());
438                 prop.setProperty(PROP_CONVERTED_FILE, setting.getConvertedVideoFile()
439                                 .getPath());
440                 prop.setProperty(PROP_FFMPEG_PATH, setting.getFFmpegPath());
441                 prop.setProperty(PROP_VHOOK_PATH, setting.getVhookPath());
442                 prop.setProperty(PROP_FONT_PATH, setting.getFontPath());
443                 prop.setProperty(PROP_FONT_INDEX, setting.getFontIndex());
444                 prop.setProperty(PROP_CMDLINE_EXT, setting.getCmdLineOptionExt());
445                 prop.setProperty(PROP_CMDLINE_MAIN, setting.getCmdLineOptionMain());
446                 prop.setProperty(PROP_CMDLINE_IN, setting.getCmdLineOptionIn());
447                 prop.setProperty(PROP_CMDLINE_OUT, setting.getCmdLineOptionOut());
448                 prop.setProperty(PROP_BACK_COMMENT, setting.getBackComment());
449                 prop.setProperty(PROP_SHOW_VIDEO, Boolean.toString((setting
450                                 .isVhook_ShowConvertingVideo())));
451                 prop.setProperty(PROP_DEL_VIDEO_AFTER_CONV, Boolean.toString(setting
452                                 .isDeleteVideoAfterConverting()));
453                 prop.setProperty(PROP_VIDEO_FIX_FILE_NAME, Boolean.toString(setting
454                                 .isVideoFixFileName()));
455                 prop.setProperty(PROP_VIDEO_FIX_FILE_NAME_FOLDER, setting
456                                 .getVideoFixFileNameFolder().getPath());
457                 prop.setProperty(PROP_DEL_COMMENT_AFTER_CONV, Boolean.toString(setting
458                                 .isDeleteCommentAfterConverting()));
459                 prop.setProperty(PROP_COMMENT_FIX_FILE_NAME, Boolean.toString(setting
460                                 .isCommentFixFileName()));
461                 prop.setProperty(PROP_COMMENT_FIX_FILE_NAME_FOLDER, setting
462                                 .getCommentFixFileNameFolder().getPath());
463
464                 prop.setProperty(PROP_NOT_ADD_VIDEOID_CONV, Boolean.toString(setting
465                                 .isNotAddVideoID_Conv()));
466
467                 prop.setProperty(PROP_CONV_FIX_FILE_NAME, (new Boolean(setting
468                                 .isConvFixFileName())).toString());
469                 prop.setProperty(PROP_CONV_FIX_FILE_NAME_FOLDER, setting
470                                 .getConvFixFileNameFolder().getPath());
471
472                 prop.setProperty(PROP_NG_WORD, setting.getNG_Word());
473                 prop.setProperty(PROP_NG_ID, setting.getNG_ID());
474                 prop.setProperty(PROP_USE_PROXY, Boolean.toString(setting.useProxy()));
475                 prop.setProperty(PROP_PROXY, setting.getProxy());
476                 prop.setProperty(PROP_PROXY_PORT, Integer.toString(setting
477                                 .getProxyPort()));
478                 prop.setProperty(PROP_FIX_FONT_SIZE, Boolean.toString(setting
479                                 .isFixFontSize()));
480                 prop.setProperty(PROP_FIX_COMMENT_NUM, Boolean.toString(setting
481                                 .isFixCommentNum()));
482                 prop.setProperty(PROP_OPAQUE_COMMENT, Boolean.toString(setting
483                                 .isOpaqueComment()));
484                 if (setting.getOptionFile() != null) {
485                         prop.setProperty(PROP_OPTION_FILE, setting.getOptionFile()
486                                         .getPath());
487                 }
488                 prop.setProperty(PROP_DISABLE_VHOOK, Boolean.toString(setting
489                                 .isVhookDisabled()));
490                 prop.setProperty(PROP_SHADOW_INDEX, Integer.toString(setting.getShadowIndex()));
491                 try {
492                         prop.storeToXML(new FileOutputStream(PROP_FILE), "settings");
493                 } catch (IOException ex) {
494                         ex.printStackTrace();
495                 }
496         }
497
498         public static ConvertingSetting loadSetting(String user, String password) {
499                 Properties prop = new Properties();
500                 try {
501                         prop.loadFromXML(new FileInputStream(PROP_FILE));
502                 } catch (IOException ex) {
503                         ex.printStackTrace();
504                 }
505                 if (user == null) {
506                         user = prop.getProperty(PROP_MAILADDR, "");
507                 }
508                 if (password == null) {
509                         password = prop.getProperty(PROP_PASSWORD, "");
510                 }
511                 String option_file_name = prop.getProperty(PROP_OPTION_FILE, null);
512                 File option_file = null;
513                 if (option_file_name != null) {
514                         option_file = new File(option_file_name);
515                 }
516                 String win_dir = System.getenv("windir");
517                 if(!win_dir.endsWith("\\")){
518                         win_dir = win_dir+"\\";
519                 }
520                 return new ConvertingSetting(user, password,
521                                 Boolean.parseBoolean(prop.getProperty(PROP_SAVE_VIDEO, "true")),
522                                 prop.getProperty(PROP_VIDEO_FILE, ".\\video.flv"),
523                                  Boolean.parseBoolean(prop.getProperty(PROP_SAVE_COMMENT, "true")),
524                                  prop.getProperty(PROP_COMMENT_FILE, ".\\comment.xml"),
525                                  Boolean.parseBoolean(prop.getProperty(PROP_SAVE_CONVERTED, "true")),
526                                  prop.getProperty(PROP_CONVERTED_FILE, ".\\video.avi"),
527                                  prop.getProperty(PROP_SHOW_COMMENT, "30"),
528                                  prop.getProperty(PROP_FFMPEG_PATH,".\\bin\\ffmpeg.exe"),
529                                  prop.getProperty(PROP_VHOOK_PATH,".\\bin\\nicovideo.dll"),
530                                  prop.getProperty(PROP_CMDLINE_EXT, "avi"),
531                                  prop.getProperty(PROP_CMDLINE_MAIN,""),
532                                  prop.getProperty(PROP_CMDLINE_IN, ""),
533                                  prop.getProperty(PROP_CMDLINE_OUT,"-s 512x384 -acodec libmp3lame -ab 128k -ar 44100 -ac 2 -vcodec libxvid -qscale 3 -async 1"),
534                                  prop.getProperty(PROP_BACK_COMMENT, "500"),
535                                  prop.getProperty(PROP_FONT_PATH, win_dir+"Fonts\\msgothic.ttc"),
536                                  Integer.parseInt(prop.getProperty(PROP_FONT_INDEX, "1")),
537                                  Boolean.parseBoolean(prop.getProperty(PROP_SHOW_VIDEO, "true")),
538                                 Boolean.parseBoolean(prop.getProperty(PROP_DEL_VIDEO_AFTER_CONV, "false")),
539                                  Boolean.parseBoolean(prop.getProperty(PROP_VIDEO_FIX_FILE_NAME, "true")),
540                                  prop.getProperty(PROP_VIDEO_FIX_FILE_NAME_FOLDER,".\\[out]video\\"),
541                                  Boolean.parseBoolean(prop.getProperty(PROP_DEL_COMMENT_AFTER_CONV, "false")),
542                                 Boolean.parseBoolean(prop.getProperty(PROP_COMMENT_FIX_FILE_NAME, "true")),
543                                  prop.getProperty(PROP_COMMENT_FIX_FILE_NAME_FOLDER, ".\\[out]comment\\"),
544                                 Boolean.parseBoolean(prop.getProperty(PROP_NOT_ADD_VIDEOID_CONV, "false")),
545                                  Boolean.parseBoolean(prop.getProperty(PROP_CONV_FIX_FILE_NAME,"true")),
546                                  prop.getProperty(PROP_CONV_FIX_FILE_NAME_FOLDER, ".\\[out]converted\\"),
547                                  prop.getProperty(PROP_NG_WORD, ""),
548                                  prop.getProperty(PROP_NG_ID, ""),
549                                  Boolean.parseBoolean(prop.getProperty(PROP_USE_PROXY, "false")),
550                                  prop.getProperty(PROP_PROXY,""),
551                                  Integer.parseInt(prop.getProperty(PROP_PROXY_PORT,"-1")),
552                                  Boolean.parseBoolean(prop.getProperty(PROP_FIX_FONT_SIZE, "true")),
553                                  Boolean.parseBoolean(prop.getProperty(PROP_FIX_COMMENT_NUM, "true")),
554                                  Boolean.parseBoolean(prop.getProperty(PROP_OPAQUE_COMMENT,"false")),
555                                  option_file, Boolean.parseBoolean(prop.getProperty(PROP_DISABLE_VHOOK,"false")),
556                                 Integer.parseInt(prop.getProperty(PROP_SHADOW_INDEX,"1"),
557                                  10)
558                 );
559         }
560
561 }