如何在 youtube 频道上获取最新上传视频的 ID [英] How to get id of lastest uploaded video on youtube channel

查看:30
本文介绍了如何在 youtube 频道上获取最新上传视频的 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Python 获取特定 YouTube 频道中最新上传视频的 ID?

How can I get the id of latest uploaded video in a specific youtube Channel using Python?

推荐答案

您可以请求 JSON 并解析它.以下代码为您提供第一个(最近的)结果并将其存储在 first 中.

You can request JSON and parse it. The following code gives you the first (most recent) result and stores it in first.

import urllib, json

author = 'Google'
inp = urllib.urlopen(r'http://gdata.youtube.com/feeds/api/videos?max-results=1&alt=json&orderby=published&author=' + author)
resp = json.load(inp)
inp.close()

first = resp['feed']['entry'][0]

# Title of the video
print first['title']

# URL
print first['link'][0]['href']

我只是在交互式 Python shell 中查看了 JSON 对象.您可以构建您自己的查询或使用我发布的查询.记得换作者.这是一种较低级别的方法,@Frederik 提到了一些更高级别的内容.

I just looked through the JSON object in an interactive Python shell. You can build your own query or use the one I posted. Remember to change the author. This is a lower level approach, and @Frederik mentioned something a bit higher level.

first 对象看起来像这样.

{
    "author": [
        {
            "name": {
                "$t": "Google"
            }, 
            "uri": {
                "$t": "http://gdata.youtube.com/feeds/api/users/google"
            }
        }
    ], 
    "category": [
        {
            "scheme": "http://schemas.google.com/g/2005#kind", 
            "term": "http://gdata.youtube.com/schemas/2007#video"
        }, 
        {
            "label": "Science & Technology", 
            "scheme": "http://gdata.youtube.com/schemas/2007/categories.cat", 
            "term": "Tech"
        }, 
        {
            "scheme": "http://gdata.youtube.com/schemas/2007/keywords.cat", 
            "term": "Google Currents"
        }, 
        {
            "scheme": "http://gdata.youtube.com/schemas/2007/keywords.cat", 
            "term": "Google"
        }, 
        {
            "scheme": "http://gdata.youtube.com/schemas/2007/keywords.cat", 
            "term": "Currents"
        }, 
        {
            "scheme": "http://gdata.youtube.com/schemas/2007/keywords.cat", 
            "term": "Magazine App"
        }, 
        {
            "scheme": "http://gdata.youtube.com/schemas/2007/keywords.cat", 
            "term": "Reader App"
        }, 
        {
            "scheme": "http://gdata.youtube.com/schemas/2007/keywords.cat", 
            "term": "Android"
        }, 
        {
            "scheme": "http://gdata.youtube.com/schemas/2007/keywords.cat", 
            "term": "ios"
        }, 
        {
            "scheme": "http://gdata.youtube.com/schemas/2007/keywords.cat", 
            "term": "Android phone"
        }, 
        {
            "scheme": "http://gdata.youtube.com/schemas/2007/keywords.cat", 
            "term": "Android tablet"
        }, 
        {
            "scheme": "http://gdata.youtube.com/schemas/2007/keywords.cat", 
            "term": "iphone"
        }, 
        {
            "scheme": "http://gdata.youtube.com/schemas/2007/keywords.cat", 
            "term": "ipad"
        }
    ], 
    "content": {
        "$t": "Google Currents is a new mobile app that lets you enjoy free online magazines and other content optimized for your Android or Apple phones and tablets. Learn more at www.google.com", 
        "type": "text"
    }, 
    "gd$comments": {
        "gd$feedLink": {
            "countHint": 463, 
            "href": "http://gdata.youtube.com/feeds/api/videos/5LOcUkm8m9w/comments"
        }
    }, 
    "gd$rating": {
        "average": 4.7557077, 
        "max": 5, 
        "min": 1, 
        "numRaters": 1752, 
        "rel": "http://schemas.google.com/g/2005#overall"
    }, 
    "id": {
        "$t": "http://gdata.youtube.com/feeds/api/videos/5LOcUkm8m9w"
    }, 
    "link": [
        {
            "href": "http://www.youtube.com/watch?v=5LOcUkm8m9w&feature=youtube_gdata", 
            "rel": "alternate", 
            "type": "text/html"
        }, 
        {
            "href": "http://gdata.youtube.com/feeds/api/videos/5LOcUkm8m9w/responses", 
            "rel": "http://gdata.youtube.com/schemas/2007#video.responses", 
            "type": "application/atom+xml"
        }, 
        {
            "href": "http://gdata.youtube.com/feeds/api/videos/5LOcUkm8m9w/related", 
            "rel": "http://gdata.youtube.com/schemas/2007#video.related", 
            "type": "application/atom+xml"
        }, 
        {
            "href": "http://m.youtube.com/details?v=5LOcUkm8m9w", 
            "rel": "http://gdata.youtube.com/schemas/2007#mobile", 
            "type": "text/html"
        }, 
        {
            "href": "http://gdata.youtube.com/feeds/api/videos/5LOcUkm8m9w", 
            "rel": "self", 
            "type": "application/atom+xml"
        }
    ], 
    "media$group": {
        "media$category": [
            {
                "$t": "Tech", 
                "label": "Science & Technology", 
                "scheme": "http://gdata.youtube.com/schemas/2007/categories.cat"
            }
        ], 
        "media$content": [
            {
                "duration": 94, 
                "expression": "full", 
                "isDefault": "true", 
                "medium": "video", 
                "type": "application/x-shockwave-flash", 
                "url": "http://www.youtube.com/v/5LOcUkm8m9w?version=3&f=videos&app=youtube_gdata", 
                "yt$format": 5
            }, 
            {
                "duration": 94, 
                "expression": "full", 
                "medium": "video", 
                "type": "video/3gpp", 
                "url": "rtsp://v1.cache8.c.youtube.com/CiILENy73wIaGQncm7xJUpyz5BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", 
                "yt$format": 1
            }, 
            {
                "duration": 94, 
                "expression": "full", 
                "medium": "video", 
                "type": "video/3gpp", 
                "url": "rtsp://v5.cache4.c.youtube.com/CiILENy73wIaGQncm7xJUpyz5BMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", 
                "yt$format": 6
            }
        ], 
        "media$description": {
            "$t": "Google Currents is a new mobile app that lets you enjoy free online magazines and other content optimized for your Android or Apple phones and tablets. Learn more at www.google.com", 
            "type": "plain"
        }, 
        "media$keywords": {
            "$t": "Google Currents, Google, Currents, Magazine App, Reader App, Android, ios, Android phone, Android tablet, iphone, ipad"
        }, 
        "media$player": [
            {
                "url": "http://www.youtube.com/watch?v=5LOcUkm8m9w&feature=youtube_gdata_player"
            }
        ], 
        "media$thumbnail": [
            {
                "height": 360, 
                "time": "00:00:47", 
                "url": "http://i.ytimg.com/vi/5LOcUkm8m9w/0.jpg", 
                "width": 480
            }, 
            {
                "height": 90, 
                "time": "00:00:23.500", 
                "url": "http://i.ytimg.com/vi/5LOcUkm8m9w/1.jpg", 
                "width": 120
            }, 
            {
                "height": 90, 
                "time": "00:00:47", 
                "url": "http://i.ytimg.com/vi/5LOcUkm8m9w/2.jpg", 
                "width": 120
            }, 
            {
                "height": 90, 
                "time": "00:01:10.500", 
                "url": "http://i.ytimg.com/vi/5LOcUkm8m9w/3.jpg", 
                "width": 120
            }
        ], 
        "media$title": {
            "$t": "Introducing Google Currents", 
            "type": "plain"
        }, 
        "yt$duration": {
            "seconds": "94"
        }
    }, 
    "published": {
        "$t": "2011-12-08T09:10:07.000Z"
    }, 
    "title": {
        "$t": "Introducing Google Currents", 
        "type": "text"
    }, 
    "updated": {
        "$t": "2011-12-14T12:57:53.000Z"
    }, 
    "yt$hd": {}, 
    "yt$statistics": {
        "favoriteCount": "312", 
        "viewCount": "420050"
    }
}

这篇关于如何在 youtube 频道上获取最新上传视频的 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆