import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
+import nicobrowser.GetFlvResult;
import nicobrowser.NicoHttpClient;
+import nicobrowser.ProgressListener;
import saccubus.ConvertStopFlag;
import saccubus.net.CommentInfo;
import saccubus.net.NicoClient;
private final NicoHttpClient client;
private final boolean hasLogin;
private final ConvertStopFlag stopFlag;
+ private nicobrowser.VideoInfo nicoBrowserVi;
public NicoBrowserAdapter(final String mail, final String pass,
final ConvertStopFlag flag, final String proxyHost, final int proxyPort) {
}
@Override
- public VideoInfo getVideoInfo(String tag) throws IOException {
- final nicobrowser.VideoInfo vi = client.getVideoInfo(tag);
+ public VideoInfo getVideoInfo(String videoId) throws IOException {
+ nicoBrowserVi = client.getVideoInfo(videoId);
+ final nicobrowser.VideoInfo vi = nicoBrowserVi;
+
final VideoInfo.OfficialOption oo =
new VideoInfo.OfficialOption(vi.getKeyMap().get("threadkey"), vi.getKeyMap().get("force_184"));
@Override
public String getWayBackKey(VideoInfo vi) throws IOException {
- throw new UnsupportedOperationException("Not supported yet.");
+ return client.getWayBackKey(nicoBrowserVi);
}
@Override
public File getComment(VideoInfo videoInfo, CommentInfo commentInfo, File file, TextProgressListener listener,
String com) {
- throw new UnsupportedOperationException("Not supported yet.");
+ try {
+ // TODO CommentInfo を使用するようにしなければ
+ return client.getCommentFile(nicoBrowserVi, file.getPath());
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE, "コメント取得失敗", ex);
+ }
+ // TODO 失敗した場合何を返す?
+ return null;
}
@Override
public File getTcomment(VideoInfo videoInfo, File file, TextProgressListener listener) {
- throw new UnsupportedOperationException("Not supported yet.");
+ try {
+ return client.getTCommentFile(nicoBrowserVi, file.getParent());
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE, "投稿者コメント取得失敗", ex);
+ }
+ // TODO 失敗した場合何を返す?
+ return null;
}
@Override
- public File getVideo(VideoInfo videoInfo, File file, TextProgressListener listener) {
- throw new UnsupportedOperationException("Not supported yet.");
+ public File getVideo(final VideoInfo videoInfo, File file, final TextProgressListener listener) {
+ try {
+ GetFlvResult res = client.getFlvFile(nicoBrowserVi, file.getPath(), new ProgressListener() {
+
+ @Override
+ public void progress(long fileSize, long downloadSize) {
+ final double p = ((double) downloadSize / fileSize) * 100.0;
+ final String msg = "動画ダウンロード:" + p + "パーセント完了";
+ listener.setText(msg);
+ }
+ });
+
+ return res.getFile();
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE, null, ex);
+ }
+ // TODO 失敗した場合何を返す?
+ return null;
}
@Override
public boolean isLoggedIn() {
return hasLogin;
}
-
- private boolean login() {
- return false;
- }
}