OSDN Git Service

merge
[coroid/inqubus.git] / frontend / src / saccubus / properties / SProperties.java
1 package saccubus.properties;
2
3 import java.io.File;
4 import java.util.Properties;
5 import java.io.IOException;
6 import java.io.FileOutputStream;
7 import java.io.FileInputStream;
8 import saccubus.VideoSaveKind;
9 import saccubus.converter.filegetter.LoginInfo;
10 import saccubus.converter.profile.CommentGetInfo;
11 import saccubus.converter.profile.Ffmpeg;
12 import saccubus.converter.profile.FfmpegOption;
13 import saccubus.converter.profile.GeneralSetting;
14 import saccubus.converter.profile.InputFileSetting;
15 import saccubus.converter.profile.OutputFileSetting;
16 import saccubus.converter.profile.Profile;
17 import saccubus.converter.profile.Proxy;
18 import saccubus.converter.profile.SFile;
19
20 /**
21  * <p>
22  * \83^\83C\83g\83\8b\82³\82«\82ã\82Î\82·
23  * </p>
24  * 
25  * <p>
26  * \90à\96¾: \83j\83R\83j\83R\93®\89æ\82Ì\93®\89æ\82ð\83R\83\81\83\93\83g\82Â\82«\82Å\95Û\91
27  * </p>
28  * 
29  * <p>
30  * \92\98\8dì\8c : Copyright (c) 2007 PSI
31  * </p>
32  * 
33  * <p>
34  * \89ï\8eÐ\96¼:
35  * </p>
36  * 
37  * @author \96¢\93ü\97Í
38  * @version 1.0
39  */
40 public class SProperties {
41
42     private static final String PROP_FILE = "./saccubus.xml";
43     public static final String[] ShadowKindArray = {
44         "00:\82È\82µ",
45         "01:\83j\83R\83j\83R\93®\89æ\95\97",
46         "02:\89E\89º",
47         "03:\88Í\82¢\8d\9e\82Ý"
48     };
49     private final BasicSetting basicSetting;
50     private final InputVideoSetting inputVideoSetting;
51     private final InputCommentSetting inputCommentSetting;
52     private final InputTcommentSetting inputTcommentSetting;
53     private final OutputVideoSetting outputVideoSetting;
54     private final MovieSetting movieSetting;
55     private final ConvertSetting convertSetting;
56
57     public SProperties(
58             BasicSetting basicSetting,
59             InputVideoSetting inputVideoSetting,
60             InputCommentSetting inputCommentSetting,
61             InputTcommentSetting tcommentSetting,
62             OutputVideoSetting outputVideoSetting,
63             MovieSetting movieSetting,
64             ConvertSetting convertSetting //            String videoshownum,
65             ) {
66 //        this.saveVideo = savevideo;
67 //        if (videofile.lastIndexOf(".") < videofile.lastIndexOf("\\")) {
68 //            videofile += ".flv";
69 //        }
70 //        VideoFile = new File(videofile);
71
72 //        if (commentfile.lastIndexOf(".") < commentfile.lastIndexOf("\\")) {
73 //            commentfile += ".xml";
74 //        }
75 //        CommentFile = new File(commentfile);
76
77 //        if (convvideofile.lastIndexOf(".") < convvideofile.lastIndexOf("\\")) {
78 //            convvideofile += ".avi";
79 //        }
80
81         this.basicSetting = basicSetting;
82         this.inputVideoSetting = inputVideoSetting;
83         this.inputCommentSetting = inputCommentSetting;
84         this.inputTcommentSetting = tcommentSetting;
85         this.outputVideoSetting = outputVideoSetting;
86         this.movieSetting = movieSetting;
87         this.convertSetting = convertSetting;
88     }
89
90     public Profile toProfile() throws IOException {
91         return new ProfileBuilder().build();
92     }
93
94     private class ProfileBuilder {
95
96         private Profile build() throws IOException {
97             GeneralSetting generalSetting = buildGeneralSetting();
98             LoginInfo loginInfo = buildLoginInfo();
99             InputFileSetting videoSetting = buildVideoSetting();
100             InputFileSetting commentSetting = buildCommentSetting();
101             CommentGetInfo commentGetInfo = buildCommentGetInfo();
102             InputFileSetting tcommentSetting = buildTcommentSetting();
103             OutputFileSetting outputFileSetting = buildOutputFileSetting();
104             Ffmpeg ffmpeg = buildFfmpeg();
105
106             return new Profile(generalSetting, loginInfo, videoSetting, commentSetting, commentGetInfo, tcommentSetting,
107                     outputFileSetting, ffmpeg);
108         }
109
110         private GeneralSetting buildGeneralSetting() {
111             final BasicSetting basic = getBasicSetting();
112             return new GeneralSetting(basic.getTempDir());
113         }
114
115         private LoginInfo buildLoginInfo() {
116             final BasicSetting basic = getBasicSetting();
117             Proxy proxy = Proxy.NO_PROXY;
118             if (basic.isProxyUse()) {
119                 proxy = new Proxy(basic.getProxyHost(), basic.getProxyPort());
120             }
121             final LoginInfo loginInfo = new LoginInfo(basic.getUser().getMail(), basic.getUser().getPassword(), proxy);
122             return loginInfo;
123         }
124
125         private InputFileSetting buildVideoSetting() {
126             final InputVideoSetting setting = getInputVideoSetting();
127             // Nicobrowser\83_\83E\83\93\83\8d\81[\83h\83t\83@\83C\83\8b\82Ì\8fê\8d\87\82Í\8fí\82É\83t\83@\83C\83\8b\8ew\92è.
128             final boolean isFile = (!setting.isAutoNaming() || setting.getProcessKind() == VideoSaveKind.NICOBROWSER);
129             File video;
130             if (setting.getProcessKind() == VideoSaveKind.NICOBROWSER) {
131                 video = setting.getFile();
132             } else {
133                 if (setting.isAutoNaming()) {
134                     video = setting.getFolder();
135                 } else {
136                     video = setting.getFile();
137                 }
138             }
139             final SFile videoFile = new SFile(isFile, video);
140             // Nicobrowser\83_\83E\83\93\83\8d\81[\83h\83t\83@\83C\83\8b\82Í\8dí\8f\9c\91Î\8fÛ\82É\82È\82ç\82È\82¢.
141             boolean delete = setting.isDeleteAfterConvert() && (setting.getProcessKind() != VideoSaveKind.NICOBROWSER);
142
143             return new InputFileSetting(videoFile, (setting.getProcessKind() == VideoSaveKind.SAVE), delete);
144         }
145
146         private InputFileSetting buildCommentSetting() {
147             return createCommentSetting(getInputCommentSetting());
148         }
149
150         private CommentGetInfo buildCommentGetInfo() {
151             final InputCommentSetting setting = getInputCommentSetting();
152             return new CommentGetInfo(setting.isSelfAdjustNumOfComment(), setting.getNumOfComment());
153         }
154
155         private InputFileSetting buildTcommentSetting() {
156             return createCommentSetting(getInputTcommentSetting());
157         }
158
159         private InputFileSetting createCommentSetting(saccubus.properties.InputFileSetting<Boolean> setting) {
160             SFile file = createSFile(setting);
161
162             return new InputFileSetting(file, setting.getProcessKind().booleanValue(), setting.isDeleteAfterConvert());
163
164         }
165
166         private SFile createSFile(ProcessFileSetting<Boolean> setting) {
167             File f;
168             if (setting.isAutoNaming()) {
169                 f = setting.getFolder();
170             } else {
171                 f = setting.getFile();
172             }
173             final SFile file = new SFile(!setting.isAutoNaming(), f);
174             return file;
175         }
176
177         private OutputFileSetting buildOutputFileSetting() {
178             final OutputVideoSetting setting = getOutputVideoSetting();
179
180             SFile file = createSFile(setting);
181             return new OutputFileSetting(file, setting.getProcessKind().booleanValue(), !setting.isCutIdName(), setting.
182                     isAddComment(), setting.isAddTcomment());
183         }
184
185         private Ffmpeg buildFfmpeg() throws IOException {
186             final MovieSetting movie = getMovieSetting();
187             final ConvertSetting conv = getConvertSetting();
188
189             FfmpegOption fo = movie.getFfmpegOption();
190             if (movie.getOptionFile() != null) {
191                 try {
192                     fo = FfmpegOption.load(movie.getOptionFile());
193                 } catch (IOException ex) {
194                     throw new IOException("\83I\83v\83V\83\87\83\93\83t\83@\83C\83\8b\82Ì\8f\91\8e®\82ª\8cë\82Á\82Ä\82¢\82Ü\82·\81F" + movie.getOptionFile().getName(), ex);
195                 }
196             }
197
198             return new Ffmpeg(
199                     movie.getFfmpeg(),
200                     movie.getVhook(),
201                     fo,
202                     conv.isVhookDisabled(),
203                     conv.getMaxNumOfComment(),
204                     conv.getFont(),
205                     conv.getFontIndex(),
206                     conv.getShadowIndex(),
207                     conv.isShowConverting(),
208                     conv.isSelfAdjustFontSize(),
209                     conv.isCommentOpaque(),
210                     conv.getNgSetting());
211         }
212     }
213
214     public static void saveSetting(SProperties setting) {
215         final Properties prop = new Properties();
216         setting.getBasicSetting().save(prop);
217         setting.getInputVideoSetting().save(prop);
218         setting.getInputCommentSetting().save(prop);
219         setting.getInputTcommentSetting().save(prop);
220         setting.getOutputVideoSetting().save(prop);
221         setting.getMovieSetting().save(prop);
222         setting.getConvertSetting().save(prop);
223         try {
224             prop.storeToXML(new FileOutputStream(PROP_FILE), "settings");
225         } catch (IOException ex) {
226             ex.printStackTrace();
227         }
228     }
229
230     public static SProperties loadSetting(String user, String password) {
231         Properties prop = new Properties();
232         try {
233             prop.loadFromXML(new FileInputStream(PROP_FILE));
234         } catch (IOException ex) {
235             ex.printStackTrace();
236         }
237
238         return new SProperties(
239                 BasicSetting.load(prop, user, password),
240                 InputVideoSetting.load(prop),
241                 InputCommentSetting.load(prop),
242                 InputTcommentSetting.load(prop),
243                 OutputVideoSetting.load(prop),
244                 MovieSetting.load(prop),
245                 ConvertSetting.load(prop));
246     }
247
248     public BasicSetting getBasicSetting() {
249         return basicSetting;
250     }
251
252     public InputVideoSetting getInputVideoSetting() {
253         return inputVideoSetting;
254     }
255
256     public InputCommentSetting getInputCommentSetting() {
257         return inputCommentSetting;
258     }
259
260     public InputTcommentSetting getInputTcommentSetting() {
261         return inputTcommentSetting;
262     }
263
264     public OutputVideoSetting getOutputVideoSetting() {
265         return outputVideoSetting;
266     }
267
268     public MovieSetting getMovieSetting() {
269         return movieSetting;
270     }
271
272     public ConvertSetting getConvertSetting() {
273         return convertSetting;
274     }
275 }