2 package saccubus.converter.filegetter;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7 import org.apache.commons.io.FilenameUtils;
8 import saccubus.ConvertStopFlag;
9 import saccubus.converter.profile.InputFileSetting;
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);
71 * @return
\93®
\89æ
\82Ì
\83^
\83C
\83g
\83\8b.
72 * @throws FileNotFoundException
\83r
\83f
\83I
\83^
\83C
\83g
\83\8b\82Ì
\8e©
\93®
\96½
\96¼
\8e\9e\81A
\8eQ
\8dl
\82Æ
\82È
\82é
\83t
\83@
\83C
\83\8b\82ª
\8c©
\82Â
\82©
\82ç
\82È
\82©
\82Á
\82½
\81B
74 public String getVideoTitle() throws FileNotFoundException {
75 String fileName = null;
76 if (!videoType.isAutoFileName()) {
77 //
\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é.
78 fileName = videoType.getInitFile().toString();
80 //
\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
81 String[] files = videoType.getInitFile().list();
83 for (String file : files) {
84 if (file.startsWith(getVideoIdWithBracket())) {
85 fileName = FilenameUtils.getBaseName(file);
90 if (fileName == null) {
91 throw new FileNotFoundException(getVideoIdWithBracket() + "
\82Ì
\83t
\83@
\83C
\83\8b\82ð
\93Á
\92è
\82Å
\82«
\82Ü
\82¹
\82ñ
\82Å
\82µ
\82½
\81B");
95 String baseName = FilenameUtils.getBaseName(fileName);
96 int s = baseName.indexOf(getVideoIdWithBracket());
97 return baseName.replace(getVideoIdWithBracket(), "");
101 *
\93®
\89æ
\83t
\83@
\83C
\83\8b\82ð
\8eæ
\93¾
\82µ
\82Ü
\82·.
102 * @param listener
\90i
\92»
\92Ê
\92m
\82ð
\8eó
\82¯
\8eæ
\82é
\82½
\82ß
\82Ì
\83\8a\83X
\83i.
103 * @return
\93®
\89æ
\83t
\83@
\83C
\83\8b.
104 * @throws IOException
\93®
\89æ
\83t
\83@
\83C
\83\8b\82ª
\91¶
\8dÝ
\82µ
\82È
\82¢,
\8eæ
\93¾
\82É
\8e¸
\94s
\82µ
\82½.
106 public final File getVideoFile(TextProgressListener listener) throws IOException {
107 File file = new FileLocator(videoType.isAutoFileName(), videoType.getInitFile(), getVideoIdWithBracket(),
108 getVideoTitle(), ".flv", ".mp4", ".swf").getFile();
109 file = videoFileGetter.get(file, listener);
114 *
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b\82ð
\8eæ
\93¾
\82µ
\82Ü
\82·.
115 * @param listener
\90i
\92»
\92Ê
\92m
\82ð
\8eó
\82¯
\8eæ
\82é
\82½
\82ß
\82Ì
\83\8a\83X
\83i.
116 * @return
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b.
117 * @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½.
119 public final File getCommentFile(TextProgressListener listener) throws IOException {
120 File file = new FileLocator(commentType.isAutoFileName(), commentType.getInitFile(), getVideoIdWithBracket(),
121 getVideoTitle(), ".xml").getFile();
122 file = commentFileGetter.get(file, listener);
127 *
\93\8a\8de
\8eÒ
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b\82ð
\8eæ
\93¾
\82µ
\82Ü
\82·.
128 * @param listener
\90i
\92»
\92Ê
\92m
\82ð
\8eó
\82¯
\8eæ
\82é
\82½
\82ß
\82Ì
\83\8a\83X
\83i.
129 * @return
\93\8a\8de
\8eÒ
\83R
\83\81\83\93\83g
\83t
\83@
\83C
\83\8b.
130 * @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½.
132 public final File getTcommFile(TextProgressListener listener) throws IOException {
133 File file = new FileLocator(tcommType.isAutoFileName(), tcommType.getInitFile(), getVideoIdWithBracket(),
134 getVideoTitle(), ".txml").getFile();
135 file = tcommFileGetter.get(file, listener);
139 private String getVideoIdWithBracket() {
140 return "[" + videoId + "]";
143 public static class InstanciationType {
145 private final boolean download;
146 private final boolean autoFileName;
147 private final File initFile;
150 *
\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.
152 public InstanciationType(InputFileSetting fileSetting) {
153 this.download = fileSetting.isDownload();
154 this.autoFileName = !fileSetting.getFile().isFile();
155 this.initFile = fileSetting.getFile().getFile();
158 public boolean isDoanload() {
162 public File getInitFile() {
166 public boolean isAutoFileName() {
171 public static class CommentInstanciationType extends InstanciationType {
173 private final boolean autoCommentNum;
174 private final int backComment;
176 public CommentInstanciationType(InputFileSetting fileSetting, boolean autoCommentNum, int backComment) {
178 this.autoCommentNum = autoCommentNum;
179 this.backComment = backComment;
182 public boolean isAutoCommentNum() {
183 return autoCommentNum;
186 public int getBackComment() {