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);
/*$Id$*/
package nicobrowser.main;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import nicobrowser.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
+import nicobrowser.Config;
+import nicobrowser.NicoHttpClient;
import nicobrowser.entity.NicoContent;
import nicobrowser.entity.NicoContent.Status;
-import org.apache.http.HttpException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
public class Main {
+ private static Log log = LogFactory.getLog(Main.class);
+
public static void main(String[] args) {
- System.out.println("Start");
new Main();
}
public Main() {
+ log.info("program start");
+
Config config = Config.getInstance();
List<NicoContent> dailyList = null;
ArrayList<List<NicoContent>> myLists = new ArrayList<List<NicoContent>>();
NicoHttpClient instance = null;
try {
- System.out.println("リストの取得");
+ log.info("リストを取得します");
instance = NicoHttpClient.getInstance();
//list = instance.loadMyList("4315046");
dailyList = instance.loadMyListDaily();
return;
}
- System.out.println("DBとの突合せ");
+ log.info("今回取得したデータを過去の取得データと比較します");
+
EntityManagerFactory factory;
EntityManager manager;
long sleep = nowDate.getTime() - prevDate.getTime();
sleep = 5000 - sleep;
if (sleep > 0) {
- System.out.print("" + sleep + "ms sleep");
+ log.info("" + sleep + "ms sleep");
Thread.sleep(sleep);
}
}
prevDate = Calendar.getInstance().getTime();
- System.out.print("FLVファイル取得: " + config.getSrcSaveDir() + File.separator + c.getFileName());
+ File saveDir = new File(config.getSrcSaveDir(), c.getFileName());
+ log.info("ファイルを取得します: " + saveDir.getCanonicalPath());
Status status;
try {
status = instance.getFlvFile(c.getNicoId(),
- config.getSrcSaveDir() + File.separator + c.getFileName(), c.getStatus(),
+ saveDir.getCanonicalPath(), c.getStatus(),
config.isExtMp4Use());
c.setStatus(status);
if (status == Status.GET_INFO) {
c.setFailTimes(c.getFailTimes() + 1);
}
} catch (Exception ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
c.setFailTimes(c.getFailTimes() + 1);
+ log.fatal("ファイル取得に失敗しました。" + c.getNicoId() + ", 通算失敗回数: " + c.getFailTimes(), ex);
}
transaction.begin();
manager.persist(c);
transaction.commit();
- System.out.println("...完了");
+ log.info("完了しました");
}
} catch (Exception ex) {
ex.printStackTrace();
setParameter(1, c.getNicoId());
List<NicoContent> resList = query.getResultList();
if (resList.isEmpty()) {
- System.out.println("NEW! " + c.getNicoId() + " : " + c.getFileName());
+ log.info("NEW! " + c.getNicoId() + " : " + c.getFileName());
manager.persist(c);
}
}