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.converter.profile.Proxy;
9 import saccubus.net.CommentInfo;
10 import saccubus.net.NicoClient;
11 import saccubus.net.VideoInfo;
12 import saccubus.util.WayBackTimeParser;
13 import yukihane.inqubus.saccubus_adapter.NicoBrowserAdapter;
16 * 動画ファイル, コメントファイルなど必要なファイルのうち, 1つでもダウンロード処理を必要とする場合のインスタンス化クラス.
19 public class WebFileInstanciator extends FileInstanciator {
21 private final NicoClient client;
22 private final VideoInfo videoInfo;
23 private final CommentInfo commentInfo;
26 ConvertStopFlag stopFlag,
27 InstanciationType videoType,
28 CommentInstanciationType commentType,
29 InstanciationType tcommType,
32 String time) throws IOException {
33 super(videoType, commentType, tcommType, tag);
35 if (li.getMail() == null || li.getPass() == null || li.getMail().equals("") || li.getPass().equals("")) {
36 throw new IllegalArgumentException("メールアドレスかパスワードが空白です。");
41 if (li.getProxy() != Proxy.NO_PROXY) {
42 host = li.getProxy().getHost();
43 port = li.getProxy().getPort();
48 client = new NicoBrowserAdapter(li.getMail(), li.getPass(), stopFlag, host, port) {
51 if (!client.isLoggedIn()) {
52 throw new IOException("ログインに失敗");
56 videoInfo = client.getVideoInfo(tag);
57 if (StringUtils.isNotBlank(time)) {
58 System.out.print("Setting wayback time...");
59 final long waybacktime = WayBackTimeParser.parse(time);
60 String waybackkey = client.getWayBackKey(videoInfo);
61 commentInfo = new CommentInfo(waybackkey, waybacktime);
66 } catch (IOException ex) {
67 throw new IOException(tag + "の情報の取得に失敗", ex);
70 if (videoType.isDoanload()) {
71 setVideoFileGetter(new VideoFileWebGetter(client, videoInfo));
74 if (commentType.isDoanload()) {
75 setCommentFileGetter(new CommentFileWebGetter(client, videoInfo, commentInfo, commentType.isAutoCommentNum(),
76 commentType.getBackComment()));
79 if (tcommType.isDoanload()) {
80 setTcommFileGetter(new TcommFileWebGetter(client, videoInfo));
86 * 実際の動画タイトルはファイル名に用いることが出来ない文字を含んである場合があるため、ファイル名に適合するように編集した値が返る。
90 public String getVideoTitle() {
91 String name = videoInfo.getVideoTitle();
92 name = Normalizer.normalize(name, Normalizer.Form.NFKC);
93 name = name.replaceAll("[\\\\/:*?\"<>|.]", "_");
94 name = name.replace('\u2212', '\uff0d'); // - U+2212(MINUS SIGN) -> U+FF0D(FULLWIDTH HYPHEN-MINUS)
95 name = name.replace('\u301c', '\uff5e'); // ~ U+301C(WAVE DASH) -> U+FF5E(FULLWIDTH TILDE)
96 name = name.replace('\u223c', '\uff5e'); // ~ U+223C(TILDE OPERATOR) -> U+FF5E(FULLWIDTH TILDE)
97 name = name.replace('\u00a2', '\uffe0'); // ¢ U+00A2(CENT SIGN) -> U+FFE0(FULLWIDTH CENT SIGN)
98 name = name.replace('\u00a3', '\uffe1'); // £ U+00A3(POUND SIGN) -> U+FFE1(FULLWIDTH POUND SIGN)
99 name = name.replace('\u00ac', '\uffe2'); // ¬ U+00AC(NOT SIGN) -> U+FFE2(FULLWIDHT NOT SIGN)