开发者

Retrieving Youtube Thumbnail URLs using gdata?

开发者 https://www.devze.com 2023-03-16 18:26 出处:网络
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:/

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 do开发者_如何学Gont 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.


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

(...)
0

精彩评论

暂无评论...
验证码 换一张
取 消