From: yuki Date: Sat, 9 Feb 2008 20:21:00 +0000 (+0000) Subject: 動画番号を指定したコンテンツ情報取得関数追加. X-Git-Tag: rel20091113_ver0.1~41 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=72c7335c82193120a27a2620c907770ab7d2fc0d;p=coroid%2FNicoBrowser.git 動画番号を指定したコンテンツ情報取得関数追加. git-svn-id: http://192.168.11.7/svn/repository/NicoBrowser@21 bdf3b611-c98c-6041-8292-703d9c9adbe7 --- diff --git a/nbproject/project.properties b/nbproject/project.properties index 7bd07a1..72c2bba 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -2,7 +2,7 @@ application.homepage=http://feather.cocolog-nifty.com/ application.title=DEMO:\u30cb\u30b3\u30cb\u30b3\u52d5\u753bRSS\u30d6\u30e9\u30a6\u30b6 application.vendor=yukihane build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form +build.classes.excludes= # This directory is removed when the project is cleaned: build.dir=build build.generated.dir=${build.dir}/generated @@ -49,7 +49,7 @@ javadoc.windowtitle= jnlp.codebase.type=user jnlp.codebase.user=http://www.example.com jnlp.enabled=true -jnlp.offline-allowed=false +jnlp.offline-allowed=true jnlp.signed=true # Property libs.Codec.classpath is set here just to make sharing of project simpler. # The library definition has always preference over this property. diff --git a/src/nicobrowser/MainWindow.form b/src/nicobrowser/MainWindow.form index 3902b21..e396afb 100644 --- a/src/nicobrowser/MainWindow.form +++ b/src/nicobrowser/MainWindow.form @@ -22,25 +22,25 @@ - + - - - + + + - + - - - + + + - - + + @@ -85,14 +85,23 @@ - + + + + - + + + + - - + + + + + - + @@ -101,23 +110,29 @@ - + + + + + + + - + - + @@ -130,6 +145,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/nicobrowser/MainWindow.java b/src/nicobrowser/MainWindow.java index 979bad0..faf4651 100644 --- a/src/nicobrowser/MainWindow.java +++ b/src/nicobrowser/MainWindow.java @@ -111,9 +111,12 @@ public class MainWindow extends javax.swing.JFrame { jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jPanel2 = new javax.swing.JPanel(); - loadButton = new javax.swing.JButton(); + listLoadButton = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); listNoField = new javax.swing.JTextField(); + unitLoadButton = new javax.swing.JButton(); + jLabel4 = new javax.swing.JLabel(); + unitNoField = new javax.swing.JTextField(); clearButton = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); @@ -131,10 +134,10 @@ public class MainWindow extends javax.swing.JFrame { jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder()); - loadButton.setText("Load"); - loadButton.addActionListener(new java.awt.event.ActionListener() { + listLoadButton.setText("Load"); + listLoadButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - loadButtonActionPerformed(evt); + listLoadButtonActionPerformed(evt); } }); @@ -142,6 +145,17 @@ public class MainWindow extends javax.swing.JFrame { listNoField.setText("1923688"); + unitLoadButton.setText("Load"); + unitLoadButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + unitLoadButtonActionPerformed(evt); + } + }); + + jLabel4.setText("No"); + + unitNoField.setText("sm9"); + clearButton.setText("Clear"); clearButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -155,24 +169,35 @@ public class MainWindow extends javax.swing.JFrame { jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() - .addComponent(loadButton) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(unitLoadButton, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE) + .addComponent(listLoadButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel3) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel3) + .addComponent(jLabel4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(listNoField, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(unitNoField) + .addComponent(listNoField, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)) + .addGap(18, 18, 18) .addComponent(clearButton) - .addContainerGap()) + .addContainerGap(36, Short.MAX_VALUE)) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(loadButton) + .addComponent(listLoadButton) .addComponent(jLabel3) .addComponent(listNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(clearButton)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel4) + .addComponent(unitLoadButton) + .addComponent(unitNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); @@ -234,7 +259,7 @@ public class MainWindow extends javax.swing.JFrame { .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 755, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 876, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) @@ -243,7 +268,7 @@ public class MainWindow extends javax.swing.JFrame { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -253,12 +278,12 @@ public class MainWindow extends javax.swing.JFrame { pack(); }// //GEN-END:initComponents - private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadButtonActionPerformed - String listNo = listNoField.getText(); - if (listNo.length() < 1) { + private void listLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listLoadButtonActionPerformed + String no = listNoField.getText(); + if (no.length() < 1) { return; } - List contList = NicoHttpClient.getInstance().loadMyList(listNo); + List contList = NicoHttpClient.getInstance().loadMyList(no); int rowHeight = -1; for (NicoContent cont : contList) { Vector v = new Vector(); @@ -278,7 +303,7 @@ public class MainWindow extends javax.swing.JFrame { tableModel.addRow(v); } jTable1.setRowHeight(rowHeight); - }//GEN-LAST:event_loadButtonActionPerformed +}//GEN-LAST:event_listLoadButtonActionPerformed private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed String mail = mailField.getText(); @@ -297,6 +322,32 @@ public class MainWindow extends javax.swing.JFrame { } }//GEN-LAST:event_clearButtonActionPerformed + private void unitLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unitLoadButtonActionPerformed + String no = unitNoField.getText(); + if (no.length() < 1) { + return; + } + NicoContent cont = NicoHttpClient.getInstance().loadMyMovie(no); + int rowHeight = -1; + Vector v = new Vector(); + ImageIcon icon = new ImageIcon(); + try { + icon = new ImageIcon(new URL(cont.getImageLink())); + if (rowHeight < 0) { + rowHeight = icon.getIconHeight(); + } + } catch (MalformedURLException ex) { + Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); + } + v.add(icon); + v.add(cont.getTitle()); + v.add(cont.getDescription()); + v.add(cont.getPageLink()); + tableModel.addRow(v); + jTable1.setRowHeight(rowHeight); + +}//GEN-LAST:event_unitLoadButtonActionPerformed + /** * @param args the command line arguments */ @@ -313,14 +364,17 @@ public class MainWindow extends javax.swing.JFrame { private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; + private javax.swing.JButton listLoadButton; private javax.swing.JTextField listNoField; - private javax.swing.JButton loadButton; private javax.swing.JButton loginButton; private javax.swing.JTextField mailField; private javax.swing.JTextField passwordField; + private javax.swing.JButton unitLoadButton; + private javax.swing.JTextField unitNoField; // End of variables declaration//GEN-END:variables } diff --git a/src/nicobrowser/NicoContent.java b/src/nicobrowser/NicoContent.java index 6d09258..6f38ac1 100644 --- a/src/nicobrowser/NicoContent.java +++ b/src/nicobrowser/NicoContent.java @@ -3,6 +3,9 @@ package nicobrowser; import java.util.Date; +/** + * ニコニコ動画コンテンツ情報. + */ public class NicoContent { private String pageLink; diff --git a/src/nicobrowser/NicoHttpClient.java b/src/nicobrowser/NicoHttpClient.java index e3f282a..979da5a 100644 --- a/src/nicobrowser/NicoHttpClient.java +++ b/src/nicobrowser/NicoHttpClient.java @@ -8,10 +8,14 @@ import com.sun.syndication.io.FeedException; import com.sun.syndication.io.SyndFeedInput; import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; +import java.text.DateFormat; +import java.text.ParseException; import java.util.ArrayList; +import java.util.Date; import java.util.Enumeration; import java.util.List; import java.util.logging.Level; @@ -20,11 +24,18 @@ import javax.swing.text.MutableAttributeSet; import javax.swing.text.html.HTML; import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.parser.ParserDelegator; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; /** * @@ -39,6 +50,8 @@ public class NicoHttpClient extends HttpClient { "https://secure.nicovideo.jp/secure/logout"; private static final String MY_LIST_PAGE_HEADER = "http://www.nicovideo.jp/mylist/"; + private static final String MOVIE_THUMBNAIL_PAGE_HEADER = + "http://www.nicovideo.jp/api/getthumbinfo/"; private NicoHttpClient() { super(); @@ -143,6 +156,76 @@ public class NicoHttpClient extends HttpClient { return contList; } + /** + * 動画番号を指定したコンテンツ情報の取得. + * @param movieNo 動画番号. + * @return コンテンツ情報. + */ + public NicoContent loadMyMovie(String movieNo) { + NicoContent cont = null; + InputStream re = null; + List list = null; + String url = new String(MOVIE_THUMBNAIL_PAGE_HEADER + movieNo); + Logger.getLogger(NicoHttpClient.class.getName()).log(Level.INFO, "動画サムネイルURL: " + url); + + GetMethod get = new GetMethod(url); + + try { + int statusCode = executeMethod(get); + re = get.getResponseBodyAsStream(); + // ドキュメントビルダーファクトリを生成 + DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); + // ドキュメントビルダーを生成 + DocumentBuilder builder = dbfactory.newDocumentBuilder(); + // パースを実行してDocumentオブジェクトを取得 + Document doc = builder.parse(re); + // ルート要素を取得(タグ名:site) + Element root = doc.getDocumentElement(); + System.out.println("ルート要素のタグ名:" + root.getTagName()); + + System.out.println("***** ページリスト *****"); + // page要素のリストを取得 + NodeList list2 = root.getElementsByTagName("thumb"); + // page要素の数だけループ + cont = new NicoContent(); + // page要素を取得 + Element element = (Element) list2.item(0); + + String watch_url = ((Element) element.getElementsByTagName("watch_url").item(0)).getFirstChild().getNodeValue(); + cont.setPageLink(watch_url); + + String thumbnail_url = ((Element) element.getElementsByTagName("thumbnail_url").item(0)).getFirstChild().getNodeValue(); + cont.setImageLink(thumbnail_url); + + String title = ((Element) element.getElementsByTagName("title").item(0)).getFirstChild().getNodeValue(); + cont.setTitle(title); + + String description = ((Element) element.getElementsByTagName("description").item(0)).getFirstChild().getNodeValue(); + cont.setDescription(description); + + // TODO 投稿日の設定 +// String first_retrieve = ((Element) element.getElementsByTagName("first_retrieve").item(0)).getFirstChild().getNodeValue(); +// cont.setPublishedDate(DateFormat.getInstance().parse(first_retrieve)); +// +// } 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); + } catch (IOException ex) { + Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex); + } catch (ParserConfigurationException ex) { + Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex); + } finally { + try { + re.close(); + } catch (IOException ex) { + Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex); + } + } + return cont; + + } + private List createContentsList(List list) { class CallBack extends HTMLEditorKit.ParserCallback { @@ -200,8 +283,8 @@ public class NicoHttpClient extends HttpClient { public String getImageLink() { return imageLink; } - - public String getDescription(){ + + public String getDescription() { return description.toString(); } } diff --git a/test/nicobrowser/NicoHttpClientTest.java b/test/nicobrowser/NicoHttpClientTest.java index 50c2868..c12d5b3 100644 --- a/test/nicobrowser/NicoHttpClientTest.java +++ b/test/nicobrowser/NicoHttpClientTest.java @@ -44,7 +44,6 @@ public class NicoHttpClientTest { @Test public void getInstance() { System.out.println("getInstance"); - NicoHttpClient expResult = null; NicoHttpClient result = NicoHttpClient.getInstance(); assertNotNull(result);