-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMixcloudCoverProvider.m
More file actions
executable file
·28 lines (21 loc) · 1.22 KB
/
Copy pathMixcloudCoverProvider.m
File metadata and controls
executable file
·28 lines (21 loc) · 1.22 KB
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
#import "MixcloudCoverProvider.h"
@implementation MixcloudCoverProvider
- (DDNotificationContactPhotoPromiseOffer *)contactPhotoPromiseOfferForNotification:(DDUserNotification *)notification {
NSString *baseURL = @"https://mixcloud.com/";
NSString *showId = [notification userInfo][@"key"];
NSString *fullPath = [NSString stringWithFormat:@"%@%@", baseURL, showId];
NSURL *url = [NSURL URLWithString:fullPath];
NSError *error = nil;
NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
if (error == nil){
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<meta name=\"twitter:image\" data-meta-side-effect=\"true\" content=\"(.+)\">" options:0 error:&error];
NSTextCheckingResult *result = [regex firstMatchInString:html options:0 range:NSMakeRange(0, html.length)];
if (result) {
NSString *imageURLStr = [html substringWithRange:[result rangeAtIndex:1]];
NSURL *imageURL = [NSURL URLWithString:imageURLStr];
return [NSClassFromString(@"DDNotificationContactPhotoPromiseOffer") offerDownloadingPromiseWithPhotoIdentifier:imageURLStr fromURL:imageURL];
}
}
return nil;
}
@end