我一直在研究有关如何从Youtube获取数据的信息。基本上,我想从播放列表(例如:http://gdata.youtube.com/feeds/api/playlists/6A40AB04892E2A1F)中获取有关视频(标题,说明和缩略图URL)的一些信息。我可以使用以下代码片段(从另一个问题中借来的)来检索标题:

String featuredFeed = "http://gdata.youtube.com/feeds/api/playlists/6A40AB04892E2A1F";

url = new URL(featuredFeed);

URLConnection connection;
connection = url.openConnection();

HttpURLConnection httpConnection = (HttpURLConnection) connection;

int responseCode = httpConnection.getResponseCode();

if (responseCode == HttpURLConnection.HTTP_OK) {
    InputStream in = httpConnection.getInputStream();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();

    Document dom = db.parse(in);
    Element docEle = dom.getDocumentElement();

    NodeList nl = docEle.getElementsByTagName("entry");
    // NodeList nl2 = ;
    if (nl != null && nl.getLength() > 0) {
        for (int i = 0; i < nl.getLength(); i++) {

            Element entry = (Element) nl.item(i);
            Element title = (Element) entry.getElementsByTagName(
                    "title").item(0);

            String titleStr = title.getFirstChild().getNodeValue();

            Log.i("TEST LOG", "TITLES: " + titleStr);

        }
    }
}

但是,我不太清楚如何检索缩略图URL。我已经看到了标签,但是我不知道如何从节点列表中调用它。
谁能告诉我如何使用此方法检索视频的缩略图URL和视频说明?

提前致谢。

最佳答案

Log.i("TEST LOG", "TITLES: " + titleStr);
(...)
                    Element groupNode = (Element)entry.getElementsByTagNameNS("*", "group").item(0);

                    NodeList tNL = groupNode.getElementsByTagNameNS("*", "thumbnail");

                    for (int k = 0; k < tNL.getLength(); k++) {
                        Element tE = (Element)tNL.item(k);

                        if (tE != null) {
                            System.out.println("Thumbnail url = " + tE.getAttribute("url"));
                        }
                    }

                    NodeList dNL = groupNode.getElementsByTagNameNS("*", "description");

                    for (int k = 0; k < dNL.getLength(); k++) {
                        Element tE = (Element)dNL.item(k);

                        if (tE != null) {
                            System.out.println("Description = " + tE.getFirstChild().getNodeValue());
                        }
                    }

                } // end for

(...)

关于java - 使用gdata检索Youtube缩略图URL?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6538531/

10-13 07:09