import nicobrowser.util.Util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpResponse;
IOException,
URISyntaxException, HttpException, InterruptedException {
byte[] buffer = new byte[1024 * 32];
- final String watchUrl = "http://www.nicovideo.jp/watch/" + videoID;
+
+ String watchUrl = "http://www.nicovideo.jp/watch/" + videoID;
log.debug("アクセス: " + watchUrl);
+ getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
HttpGet get = new HttpGet(watchUrl);
HttpResponse response = execute(get);
+ String redirectId = videoID;
+ if (response.containsHeader("Location")) {
+ redirectId = response.getFirstHeader("Location").getValue().replace("/watch/", "");
+ response.getEntity().consumeContent();
+ watchUrl = "http://www.nicovideo.jp/watch/" + redirectId;
+ log.debug("アクセス: " + watchUrl);
+ get = new HttpGet(watchUrl);
+ response = execute(get);
+ }
+ getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
+
final String userId = Util.getUserId(response.getEntity().getContent());
log.debug("userId: " + userId);
response.getEntity().consumeContent();
response.getEntity().consumeContent();
}
- URL url = getFlvUrl(videoID);
+ URL url = getFlvUrl(redirectId);
if (nowStatus == Status.GET_LOW && url.toString().contains("low")) {
log.info("lowファイル取得済みのためスキップ" + videoID + ":" + fileName);
return new GetFlvResult(nowStatus, userName);