OSDN Git Service

NicoBrowser連携でファイル名取得するフィールドを間違っていた
[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.filegetter.LoginInfo;
12 import saccubus.converter.profile.CommentGetInfo;
13 import saccubus.converter.profile.Ffmpeg;
14 import saccubus.converter.profile.FfmpegOption;
15 import saccubus.converter.profile.GeneralSetting;
16 import saccubus.converter.profile.InputFileSetting;
17 import saccubus.converter.profile.OutputFileSetting;
18 import saccubus.converter.profile.Profile;
19 import saccubus.converter.profile.Proxy;
20 import saccubus.converter.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         }
147
148         private InputFileSetting buildCommentSetting() {
149             return createCommentSetting(getInputCommentSetting());
150         }
151
152         private CommentGetInfo buildCommentGetInfo() {
153             final InputCommentSetting setting = getInputCommentSetting();
154             return new CommentGetInfo(setting.isSelfAdjustNumOfComment(), setting.getNumOfComment());
155         }
156
157         private InputFileSetting buildTcommentSetting() {
158             return createCommentSetting(getInputTcommentSetting());
159         }
160
161         private InputFileSetting createCommentSetting(saccubus.properties.InputFileSetting<Boolean> setting) {
162             SFile file = createSFile(setting);
163
164             return new InputFileSetting(file, setting.getProcessKind().booleanValue(), setting.isDeleteAfterConvert());
165
166         }
167
168         private SFile createSFile(ProcessFileSetting<Boolean> setting) {
169             File f;
170             if (setting.isAutoNaming()) {
171                 f = setting.getFolder();
172             } else {
173                 f = setting.getFile();
174             }
175             final SFile file = new SFile(!setting.isAutoNaming(), f);
176             return file;
177         }
178
179         private OutputFileSetting buildOutputFileSetting() {
180             final OutputVideoSetting setting = getOutputVideoSetting();
181
182             SFile file = createSFile(setting);
183             return new OutputFileSetting(file, setting.getProcessKind().booleanValue(), !setting.isCutIdName(), setting.
184                     isAddComment(), setting.isAddTcomment());
185         }
186
187         private Ffmpeg buildFfmpeg() throws IOException {
188             final MovieSetting movie = getMovieSetting();
189             final ConvertSetting conv = getConvertSetting();
190
191             FfmpegOption fo = movie.getFfmpegOption();
192             if (movie.getOptionFile() != null) {
193                 try {
194                     fo = FfmpegOption.load(movie.getOptionFile());
195                 } catch (IOException ex) {
196                     throw new IOException("オプションファイルの書式が誤っています:" + movie.getOptionFile().getName(), ex);
197                 }
198             }
199
200             return new Ffmpeg(
201                     movie.getFfmpeg(),
202                     movie.getVhook(),
203                     fo,
204                     conv.isVhookDisabled(),
205                     conv.getMaxNumOfComment(),
206                     conv.getFont(),
207                     conv.getFontIndex(),
208                     conv.getShadowIndex(),
209                     conv.isShowConverting(),
210                     conv.isSelfAdjustFontSize(),
211                     conv.isCommentOpaque(),
212                     conv.getNgSetting());
213         }
214     }
215
216     public static void saveSetting(SProperties setting) {
217         final Properties prop = new Properties();
218         setting.getBasicSetting().save(prop);
219         setting.getInputVideoSetting().save(prop);
220         setting.getInputCommentSetting().save(prop);
221         setting.getInputTcommentSetting().save(prop);
222         setting.getOutputVideoSetting().save(prop);
223         setting.getMovieSetting().save(prop);
224         setting.getConvertSetting().save(prop);
225         try {
226             prop.storeToXML(new FileOutputStream(PROP_FILE), "settings");
227         } catch (IOException ex) {
228             Logger.getLogger(SProperties.class.getName()).log(Level.SEVERE, "コンフィグファイルの保存に失敗", ex);
229         }
230     }
231
232     public static SProperties loadSetting(String user, String password) {
233         Properties prop = new Properties();
234         try {
235             prop.loadFromXML(new FileInputStream(PROP_FILE));
236         } catch (IOException ex) {
237             Logger.getLogger(SProperties.class.getName()).log(Level.INFO, "コンフィグファイルが存在しないため自動生成します", ex);
238         }
239
240         return new SProperties(
241                 BasicSetting.load(prop, user, password),
242                 InputVideoSetting.load(prop),
243                 InputCommentSetting.load(prop),
244                 InputTcommentSetting.load(prop),
245                 OutputVideoSetting.load(prop),
246                 MovieSetting.load(prop),
247                 ConvertSetting.load(prop));
248     }
249
250     public BasicSetting getBasicSetting() {
251         return basicSetting;
252     }
253
254     public InputVideoSetting getInputVideoSetting() {
255         return inputVideoSetting;
256     }
257
258     public InputCommentSetting getInputCommentSetting() {
259         return inputCommentSetting;
260     }
261
262     public InputTcommentSetting getInputTcommentSetting() {
263         return inputTcommentSetting;
264     }
265
266     public OutputVideoSetting getOutputVideoSetting() {
267         return outputVideoSetting;
268     }
269
270     public MovieSetting getMovieSetting() {
271         return movieSetting;
272     }
273
274     public ConvertSetting getConvertSetting() {
275         return convertSetting;
276     }
277 }