forked from mipstian/catch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTCFeedParser.m
37 lines (26 loc) · 1.17 KB
/
CTCFeedParser.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#import "CTCFeedParser.h"
@implementation CTCFeedParser
+ (NSArray*)parseFiles:(NSXMLDocument*)feed
error:(NSError * __autoreleasing *)outError {
NSLog(@"Parsing feed");
NSError *error = nil;
// Get file URLs with XPath
NSArray *fileNodes = [feed nodesForXPath:@"//rss/channel/item" error:&error];
if (!fileNodes) {
*outError = error;
return nil;
}
// Extract URLs from NSXMLNodes
NSMutableArray *feedFiles = [NSMutableArray arrayWithCapacity:fileNodes.count];
for(NSXMLNode *fileNode in fileNodes) {
NSString *url = [[[fileNode nodesForXPath:@"enclosure/@url" error:&error] lastObject] stringValue];
NSString *title = [[[fileNode nodesForXPath:@"title" error:&error] lastObject] stringValue];
NSString *showName = [[[fileNode nodesForXPath:@"showrss:showname" error:&error] lastObject] stringValue];
[feedFiles addObject:@{@"title": title,
@"url": url,
@"showName": showName ?: NSNull.null}];
}
NSLog(@"Parsed %lu files", (unsigned long)fileNodes.count);
return feedFiles;
}
@end