forked from mipstian/catch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CTCFeedParser.m
46 lines (32 loc) · 1.55 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
38
39
40
41
42
43
44
45
46
#import "CTCFeedParser.h"
@implementation CTCFeedParser
+ (NSArray*)parseFiles:(NSXMLDocument*)feed
error:(NSError * __autoreleasing *)outError {
NSLog(@"Parsing feed");
NSError *error = nil;
// Get files with XPath
NSArray *fileNodes = [feed nodesForXPath:@"//rss/channel/item" error:&error];
if (!fileNodes) {
*outError = error;
return nil;
}
// Extract files from NSXMLNodes
NSMutableArray *feedFiles = [NSMutableArray arrayWithCapacity:fileNodes.count];
for(NSXMLNode *fileNode in fileNodes) {
// Get the .torrent URL or magnet link
NSString *url = [[[fileNode nodesForXPath:@"enclosure/@url" error:&error] lastObject] stringValue];
// Get the title (includes show name and season/episode numbers)
NSString *title = [[[fileNode nodesForXPath:@"title" error:&error] lastObject] stringValue];
// Get the show name from the generic "tv:" namespace, fallback to the old "showrss:" namespace
NSString *showName = [[[fileNode nodesForXPath:@"tv:show_name" error:&error] lastObject] stringValue];
if (!showName) {
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