*/
public class NicoHttpClient {
- private static Log log = LogFactory.getLog(NicoHttpClient.class);
+ private static Log logger = LogFactory.getLog(NicoHttpClient.class);
private final DefaultHttpClient http;
private static final String LOGIN_PAGE =
"https://secure.nicovideo.jp/secure/login?site=niconico";
//post.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
HttpResponse response = http.execute(post);
- log.debug("ログインステータスコード: " + response.getStatusLine().getStatusCode());
+ logger.debug("ログインステータスコード: " + response.getStatusLine().getStatusCode());
// ログイン可否の判定.
HttpEntity entity = response.getEntity();
auth = true;
}
} catch (IOException ex) {
- log.error("ログイン時に問題が発生", ex);
+ logger.error("ログイン時に問題が発生", ex);
}
return auth;
}
HttpGet method = new HttpGet(LOGOUT_PAGE);
try {
HttpResponse response = http.execute(method);
- log.debug("ログアウトステータスコード: " + response.getStatusLine().getStatusCode());
+ logger.debug("ログアウトステータスコード: " + response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
result = true;
}
response.getEntity().consumeContent();
} catch (IOException ex) {
- log.error("ログアウト時に問題が発生", ex);
+ logger.error("ログアウト時に問題が発生", ex);
}
return result;
}
*/
public SearchResult search(SearchKind kind, String word, SortKind sort, SortOrder order, int page) throws
IOException {
- log.debug("検索:" + word);
+ logger.debug("検索:" + word);
InputStream is = null;
ArrayList<NicoContent> conts = new ArrayList<NicoContent>();
TreeMap<Integer, String> otherPages = Util.getOtherPages(is);
return new SearchResult(conts, otherPages);
} catch (IOException ex) {
- log.error("検索結果処理時に例外発生", ex);
+ logger.error("検索結果処理時に例外発生", ex);
throw ex;
} finally {
if (is != null) {
public List<NicoContent> loadMyListDaily() throws URISyntaxException, HttpException, InterruptedException {
List<NicoContent> list = new ArrayList<NicoContent>();
String url = "http://www.nicovideo.jp/ranking/mylist/daily/all?rss=atom";
- log.debug("全動画サイトのマイリスト登録数ランキング(本日)[全体] : " + url);
+ logger.debug("全動画サイトのマイリスト登録数ランキング(本日)[全体] : " + url);
HttpGet get = new HttpGet(url);
deleteRankString(list);
response.getEntity().consumeContent();
} catch (FeedException ex) {
- log.error("", ex);
+ logger.error("", ex);
} catch (IOException ex) {
- log.error("", ex);
+ logger.error("", ex);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
- log.error("", ex);
+ logger.error("", ex);
}
}
}
* @return コンテンツリスト.
*/
public List<NicoContent> getContentsFromRss(String url) {
- log.debug("アクセスURL: " + url);
+ logger.debug("アクセスURL: " + url);
List<NicoContent> list = accessRssUrl(url);
if (url.contains("ranking")) {
deleteRankString(list);
*/
public List<NicoContent> loadMyList(String listNo) {
String url = MY_LIST_PAGE_HEADER + listNo + "?rss=atom";
- log.debug("マイリストURL: " + url);
+ logger.debug("マイリストURL: " + url);
return accessRssUrl(url);
}
*/
public InputStream getThumbInfo(String movieNo) throws IOException {
String url = MOVIE_THUMBNAIL_PAGE_HEADER + movieNo;
- log.debug("動画サムネイルURL: " + url);
+ logger.debug("動画サムネイルURL: " + url);
HttpGet get = new HttpGet(url);
HttpResponse response = http.execute(get);
Element root = doc.getDocumentElement();
if ("fail".equals(root.getAttribute("status"))) {
- log.warn("情報取得できません: " + movieNo);
+ logger.warn("情報取得できません: " + movieNo);
return null;
}
// } catch (ParseException ex) {
// Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
} catch (SAXException ex) {
- log.error("", ex);
+ logger.error("", ex);
} catch (IOException ex) {
- log.error("", ex);
+ logger.error("", ex);
} catch (ParserConfigurationException ex) {
- log.error("", ex);
+ logger.error("", ex);
} finally {
try {
if (re != null) {
re.close();
}
} catch (IOException ex) {
- log.error("", ex);
+ logger.error("", ex);
}
}
return cont;
try {
HttpResponse response = http.execute(get);
reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
- if (log.isTraceEnabled()) {
+ if (logger.isTraceEnabled()) {
reader.mark(1024 * 1024);
while (true) {
String str = reader.readLine();
if (str == null) {
break;
}
- log.trace(str);
+ logger.trace(str);
}
reader.reset();
}
contList = getNicoContents(reader);
} catch (FeedException ex) {
- log.warn("アクセスできません: " + url);
- log.debug("", ex);
+ logger.warn("アクセスできません: " + url);
+ logger.debug("", ex);
} catch (IOException ex) {
- log.error("", ex);
+ logger.error("", ex);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
- log.error("", ex);
+ logger.error("", ex);
}
}
}
@Override
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
- log.debug("--------<" + t.toString() + ">--------");
- log.debug(a);
+ logger.debug("--------<" + t.toString() + ">--------");
+ logger.debug(a);
if (HTML.Tag.IMG.equals(t)) {
imageLink = a.getAttribute(HTML.Attribute.SRC).toString();
}
descFlag = true;
}
}
- log.debug("--------<" + t.toString() + ">--------");
- log.debug(a);
+ logger.debug("--------<" + t.toString() + ">--------");
+ logger.debug(a);
}
@Override
if (HTML.Tag.P.equals(t)) {
descFlag = false;
}
- log.debug("--------</" + t.toString() + ">--------");
+ logger.debug("--------</" + t.toString() + ">--------");
}
@Override
if (descFlag) {
description.append(data);
}
- log.debug("--------TEXT--------");
- log.debug(data);
+ logger.debug("--------TEXT--------");
+ logger.debug(data);
}
private void printAttributes(MutableAttributeSet a) {
Enumeration e = a.getAttributeNames();
while (e.hasMoreElements()) {
Object key = e.nextElement();
- log.debug("---- " + key.toString() + " : " + a.getAttribute(key));
+ logger.debug("---- " + key.toString() + " : " + a.getAttribute(key));
}
}
Reader reader = new StringReader(sc.getValue());
new ParserDelegator().parse(reader, callBack, true);
} catch (IOException ex) {
- log.error("RSSの読み込み失敗: " + content.getTitle());
+ logger.error("RSSの読み込み失敗: " + content.getTitle());
}
}
}
private LinkedHashMap<String, String> getParameterMap(String accessUrl) throws IOException, IllegalStateException {
- log.debug("アクセス: " + accessUrl);
+ logger.debug("アクセス: " + accessUrl);
HttpGet get = new HttpGet(accessUrl);
String resultString;
BufferedReader reader = null;
}
resultString = strBuilder.toString();
response.getEntity().consumeContent();
- log.debug(resultString);
+ logger.debug(resultString);
} finally {
if (reader != null) {
reader.close();
String realId = videoId;
String title;
String watchUrl = WATCH_PAGE + videoId;
- log.debug("アクセス: " + watchUrl);
+ logger.debug("アクセス: " + watchUrl);
http.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
try {
HttpGet get = new HttpGet(watchUrl);
final URL url = vi.getVideoUrl();
if (nowStatus == Status.GET_LOW || !needLowFile) {
if (url.toString().contains("low")) {
- log.info("エコノミー動画のためスキップ: " + vi.getRealVideoId());
+ logger.info("エコノミー動画のためスキップ: " + vi.getRealVideoId());
return new GetFlvResult(null, nowStatus, userName);
}
}
HttpGet get = new HttpGet(url.toURI());
HttpResponse response = http.execute(get);
String contentType = response.getEntity().getContentType().getValue();
- log.debug(contentType);
- log.debug(downloadFile.toString());
+ logger.debug(contentType);
+ logger.debug(downloadFile.toString());
if ("text/plain".equals(contentType) || "text/html".equals(contentType)) {
- log.error("取得できませんでした. サーバが混みあっている可能性があります: " + vi.getRealVideoId());
+ logger.error("取得できませんでした. サーバが混みあっている可能性があります: " + vi.getRealVideoId());
response.getEntity().consumeContent();
return new GetFlvResult(null, Status.GET_INFO, userName);
}
BufferedInputStream in = new BufferedInputStream(response.getEntity().getContent());
File file = new File(downloadFile.toString() + "." + ext);
- log.info("保存します(" + fileSize / 1024 + "KB): " + file.getPath());
+ logger.info("保存します(" + fileSize / 1024 + "KB): " + file.getPath());
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream out = new BufferedOutputStream(fos);