使用 gdata 检索 Youtube 缩略图 URL?

发布于 2024-11-18 04:55:47 字数 1523 浏览 5 评论 0 原文

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

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 和视频描述?

提前致谢。

Ive been researching information on how to get data from Youtube. Basically what I want to do is to get some information on videos (titles, descritions, and thumbnail URLs) from a playlist (ex: http://gdata.youtube.com/feeds/api/playlists/6A40AB04892E2A1F). I was able to retrieve the titles using this code snippet (which I borrowed from another question):

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);

        }
    }
}

However I can't quite figure out how you can retrieve thumbnail URLs. I've seen the tag, but I dont know how to call it from a nodelist.
Can anyone tell how I can retrieve the video's thumbnail URL and video descriptions, using this method?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罪歌 2024-11-25 04:55:47
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

(...)
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

(...)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文