Commit 9c5ebae7 authored by Felix Paul Kühne's avatar Felix Paul Kühne

MediaLibraryKit: upgrade ObjC syntax

parent 7b83407a
......@@ -96,9 +96,7 @@
else
{
xmlErrorPtr theLastErrorPtr = xmlGetLastError();
NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
theLastErrorPtr ? [NSString stringWithUTF8String:theLastErrorPtr->message] : @"unknown", NSLocalizedDescriptionKey,
NULL];
NSDictionary *theUserInfo = @{NSLocalizedDescriptionKey: theLastErrorPtr ? @(theLastErrorPtr->message) : @"unknown"};
theError = [NSError errorWithDomain:@"CXMLErrorDomain" code:1 userInfo:theUserInfo];
......
......@@ -72,11 +72,9 @@
{
xmlErrorPtr theLastErrorPtr = xmlGetLastError();
NSString* message = [NSString stringWithUTF8String:
(theLastErrorPtr ? theLastErrorPtr->message : "Unknown error")];
NSString* message = @(theLastErrorPtr ? theLastErrorPtr->message : "Unknown error");
NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
message, NSLocalizedDescriptionKey, NULL];
NSDictionary *theUserInfo = @{NSLocalizedDescriptionKey: message};
theError = [NSError errorWithDomain:@"CXMLErrorDomain" code:1 userInfo:theUserInfo];
xmlResetLastError();
......@@ -136,10 +134,8 @@
else
{
xmlErrorPtr theLastErrorPtr = xmlGetLastError();
NSString* message = [NSString stringWithUTF8String:
(theLastErrorPtr ? theLastErrorPtr->message : "Unknown error")];
NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
message, NSLocalizedDescriptionKey, NULL];
NSString* message = @(theLastErrorPtr ? theLastErrorPtr->message : "Unknown error");
NSDictionary *theUserInfo = @{NSLocalizedDescriptionKey: message};
theError = [NSError errorWithDomain:@"CXMLErrorDomain" code:1 userInfo:theUserInfo];
xmlResetLastError();
......
......@@ -168,8 +168,8 @@
while (theCurrentNamespace != NULL)
{
NSString *thePrefix = theCurrentNamespace->prefix ? [NSString stringWithUTF8String:(const char *)theCurrentNamespace->prefix] : @"";
NSString *theURI = [NSString stringWithUTF8String:(const char *)theCurrentNamespace->href];
NSString *thePrefix = theCurrentNamespace->prefix ? @((const char *)theCurrentNamespace->prefix) : @"";
NSString *theURI = @((const char *)theCurrentNamespace->href);
CXMLNamespaceNode *theNode = [[CXMLNamespaceNode alloc] initWithPrefix:thePrefix URI:theURI parentElement:self];
[theNamespaces addObject:theNode];
[theNode release];
......@@ -189,8 +189,8 @@
{
if (xmlStrcmp(theCurrentNamespace->prefix, thePrefix) == 0)
{
NSString *thePrefixString = theCurrentNamespace->prefix ? [NSString stringWithUTF8String:(const char *)theCurrentNamespace->prefix] : @"";
NSString *theURI = [NSString stringWithUTF8String:(const char *)theCurrentNamespace->href];
NSString *thePrefixString = theCurrentNamespace->prefix ? @((const char *)theCurrentNamespace->prefix) : @"";
NSString *theURI = @((const char *)theCurrentNamespace->href);
return [[[CXMLNamespaceNode alloc] initWithPrefix:thePrefixString URI:theURI parentElement:self] autorelease];
}
theCurrentNamespace = theCurrentNamespace->next;
......@@ -212,8 +212,8 @@
if (theCurrentNamespace->prefix == 0
|| (theCurrentNamespace->prefix)[0] == 0)
{
NSString *thePrefix = theCurrentNamespace->prefix ? [NSString stringWithUTF8String:(const char *)theCurrentNamespace->prefix] : @"";
NSString *theURI = [NSString stringWithUTF8String:(const char *)theCurrentNamespace->href];
NSString *thePrefix = theCurrentNamespace->prefix ? @((const char *)theCurrentNamespace->prefix) : @"";
NSString *theURI = @((const char *)theCurrentNamespace->href);
return [[[CXMLNamespaceNode alloc] initWithPrefix:thePrefix URI:theURI parentElement:self] autorelease];
}
theCurrentNamespace = theCurrentNamespace->next;
......@@ -233,7 +233,7 @@
if (xmlStrcmp(theCurrentNamespace->href, theXMLURI) == 0)
{
if(theCurrentNamespace->prefix)
return [NSString stringWithUTF8String:(const char *)theCurrentNamespace->prefix];
return @((const char *)theCurrentNamespace->prefix);
return @"";
}
......
......@@ -77,12 +77,12 @@ return((CXMLNodeKind)_node->type); // TODO this isn't 100% accurate!
if (_node->name == NULL)
return(NULL);
NSString *localName = [NSString stringWithUTF8String:(const char *)_node->name];
NSString *localName = @((const char *)_node->name);
if (_node->ns == NULL || _node->ns->prefix == NULL)
return localName;
return [NSString stringWithFormat:@"%@:%@", [NSString stringWithUTF8String:(const char *)_node->ns->prefix], localName];
return [NSString stringWithFormat:@"%@:%@", @((const char *)_node->ns->prefix), localName];
}
- (NSString *)stringValue
......@@ -90,10 +90,10 @@ return((CXMLNodeKind)_node->type); // TODO this isn't 100% accurate!
NSAssert(_node != NULL, @"CXMLNode does not have attached libxml2 _node.");
if (_node->type == XML_TEXT_NODE || _node->type == XML_CDATA_SECTION_NODE)
return [NSString stringWithUTF8String:(const char *)_node->content];
return @((const char *)_node->content);
if (_node->type == XML_ATTRIBUTE_NODE)
return [NSString stringWithUTF8String:(const char *)_node->children->content];
return @((const char *)_node->children->content);
NSMutableString *theStringValue = [[[NSMutableString alloc] init] autorelease];
......@@ -221,13 +221,13 @@ NSAssert(_node != NULL, @"CXMLNode does not have attached libxml2 _node.");
if (_node->name == NULL)
return(NULL);
else
return([NSString stringWithUTF8String:(const char *)_node->name]);
return(@((const char *)_node->name));
}
- (NSString *)prefix
{
if (_node->ns && _node->ns->prefix)
return([NSString stringWithUTF8String:(const char *)_node->ns->prefix]);
return(@((const char *)_node->ns->prefix));
else
return(@"");
}
......@@ -235,7 +235,7 @@ else
- (NSString *)URI
{
if (_node->ns)
return([NSString stringWithUTF8String:(const char *)_node->ns->href]);
return(@((const char *)_node->ns->href));
else
return(NULL);
}
......@@ -329,7 +329,7 @@ if (theXPathObject == NULL)
return(NULL);
}
if (xmlXPathNodeSetIsEmpty(theXPathObject->nodesetval))
theResult = [NSArray array]; // TODO better to return NULL?
theResult = @[]; // TODO better to return NULL?
else
{
NSMutableArray *theArray = [NSMutableArray array];
......
......@@ -53,13 +53,13 @@ theXPathContext->node = _node;
for (NSString *thePrefix in inNamespaceMappings)
{
xmlXPathRegisterNs(theXPathContext, (xmlChar *)[thePrefix UTF8String], (xmlChar *)[[inNamespaceMappings objectForKey:thePrefix] UTF8String]);
xmlXPathRegisterNs(theXPathContext, (xmlChar *)[thePrefix UTF8String], (xmlChar *)[inNamespaceMappings[thePrefix] UTF8String]);
}
// TODO considering putting xmlChar <-> UTF8 into a NSString category
xmlXPathObjectPtr theXPathObject = xmlXPathEvalExpression((const xmlChar *)[xpath UTF8String], theXPathContext);
if (xmlXPathNodeSetIsEmpty(theXPathObject->nodesetval))
theResult = [NSArray array]; // TODO better to return NULL?
theResult = @[]; // TODO better to return NULL?
else
{
NSMutableArray *theArray = [NSMutableArray array];
......
......@@ -41,7 +41,7 @@
{
[self.nodePool addObject:child];
CXMLNode *theCurrentNode = [self.children objectAtIndex:index];
CXMLNode *theCurrentNode = (self.children)[index];
xmlAddPrevSibling(theCurrentNode->_node, child->_node);
}
......
......@@ -2,6 +2,7 @@ Changes between 2.0.0 and 2.1.0 (Aspen Branch)
----------------------------------------------
The entire library was cleaned and relicensed to LGPL 2.1 or later.
Please note that the Objective-C syntax was updated, so MediaLibraryKit may no longer compile with outdated versions of Xcode / clang.
Features:
- added automatic support for HiDPI thumbnails depending on the iOS device the
......
......@@ -50,7 +50,7 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
[request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES"]];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
[request setSortDescriptors:[NSArray arrayWithObject:descriptor]];
[request setSortDescriptors:@[descriptor]];
NSError *error;
NSArray *movies = [moc executeFetchRequest:request error:&error];
......@@ -160,7 +160,7 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
- (void)setIsSafe:(BOOL)isSafe
{
[self willChangeValueForKey:@"isSafe"];
[self setPrimitiveValue:[NSNumber numberWithBool:isSafe] forKey:@"isSafe"];
[self setPrimitiveValue:@(isSafe) forKey:@"isSafe"];
[self willChangeValueForKey:@"isSafe"];
}
......@@ -175,7 +175,7 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
- (void)setIsBeingParsed:(BOOL)isBeingParsed
{
[self willChangeValueForKey:@"isBeingParsed"];
[self setPrimitiveValue:[NSNumber numberWithBool:isBeingParsed] forKey:@"isBeingParsed"];
[self setPrimitiveValue:@(isBeingParsed) forKey:@"isBeingParsed"];
[self willChangeValueForKey:@"isBeingParsed"];
}
......@@ -190,7 +190,7 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
- (void)setThumbnailTimeouted:(BOOL)thumbnailTimeouted
{
[self willChangeValueForKey:@"thumbnailTimeouted"];
[self setPrimitiveValue:[NSNumber numberWithBool:thumbnailTimeouted] forKey:@"thumbnailTimeouted"];
[self setPrimitiveValue:@(thumbnailTimeouted) forKey:@"thumbnailTimeouted"];
[self willChangeValueForKey:@"thumbnailTimeouted"];
}
......@@ -221,7 +221,7 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
{
NSFileManager *manager = [NSFileManager defaultManager];
NSDictionary *fileAttributes = [manager attributesOfItemAtPath:[[[NSURL URLWithString:self.url] path] stringByResolvingSymlinksInPath] error:nil];
NSNumber *fileSize = [fileAttributes objectForKey:NSFileSize];
NSNumber *fileSize = fileAttributes[NSFileSize];
return [fileSize unsignedLongLongValue];
}
......
......@@ -89,16 +89,16 @@
NSArray *tracks = [_media tracksInformation];
NSMutableSet *tracksSet = [NSMutableSet setWithCapacity:[tracks count]];
for (NSDictionary *track in tracks) {
NSString *type = [track objectForKey:VLCMediaTracksInformationType];
NSString *type = track[VLCMediaTracksInformationType];
NSManagedObject *trackInfo = nil;
if ([type isEqualToString:VLCMediaTracksInformationTypeVideo]) {
trackInfo = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"VideoTrackInformation"];
[trackInfo setValue:[track objectForKey:VLCMediaTracksInformationVideoWidth] forKey:@"width"];
[trackInfo setValue:[track objectForKey:VLCMediaTracksInformationVideoHeight] forKey:@"height"];
[trackInfo setValue:track[VLCMediaTracksInformationVideoWidth] forKey:@"width"];
[trackInfo setValue:track[VLCMediaTracksInformationVideoHeight] forKey:@"height"];
} else if ([type isEqualToString:VLCMediaTracksInformationTypeAudio]) {
trackInfo = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"AudioTrackInformation"];
[trackInfo setValue:[track objectForKey:VLCMediaTracksInformationAudioRate] forKey:@"bitrate"];
[trackInfo setValue:[track objectForKey:VLCMediaTracksInformationAudioChannelsNumber] forKey:@"channelsNumber"];
[trackInfo setValue:track[VLCMediaTracksInformationAudioRate] forKey:@"bitrate"];
[trackInfo setValue:track[VLCMediaTracksInformationAudioChannelsNumber] forKey:@"channelsNumber"];
}
if (trackInfo)
[tracksSet addObject:trackInfo];
......@@ -159,7 +159,7 @@ static inline NSString *hashFromFile(MLFile *file)
- (void)addFile:(MLFile *)file
{
if ([_fileDescriptionToOperation objectForKey:hashFromFile(file)])
if (_fileDescriptionToOperation[hashFromFile(file)])
return;
if (![[MLCrashPreventer sharedPreventer] isFileSafe:file]) {
APLog(@"%@ is unsafe and will crash, ignoring", file);
......@@ -183,13 +183,13 @@ static inline NSString *hashFromFile(MLFile *file)
- (void)setHighPriorityForFile:(MLFile *)file
{
MLParsingOperation *op = [_fileDescriptionToOperation objectForKey:hashFromFile(file)];
MLParsingOperation *op = _fileDescriptionToOperation[hashFromFile(file)];
[op setQueuePriority:NSOperationQueuePriorityHigh];
}
- (void)setDefaultPriorityForFile:(MLFile *)file
{
MLParsingOperation *op = [_fileDescriptionToOperation objectForKey:hashFromFile(file)];
MLParsingOperation *op = _fileDescriptionToOperation[hashFromFile(file)];
[op setQueuePriority:NSOperationQueuePriorityNormal];
}
......
......@@ -99,7 +99,7 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
{
int directory = NSLibraryDirectory;
NSArray *paths = NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES);
NSString *directoryPath = [paths objectAtIndex:0];
NSString *directoryPath = paths[0];
#if DELETE_LIBRARY_ON_EACH_LAUNCH
[[NSFileManager defaultManager] removeItemAtPath:directoryPath error:nil];
#endif
......@@ -111,7 +111,7 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
{
int directory = NSLibraryDirectory;
NSArray *paths = NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES);
NSString *directoryPath = [paths objectAtIndex:0];
NSString *directoryPath = paths[0];
#if DELETE_LIBRARY_ON_EACH_LAUNCH
[[NSFileManager defaultManager] removeItemAtPath:directoryPath error:nil];
#endif
......@@ -129,10 +129,9 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
NSURL *url = [NSURL fileURLWithPath:path];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSNumber *yes = [NSNumber numberWithBool:YES];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
yes, NSMigratePersistentStoresAutomaticallyOption,
yes, NSInferMappingModelAutomaticallyOption, nil];
NSNumber *yes = @YES;
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: yes,
NSInferMappingModelAutomaticallyOption: yes};
NSError *error;
NSPersistentStore *persistentStore = [coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:options error:&error];
......@@ -229,7 +228,7 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
- (void)noMetaDataInRemoteDBForFile:(MLFile *)file
{
file.noOnlineMetaData = [NSNumber numberWithBool:YES];
file.noOnlineMetaData = @YES;
[self computeThumbnailForFile:file];
}
......@@ -263,16 +262,16 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
MLShow *show = grabber.userData;
NSArray *results = grabber.episodesResults;
[show setValue:[grabber.results objectForKey:@"serieArtworkURL"] forKey:@"artworkURL"];
[show setValue:(grabber.results)[@"serieArtworkURL"] forKey:@"artworkURL"];
for (id result in results) {
if ([[result objectForKey:@"serie"] boolValue]) {
if ([result[@"serie"] boolValue]) {
continue;
}
MLShowEpisode *showEpisode = [MLShowEpisode episodeWithShow:show episodeNumber:[result objectForKey:@"episodeNumber"] seasonNumber:[result objectForKey:@"seasonNumber"] createIfNeeded:YES];
showEpisode.name = [result objectForKey:@"title"];
showEpisode.theTVDBID = [result objectForKey:@"id"];
showEpisode.shortSummary = [result objectForKey:@"shortSummary"];
showEpisode.artworkURL = [result objectForKey:@"artworkURL"];
MLShowEpisode *showEpisode = [MLShowEpisode episodeWithShow:show episodeNumber:result[@"episodeNumber"] seasonNumber:result[@"seasonNumber"] createIfNeeded:YES];
showEpisode.name = result[@"title"];
showEpisode.theTVDBID = result[@"id"];
showEpisode.shortSummary = result[@"shortSummary"];
showEpisode.artworkURL = result[@"artworkURL"];
if (!showEpisode.artworkURL) {
for (MLFile *file in showEpisode.files)
[self computeThumbnailForFile:file];
......@@ -299,13 +298,13 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
MLShow *show = grabber.userData;
NSArray *results = grabber.results;
if ([results count] > 0) {
NSDictionary *result = [results objectAtIndex:0];
NSString *showId = [result objectForKey:@"id"];
NSDictionary *result = results[0];
NSString *showId = result[@"id"];
show.theTVDBID = showId;
show.name = [result objectForKey:@"title"];
show.shortSummary = [result objectForKey:@"shortSummary"];
show.releaseYear = [result objectForKey:@"releaseYear"];
show.name = result[@"title"];
show.shortSummary = result[@"shortSummary"];
show.releaseYear = result[@"releaseYear"];
// Fetch episodes info
MLTVShowEpisodesInfoGrabber *grabber = [[[MLTVShowEpisodesInfoGrabber alloc] init] autorelease];
......@@ -410,9 +409,9 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
{
file.type = kMLFileTypeTVShowEpisode;
NSNumber *seasonNumber = [tvShowEpisodeInfo objectForKey:@"season"];
NSNumber *episodeNumber = [tvShowEpisodeInfo objectForKey:@"episode"];
NSString *tvShowName = [tvShowEpisodeInfo objectForKey:@"tvShowName"];
NSNumber *seasonNumber = tvShowEpisodeInfo[@"season"];
NSNumber *episodeNumber = tvShowEpisodeInfo[@"episode"];
NSString *tvShowName = tvShowEpisodeInfo[@"tvShowName"];
BOOL hasNoTvShow = NO;
if (!tvShowName) {
tvShowName = @"Untitled TV MLShow";
......@@ -432,13 +431,13 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
episode.name = file.title;
file.seasonNumber = seasonNumber;
file.episodeNumber = episodeNumber;
episode.shouldBeDisplayed = [NSNumber numberWithBool:YES];
episode.shouldBeDisplayed = @YES;
[episode addFilesObject:file];
file.showEpisode = episode;
// The rest of the meta data will be fetched using the MLShow
file.hasFetchedInfo = [NSNumber numberWithBool:YES];
file.hasFetchedInfo = @YES;
}
......@@ -456,16 +455,16 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
- (void)movieInfoGrabberDidFinishGrabbing:(MLMovieInfoGrabber *)grabber
{
NSNumber *yes = [NSNumber numberWithBool:YES];
NSNumber *yes = @YES;
NSArray *results = grabber.results;
MLFile *file = grabber.userData;
if ([results count] > 0) {
NSDictionary *result = [results objectAtIndex:0];
file.artworkURL = [result objectForKey:@"artworkURL"];
file.title = [result objectForKey:@"title"];
file.shortSummary = [result objectForKey:@"shortSummary"];
file.releaseYear = [result objectForKey:@"releaseYear"];
NSDictionary *result = results[0];
file.artworkURL = result[@"artworkURL"];
file.title = result[@"title"];
file.shortSummary = result[@"shortSummary"];
file.releaseYear = result[@"releaseYear"];
}
else {
[self noMetaDataInRemoteDBForFile:file];
......@@ -544,7 +543,7 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
NSDate *openedDate = nil; // FIXME kMDItemLastUsedDate
NSDate *modifiedDate = nil; // FIXME [result valueForAttribute:@"kMDItemFSContentChangeDate"];
#endif
NSNumber *size = [attributes objectForKey:NSFileSize]; // FIXME [result valueForAttribute:@"kMDItemFSSize"];
NSNumber *size = attributes[NSFileSize]; // FIXME [result valueForAttribute:@"kMDItemFSSize"];
MLFile *file = [self createObjectForEntity:@"File"];
file.url = [url absoluteString];
......@@ -552,12 +551,12 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
// Yes, this is a negative number. VLCTime nicely display negative time
// with "XX minutes remaining". And we are using this facility.
NSNumber *no = [NSNumber numberWithBool:NO];
NSNumber *yes = [NSNumber numberWithBool:YES];
NSNumber *no = @NO;
NSNumber *yes = @YES;
file.currentlyWatching = no;
file.lastPosition = [NSNumber numberWithDouble:0];
file.remainingTime = [NSNumber numberWithDouble:0];
file.lastPosition = @0.0;
file.remainingTime = @0.0;
file.unread = yes;
#if !TARGET_OS_IPHONE
......@@ -588,7 +587,7 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
NSURL *url = [NSURL fileURLWithPath:path];
NSString *urlString = [url absoluteString];
[fetchPredicates addObject:[NSPredicate predicateWithFormat:@"url == %@", urlString]];
[urlToObject setObject:path forKey:urlString];
urlToObject[urlString] = path;
}
......@@ -606,7 +605,7 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
// Remove objects that are already in db.
for (MLFile *dbResult in dbResults) {
NSString *urlString = dbResult.url;
[filePathsToAdd removeObject:[urlToObject objectForKey:urlString]];
[filePathsToAdd removeObject:urlToObject[urlString]];
}
// Add only the newly added items
......@@ -649,7 +648,7 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
APLog(@"Marking - %@", [fileURL absoluteString]);
file.isSafe = YES; // It doesn't exists, it's safe.
}
file.isOnDisk = [NSNumber numberWithBool:exists];
file.isOnDisk = @(exists);
}
// Get the file to parse
......@@ -695,7 +694,7 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
[self fetchMetaDataForShow:show];
// Get updated TV Shows
NSNumber *lastServerTime = [NSNumber numberWithInteger:[[NSUserDefaults standardUserDefaults] integerForKey:kLastTVDBUpdateServerTime]];
NSNumber *lastServerTime = @([[NSUserDefaults standardUserDefaults] integerForKey:kLastTVDBUpdateServerTime]);
#if HAVE_BLOCK
[MLTVShowInfoGrabber fetchUpdatesSinceServerTime:lastServerTime andExecuteBlock:^(NSArray *updates){
NSFetchRequest *request = [self fetchRequestForEntity:@"Show"];
......
......@@ -153,12 +153,10 @@
if (!artworkURL)
artworkURL = [node stringValueForXPath:@"./backdrop"];
NSString *shortSummary = [node stringValueForXPath:@"./short_overview"];
[array addObject:[NSDictionary dictionaryWithObjectsAndKeys:
title, @"title",
shortSummary ?: @"", @"shortSummary",
releaseYear ?: @"", @"releaseYear",
artworkURL, @"artworkURL",
nil]];
[array addObject:@{@"title": title,
@"shortSummary": shortSummary ?: @"",
@"releaseYear": releaseYear ?: @"",
@"artworkURL": artworkURL}];
}
self.results = array;
}
......
......@@ -37,7 +37,7 @@
[request setEntity:entity];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
[request setSortDescriptors:[NSArray arrayWithObject:descriptor]];
[request setSortDescriptors:@[descriptor]];
NSArray *shows = [moc executeFetchRequest:request error:nil];
[request release];
......@@ -57,7 +57,7 @@
if ([dbResults count] <= 0)
return nil;
return [dbResults objectAtIndex:0];
return dbResults[0];
}
......
......@@ -43,7 +43,7 @@
[request setEntity:entity];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
[request setSortDescriptors:[NSArray arrayWithObject:descriptor]];
[request setSortDescriptors:@[descriptor]];
[request setPredicate:[NSPredicate predicateWithFormat:@"files.@count > 0"]];
NSArray *episodes = [moc executeFetchRequest:request error:nil];
......
......@@ -120,7 +120,7 @@
NSString *serieArtworkURL = nil;
if ([nodesSerie count] == 1) {
NSXMLNode *node = [nodesSerie objectAtIndex:0];
NSXMLNode *node = nodesSerie[0];
serieArtworkURL = [node stringValueForXPath:@"./poster"];
}
......@@ -136,18 +136,15 @@
NSNumber *episodeNumber = [node numberValueForXPath:@"./EpisodeNumber"];
NSString *artworkURL = [node stringValueForXPath:@"./filename"];
NSString *shortSummary = [node stringValueForXPath:@"./Overview"];
[array addObject:[NSDictionary dictionaryWithObjectsAndKeys:
episodeId, @"id",
title ?: @"", @"title",
shortSummary ?: @"", @"shortSummary",
episodeNumber, @"episodeNumber",
seasonNumber, @"seasonNumber",
[NSString stringWithFormat:TVDB_COVERS_URL, TVDB_IMAGES_HOSTNAME, artworkURL], @"artworkURL",
nil]];
[array addObject:@{@"id": episodeId,
@"title": title ?: @"",
@"shortSummary": shortSummary ?: @"",
@"episodeNumber": episodeNumber,
@"seasonNumber": seasonNumber,
@"artworkURL": [NSString stringWithFormat:TVDB_COVERS_URL, TVDB_IMAGES_HOSTNAME, artworkURL]}];
}
self.episodesResults = array;
self.results = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:TVDB_COVERS_URL, TVDB_IMAGES_HOSTNAME, serieArtworkURL], @"serieArtworkURL", nil];
self.results = @{@"serieArtworkURL": [NSString stringWithFormat:TVDB_COVERS_URL, TVDB_IMAGES_HOSTNAME, serieArtworkURL]};
}
else {
self.episodesResults = nil;
......
......@@ -284,13 +284,11 @@ static NSNumber *gServerTime = nil;
NSString *artworkURL = [node stringValueForXPath:@"./banner"];
NSString *shortSummary = [node stringValueForXPath:@"./Overview"];
[array addObject:[NSDictionary dictionaryWithObjectsAndKeys:
title, @"title",
id, @"id",
shortSummary ?: @"", @"shortSummary",
releaseYear ?: @"", @"releaseYear",
[NSString stringWithFormat:TVDB_COVERS_URL, TVDB_IMAGES_HOSTNAME, artworkURL], @"banner",
nil]];
[array addObject:@{@"title": title,
@"id": id,
@"shortSummary": shortSummary ?: @"",
@"releaseYear": releaseYear ?: @"",
@"banner": [NSString stringWithFormat:TVDB_COVERS_URL, TVDB_IMAGES_HOSTNAME, artworkURL]}];
}
self.results = array;
}
......
......@@ -156,7 +156,7 @@ static inline NSString *hashFromFile(MLFile *file)
- (void)addFile:(MLFile *)file
{
if ([_fileDescriptionToOperation objectForKey:hashFromFile(file)])
if (_fileDescriptionToOperation[hashFromFile(file)])
return;
if (![[MLCrashPreventer sharedPreventer] isFileSafe:file]) {
APLog(@"'%@' is unsafe and will crash, ignoring", file.title);
......@@ -180,13 +180,13 @@ static inline NSString *hashFromFile(MLFile *file)
- (void)setHighPriorityForFile:(MLFile *)file
{
ThumbnailOperation *op = [_fileDescriptionToOperation objectForKey:hashFromFile(file)];
ThumbnailOperation *op = _fileDescriptionToOperation[hashFromFile(file)];
[op setQueuePriority:NSOperationQueuePriorityHigh];
}
- (void)setDefaultPriorityForFile:(MLFile *)file
{
ThumbnailOperation *op = [_fileDescriptionToOperation objectForKey:hashFromFile(file)];
ThumbnailOperation *op = _fileDescriptionToOperation[hashFromFile(file)];
[op setQueuePriority:NSOperationQueuePriorityNormal];
}
@end
......@@ -78,7 +78,7 @@ static inline int intFromChar(char n)
static inline NSNumber *numberFromTwoChars(char high, char low)
{
return [NSNumber numberWithInt:intFromChar(high) * 10 + intFromChar(low)];
return @(intFromChar(high) * 10 + intFromChar(low));
}
+ (NSDictionary *)tvShowEpisodeInfoFromString:(NSString *)string
......@@ -100,7 +100,7 @@ static inline NSNumber *numberFromTwoChars(char high, char low)
NSNumber *episode = numberFromTwoChars(c(str,i+4), c(str,i+5));
NSString *tvShowName = i > 0 ? [str substringToIndex:i-1] : nil;
tvShowName = tvShowName ? [[MLTitleDecrapifier decrapify:tvShowName] capitalizedString] : nil;
return [NSDictionary dictionaryWithObjectsAndKeys:season, @"season", episode, @"episode", tvShowName, @"tvShowName", nil];
return @{@"season": season, @"episode": episode, @"tvShowName": tvShowName};
}
}
return nil;
......
......@@ -30,7 +30,7 @@
NSArray *nodes = [self nodesForXPath:string error:nil];
if ([nodes count] == 0)
return nil;
return [[nodes objectAtIndex:0] stringValue];
return [nodes[0] stringValue];
}
- (NSNumber *)numberValueForXPath:(NSString *)string
......@@ -38,10 +38,10 @@
NSArray *nodes = [self nodesForXPath:string error:nil];
if ([nodes count] == 0)
return nil;
NSScanner *scanner = [NSScanner scannerWithString:[[nodes objectAtIndex:0] stringValue]];
NSScanner *scanner = [NSScanner scannerWithString:[nodes[0] stringValue]];
NSInteger i;
if ([scanner scanInteger:&i])
return [NSNumber numberWithInteger:i];
return @(i);
return nil;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment