OSDN Git Service

過去ログ取得時点をConverterコンストラクタ引数からProfileに移動
[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 java.util.logging.Level;
9 import java.util.logging.Logger;
10 import saccubus.VideoSaveKind;
11 import saccubus.converter.classic.profile.LoginInfo;
12 import saccubus.converter.classic.profile.CommentGetInfo;
13 import saccubus.converter.classic.profile.Ffmpeg;
14 import saccubus.converter.classic.profile.FfmpegOption;
15 import saccubus.converter.classic.profile.GeneralSetting;
16 import saccubus.converter.classic.profile.InputFileSetting;
17 import saccubus.converter.classic.profile.OutputFileSetting;
18 import saccubus.converter.classic.profile.Profile;
19 import saccubus.converter.classic.profile.Proxy;
20 import saccubus.converter.classic.profile.SFile;
21
22 /**
23  * <p>
24  * タイトル: さきゅばす
25  * </p>
26  *
27  * <p>
28  * 説明: ニコニコ動画の動画をコメントつきで保存
29  * </p>
30  *
31  * <p>
32  * 著作権: Copyright (c) 2007 PSI
33  * </p>
34  *
35  * <p>
36  * 会社名:
37  * </p>
38  *
39  * @author 未入力
40  * @version 1.0
41  */
42 public class SProperties {
43
44     private static final String PROP_FILE = "./saccubus.xml";
45     public static final String[] ShadowKindArray = {
46         "00:なし",
47         "01:ニコニコ動画風",
48         "02:右下",
49         "03:囲い込み"
50     };
51     private final BasicSetting basicSetting;
52     private final InputVideoSetting inputVideoSetting;
53     private final InputCommentSetting inputCommentSetting;
54     private final InputTcommentSetting inputTcommentSetting;
55     private final OutputVideoSetting outputVideoSetting;
56     private final MovieSetting movieSetting;
57     private final ConvertSetting convertSetting;
58
59     public SProperties(
60             BasicSetting basicSetting,
61             InputVideoSetting inputVideoSetting,
62             InputCommentSetting inputCommentSetting,
63             InputTcommentSetting tcommentSetting,
64             OutputVideoSetting outputVideoSetting,
65             MovieSetting movieSetting,
66             ConvertSetting convertSetting //            String videoshownum,
67             ) {
68 //        this.saveVideo = savevideo;
69 //        if (videofile.lastIndexOf(".") < videofile.lastIndexOf("\\")) {
70 //            videofile += ".flv";
71 //        }
72 //        VideoFile = new File(videofile);
73
74 //        if (commentfile.lastIndexOf(".") < commentfile.lastIndexOf("\\")) {
75 //            commentfile += ".xml";
76 //        }
77 //        CommentFile = new File(commentfile);
78
79 //        if (convvideofile.lastIndexOf(".") < convvideofile.lastIndexOf("\\")) {
80 //            convvideofile += ".avi";
81 //        }
82
83         this.basicSetting = basicSetting;
84         this.inputVideoSetting = inputVideoSetting;
85         this.inputCommentSetting = inputCommentSetting;
86         this.inputTcommentSetting = tcommentSetting;
87         this.outputVideoSetting = outputVideoSetting;
88         this.movieSetting = movieSetting;
89         this.convertSetting = convertSetting;
90     }
91
92     public Profile toProfile() throws IOException {
93         return new ProfileBuilder().build();
94     }
95
96     private class ProfileBuilder {
97
98         private Profile build() throws IOException {
99             GeneralSetting generalSetting = buildGeneralSetting();
100             LoginInfo loginInfo = buildLoginInfo();
101             InputFileSetting videoSetting = buildVideoSetting();
102             InputFileSetting commentSetting = buildCommentSetting();
103             CommentGetInfo commentGetInfo = buildCommentGetInfo();
104             InputFileSetting tcommentSetting = buildTcommentSetting();
105             OutputFileSetting outputFileSetting = buildOutputFileSetting();
106             Ffmpeg ffmpeg = buildFfmpeg();
107
108             return new Profile(generalSetting, loginInfo, videoSetting, commentSetting, commentGetInfo, tcommentSetting,
109                     outputFileSetting, ffmpeg);
110         }
111
112         private GeneralSetting buildGeneralSetting() {
113             final BasicSetting basic = getBasicSetting();
114             return new GeneralSetting(basic.getTempDir());
115         }
116
117         private LoginInfo buildLoginInfo() {
118             final BasicSetting basic = getBasicSetting();
119             Proxy proxy = Proxy.NO_PROXY;
120             if (basic.isProxyUse()) {
121                 proxy = new Proxy(basic.getProxyHost(), basic.getProxyPort());
122             }
123             final LoginInfo loginInfo = new LoginInfo(basic.getUser().getMail(), basic.getUser().getPassword(), proxy);
124             return loginInfo;
125         }
126
127         private InputFileSetting buildVideoSetting() {
128             final InputVideoSetting setting = getInputVideoSetting();
129             // Nicobrowserダウンロードファイルの場合は常にファイル指定.
130             final boolean isFile = (!setting.isAutoNaming() || setting.getProcessKind() == VideoSaveKind.NICOBROWSER);
131             File video;
132             if (setting.getProcessKind() == VideoSaveKind.NICOBROWSER) {
133                 video = setting.getNicoBrowserFile();
134             } else {
135                 if (setting.isAutoNaming()) {
136                     video = setting.getFolder();
137                 } else {
138                     video = setting.getFile();
139                 }
140             }
141             final SFile videoFile = new SFile(isFile, video);
142             // Nicobrowserダウンロードファイルは削除対象にならない.
143             boolean delete = setting.isDeleteAfterConvert() && (setting.getProcessKind() != VideoSaveKind.NICOBROWSER);
144
145             return new InputFileSetting(videoFile, (setting.getProcessKind() == VideoSaveKind.SAVE), delete,
146                     buildCommentGetInfo(), inputCommentSetting.getBackLogPoint());
147         }
148
149         private InputFileSetting buildCommentSetting() {
150             return createCommentSetting(getInputCommentSetting());
151         }
152
153         private CommentGetInfo buildCommentGetInfo() {
154             final InputCommentSetting setting = getInputCommentSetting();
155             return new CommentGetInfo(setting.isSelfAdjustNumOfComment(), setting.getNumOfComment(), setting.
156                     isReduceComment());
157         }
158
159         private InputFileSetting buildTcommentSetting() {
160             return createCommentSetting(getInputTcommentSetting());
161         }
162
163         private InputFileSetting createCommentSetting(saccubus.properties.InputFileSetting<Boolean> setting) {
164             SFile file = createSFile(setting);
165
166             return new InputFileSetting(file, setting.getProcessKind().booleanValue(), setting.isDeleteAfterConvert(),
167                     buildCommentGetInfo(), inputCommentSetting.getBackLogPoint());
168
169         }
170
171         private SFile createSFile(ProcessFileSetting<Boolean> setting) {
172             File f;
173             if (setting.isAutoNaming()) {
174                 f = setting.getFolder();
175             } else {
176                 f = setting.getFile();
177             }
178             final SFile file = new SFile(!setting.isAutoNaming(), f);
179             return file;
180         }
181
182         private OutputFileSetting buildOutputFileSetting() {
183             final OutputVideoSetting setting = getOutputVideoSetting();
184
185             SFile file = createSFile(setting);
186             return new OutputFileSetting(file, setting.getProcessKind().booleanValue(), !setting.isCutIdName(), setting.
187                     isAddComment(), setting.isAddTcomment());
188         }
189
190         private Ffmpeg buildFfmpeg() throws IOException {
191             final MovieSetting movie = getMovieSetting();
192             final ConvertSetting conv = getConvertSetting();
193
194             FfmpegOption fo = movie.getFfmpegOption();
195             if (movie.getOptionFile() != null) {
196                 try {
197                     fo = FfmpegOption.load(movie.getOptionFile());
198                 } catch (IOException ex) {
199                     throw new IOException("オプションファイルの書式が誤っています:" + movie.getOptionFile().getName(), ex);
200                 }
201             }
202
203             return new Ffmpeg(
204                     movie.getFfmpeg(),
205                     movie.getVhook(),
206                     fo,
207                     conv.isVhookDisabled(),
208                     conv.getMaxNumOfComment(),
209                     conv.getFont(),
210                     conv.getFontIndex(),
211                     conv.getShadowIndex(),
212                     conv.isShowConverting(),
213                     conv.isSelfAdjustFontSize(),
214                     conv.isCommentOpaque(),
215                     conv.getNgSetting());
216         }
217     }
218
219     public static void saveSetting(SProperties setting) {
220         final Properties prop = new Properties();
221         setting.getBasicSetting().save(prop);
222         setting.getInputVideoSetting().save(prop);
223         setting.getInputCommentSetting().save(prop);
224         setting.getInputTcommentSetting().save(prop);
225         setting.getOutputVideoSetting().save(prop);
226         setting.getMovieSetting().save(prop);
227         setting.getConvertSetting().save(prop);
228         try {
229             prop.storeToXML(new FileOutputStream(PROP_FILE), "settings");
230         } catch (IOException ex) {
231             Logger.getLogger(SProperties.class.getName()).log(Level.SEVERE, "コンフィグファイルの保存に失敗", ex);
232         }
233     }
234
235     public static SProperties loadSetting(String user, String password) {
236         Properties prop = new Properties();
237         try {
238             prop.loadFromXML(new FileInputStream(PROP_FILE));
239         } catch (IOException ex) {
240             Logger.getLogger(SProperties.class.getName()).log(Level.INFO, "コンフィグファイルが存在しないため自動生成します", ex);
241         }
242
243         return new SProperties(
244                 BasicSetting.load(prop, user, password),
245                 InputVideoSetting.load(prop),
246                 InputCommentSetting.load(prop),
247                 InputTcommentSetting.load(prop),
248                 OutputVideoSetting.load(prop),
249                 MovieSetting.load(prop),
250                 ConvertSetting.load(prop));
251     }
252
253     public BasicSetting getBasicSetting() {
254         return basicSetting;
255     }
256
257     public InputVideoSetting getInputVideoSetting() {
258         return inputVideoSetting;
259     }
260
261     public InputCommentSetting getInputCommentSetting() {
262         return inputCommentSetting;
263     }
264
265     public InputTcommentSetting getInputTcommentSetting() {
266         return inputTcommentSetting;
267     }
268
269     public OutputVideoSetting getOutputVideoSetting() {
270         return outputVideoSetting;
271     }
272
273     public MovieSetting getMovieSetting() {
274         return movieSetting;
275     }
276
277     public ConvertSetting getConvertSetting() {
278         return convertSetting;
279     }
280 }