// // NYTVideo.m // Notifications for YouTube // // Created by Kim Wittenburg on 14.07.13. // Copyright (c) 2013 Kim Wittenburg. All rights reserved. // #import "NYTVideo.h" // API Imports #import "ISO8601DateFormatter.h" @implementation NYTVideo static ISO8601DateFormatter *formatter = nil; + (ISO8601DateFormatter *)dateFormatter { // For efficiency use one instace for the entire app if (!formatter) { formatter = [[ISO8601DateFormatter alloc] init]; formatter.includeTime = YES; } return formatter; } - (id)initWithMediaGroupNode:(NSXMLNode *)node { self = [super init]; if (self) { static NSString *const videoIDPath = @"./yt:videoid"; static NSString *const uploaderIDPath = @"./yt:uploaderId"; static NSString *const uploadedDatePath = @"./yt:uploaded"; static NSString *const titlePath = @"./media:title"; static NSString *const urlPath = @"./media:player/@url"; static NSString *const descriptionPath = @"./media:description"; static NSString *const uploaderDisplayNamePath = @"./media:credit[@role='uploader']/@yt:display"; NSXMLElement *videoIDElement = [node nodesForXPath:videoIDPath error:nil][0]; NSXMLElement *uploaderIDElement = [node nodesForXPath:uploaderIDPath error:nil][0]; NSXMLElement *uploadedDateElement = [node nodesForXPath:uploadedDatePath error:nil][0]; NSXMLElement *titleElement = [node nodesForXPath:titlePath error:nil][0]; NSXMLElement *urlElement = [node nodesForXPath:urlPath error:nil][0]; NSXMLElement *descriptionElement = [node nodesForXPath:descriptionPath error:nil][0]; NSXMLElement *uploaderDisplayNameElement = [node nodesForXPath:uploaderDisplayNamePath error:nil][0]; _videoID = videoIDElement.stringValue; _uploaderID = uploaderIDElement.stringValue; _uploadedDate = [[NYTVideo dateFormatter] dateFromString:uploadedDateElement.stringValue]; _title = titleElement.stringValue; _URL = urlElement.stringValue; _videoDescription = descriptionElement.stringValue; _uploaderDisplayName = uploaderDisplayNameElement.stringValue; } return self; } - (NSString *)description { return self.videoID; } - (BOOL)isEqual:(id)object { if (self == object) { return YES; } if (object == nil) { return NO; } if (![object isKindOfClass:[NYTVideo class]]) { return NO; } return [self isEqualToVideo:object]; } - (BOOL)isEqualToVideo:(NYTVideo *)video { return [self.videoID isEqualToString:video.videoID]; } @end