import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import nicobrowser.entity.NicoContent.Status;
import nicobrowser.util.Result;
import nicobrowser.util.Util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpResponse;
*/
public class NicoHttpClient extends DefaultHttpClient {
+ private static Log log = LogFactory.getLog(NicoHttpClient.class);
static NicoHttpClient instance;
private static final String LOGIN_PAGE =
"https://secure.nicovideo.jp/secure/login?site=niconico";
//post.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
HttpResponse response = execute(post);
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.INFO, "ログインステータスコード: " + response.getStatusLine().
- getStatusCode());
+ log.debug("ログインステータスコード: " + response.getStatusLine().getStatusCode());
// ログイン可否の判定.
HttpEntity entity = response.getEntity();
auth = true;
}
} catch (IOException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("ログイン時に問題が発生", ex);
}
return auth;
}
HttpGet method = new HttpGet(LOGOUT_PAGE);
try {
HttpResponse response = execute(method);
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.INFO, "ログアウトステータスコード: " + response.getStatusLine().
- getStatusCode());
+ log.debug("ログアウトステータスコード: " + response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
result = true;
}
response.getEntity().consumeContent();
} catch (IOException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("ログアウト時に問題が発生", ex);
}
return result;
}
* @return 検索結果.
*/
public List<NicoContent> search(String word) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.INFO, "検索:" + word);
+ log.debug("検索:" + word);
InputStream is = null;
List<NicoContent> conts = new ArrayList<NicoContent>();
is.close();
}
} catch (IOException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("検索結果処理時に例外発生", ex);
}
return conts;
}
public List<NicoContent> loadMyListDaily() throws URISyntaxException, HttpException, InterruptedException {
List<NicoContent> list = new ArrayList<NicoContent>();
String url = new String("http://www.nicovideo.jp/ranking/mylist/daily/all?rss=atom");
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.INFO, "全動画サイトのマイリスト登録数ランキング(本日)[全体] : " + url);
+ log.debug("全動画サイトのマイリスト登録数ランキング(本日)[全体] : " + url);
HttpGet get = new HttpGet(url);
list = getNicoContents(reader);
response.getEntity().consumeContent();
} catch (FeedException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("", ex);
} catch (IOException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("", ex);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("", ex);
}
}
}
public List<NicoContent> loadMyList(String listNo) throws URISyntaxException, HttpException, InterruptedException {
List<NicoContent> contList = new ArrayList<NicoContent>();
String url = new String(MY_LIST_PAGE_HEADER + listNo + "?rss=atom");
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.INFO, "マイリストURL: " + url);
+ log.debug("マイリストURL: " + url);
HttpGet get = new HttpGet(url);
reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
contList = getNicoContents(reader);
} catch (FeedException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, "FeedExceitpion" + listNo);
+ log.fatal("FeedExceitpion" + listNo, ex);
} catch (IOException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("", ex);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("", ex);
}
}
}
InputStream re = null;
List<SyndEntryImpl> list = null;
String url = new String(MOVIE_THUMBNAIL_PAGE_HEADER + movieNo);
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.INFO, "動画サムネイルURL: " + url);
+ log.debug("動画サムネイルURL: " + url);
HttpGet get;
Element root = doc.getDocumentElement();
if ("fail".equals(root.getAttribute("status"))) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.INFO, "情報取得できません: " + movieNo);
+ log.warn("情報取得できません: " + movieNo);
return null;
}
// } catch (ParseException ex) {
// Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
} catch (SAXException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("", ex);
} catch (IOException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("", ex);
} catch (ParserConfigurationException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("", ex);
} finally {
try {
if (re != null) {
re.close();
}
} catch (IOException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("", ex);
}
}
return cont;
Enumeration e = a.getAttributeNames();
while (e.hasMoreElements()) {
Object key = e.nextElement();
- System.out.println("---- " + key.toString() + " : " + a.getAttribute(key));
+ log.debug("---- " + key.toString() + " : " + a.getAttribute(key));
}
}
Reader reader = new StringReader(sc.getValue());
new ParserDelegator().parse(reader, callBack, true);
} catch (IOException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ log.fatal("RSSの読み込み失敗: " + content.getTitle());
}
}
String[] urls = resultString.split("&");
final String marker = "url=";
for (String url : urls) {
- System.out.println(url);
if (url.contains(marker)) {
String result = url.substring(marker.length());
result = URLDecoder.decode(result, "UTF-8");
+
return new URL(result);
}
}
URL url = getFlvUrl(videoID);
if (nowStatus == Status.GET_LOW && url.toString().contains("low")) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.INFO, "lowファイル取得済みのためスキップ" + videoID + ":" +
- fileName);
+ log.info("lowファイル取得済みのためスキップ" + videoID + ":" + fileName);
return nowStatus;
}
get = new HttpGet(url.toURI());
response = execute(get);
String contentType = response.getEntity().getContentType().getValue();
- System.out.println(contentType);
- System.out.println(fileName);
+ log.debug(contentType);
+ log.debug(fileName);
if ("text/plain".equals(contentType) || "text/html".equals(contentType)) {
return Status.GET_INFO;
}
// postfix++;
// file = new File(fileName + "(" + postfix + ")" + "." + ext);
// }
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.INFO, "保存します:" + file.getPath());
+ log.info("保存します:" + file.getPath());
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream out = new BufferedOutputStream(fos);