2 package saccubus.converter.filegetter;
5 import java.io.IOException;
6 import org.apache.commons.io.FilenameUtils;
7 import saccubus.ConvertStopFlag;
8 import saccubus.converter.profile.InputFileSetting;
9 import saccubus.converter.profile.Profile;
10 import saccubus.net.TextProgressListener;
13 *
\83_
\83E
\83\93\83\8d\81[
\83h
\8f\88\97\9d\82ð
\91S
\82
\95K
\97v
\82Æ
\82µ
\82È
\82¢
\8fê
\8d\87\82Ì
\83t
\83@
\83C
\83\8b\83C
\83\93\83X
\83^
\83\93\83X
\89»
\83N
\83\89\83X.
16 public class FileInstanciator {
18 private final InstanciationType videoType;
19 private final InstanciationType commentType;
20 private final InstanciationType tcommType;
21 private final String videoId;
22 private FileGetter videoFileGetter;
23 private FileGetter commentFileGetter;
24 private FileGetter tcommFileGetter;
26 protected void setVideoFileGetter(FileGetter getter) {
27 this.videoFileGetter = getter;
30 protected void setCommentFileGetter(FileGetter getter) {
31 this.commentFileGetter = getter;
34 protected void setTcommFileGetter(FileGetter getter) {
35 this.tcommFileGetter = getter;
38 public static FileInstanciator create(
39 ConvertStopFlag stopFlag,
40 InstanciationType videoType,
41 CommentInstanciationType commentType,
42 InstanciationType tcommType,
44 String tag, String time) throws
46 FileInstanciator getter;
47 if (videoType.isDoanload() || commentType.isDoanload() || tcommType.isDoanload()) {
48 getter = new WebFileInstanciator(stopFlag, videoType, commentType, tcommType, li, tag, time);
50 getter = new FileInstanciator(videoType, commentType, tcommType, tag);
55 protected FileInstanciator(
56 InstanciationType videoType,
57 InstanciationType commentType,
58 InstanciationType tcommType,
60 this.videoType = videoType;
61 this.commentType = commentType;
62 this.tcommType = tcommType;
63 this.videoId = videoId;
64 FileGetter getter = new FileGetter();
65 setVideoFileGetter(getter);
66 setCommentFileGetter(getter);
67 setTcommFileGetter(getter);
70 /** @return
\93®
\89æ
\82Ì
\83^
\83C
\83g
\83\8b.
\95ª
\82©
\82ç
\82È
\82¢
\8fê
\8d\87\82Ínull. */
71 public String getVideoTitle() {
72 String fileName = null;
73 if (!videoType.isAutoFileName()) {
74 //
\93®
\89æ
\83t
\83@
\83C
\83\8b\96¼
\82ð
\92¼
\90Ú
\8ew
\92è
\82µ
\82Ä
\82¢
\82é
\8fê
\8d\87\82Í
\81A
\82»
\82Ì
\83t
\83@
\83C
\83\8b\96¼
\82ð
\8aî
\82É
\83^
\83C
\83g
\83\8b\82ð
\8eæ
\93¾
\82·
\82é.
75 fileName = videoType.getInitFile().toString();
77 //
\8e©
\93®
\96½
\96¼
\82Ì
\8fê
\8d\87\82Í
\81A
\83f
\83B
\83\8c\83N
\83g
\83\8a\93à
\82É
\82 \82é
\83t
\83@
\83C
\83\8b\82©
\82ç
\83^
\83C
\83g
\83\8b\96¼
\82ð
\97Þ
\90\84\81B
78 String[] files = videoType.getInitFile().list();
80 for (String file : files) {
81 if (file.startsWith(getVideoIdWithBracket())) {
82 fileName = FilenameUtils.getBaseName(file);
89 if (fileName == null) {
92 String baseName = FilenameUtils.getBaseName(fileName);
93 int s = baseName.indexOf(getVideoIdWithBracket());
94 return baseName.replace(getVideoIdWithBracket(), "");
98 *
\93®
\89æ
\83t
\83@
\83C
\83\8b\82ð
\8eæ
\93¾
\82µ
\82Ü
\82·.
99 * @param listener
\90i
\92»
\92Ê
\92m
\82ð
\8eó
\82¯
\8eæ
\82é
\82½
\82ß
\82Ì
\83\8a\83X
\83i.
100 * @return
\93®
\89æ
\83t
\83@
\83C
\83\8b.
101 * @throws IOException
\93®
\89æ
\83t
\83@
\83C
\83\8b\82ª
\91¶
\8dÝ
\82µ
\82È
\82¢,
\8eæ
\93¾
\82É
\8e¸
\94s
\82µ
\82½.
103 public final File getVideoFile(TextProgressListener listener) {
104 File file = new FileLocator(videoType.isAutoFileName(), videoType.getInitFile(), getVideoIdWithBracket(),
105 getVideoTitle(), ".flv").getFile();
106 file = videoFileGetter.get(file, listener);
111 *
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b\82ð
\8eæ
\93¾
\82µ
\82Ü
\82·.
112 * @param listener
\90i
\92»
\92Ê
\92m
\82ð
\8eó
\82¯
\8eæ
\82é
\82½
\82ß
\82Ì
\83\8a\83X
\83i.
113 * @return
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b.
114 * @throws IOException
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b\82ª
\91¶
\8dÝ
\82µ
\82È
\82¢,
\8eæ
\93¾
\82É
\8e¸
\94s
\82µ
\82½.
116 public final File getCommentFile(TextProgressListener listener) {
117 File file = new FileLocator(commentType.isAutoFileName(), commentType.getInitFile(), getVideoIdWithBracket(),
118 getVideoTitle(), ".xml").getFile();
119 file = commentFileGetter.get(file, listener);
124 *
\93\8a\8de
\8eÒ
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b\82ð
\8eæ
\93¾
\82µ
\82Ü
\82·.
125 * @param listener
\90i
\92»
\92Ê
\92m
\82ð
\8eó
\82¯
\8eæ
\82é
\82½
\82ß
\82Ì
\83\8a\83X
\83i.
126 * @return
\93\8a\8de
\8eÒ
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b.
127 * @throws IOException
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b\82ª
\91¶
\8dÝ
\82µ
\82È
\82¢,
\8eæ
\93¾
\82É
\8e¸
\94s
\82µ
\82½.
129 public final File getTcommFile(TextProgressListener listener) {
130 File file = new FileLocator(tcommType.isAutoFileName(), tcommType.getInitFile(), getVideoIdWithBracket(),
131 getVideoTitle(), ".xml").getFile();
132 file = tcommFileGetter.get(file, listener);
136 private String getVideoIdWithBracket() {
137 return "[" + videoId + "]";
140 public static class InstanciationType {
142 private final boolean download;
143 private final boolean autoFileName;
144 private final File initFile;
147 *
\83t
\83@
\83C
\83\8b\82ð
\83C
\83\93\83X
\83^
\83\93\83X
\89»
\82·
\82é
\95û
\96@
\82ð
\8ew
\92è
\82·
\82é
\83N
\83\89\83X.
149 public InstanciationType(InputFileSetting fileSetting) {
150 this.download = fileSetting.isDownload();
151 this.autoFileName = !fileSetting.getFile().isFile();
152 this.initFile = fileSetting.getFile().getFile();
155 public boolean isDoanload() {
159 public File getInitFile() {
163 public boolean isAutoFileName() {
168 public static class CommentInstanciationType extends InstanciationType {
170 private final boolean autoCommentNum;
171 private final int backComment;
173 public CommentInstanciationType(InputFileSetting fileSetting, boolean autoCommentNum, int backComment) {
175 this.autoCommentNum = autoCommentNum;
176 this.backComment = backComment;
179 public boolean isAutoCommentNum() {
180 return autoCommentNum;
183 public int getBackComment() {