我正在使用 python 开发网络服务,我想过滤掉无法在 youtube 页面之外播放的视频。
就像在这个链接 [https://www.youtube.com/v/SC3pupLn-_8?version=3&f=videos&app=youtube_gdata] 你必须在 youtube 页面上观看视频是否有任何方法可以过滤哪些视频属于同一类别。所以我只选择那些可以不受限制地播放的视频。
import gdata.youtube.service
#------------------------------------------------------------------------------
yt_service = gdata.youtube.service.YouTubeService()
yt_service.developer_key = 'YOUR API DEVELOPER KEY'
count=0
def PrintEntryDetails(entry):
if entry.media.category[0].text == "Movies" :
global count
count = count + 1
if entry.noembed != None:
print 'Video embedding not enable: %s' % entry.noembed.text
else :
print "entry embedable"
print 'Video title: %s' % entry.media.title.text
print 'Video category: %s' % entry.media.category[0].text
print 'Video published on: %s ' % entry.published.text
print 'Video description: %s' % entry.media.description.text
if entry.media.private != None :
print entry.media.private.text
else :
print "Right not found"
if entry.media.keywords :
print 'Video tags: %s' % entry.media.keywords.text
print 'Video watch page: %s' % entry.media.player.url
print 'Video flash player URL: %s' % entry.GetSwfUrl()
print 'Video duration: %s' % entry.media.duration.seconds
# For video statistics
if entry.statistics :
print 'Video view count: %s' % entry.statistics.view_count
# For video rating
if entry.rating :
print 'Video rating: %s' % entry.rating.average
# show alternate formats
for alternate_format in entry.media.content:
if 'isDefault' not in alternate_format.extension_attributes:
print 'Alternate format: %s | url: %s ' % (alternate_format.type,
alternate_format.url)
# show thumbnails
for thumbnail in entry.media.thumbnail:
print 'Thumbnail url: %s' % thumbnail.url
print "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
else :
pass
def PrintVideoFeed(feed):
counter = 0
for entry in feed.entry:
PrintEntryDetails(entry)
counter = counter+1
#print counter
def SearchAndPrint():
max = 20
yt_service = gdata.youtube.service.YouTubeService()
query = gdata.youtube.service.YouTubeVideoQuery()
# OrderBy must be one of: published viewCount rating relevance
query.orderby = "relevance"
query.racy = 'include'
query.author = "tseries"
query.max_results = 50
index = 01
for i in (range(max)):
query.start_index = index
index = index + 50
query.format = "5"
feed = yt_service.YouTubeQuery(query)
PrintVideoFeed(feed)
SearchAndPrint()
print "**********************************************************"
print "Total Movies"
print count