}
getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
- final String userId = Util.getUserId(response.getEntity().getContent());
- log.debug("userId: " + userId);
+ final URL notifierUrl = Util.getNotifierUrl(response.getEntity().getContent());
+ log.debug("違反通報ページ: " + notifierUrl);
response.getEntity().consumeContent();
String userName = null;
- if (userId != null) {
- final String userUrl = "http://www.nicovideo.jp/user/" + userId;
- log.debug("アクセス: " + watchUrl);
- get = new HttpGet(userUrl);
+ if (notifierUrl != null) {
+ get = new HttpGet(notifierUrl.toString());
response = execute(get);
userName = Util.getUserName(response.getEntity().getContent());
response.getEntity().consumeContent();
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
+/* $Id$ */
package nicobrowser.util
import org.cyberneko.html.parsers.SAXParser
-/**
- *
- * @author yuki
- */
class UserInfo {
+ /**
+ * 動画閲覧ページからユーザIDを取得する.
+ * @params is 動画閲覧ページ.
+ * @return ユーザID. 取得できなければnull.
+ */
String getUserId(InputStream is){
def html = new XmlSlurper(new SAXParser()).parse(is)
def res = html.'**'.find{it.attributes()['href']?.startsWith '/user/'}
return res.attributes()['href'].replaceAll('/user/','').toString()
}
+ String getNotifierUrl(InputStream is){
+ def html = new XmlSlurper(new SAXParser()).parse(is)
+ def res = html.'**'.find{it.text() == 'この動画を違反通報'}
+
+ // 公式動画(IDがsoで始まる動画)のように投稿者が無い場合がある
+ if(res==null) return null
+
+ return res.attributes()['href'].toString()
+ }
+
String getUserName(InputStream is){
def html = new XmlSlurper(new SAXParser()).parse(is)
- def title = html.'HEAD'.'TITLE'.text()
- def i = title.indexOf('さんのユーザーページ')
- if(i<=0) return null
- return title.substring(0,i)
+ def statement = html.'BODY'.'DIV'.'P'.find{it.text().contains('が投稿した動画を、違反動画として通報します。')}//'STRONG'.text().toString()
+ statement.'STRONG'.toString()
}
}
package nicobrowser.util;
import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class Util {
/**
* ユーザIDを取得する
* @param is ニコニコ動画のウォッチページストリーム.
- * @return ユーザID.
+ * @return ユーザID. 取得できなければnull.
*/
public static String getUserId(InputStream is) {
return ui.getUserId(is);
}
/**
+ * 違反通報ページURLを取得する.
+ * @param is ニコニコ動画のウォッチページストリーム.
+ * @return 違反通報ページURL. 取得できなければnull.
+ */
+ public static URL getNotifierUrl(InputStream is) {
+ String res = ui.getNotifierUrl(is);
+ if (res == null) {
+ return null;
+ }
+
+ try {
+ return new URL(res);
+ } catch (MalformedURLException ex) {
+ Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
+ return null;
+ }
+ }
+
+ /**
* ユーザ名を取得する.
- * @param is ユーザページのストリーム.
- * @return ユーザ名.
+ * @param is 違反通報ページストリーム.
+ * @return ユーザ名. 取得できなければnull.
*/
public static String getUserName(InputStream is) {
return ui.getUserName(is);
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.net.URL;
import org.junit.Test;
import static org.junit.Assert.*;
@Test
public void testGetUserName() throws FileNotFoundException {
- InputStream is = new FileInputStream("testdata/user_336619.html");
+ InputStream is = new FileInputStream("testdata/notifier.html");
String name = Util.getUserName(is);
- assertEquals("ZAKO2012", name);
+ assertEquals("nakano", name);
+ }
+
+ /**
+ * Test of getNotifierUrl method, of class Util.
+ */
+ @Test
+ public void testGetNotifierUrl() throws FileNotFoundException {
+ InputStream is = new FileInputStream("testdata/sm8769630.html");
+ URL url = Util.getNotifierUrl(is);
+ assertEquals("http://www.smilevideo.jp/view/8769630/335912", url.toString());
}
}
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\r
+"http://www.w3.org/TR/html4/loose.dtd"> \r
+<html> \r
+<head> \r
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> \r
+<meta http-equiv="Content-Script-Type" content="text/javascript"> \r
+<meta http-equiv="Content-Style-Type" content="text/css"> \r
+<meta name="copyright" content="(C) niwango, inc. All rights reserved."> \r
+<title>SMILEVIDEO | 違反動画の通報</title> \r
+<link rel="shortcut icon" href="/img/favicon.ico"> \r
+<link rel="stylesheet" type="text/css" charset="utf-8" href="/css/common.css"> \r
+<script type="text/javascript" src="/js/_.js"></script> \r
+ \r
+<link rel="stylesheet" type="text/css" charset="utf-8" href="/allegation/css/allegation.css"> \r
+<script type="text/javascript" charset="utf-8" src="/allegation/js/lib/jquery.js"></script> \r
+<script type="text/javascript" charset="utf-8" src="/allegation/js/allegation.js"></script> \r
+ \r
+</head> \r
+<body> \r
+ \r
+ \r
+ \r
+<div class="mb16p4"><p><img src="/img/tpl/head/logo_306.gif" alt="SMILEVIDEO"></p><script type="text/javascript" charset="utf-8" src="/js/version.js"></script><p class="TXT12" style="margin-top:4px;"><strong>Version <script type="text/javascript">getVersion();</script></strong></p></div> \r
+<div class="mb16p4"> \r
+<h1>違反動画の通報</h1> \r
+</div> \r
+ \r
+<div class="mb16p4"> \r
+<p class="TXT12"><strong>nakano</strong> が投稿した動画を、違反動画として通報します。</p> \r
+</div> \r
+ \r
+<div class="mb16p4"> \r
+<div class="text_frm"> \r
+ \r
+<p class="TXT12">動画ID:<strong>9</strong></p> \r
+<p style="margin:4px 0px;"><img src="http://tn-skr2.smilevideo.jp/smile?i=9" alt="" class="video_thumbnail"></p> \r
+<h2 style="color:#579;">新・豪血寺一族 -煩悩解放 - レッツゴー!陰陽師</h2> \r
+<p class="TXT12"><strong>00:05:20</strong></p> \r
+<p class="TXT12" style="margin-top:4px;">レッツゴー!陰陽師(フルコーラスバージョン)</p> \r
+ \r
+</div> \r
+</div> \r
+ \r
+<div class="mb16p4"> \r
+<p class="TXT12">通報する場合は、ニコニコ動画アカウントでログインしてください。</p> \r
+</div> \r
+ \r
+<div class="mb16p4"> \r
+<div class="form_frm"> \r
+<form name="login" id="login" action="https://secure.nicovideo.jp/secure/login" method="post"> \r
+<input type="hidden" name="site" value='smile3'> \r
+<input type="hidden" name="lang" value="jp"> \r
+<input type="hidden" name="next_url" value='/allegation/9'> \r
+<table border="0" cellspacing="4" cellpadding="0" summary="ログイン" class="TXT12" style="margin:0px auto;"> \r
+<tr> \r
+<td nowrap>メールアドレス:</td> \r
+<td><input class="TXT12" style="width:160px;" type="text" name="mail" id="mail" value=""></td> \r
+</tr> \r
+<tr><td class="dot_1" colspan="2"><img src="/img/_.gif" alt="" width="1" height="1"></td></tr> \r
+<tr> \r
+<td nowrap>パスワード:</td> \r
+<td><input class="TXT12" style="width:160px;" type="password" name="password" id="password" value=""></td> \r
+</tr> \r
+<tr><td class="dot_1" colspan="2"><img src="/img/_.gif" alt="" width="1" height="1"></td></tr> \r
+</table> \r
+<div style="padding:4px;"><input type="submit" name="login" value="ログイン" class="TXT12"></div> \r
+</form> \r
+</div> \r
+</div> \r
+ \r
+ \r
+ \r
+<div style="padding:4px;border:1px solid #cccccc;margin:0 auto 10px;background-color:#f0f0f0;width:400px;"> \r
+<p class="TXT12"> \r
+<a href="http://www5.ssw.co.jp/nmm/" target="_blank" id="nmm">無料ツールで動画を作成</a><a href="http://www.niconicommons.jp/" target="_blank" id="ncs">動画の素材を検索</a></p> \r
+</div> \r
+ \r
+<div style="padding:4px;"> \r
+<p class="TXT12"><a href="/static/www/help/" target="_blank">ヘルプ</a> <a href="/rule">利用規約</a> <a href="http://rcp-smile.nicovideo.jp/static/rule/" target="_blank">ライツコントロールプログラムのご案内</a> <a href="/static/www/handbook/">動画投稿ハンドブック</a></p> \r
+</div> \r
+ \r
+<table border="0" cellpadding="0" cellspacing="4" style="margin:0 auto;"> \r
+<tr> \r
+<td class="TXT10">worldwide:</td> \r
+<td><a href="http://www.smilevideo.jp"><img src="/img/tpl/foot/ww_jp.gif"></a></td> \r
+<td><a href="http://tw.smilevideo.jp"><img src="/img/tpl/foot/ww_tw.gif"></a></td> \r
+<td><a href="http://es.smilevideo.jp"><img src="/img/tpl/foot/ww_es.gif"></a></td> \r
+<td><a href="http://de.smilevideo.jp"><img src="/img/tpl/foot/ww_de.gif"></a></td> \r
+</tr> \r
+<tr> \r
+</table> \r
+ \r
+<div class="mb16p4"><a href="http://niwango.jp/" target="_blank"><img src="/img/tpl/foot/copyright.gif" alt="(C) niwango, inc. All rights reserved."></a></div> \r
+<script type="text/javascript" src="/js/__utm.js?d=20081222"></script> \r
+ \r
+ \r
+</body> \r
+</html>
\ No newline at end of file