2 package saccubus.converter.filegetter;
4 import java.io.IOException;
5 import java.text.Normalizer;
6 import org.apache.commons.lang.StringUtils;
7 import saccubus.ConvertStopFlag;
8 import saccubus.net.CommentInfo;
9 import saccubus.net.NicoClient;
10 import saccubus.net.VideoInfo;
11 import saccubus.util.WayBackTimeParser;
12 import yukihane.inqubus.saccubus_adapter.NicoBrowserAdapter;
13 import yukihane.saccubus.converter.profile.ProxyProfile;
14 import yukihane.saccubus.converter.profile.LoinProfile;
17 * 動画ファイル, コメントファイルなど必要なファイルのうち, 1つでもダウンロード処理を必要とする場合のインスタンス化クラス.
20 public class WebFileInstanciator extends FileInstanciator {
22 private final NicoClient client;
23 private final VideoInfo videoInfo;
24 private final CommentInfo commentInfo;
27 ConvertStopFlag stopFlag,
28 InstanciationType videoType,
29 CommentInstanciationType commentType,
30 InstanciationType tcommType,
34 long time) throws IOException {
35 super(videoType, commentType, tcommType, tag);
37 if (li.getMail() == null || li.getPass() == null || li.getMail().equals("") || li.getPass().equals("")) {
38 throw new IllegalArgumentException("メールアドレスかパスワードが空白です。");
44 host = proxy.getHost();
45 port = proxy.getPort();
50 client = new NicoBrowserAdapter(li.getMail(), li.getPass(), stopFlag, host, port) {
53 if (!client.isLoggedIn()) {
54 throw new IOException("ログインに失敗");
58 videoInfo = client.getVideoInfo(tag);
60 System.out.print("Setting wayback time...");
61 final long waybacktime = time;
62 String waybackkey = client.getWayBackKey(videoInfo);
63 commentInfo = new CommentInfo(waybackkey, waybacktime);
68 } catch (IOException ex) {
69 final String text = tag + "の情報の取得に失敗";
70 final String cause = (ex.getMessage() != null) ? "(" + ex.getMessage() + ")" : "";
72 throw new IOException(text + cause, ex);
75 if (videoType.isDownload()) {
76 setVideoFileGetter(new VideoFileWebGetter(client, videoInfo));
79 if (commentType.isDownload()) {
80 setCommentFileGetter(new CommentFileWebGetter(client, videoInfo, commentInfo, commentType.isAutoCommentNum(),
81 commentType.getBackComment(), commentType.isReduceComment()));
84 if (tcommType.isDownload()) {
85 setTcommFileGetter(new TcommFileWebGetter(client, videoInfo));
91 * 実際の動画タイトルはファイル名に用いることが出来ない文字を含んである場合があるため、ファイル名に適合するように編集した値が返る。
95 public String getVideoTitle() {
96 String name = videoInfo.getVideoTitle();
97 name = Normalizer.normalize(name, Normalizer.Form.NFKC);
98 name = name.replaceAll("[\\\\/:*?\"<>|.]", "_");
99 name = name.replace('\u2212', '\uff0d'); // - U+2212(MINUS SIGN) -> U+FF0D(FULLWIDTH HYPHEN-MINUS)
100 name = name.replace('\u301c', '\uff5e'); // ~ U+301C(WAVE DASH) -> U+FF5E(FULLWIDTH TILDE)
101 name = name.replace('\u223c', '\uff5e'); // ~ U+223C(TILDE OPERATOR) -> U+FF5E(FULLWIDTH TILDE)
102 name = name.replace('\u00a2', '\uffe0'); // ¢ U+00A2(CENT SIGN) -> U+FFE0(FULLWIDTH CENT SIGN)
103 name = name.replace('\u00a3', '\uffe1'); // £ U+00A3(POUND SIGN) -> U+FFE1(FULLWIDTH POUND SIGN)
104 name = name.replace('\u00ac', '\uffe2'); // ¬ U+00AC(NOT SIGN) -> U+FFE2(FULLWIDHT NOT SIGN)