Retrieving Channel Data from YouTube in Python

Sept, 2013

Retrieving The Most Subscribed / Viewed YouTube Channels

A list of the most subscribed channels can be obtained from a channel feed in the YouTube API v2.0. Note, it was found that a couple top channels were missing from the YouTube most subscribed channel feed (bug report #3748). Below is a Python script that retrieves and parses the 100 most subscribed channels from the YouTube API:



#Written for Python v. 2.7.1, Feedparser v. 5.1.3 import feedparser

print '

--Retrieving Most Subscribed Channels--

' ftop100 = open('top100.txt','w')

for start in range(1, 101, 50):

uri = 'http://gdata.youtube.com/feeds/api/channelstandardfeeds/most_subscrib ed?start-index=' + str(start) + '&time=all_time&&max-results=50&v=2'

feed = feedparser.parse(uri)

for post in feed.entries:

print post.author

ftop100.write( post.author + '

' ) ftop100.close()

Changing the uri from “most_subscribed” to “most_viewed” will retrieve the most viewed YouTube channels. Similarly, adding a channel type suffix to either will retrieve top channels of a particular type (e.g. “most_subscribed_Comedians”). Currently nine channel types are permitted: Comedians, Directors, Gurus, Musicians, Non-Profit, Partners, Politicians, Reporters, Sponsors.