* @author 未入力
* @version 1.0
*/
-public class Download extends SwingWorker<DownloadResult, DownloadProgress> implements Callable<Boolean> {
+public class Download extends Worker<DownloadResult, DownloadProgress> {
private static final Logger logger = Logger.getLogger(Download.class.getName());
private final DownloadProfile profile;
private final String videoId;
+ public Download(DownloadProfile profile, String videoId) {
+ this(profile, videoId, null);
+ }
+
/**
* コンバータを構築します.
* @param videoId 対象となる動画のID.
* @param listener
* @param flag
*/
- public Download(DownloadProfile profile, String videoId) {
+ public Download(DownloadProfile profile, String videoId, SaccubusListener<DownloadProgress> listener) {
+ // TODO listener登録
+ super(listener);
this.videoId = videoId;
this.profile = profile;
}
- @Override
- public Boolean call() throws Exception {
- try {
- final DownloadResult result = doInBackground();
- return Boolean.valueOf(result.getResultValue());
- } finally {
- // TODO 何か処理が必要?
-// getStopFlag().finished();
- }
- }
-
+// @Override
+// public Boolean call() throws Exception {
+// try {
+// final DownloadResult result = doInBackground();
+// return Boolean.valueOf(result.getResultValue());
+// } finally {
+// // TODO 何か処理が必要?
+//// getStopFlag().finished();
+// }
+// }
// // TODO Runnableを実装しなくなったので削除する
// public void run() {
// try {
// }
// }
@Override
- protected DownloadResult doInBackground() throws Exception {
- if (!needsDownload(profile)) {
- publish(new DownloadProgress("何もすることがありません"));
- return new DownloadResult(true);
- }
+ public DownloadResult call() throws Exception {
publish(new DownloadProgress("ログイン中"));
client = createClientAndLogin();
vi = client.getVideoInfo(videoId);
- final String name = profile.getVideoSetting().getFileName();
- final String replaceFrom = profile.getGeneralSetting().getReplaceFrom();
- final String replaceTo = profile.getGeneralSetting().getReplaceTo();
+ final String name = profile.getVideoProfile().getFileName();
+ final String replaceFrom = profile.getGeneralProfile().getReplaceFrom();
+ final String replaceTo = profile.getGeneralProfile().getReplaceTo();
videoNamePattern = new NamePattern(name, replaceFrom, replaceTo, vi.getTitleInWatchPage());
if (needsBackLog()) {
final String key = client.getWayBackKey(vi);
- wbi = new WayBackInfo(key, profile.getCommentSetting().getBackLogPoint());
+ wbi = new WayBackInfo(key, profile.getCommentProfile().getBackLogPoint());
}
}
checkStop();
File commentFile;
- if (profile.getCommentSetting().isDownload()) {
- final CommentProfile prof = profile.getCommentSetting();
- final GeneralProfile gene = profile.getGeneralSetting();
+ if (profile.getCommentProfile().isDownload()) {
+ final CommentProfile prof = profile.getCommentProfile();
+ final GeneralProfile gene = profile.getGeneralProfile();
final NamePattern pattern = new NamePattern(prof.getFileName(), gene.getReplaceFrom(), gene.getReplaceTo(),
vi.getTitleInWatchPage());
// TODO コメントファイルに{low}は使えないことをどこかに書くべきか
final String name = pattern.createFileName(videoId, true);
- final File file = new File(profile.getCommentSetting().getDir(), name);
+ final File file = new File(profile.getCommentProfile().getDir(), name);
- commentFile = client.getCommentFile(vi, file.getPath(), wbi, profile.getCommentSetting().
+ commentFile = client.getCommentFile(vi, file.getPath(), wbi, profile.getCommentProfile().
getLengthRelatedCommentSize(),
- profile.getCommentSetting().isDisablePerMinComment());
+ profile.getCommentProfile().isDisablePerMinComment());
} else {
- commentFile = profile.getCommentSetting().getLocalFile();
+ commentFile = profile.getCommentProfile().getLocalFile();
}
checkStop();
File videoFile;
- GetFlvResult vf = null;
- if (profile.getVideoSetting().isDownload()) {
- vf = client.getFlvFile(vi, profile.getVideoSetting().getDir(), videoNamePattern,
+ GetFlvResult vf;
+ if (profile.getVideoProfile().isDownload()) {
+ vf = client.getFlvFile(vi, profile.getVideoProfile().getDir(), videoNamePattern,
Status.GET_INFO, true, new ProgressListener() {
@Override
videoFile = vf.getFile();
} else {
- videoFile = profile.getVideoSetting().getLocalFile();
+ videoFile = profile.getVideoProfile().getLocalFile();
}
- return new DownloadResult(true);
+ return new DownloadResult(true, videoFile, commentFile);
// TODO FFMPEG 実行開始は別タスクとして実装する.
/** @return 何かダウンロードするものがあればtrue. */
private static boolean needsDownload(DownloadProfile profile) {
- return (profile.getVideoSetting().isDownload() || profile.getCommentSetting().isDownload());
+ return (profile.getVideoProfile().isDownload() || profile.getCommentProfile().isDownload());
}
// TODO どこかに処理を移す必要がある.
// }
// }
// }
-
/**
* HttpClientを生成し, ニコニコ動画サーバへログインします.
* @return 生成したHttpClientインスタンス.
*/
// TODO HttpException を投げるのをやめたい. コンパイル時にHttpComponentが必要になるので.
private NicoHttpClient createClientAndLogin() throws IOException, InterruptedException, HttpException {
- final NicoHttpClient client = createClient(profile.getProxySetting());
+ final NicoHttpClient client = createClient(profile.getProxyProfile());
final boolean hasLogin;
try {
hasLogin = client.login(profile.getLoginInfo().getMail(), profile.getLoginInfo().getPassword());
/** @return ログインする必要があればtrue. */
private boolean needsLogin() {
- return profile.getVideoSetting().isDownload() || profile.getCommentSetting().isDownload();
+ return profile.getVideoProfile().isDownload() || profile.getCommentProfile().isDownload();
}
/** @return 過去ログ取得の必要があればtrue. */
private boolean needsBackLog() {
- return profile.getCommentSetting().getBackLogPoint() >= 0L;
+ return profile.getCommentProfile().getBackLogPoint() >= 0L;
}
private void checkStop() throws InterruptedException {