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 saccubus.VideoSaveKind;
9 import saccubus.converter.filegetter.LoginInfo;
10 import saccubus.converter.classic.profile.CommentGetInfo;
11 import saccubus.converter.classic.profile.Ffmpeg;
12 import saccubus.converter.classic.profile.FfmpegOption;
13 import saccubus.converter.classic.profile.GeneralSetting;
14 import saccubus.converter.classic.profile.InputFileSetting;
15 import saccubus.converter.classic.profile.OutputFileSetting;
16 import saccubus.converter.classic.profile.Profile;
17 import saccubus.converter.classic.profile.Proxy;
18 import saccubus.converter.classic.profile.SFile;
26 * 説明: ニコニコ動画の動画をコメントつきで保存
30 * 著作権: Copyright (c) 2007 PSI
40 public class SProperties {
42 private static final String PROP_FILE = "./saccubus.xml";
43 public static final String[] ShadowKindArray = {
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;
58 BasicSetting basicSetting,
59 InputVideoSetting inputVideoSetting,
60 InputCommentSetting inputCommentSetting,
61 InputTcommentSetting tcommentSetting,
62 OutputVideoSetting outputVideoSetting,
63 MovieSetting movieSetting,
64 ConvertSetting convertSetting // String videoshownum,
66 // this.saveVideo = savevideo;
67 // if (videofile.lastIndexOf(".") < videofile.lastIndexOf("\\")) {
68 // videofile += ".flv";
70 // VideoFile = new File(videofile);
72 // if (commentfile.lastIndexOf(".") < commentfile.lastIndexOf("\\")) {
73 // commentfile += ".xml";
75 // CommentFile = new File(commentfile);
77 // if (convvideofile.lastIndexOf(".") < convvideofile.lastIndexOf("\\")) {
78 // convvideofile += ".avi";
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;
90 public Profile toProfile() throws IOException {
91 return new ProfileBuilder().build();
94 private class ProfileBuilder {
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();
106 return new Profile(generalSetting, loginInfo, videoSetting, commentSetting, commentGetInfo, tcommentSetting,
107 outputFileSetting, ffmpeg);
110 private GeneralSetting buildGeneralSetting() {
111 final BasicSetting basic = getBasicSetting();
112 return new GeneralSetting(basic.getTempDir());
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());
121 final LoginInfo loginInfo = new LoginInfo(basic.getUser().getMail(), basic.getUser().getPassword(), proxy);
125 private InputFileSetting buildVideoSetting() {
126 final InputVideoSetting setting = getInputVideoSetting();
127 // Nicobrowserダウンロードファイルの場合は常にファイル指定.
128 final boolean isFile = (!setting.isAutoNaming() || setting.getProcessKind() == VideoSaveKind.NICOBROWSER);
130 if (setting.getProcessKind() == VideoSaveKind.NICOBROWSER) {
131 video = setting.getFile();
133 if (setting.isAutoNaming()) {
134 video = setting.getFolder();
136 video = setting.getFile();
139 final SFile videoFile = new SFile(isFile, video);
140 // Nicobrowserダウンロードファイルは削除対象にならない.
141 boolean delete = setting.isDeleteAfterConvert() && (setting.getProcessKind() != VideoSaveKind.NICOBROWSER);
143 return new InputFileSetting(videoFile, (setting.getProcessKind() == VideoSaveKind.SAVE), delete);
146 private InputFileSetting buildCommentSetting() {
147 return createCommentSetting(getInputCommentSetting());
150 private CommentGetInfo buildCommentGetInfo() {
151 final InputCommentSetting setting = getInputCommentSetting();
152 return new CommentGetInfo(setting.isSelfAdjustNumOfComment(), setting.getNumOfComment());
155 private InputFileSetting buildTcommentSetting() {
156 return createCommentSetting(getInputTcommentSetting());
159 private InputFileSetting createCommentSetting(saccubus.properties.InputFileSetting<Boolean> setting) {
160 SFile file = createSFile(setting);
162 return new InputFileSetting(file, setting.getProcessKind().booleanValue(), setting.isDeleteAfterConvert());
166 private SFile createSFile(ProcessFileSetting<Boolean> setting) {
168 if (setting.isAutoNaming()) {
169 f = setting.getFolder();
171 f = setting.getFile();
173 final SFile file = new SFile(!setting.isAutoNaming(), f);
177 private OutputFileSetting buildOutputFileSetting() {
178 final OutputVideoSetting setting = getOutputVideoSetting();
180 SFile file = createSFile(setting);
181 return new OutputFileSetting(file, setting.getProcessKind().booleanValue(), !setting.isCutIdName(), setting.
182 isAddComment(), setting.isAddTcomment());
185 private Ffmpeg buildFfmpeg() throws IOException {
186 final MovieSetting movie = getMovieSetting();
187 final ConvertSetting conv = getConvertSetting();
189 FfmpegOption fo = movie.getFfmpegOption();
190 if (movie.getOptionFile() != null) {
192 fo = FfmpegOption.load(movie.getOptionFile());
193 } catch (IOException ex) {
194 throw new IOException("オプションファイルの書式が誤っています:" + movie.getOptionFile().getName(), ex);
202 conv.isVhookDisabled(),
203 conv.getMaxNumOfComment(),
206 conv.getShadowIndex(),
207 conv.isShowConverting(),
208 conv.isSelfAdjustFontSize(),
209 conv.isCommentOpaque(),
210 conv.getNgSetting());
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);
224 prop.storeToXML(new FileOutputStream(PROP_FILE), "settings");
225 } catch (IOException ex) {
226 ex.printStackTrace();
230 public static SProperties loadSetting(String user, String password) {
231 Properties prop = new Properties();
233 prop.loadFromXML(new FileInputStream(PROP_FILE));
234 } catch (IOException ex) {
235 ex.printStackTrace();
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));
248 public BasicSetting getBasicSetting() {
252 public InputVideoSetting getInputVideoSetting() {
253 return inputVideoSetting;
256 public InputCommentSetting getInputCommentSetting() {
257 return inputCommentSetting;
260 public InputTcommentSetting getInputTcommentSetting() {
261 return inputTcommentSetting;
264 public OutputVideoSetting getOutputVideoSetting() {
265 return outputVideoSetting;
268 public MovieSetting getMovieSetting() {
272 public ConvertSetting getConvertSetting() {
273 return convertSetting;