1 package saccubus.properties;
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;
28 * 説明: ニコニコ動画の動画をコメントつきで保存
32 * 著作権: Copyright (c) 2007 PSI
42 public class SProperties {
44 private static final String PROP_FILE = "./saccubus.xml";
45 public static final String[] ShadowKindArray = {
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;
60 BasicSetting basicSetting,
61 InputVideoSetting inputVideoSetting,
62 InputCommentSetting inputCommentSetting,
63 InputTcommentSetting tcommentSetting,
64 OutputVideoSetting outputVideoSetting,
65 MovieSetting movieSetting,
66 ConvertSetting convertSetting // String videoshownum,
68 // this.saveVideo = savevideo;
69 // if (videofile.lastIndexOf(".") < videofile.lastIndexOf("\\")) {
70 // videofile += ".flv";
72 // VideoFile = new File(videofile);
74 // if (commentfile.lastIndexOf(".") < commentfile.lastIndexOf("\\")) {
75 // commentfile += ".xml";
77 // CommentFile = new File(commentfile);
79 // if (convvideofile.lastIndexOf(".") < convvideofile.lastIndexOf("\\")) {
80 // convvideofile += ".avi";
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;
92 public Profile toProfile() throws IOException {
93 return new ProfileBuilder().build();
96 private class ProfileBuilder {
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();
108 return new Profile(generalSetting, loginInfo, videoSetting, commentSetting, commentGetInfo, tcommentSetting,
109 outputFileSetting, ffmpeg);
112 private GeneralSetting buildGeneralSetting() {
113 final BasicSetting basic = getBasicSetting();
114 return new GeneralSetting(basic.getTempDir());
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());
123 final LoginInfo loginInfo = new LoginInfo(basic.getUser().getMail(), basic.getUser().getPassword(), proxy);
127 private InputFileSetting buildVideoSetting() {
128 final InputVideoSetting setting = getInputVideoSetting();
129 // Nicobrowserダウンロードファイルの場合は常にファイル指定.
130 final boolean isFile = (!setting.isAutoNaming() || setting.getProcessKind() == VideoSaveKind.NICOBROWSER);
132 if (setting.getProcessKind() == VideoSaveKind.NICOBROWSER) {
133 video = setting.getNicoBrowserFile();
135 if (setting.isAutoNaming()) {
136 video = setting.getFolder();
138 video = setting.getFile();
141 final SFile videoFile = new SFile(isFile, video);
142 // Nicobrowserダウンロードファイルは削除対象にならない.
143 boolean delete = setting.isDeleteAfterConvert() && (setting.getProcessKind() != VideoSaveKind.NICOBROWSER);
145 return new InputFileSetting(videoFile, (setting.getProcessKind() == VideoSaveKind.SAVE), delete,
146 buildCommentGetInfo());
149 private InputFileSetting buildCommentSetting() {
150 return createCommentSetting(getInputCommentSetting());
153 private CommentGetInfo buildCommentGetInfo() {
154 final InputCommentSetting setting = getInputCommentSetting();
155 return new CommentGetInfo(setting.isSelfAdjustNumOfComment(), setting.getNumOfComment(), setting.
159 private InputFileSetting buildTcommentSetting() {
160 return createCommentSetting(getInputTcommentSetting());
163 private InputFileSetting createCommentSetting(saccubus.properties.InputFileSetting<Boolean> setting) {
164 SFile file = createSFile(setting);
166 return new InputFileSetting(file, setting.getProcessKind().booleanValue(), setting.isDeleteAfterConvert(),
167 buildCommentGetInfo());
171 private SFile createSFile(ProcessFileSetting<Boolean> setting) {
173 if (setting.isAutoNaming()) {
174 f = setting.getFolder();
176 f = setting.getFile();
178 final SFile file = new SFile(!setting.isAutoNaming(), f);
182 private OutputFileSetting buildOutputFileSetting() {
183 final OutputVideoSetting setting = getOutputVideoSetting();
185 SFile file = createSFile(setting);
186 return new OutputFileSetting(file, setting.getProcessKind().booleanValue(), !setting.isCutIdName(), setting.
187 isAddComment(), setting.isAddTcomment());
190 private Ffmpeg buildFfmpeg() throws IOException {
191 final MovieSetting movie = getMovieSetting();
192 final ConvertSetting conv = getConvertSetting();
194 FfmpegOption fo = movie.getFfmpegOption();
195 if (movie.getOptionFile() != null) {
197 fo = FfmpegOption.load(movie.getOptionFile());
198 } catch (IOException ex) {
199 throw new IOException("オプションファイルの書式が誤っています:" + movie.getOptionFile().getName(), ex);
207 conv.isVhookDisabled(),
208 conv.getMaxNumOfComment(),
211 conv.getShadowIndex(),
212 conv.isShowConverting(),
213 conv.isSelfAdjustFontSize(),
214 conv.isCommentOpaque(),
215 conv.getNgSetting());
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);
229 prop.storeToXML(new FileOutputStream(PROP_FILE), "settings");
230 } catch (IOException ex) {
231 Logger.getLogger(SProperties.class.getName()).log(Level.SEVERE, "コンフィグファイルの保存に失敗", ex);
235 public static SProperties loadSetting(String user, String password) {
236 Properties prop = new Properties();
238 prop.loadFromXML(new FileInputStream(PROP_FILE));
239 } catch (IOException ex) {
240 Logger.getLogger(SProperties.class.getName()).log(Level.INFO, "コンフィグファイルが存在しないため自動生成します", ex);
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));
253 public BasicSetting getBasicSetting() {
257 public InputVideoSetting getInputVideoSetting() {
258 return inputVideoSetting;
261 public InputCommentSetting getInputCommentSetting() {
262 return inputCommentSetting;
265 public InputTcommentSetting getInputTcommentSetting() {
266 return inputTcommentSetting;
269 public OutputVideoSetting getOutputVideoSetting() {
270 return outputVideoSetting;
273 public MovieSetting getMovieSetting() {
277 public ConvertSetting getConvertSetting() {
278 return convertSetting;