views:

554

answers:

2

I'm using the Python version of the YouTube API to get a YouTubeVideoFeed object using the following URL:

http://gdata.youtube.com/feeds/api/users/USERNAME/uploads

Note: I've replaced USERNAME with the account I need to follow.

So far getting the feed, iterating the entries, getting player urls, titles and thumbnails has all been straightforward. But now I want to add a "Visit Channel" link to the page. I can't figure out how to get the "public" URL of a channel (in this case, the default channel from the user) out of the feed. From what I can tell, the only URLs stored directly in the feed point to the http://gdata.youtube.com/, not the public site.

How can I link to a channel based on a feed?

A: 

you might be confusing usernames... when I use my username I get my public page http://gdata.youtube.com/feeds/api/users/drdredel/uploads They have some wacky distinction between your gmail username and your youtube username. Or am I misunderstanding your question?

Dr.Dredel
When I click your link it considers it an atom feed, I just want the public youtube channel page that people would normally visit.
Soviut
is that accessed via api? why not just go there directly like so: http://www.youtube.com/user/drdredel ? again, maybe I'm not understanding you.
Dr.Dredel
Perhaps I need to adjust what settings my script expects. Right now it takes the gdata.youtube.com url, but perhaps I should just be passing a channel name or username.
Soviut
+1  A: 

Well, the youtube.com/user/USERNAME is a pretty safe bet if you want to construct the URL yourself, but I think what you want is the link rel='alternate'

You have to get the link array from the feed and iterate to find alternate, then grab the href

something like:

client = gdata.youtube.service.YouTubeService()

feed = client.GetYouTubeVideoFeed('http://gdata.youtube.com/feeds/api/users/username/uploads')

for link in feed.link:
  if link.rel == 'alternate':
    print link.href

Output:

http://www.youtube.com/profile_videos?user=username

The most correct thing would be to grab the 'alternate' link from the user profile feed, as technically the above URL goes to the uploaded videos, not the main channel page

feed = client.GetYouTubeUserEntry('http://gdata.youtube.com/feeds/api/users/username')

for link in feed.link:
  if link.rel == 'alternate':
    print link.href

output: http://www.youtube.com/profile?user=username

Steph Liu