}
String[] params = resultString.split("&");
-// final String marker = "url=";
Map<String, String> map = new HashMap<String, String>();
for (String param : params) {
String[] elm = param.split("=");
map.put(elm[0], elm[1]);
- // if (url.contains(marker)) {
- // String result = url.substring(marker.length());
- // result = URLDecoder.decode(result, "UTF-8");
- //
- // return new URL(result);
- // }
}
-// throw new IOException("ダウンロードに失敗しました(削除済みの可能性もあります)。 ID: " + videoID + ", パラメータ:" + resultString);
return new VideoInfo(realVideoId, map);
}
+ /**
+ * watchページへアクセスし, ビデオIDを取得する.
+ * soXXXXなど, 実際のビデオIDと異なる場合がある.
+ * @param videoId 取得したいビデオのビデオID.
+ * @return 実際のビデオID.
+ * @throws IOException
+ */
private String getRealVideoId(String videoId) throws IOException {
+ String realId = accessWatchPage(videoId);
+
+ // ステータスコード302など、リダイレクトが必要な場合
+ if (!videoId.equals(realId)) {
+ realId = getRealVideoId(realId);
+ }
+ return realId;
+ }
+
+ /**
+ * WATCHページへアクセスする. getflvを行うためには, 必ず事前にWATCHページへアクセスしておく必要があるため.
+ * @param videoId ビデオID.
+ * @return
+ * @throws IOException
+ */
+ private String accessWatchPage(String videoId) throws IOException {
+ String realId = videoId;
String watchUrl = WATCH_PAGE + videoId;
log.debug("アクセス: " + watchUrl);
http.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
try {
HttpGet get = new HttpGet(watchUrl);
HttpResponse response = http.execute(get);
- String realID = videoId;
-
- // ステータスコード302など、リダイレクトが必要な場合
if (response.containsHeader("Location")) {
- realID = response.getFirstHeader("Location").getValue().replace("/watch/", "");
- response.getEntity().consumeContent();
- watchUrl = WATCH_PAGE + realID;
- log.debug("アクセス: " + watchUrl);
- HttpGet watchGet = new HttpGet(watchUrl);
- HttpResponse watchResponse = http.execute(get);
- watchResponse.getEntity().consumeContent();
- } else {
- response.getEntity().consumeContent();
+ realId = response.getFirstHeader("Location").getValue().replace("/watch/", "");
}
- return realID;
+ BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+ String line;
+ while((line = reader.readLine())!=null){
+ System.out.println(line);
+ }
+ reader.close();
+ response.getEntity().consumeContent();
} finally {
http.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
}
+ return realId;
}
/**