FSParseRssPodcastFeedRequest.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * This file is part of the FreeStreamer project,
  3. * (C)Copyright 2011-2013 Matias Muhonen.
  4. * See the file ''LICENSE'' for using the code.
  5. */
  6. #import "FSParseRssPodcastFeedRequest.h"
  7. #import "FSPlaylistItem.h"
  8. static NSString *const kXPathQueryItems = @"/rss/channel/item";
  9. @interface FSParseRssPodcastFeedRequest (PrivateMethods)
  10. - (void)parseItems:(xmlNodePtr)node;
  11. @end
  12. @implementation FSParseRssPodcastFeedRequest
  13. - (void)parseItems:(xmlNodePtr)node
  14. {
  15. FSPlaylistItem *item = [[FSPlaylistItem alloc] init];
  16. for (xmlNodePtr n = node->children; n != NULL; n = n->next) {
  17. NSString *nodeName = @((const char *)n->name);
  18. if ([nodeName isEqualToString:@"title"]) {
  19. item.title = [self contentForNode:n];
  20. } else if ([nodeName isEqualToString:@"enclosure"]) {
  21. item.url = [self contentForNodeAttribute:n attribute:"url"];
  22. }
  23. }
  24. [_playlistItems addObject:item];
  25. }
  26. - (void)parseResponseData
  27. {
  28. if (!_playlistItems) {
  29. _playlistItems = [[NSMutableArray alloc] init];
  30. }
  31. [_playlistItems removeAllObjects];
  32. // RSS feed publication date format:
  33. // Sun, 22 Jul 2012 17:35:05 GMT
  34. [_dateFormatter setDateFormat:@"EEE, dd MMMM yyyy HH:mm:ss V"];
  35. [_dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]];
  36. [self performXPathQuery:kXPathQueryItems];
  37. }
  38. - (void)parseXMLNode:(xmlNodePtr)node xPathQuery:(NSString *)xPathQuery
  39. {
  40. if ([xPathQuery isEqualToString:kXPathQueryItems]) {
  41. [self parseItems:node];
  42. }
  43. }
  44. - (NSArray *)playlistItems
  45. {
  46. return _playlistItems;
  47. }
  48. @end