Finding the total number of comments for a Video Entry with the Python Client Library


The snippet below shows how to retrieve the total number of comments for a video entry by examining the comment feed object using the interactive shell:
>>> import gdata.youtube.service
>>> client = gdata.youtube.service.YouTubeService()
>>> feed = client.GetRecentlyFeaturedVideoFeed()
>>> # fetching the first entry from the recently featured video feed
>>> entry = feed.entry[0]
>>> entry.title.text
"Follow Obama's nomination week: youtube.com/2008conventions"
>>> # fetching the comment feed
>>> comments = client.GetYouTubeVideoCommentFeed(video_id='9N4GOpSt5OI')
>>> # printing the text contents of the total_results element
>>> # note that this element is part of every feed
>>> comments.total_results.text
'578'
Alternatively, if you want to eliminate the actual request to catch the comment feed itself, you can parse out the number of comments by examining the 'countHint' attribute of the comment feedLink:
>>> entry.comments.feed_link[0].count_hint
'50'