import java.io.IOException;
import java.net.URISyntaxException;
import java.util.concurrent.Callable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import nicobrowser.GetFlvResult;
import nicobrowser.NamePattern;
import nicobrowser.NicoHttpClient;
import nicobrowser.WayBackInfo;
import nicobrowser.entity.NicoContent.Status;
import saccubus.ConvertStopFlag;
-import saccubus.converter.filegetter.FileInstanciator;
-import saccubus.net.CommentInfo;
import saccubus.net.TextProgressListener;
-import yukihane.inqubus.saccubus_adapter.NicoBrowserAdapter;
import yukihane.saccubus.converter.profile.CommentProfile;
import yukihane.saccubus.converter.profile.FfmpegOption;
-import yukihane.saccubus.converter.profile.LoinProfile;
+import yukihane.saccubus.converter.profile.GeneralProfile;
+import yukihane.saccubus.converter.profile.OutputProfile;
import yukihane.saccubus.converter.profile.Profile;
import yukihane.saccubus.converter.profile.ProxyProfile;
-import yukihane.saccubus.converter.profile.VideoProfile;
/**
* <p>タイトル: さきゅばす</p>
// TODO ログインしないで良い場合もある.
sendText("ログイン中");
- final NicoHttpClient client = createClient(profile.getProxySetting());
- final boolean hasLogin;
- try {
- hasLogin = client.login(profile.getLoginInfo().getMail(), profile.getLoginInfo().getPass());
- if (!hasLogin) {
- throw new IOException("login fail");
+
+
+ NicoHttpClient client = null;
+ nicobrowser.VideoInfo vi = null;
+ NamePattern videoNamePattern = null;
+ WayBackInfo wbi = null;
+ if (needsLogin()) {
+ client = createClientAndLogin();
+ vi = client.getVideoInfo(movieId);
+
+ final String name = profile.getVideoSetting().getFileName();
+ final String replaceFrom = profile.getGeneralSetting().getReplaceFrom();
+ final String replaceTo = profile.getGeneralSetting().getReplaceTo();
+ videoNamePattern = new NamePattern(name, replaceFrom, replaceTo, vi.getTitleInWatchPage());
+
+ if (needsBackLog()) {
+ final String key = client.getWayBackKey(vi);
+ wbi = new WayBackInfo(key, profile.getCommentSetting().getBackLogPoint());
}
- } catch (URISyntaxException ex) {
- throw new IOException("login fail", ex);
}
- final nicobrowser.VideoInfo vi = client.getVideoInfo(movieId);
-
-// final FileInstanciator fi = createInstanciator();
stopFlagReturn();
- WayBackInfo wbi = null;
- if (profile.getCommentSetting().getBackLogPoint() >= 0L) {
- final String key = client.getWayBackKey(vi);
- wbi = new WayBackInfo(key, profile.getCommentSetting().getBackLogPoint());
- }
- File commentFile = client.getCommentFile(vi, profile.getCommentSetting().getFile().getPath(), wbi, profile.
- getCommentSetting().getBackComment(), profile.getCommentSetting().isReduceComment());
+ File commentFile;
+ if (profile.getCommentSetting().isDownload()) {
+ final CommentProfile prof = profile.getCommentSetting();
+ final GeneralProfile gene = profile.getGeneralSetting();
+
+ final NamePattern pattern = new NamePattern(prof.getFileName(), gene.getReplaceFrom(), gene.getReplaceTo(),
+ vi.getTitleInWatchPage());
+ // TODO コメントファイルに{low}は使えないことをどこかに書くべきか
+ final String name = pattern.createFileName(movieId, true);
+ final File file = new File(profile.getCommentSetting().getDir(), name);
+
+ commentFile = client.getCommentFile(vi, file.getPath(), wbi, profile.getCommentSetting().getBackComment(),
+ profile.getCommentSetting().isReduceComment());
+ } else {
+ commentFile = profile.getCommentSetting().getLocalFile();
+ }
stopFlagReturn();
- // File tcommFile = fi.getTcommFile(getListener());
- //
- // stopFlagReturn();
- // final File videoFile = getVideoFile(client, getListener(), profile.getVideoSetting());
- GetFlvResult vf = client.getFlvFile(vi, profile.getVideoSetting().getDir(), new NamePattern("test", "_", "_",
- "title"), Status.GET_INFO, true, new ProgressListener() {
-
- @Override
- public void progress(long fileSize, long downloadSize) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
- @Override
- public boolean getCancel() {
- throw new UnsupportedOperationException("Not supported yet.");
- }
- });
+ File videoFile;
+ GetFlvResult vf = null;
+ if (profile.getVideoSetting().isDownload()) {
+ vf = client.getFlvFile(vi, profile.getVideoSetting().getDir(), videoNamePattern,
+ Status.GET_INFO, true, new ProgressListener() {
+
+ @Override
+ public void progress(long fileSize, long downloadSize) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
- final File videoFile = vf.getFile();
+ @Override
+ public boolean getCancel() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ });
+
+ videoFile = vf.getFile();
+ } else {
+ videoFile = profile.getVideoSetting().getLocalFile();
+ }
if (!profile.getOutputFileSetting().isConvert()) {
sendText("動画・コメントを保存し、変換は行いませんでした。");
commentFile = null;
}
-// if (profile.getOutputFileSetting().isAddTcomment()) {
-// if (!tcommFile.isFile()) {
-// throw new IOException("入力投稿者コメントファイルが存在しません" + tcommFile.getPath());
-// }
-// } else {
-// tcommFile = null;
-// }
-
/*ビデオ名の確定*/
- File convertedVideoFile = videoFile;
-// if (!profile.getOutputFileSetting().getFile().isFile()) {
-// String conv_name = fi.getVideoTitle();
-// if (profile.getOutputFileSetting().isAppendPrefixVideoId()) {
-// conv_name = getVideoIDWithBracket() + conv_name;
-// }
-// convertedVideoFile = new File(profile.getOutputFileSetting().getFile().getFile(),
-// conv_name + ov.getExtOption());
-// } else {
-// String filename = profile.getOutputFileSetting().getFile().getFile().getPath();
-// if (!filename.endsWith(ov.getExtOption())) {
-// filename = filename.substring(0, filename.lastIndexOf('.')) + ov.getExtOption();
-// convertedVideoFile = new File(filename);
-// } else {
-// convertedVideoFile = profile.getOutputFileSetting().getFile().getFile();
-// }
-// }
+ final boolean isNotLow = (vf == null) ? true : (vf.getStatus() != Status.GET_LOW);
+ File convertedVideoFile = getOutputFileName(vi.getTitleInWatchPage(), isNotLow);
boolean res = new FfmpegCommand(getListener(), getStopFlag(), commentFile, videoFile,
convertedVideoFile, profile.getFfmpeg(), profile.getGeneralSetting()).execute();
return res;
}
-// private FileInstanciator createInstanciator() throws IOException {
-// FileInstanciator fi;
-//
-// FileInstanciator.InstanciationType videoType = new FileInstanciator.InstanciationType(profile.getVideoSetting());
-//
-// FileInstanciator.CommentInstanciationType commentType = new FileInstanciator.CommentInstanciationType(profile.
-// getCommentSetting(), profile.getCommentSetting().isSelfAdjustCommentNum(), profile.getCommentSetting().
-// getBackComment(), profile.getCommentSetting().isReduceComment());
-//
-// FileInstanciator.InstanciationType tcommType = new FileInstanciator.InstanciationType(
-// profile.getCommentSetting());
-//
-// fi = FileInstanciator.create(getStopFlag(), videoType, commentType, tcommType, profile.getLoginInfo(), profile.
-// getProxySetting(), movieId, profile.getCommentSetting().getBackLogPoint());
-// return fi;
-// }
+ public boolean isConverted() {
+ return getStopFlag().isFinished();
+ }
+
+ @Override
+ public ConvertStopFlag getStopFlag() {
+ return super.getStopFlag();
+ }
+
+ /** @return 何か実行すべき処理があればtrue. */
+ private static boolean shouldRun(Profile profile) {
+ return profile.getOutputFileSetting().isConvert() || needsDownload(profile);
+ }
+
+ /** @return 何かダウンロードするものがあればtrue. */
+ private static boolean needsDownload(Profile profile) {
+ return (profile.getVideoSetting().isDownload() || profile.getCommentSetting().isDownload());
+ }
/**
* (ネットワーク設定以外の)設定を検証する.
}
}
- private String getVideoIDWithBracket() {
- return "[" + movieId + "]";
- }
-
- public boolean isConverted() {
- return getStopFlag().isFinished();
- }
-
- @Override
- public ConvertStopFlag getStopFlag() {
- return super.getStopFlag();
- }
-
- /** @return 何か実行すべき処理があればtrue. */
- private static boolean shouldRun(Profile profile) {
- return profile.getOutputFileSetting().isConvert() || needsDownload(profile);
- }
-
- /** @return 何かダウンロードするものがあればtrue. */
- private static boolean needsDownload(Profile profile) {
- return (profile.getVideoSetting().isDownload() || profile.getCommentSetting().isDownload());
- }
-
-// private File getCommentFile(NicoBrowserAdapter client, VideoInfo vi, CommentProfile prof,
-// TextProgressListener listener) throws IOException {
-// if (prof.isDownload()) {
-// WayBackInfo wbi = null;
-// if (profile.getCommentSetting().getBackLogPoint() >= 0L) {
-// final String key = client.getWayBackKey(vi);
-// wbi = new WayBackInfo(key, profile.getCommentSetting().getBackLogPoint());
-// }
-//
-// return client.getCommentFile(nicoBrowserVi, prof.getFile().getPath(), wbi, prof.getBackComment(), prof.
-// isReduceComment());
-//
-//
-// } else {
-// }
-// }
- private File getVideoFile(NicoBrowserAdapter client, TextProgressListener listener, VideoProfile videoSetting) {
- throw new UnsupportedOperationException("Not yet implemented");
+ /**
+ * HttpClientを生成し, ニコニコ動画サーバへログインします.
+ * @return 生成したHttpClientインスタンス.
+ * @throws IOException ログイン失敗.
+ * @throws InterruptedException ログイン失敗.
+ */
+ private NicoHttpClient createClientAndLogin() throws IOException, InterruptedException {
+ final NicoHttpClient client = createClient(profile.getProxySetting());
+ final boolean hasLogin;
+ try {
+ hasLogin = client.login(profile.getLoginInfo().getMail(), profile.getLoginInfo().getPass());
+ if (!hasLogin) {
+ throw new IOException("login fail");
+ }
+ } catch (URISyntaxException ex) {
+ throw new IOException("login fail", ex);
+ }
+ return client;
}
private NicoHttpClient createClient(ProxyProfile proxy) {
return new NicoHttpClient();
}
}
+
+ /** @return ログインする必要があればtrue. */
+ private boolean needsLogin() {
+ return profile.getVideoSetting().isDownload() || profile.getCommentSetting().isDownload();
+ }
+
+ /** @return 過去ログ取得の必要があればtrue. */
+ private boolean needsBackLog() {
+ return profile.getCommentSetting().getBackLogPoint() >= 0L;
+ }
+
+ /**
+ * 出力ファイルの保存先を確定します.
+ * @param title 動画タイトル.
+ * @param isNotLow 入力動画ファイルがlowでないかどうか.
+ * @return 出力ファイルの保存先.
+ */
+ private File getOutputFileName(String title, boolean isNotLow) {
+ final OutputProfile prof = profile.getOutputFileSetting();
+ final GeneralProfile gene = profile.getGeneralSetting();
+ final File dir = prof.getDir();
+ final String replaceFrom = gene.getReplaceFrom();
+ final String replaceTo = gene.getReplaceTo();
+ final NamePattern pattern = new NamePattern(prof.getFileName(), replaceFrom, replaceTo, title);
+ final String name = pattern.createFileName(movieId, isNotLow);
+ return new File(dir, name);
+ }
}