package saccubus.converter;
- import yukihane.saccubus.converter.profile.Profile;
-import java.util.regex.Matcher;
-import saccubus.converter.profile.Profile;
-import saccubus.converter.profile.FfmpegOption;
--import saccubus.converter.filegetter.FileInstanciator;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.Callable;
++import java.util.regex.Matcher;
+ import java.util.regex.Pattern;
import saccubus.ConvertStopFlag;
- import yukihane.saccubus.converter.profile.FfmpegOption;
++import saccubus.converter.filegetter.FileInstanciator;
import saccubus.net.TextProgressListener;
++import yukihane.saccubus.converter.profile.FfmpegOption;
++import yukihane.saccubus.converter.profile.Profile;
/**
* <p>タイトル: さきゅばす</p>
*/
public class Converter extends AbstractCommand implements Runnable, Callable<Boolean> {
- private static final String VIDEO_URL_PARSER = "http://www.nicovideo.jp/watch/";
- private final Profile Setting;
- private final String Tag;
- private final String Time;
+ private final Profile profile;
+ private final String movieId;
+ private final String time;
- public Converter(String url, String time, Profile setting,
+ /**
+ * コンバータを構築します.
+ * @param url 対象となる動画のURL.
+ * @param time
+ * @param profile
+ * @param listener
+ * @param flag
+ */
+ public Converter(String url, String time, Profile profile,
TextProgressListener listener, ConvertStopFlag flag) {
super(listener, flag);
- url = url.trim();
- if (url.startsWith(VIDEO_URL_PARSER)) {
- int index = url.indexOf('?', VIDEO_URL_PARSER.length());
- if (index >= 0) {
- movieId = url.substring(VIDEO_URL_PARSER.length(), index);
- } else {
- movieId = url.substring(VIDEO_URL_PARSER.length());
- }
+
+ // TODO 入力欄の値から動画IDの切り出しはGUI側でやるべきだろう
+ final int startIdIdx = url.lastIndexOf("/") + 1;
+ final String altId = url.substring(startIdIdx);
+ final Pattern idPattern = Pattern.compile("([a-z]*\\d+)");
+ final Matcher idMatcher = idPattern.matcher(altId);
+ if (idMatcher.find()) {
- Tag = idMatcher.group(1);
++ this.movieId = idMatcher.group(1);
} else {
- movieId = url;
+ throw new IllegalArgumentException("URL/IDの指定が不正です: " + url);
}
- Time = time;
- Setting = setting;
+
+ this.time = time;
+ this.profile = profile;
}
public Boolean call() throws Exception {
private FileInstanciator createInstanciator() throws IOException {
FileInstanciator fi;
- FileInstanciator.InstanciationType videoType = new FileInstanciator.InstanciationType(Setting.getVideoSetting());
+ FileInstanciator.InstanciationType videoType = new FileInstanciator.InstanciationType(profile.getVideoSetting());
- FileInstanciator.CommentInstanciationType commentType = new FileInstanciator.CommentInstanciationType(Setting.
- getCommentSetting(), Setting.getCommentGetInfo().isSelfAdjustCommentNum(), Setting.getCommentGetInfo().
- getBackComment(), Setting.getCommentGetInfo().isReduceComment());
+ FileInstanciator.CommentInstanciationType commentType = new FileInstanciator.CommentInstanciationType(profile.
- getCommentSetting(), profile.getCommentGetInfo().isselfAdjustCommentNum(), profile.getCommentGetInfo().
- getBackComment());
++ getCommentSetting(), profile.getCommentGetInfo().isSelfAdjustCommentNum(), profile.getCommentGetInfo().
++ getBackComment(), profile.getCommentGetInfo().isReduceComment());
FileInstanciator.InstanciationType tcommType = new FileInstanciator.InstanciationType(
- Setting.getTcommentSetting());
+ profile.getTcommentSetting());
- fi = FileInstanciator.create(getStopFlag(), videoType, commentType, tcommType, Setting.getLoginInfo(), Tag, Time);
+ fi = FileInstanciator.create(getStopFlag(), videoType, commentType, tcommType, profile.getLoginInfo(), profile.
+ getProxySetting(), movieId, time);
return fi;
}
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package saccubus.converter.profile;
+package saccubus.converter.classic.profile;
/**
- *
+ * コメント取得に関するプロファイルです.
* @author yuki
*/
-public class CommentGetInfo {
+public class CommentGetInfo implements yukihane.saccubus.converter.profile.CommentGetInfo {
+ /** コメント取得数を自動調整するのであればtrue. */
private final boolean selfAdjustCommentNum;
+ /** コメント取得数を自動調整しない場合の取得数. */
private final int backComment;
+ /** 旧仕様(2010年末までバージョン)でコメントを取得する場合はtrue. */
+ private final boolean reduceComment;
- public CommentGetInfo(boolean selfAdjustCommentNum, int backComment) {
+ public CommentGetInfo(boolean selfAdjustCommentNum, int backComment, boolean reduceComment) {
this.selfAdjustCommentNum = selfAdjustCommentNum;
this.backComment = backComment;
+ this.reduceComment = reduceComment;
}
- public boolean isselfAdjustCommentNum() {
++ @Override
+ public boolean isSelfAdjustCommentNum() {
return selfAdjustCommentNum;
}
++ @Override
public int getBackComment() {
return backComment;
}
+
++ @Override
+ public boolean isReduceComment() {
+ return reduceComment;
+ }
}