Retrieve videos for YouTube playlist

179 views
Skip to first unread message

revojoel

unread,
Sep 23, 2010, 9:49:51 AM9/23/10
to Google Data APIs Objective-C Client Library Discussion
I am successfully retrieving an array of playlists but I am at a loss
for how to retrieve the videos in the playlist.

- (void)viewDidLoad {
// construct the feed url
NSURL *feedURL = [GDataServiceGoogleYouTube
youTubeURLForUserID:kYouTubeUserID userFeedID:uploadsID];

NSLog(@"DEBUG:Start animating"); //DEBUG
[activityIndicator startAnimating];

[service fetchFeedWithURL:feedURL
delegate: self

didFinishSelector:@selector(allPlayListsFetchTicket:finishedWithFeed:error:)];
}

- (void)allPlayListsFetchTicket:(GDataServiceTicket *)ticket
finishedWithFeed:(GDataFeedBase *)aFeed
error:(NSError *)error {

self.feed = (GDataFeedYouTubeVideo *)aFeed;

[self.tableView reloadData];

}


I can get a GDataEntryYouTubePlaylist object from each object in the
feed.

NSArray *entries = [feed entries];

for (int i=0; i < [entries count] ; i++) {

GDataEntryBase *entry = [entries objectAtIndex:i];
GDataTextConstruct *titleTextConstruct = [entry title];
NSString *title = [titleTextConstruct stringValue];
GDataEntryYouTubePlaylist *playlist = (GDataEntryYouTubePlaylist
*)entry;
NSString *playlistURL = [[playlist alternateLink] href];
NSString *playListContentElementURL = [[[playlist content]
sourceURL]
absoluteString];
}

I just do not understand which service method to use for pulling a
feed of playlists. I've tried some combinations but have had no
success.

Does anyone have an example or guidance.

Thanks for you help.

revojoel



Greg Robbins

unread,
Sep 25, 2010, 10:02:33 AM9/25/10
to gdata-objec...@googlegroups.com
For a user, you can fetch the feed of playlist links; each of those has the URL to a playlist, which contains video entries.

- (void)fetchPlaylistLinksFeed {
  NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:kGDataServiceDefaultUser
    userFeedID:kGDataYouTubeUserFeedIDPlaylists];
  GDataServiceGoogleYouTube *service = [self youTubeService];
  GDataServiceTicket *ticket = [service fetchFeedWithURL:feedURL
    delegate:self
    didFinishSelector:@selector(playlistLinksTicket:finishedWithFeed:error:)];
}

- (void)playlistLinksTicket:(GDataServiceTicket *)ticket
    finishedWithFeed:(GDataFeedYouTubePlaylistLink *)feed
    error:(NSError *)error {
  // fetch the user's first playlist
  GDataEntryYouTubePlaylistLink *entry = [feed firstEntry];
  [self fetchPlaylistLink:entry];
}

- (void)fetchPlaylistLink:(GDataEntryYouTubePlaylistLink *)entry {
  GDataServiceGoogleYouTube *service = [self youTubeService];
  NSURL *playlistFeedURL = [[entry content] sourceURL];

  GDataServiceTicket *ticket = [service fetchFeedWithURL:playlistFeedURL
    delegate:self
    didFinishSelector:@selector(playlistTicket:finishedWithFeed:error:)];
}  
                        
- (void)playlistTicket:(GDataServiceTicket *)ticket
    finishedWithFeed:(GDataFeedYouTubePlaylist *)feed
    error:(NSError *)error {
  NSLog(@"feed=%@", feed);
  NSLog(@"video entries=%@", [feed entries]);
}  

Jonathan Lundell

unread,
Feb 19, 2012, 5:56:28 PM2/19/12
to gdata-objec...@googlegroups.com
(OK, it's a belated reply...)

When I run the sample code, the returned video entries are GDataEntryBase; I expected them to be GDataEntryYouTubeVideo or GDataEntryYouTubePlaylist. Consequently, media:group isn't parsed. (FWIW, I used the user @"TEDtalksDirector" in my test case.)

Greg Robbins

unread,
Feb 20, 2012, 12:45:10 AM2/20/12
to gdata-objec...@googlegroups.com
The library instantiates GDataEntryBase for entries when the needed entry class is not compiled and linked into the application.

That can happen if the entry source file is missing from the project, the GDATA_INCLUDE_YOUTUBE_SERVICE preprocessor value is not defined, or the linker is excluding unreferenced classes because the target lacks the -ObjC or -all_load linker flags.

Jonathan Lundell

unread,
Feb 20, 2012, 10:02:58 AM2/20/12
to gdata-objec...@googlegroups.com
On Feb 19, 2012, at 9:45 PM, Greg Robbins wrote:
> The library instantiates GDataEntryBase for entries when the needed entry class is not compiled and linked into the application.
>
> That can happen if the entry source file is missing from the project, the GDATA_INCLUDE_YOUTUBE_SERVICE preprocessor value is not defined, or the linker is excluding unreferenced classes because the target lacks the -ObjC or -all_load linker flags.
>

Thanks.

For the benefit of future generations: I'm building a static library selectively for the YouTube service only, and linking that with my app. Adding -all_load to the apps linker flags fixed my problem.

Suleman Imdad

unread,
Jan 11, 2013, 7:43:43 PM1/11/13
to gdata-objec...@googlegroups.com
Hi 

Can you please share an example project where I can retrieve all videos from a Youtube playlist that can play back to back?

Thanks, 
Suleman. 
Reply all
Reply to author
Forward
0 new messages