1 package saccubus.converter;
3 import saccubus.converter.profile.Profile;
4 import saccubus.converter.profile.FfmpegOption;
5 import saccubus.converter.filegetter.FileInstanciator;
7 import java.io.IOException;
8 import saccubus.ConvertStopFlag;
9 import saccubus.net.TextProgressListener;
12 * <p>
\83^
\83C
\83g
\83\8b:
\82³
\82«
\82ã
\82Î
\82·</p>
14 * <p>
\90à
\96¾:
\83j
\83R
\83j
\83R
\93®
\89æ
\82Ì
\93®
\89æ
\82ð
\83R
\83\81\83\93\83g
\82Â
\82«
\82Å
\95Û
\91¶</p>
16 * <p>
\92\98\8dì
\8c : Copyright (c) 2007 PSI</p>
18 * <p>
\89ï
\8eÐ
\96¼: </p>
20 * @author
\96¢
\93ü
\97Í
23 public class Converter extends AbstractCommand implements Runnable {
25 private static final String VIDEO_URL_PARSER = "http://www.nicovideo.jp/watch/";
26 private final Profile Setting;
27 private final String Tag;
28 private final String Time;
30 public Converter(String url, String time, Profile setting,
31 TextProgressListener listener, ConvertStopFlag flag) {
32 super(listener, flag);
34 if (url.startsWith(VIDEO_URL_PARSER)) {
35 int index = url.indexOf('?', VIDEO_URL_PARSER.length());
37 Tag = url.substring(VIDEO_URL_PARSER.length(), index);
39 Tag = url.substring(VIDEO_URL_PARSER.length());
52 } catch (Exception ex) {
53 String text = (ex.getMessage() != null) ? ex.getMessage() : "
\97\
\8aú
\82µ
\82È
\82¢
\83G
\83\89\81[
\94
\90¶
\82Ì
\82½
\82ß
\92\86\92f
\82µ
\82Ü
\82µ
\82½
\81B";
57 getStopFlag().finished();
61 private void runConvert() throws IOException, InterruptedException {
62 if (!Setting.shouldRun()) {
63 sendText("
\89½
\82à
\82·
\82é
\82±
\82Æ
\82ª
\82 \82è
\82Ü
\82¹
\82ñ");
68 final FfmpegOption ov = Setting.getFfmpeg().getFfmpegOption();
70 sendText("
\83\8d\83O
\83C
\83\93\92\86");
72 final FileInstanciator fi = createInstanciator();
76 final File videoFile = fi.getVideoFile(getListener());
80 File commentFile = fi.getCommentFile(getListener());
84 File tcommFile = fi.getTcommFile(getListener());
86 if (!Setting.needsConvert()) {
87 sendText("
\93®
\89æ
\81E
\83R
\83\81\83\93\83g
\82ð
\95Û
\91¶
\82µ
\81A
\95Ï
\8a·
\82Í
\8ds
\82¢
\82Ü
\82¹
\82ñ
\82Å
\82µ
\82½
\81B");
90 // TODO
\96{
\97\88videoFile
\82Ì
\8eæ
\93¾
\8e¸
\94s
\8e\9e\82Ínull
\82Å
\82Í
\82È
\82IOException
\82É
\82µ
\82½
\82¢
\82ª...
91 if (videoFile == null || !videoFile.isFile()) {
92 throw new IOException("
\93ü
\97Í
\93®
\89æ
\83t
\83@
\83C
\83\8b\82ª
\91¶
\8dÝ
\82µ
\82Ü
\82¹
\82ñ
\81B");
95 if (Setting.getOutputFileSetting().isAddComment()) {
96 if (commentFile == null || !commentFile.isFile()) {
97 throw new IOException("
\93ü
\97Í
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b\82ª
\91¶
\8dÝ
\82µ
\82Ü
\82¹
\82ñ
\81B");
103 if (Setting.getOutputFileSetting().isAddTcomment()) {
104 if (tcommFile == null || !tcommFile.isFile()) {
105 throw new IOException("
\93ü
\97Í
\93\8a\8de
\8eÒ
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b\82ª
\91¶
\8dÝ
\82µ
\82Ü
\82¹
\82ñ
\81B");
111 /*
\83r
\83f
\83I
\96¼
\82Ì
\8am
\92è*/
112 File convertedVideoFile;
113 if (!Setting.getOutputFileSetting().getFile().isFile()) {
114 if (fi.getVideoTitle() == null) {
115 sendText("
\95Ï
\8a·
\8cã
\82Ì
\83r
\83f
\83I
\83t
\83@
\83C
\83\8b\96¼
\82ª
\8am
\92è
\82Å
\82«
\82Ü
\82¹
\82ñ
\81B");
118 String conv_name = fi.getVideoTitle();
119 if (Setting.getOutputFileSetting().isAppendPrefixVideoId()) {
120 conv_name = getVideoIDWithBracket() + conv_name;
122 convertedVideoFile = new File(Setting.getOutputFileSetting().getFile().getFile(),
123 conv_name + ov.getExtOption());
125 String filename = Setting.getOutputFileSetting().getFile().getFile().getPath();
126 if (!filename.endsWith(ov.getExtOption())) {
127 filename = filename.substring(0, filename.lastIndexOf('.')) + ov.getExtOption();
128 convertedVideoFile = new File(filename);
130 convertedVideoFile = Setting.getOutputFileSetting().getFile().getFile();
134 boolean res = new FfmpegCommand(getListener(), getStopFlag(), commentFile, tcommFile, videoFile,
135 convertedVideoFile, Setting.getFfmpeg()).execute();
137 if (Setting.getCommentSetting().isDelete()) {
138 commentFile.delete();
140 if (Setting.getVideoSetting().isDelete()) {
143 if (Setting.getTcommentSetting().isDelete()) {
149 private FileInstanciator createInstanciator() throws IOException {
152 FileInstanciator.InstanciationType videoType = new FileInstanciator.InstanciationType(Setting.getVideoSetting());
154 FileInstanciator.CommentInstanciationType commentType = new FileInstanciator.CommentInstanciationType(Setting.
155 getCommentSetting(), Setting.getCommentGetInfo().isselfAdjustCommentNum(), Setting.getCommentGetInfo().
158 FileInstanciator.InstanciationType tcommType = new FileInstanciator.InstanciationType(
159 Setting.getTcommentSetting());
161 fi = FileInstanciator.create(getStopFlag(), videoType, commentType, tcommType, Setting.getLoginInfo(), Tag, Time);
166 * (
\83l
\83b
\83g
\83\8f\81[
\83N
\90Ý
\92è
\88È
\8aO
\82Ì)
\90Ý
\92è
\82ð
\8c\9f\8fØ
\82·
\82é.
167 * @throws IllegalArgumentException
\90Ý
\92è
\82É
\95s
\94õ
\82ª
\82 \82é
\8fê
\8d\87.
169 private void validSetting() {
170 if (Setting.needsConvert()) {
171 File a = Setting.getFfmpeg().getFfmpeg();
173 throw new IllegalArgumentException("FFmpeg
\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\81B");
175 if (Setting.getFfmpeg().getVhook().getPath().indexOf(' ') >= 0) {
176 throw new IllegalArgumentException("
\82·
\82¢
\82Ü
\82¹
\82ñ
\81B
\8c»
\8dÝvhook
\83\89\83C
\83u
\83\89\83\8a\82É
\82Í
\94¼
\8ap
\8bó
\94\92\82Í
\8eg
\82¦
\82Ü
\82¹
\82ñ
\81B");
178 a = Setting.getFfmpeg().getVhook();
180 throw new IllegalArgumentException("Vhook
\83\89\83C
\83u
\83\89\83\8a\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\81B");
182 a = Setting.getFfmpeg().getFont();
184 throw new IllegalArgumentException("
\83t
\83H
\83\93\83g
\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\81B");
187 if (Setting.getVideoSetting().isDelete()) {
188 throw new IllegalArgumentException("
\95Ï
\8a·
\82µ
\82È
\82¢
\82Ì
\82É
\81A
\93®
\89æ
\8dí
\8f\9c\82µ
\82¿
\82á
\82Á
\82Ä
\97Ç
\82¢
\82ñ
\82Å
\82·
\82©
\81H");
190 if (Setting.getCommentSetting().isDelete()) {
191 throw new IllegalArgumentException("
\95Ï
\8a·
\82µ
\82È
\82¢
\82Ì
\82É
\81A
\83R
\83\81\83\93\83g
\8dí
\8f\9c\82µ
\82¿
\82á
\82Á
\82Ä
\97Ç
\82¢
\82ñ
\82Å
\82·
\82©
\81H");
193 if (Setting.getTcommentSetting().isDelete()) {
194 throw new IllegalArgumentException("
\95Ï
\8a·
\82µ
\82È
\82¢
\82Ì
\82É
\81A
\93\8a\8de
\8eÒ
\83R
\83\81\83\93\83g
\8dí
\8f\9c\82µ
\82¿
\82á
\82Á
\82Ä
\97Ç
\82¢
\82ñ
\82Å
\82·
\82©
\81H");
199 private String getVideoIDWithBracket() {
200 return "[" + Tag + "]";
203 public boolean isConverted() {
204 return getStopFlag().isFinished();
208 public ConvertStopFlag getStopFlag() {
209 return super.getStopFlag();