Commit 4edb98f3 authored by Pierre's avatar Pierre

Store the thumbnails outside the db.

parent fe503ffc
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// //
#import <CoreData/CoreData.h> #import <CoreData/CoreData.h>
#import <UIKit/UIKit.h>
@class MLShowEpisode; @class MLShowEpisode;
...@@ -40,13 +41,13 @@ extern NSString *kMLFileTypeTVShowEpisode; ...@@ -40,13 +41,13 @@ extern NSString *kMLFileTypeTVShowEpisode;
@property (nonatomic, retain) NSNumber *unread; @property (nonatomic, retain) NSNumber *unread;
@property (nonatomic, retain) NSNumber *hasFetchedInfo; @property (nonatomic, retain) NSNumber *hasFetchedInfo;
@property (nonatomic, retain) NSNumber *noOnlineMetaData; @property (nonatomic, retain) NSNumber *noOnlineMetaData;
@property (nonatomic, retain) NSData * computedThumbnail;
@property (nonatomic, retain) MLShowEpisode *showEpisode; @property (nonatomic, retain) MLShowEpisode *showEpisode;
@property (nonatomic, retain) NSSet *labels; @property (nonatomic, retain) NSSet *labels;
@property (nonatomic, retain) NSSet *tracks; @property (nonatomic, retain) NSSet *tracks;
@property (nonatomic, retain) NSNumber *isOnDisk; @property (nonatomic, retain) NSNumber *isOnDisk;
@property (nonatomic, retain) NSNumber *duration; @property (nonatomic, retain) NSNumber *duration;
@property (nonatomic, retain) UIImage *computedThumbnail;
@property (nonatomic, assign) BOOL isSafe; @property (nonatomic, assign) BOOL isSafe;
@property (nonatomic, assign) BOOL isBeingParsed; @property (nonatomic, assign) BOOL isBeingParsed;
@property (nonatomic, assign) BOOL thumbnailTimeouted; @property (nonatomic, assign) BOOL thumbnailTimeouted;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
// May be internal // May be internal
- (NSFetchRequest *)fetchRequestForEntity:(NSString *)entity; - (NSFetchRequest *)fetchRequestForEntity:(NSString *)entity;
- (id)createObjectForEntity:(NSString *)entity; - (id)createObjectForEntity:(NSString *)entity;
- (NSString *)thumbnailFolderPath;
- (void)applicationWillStart; - (void)applicationWillStart;
- (void)applicationWillExit; - (void)applicationWillExit;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#import "MLThumbnailerQueue.h" #import "MLThumbnailerQueue.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NSString *kMLFileTypeMovie = @"movie"; NSString *kMLFileTypeMovie = @"movie";
NSString *kMLFileTypeClip = @"clip"; NSString *kMLFileTypeClip = @"clip";
...@@ -102,13 +103,37 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode"; ...@@ -102,13 +103,37 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
@dynamic unread; @dynamic unread;
@dynamic hasFetchedInfo; @dynamic hasFetchedInfo;
@dynamic noOnlineMetaData; @dynamic noOnlineMetaData;
@dynamic computedThumbnail;
@dynamic showEpisode; @dynamic showEpisode;
@dynamic labels; @dynamic labels;
@dynamic tracks; @dynamic tracks;
@dynamic isOnDisk; @dynamic isOnDisk;
@dynamic duration; @dynamic duration;
- (NSString *)thumbnailPath
{
NSString *folder = [[MLMediaLibrary sharedMediaLibrary] thumbnailFolderPath];
NSURL *url = [[self objectID] URIRepresentation];
return [[folder stringByAppendingPathComponent:[url path]] stringByAppendingString:@".png"];
}
- (UIImage *)computedThumbnail
{
return [UIImage imageWithContentsOfFile:[self thumbnailPath]];
}
- (void)setComputedThumbnail:(UIImage *)image
{
NSURL *url = [NSURL fileURLWithPath:[self thumbnailPath]];
NSFileManager *manager = [NSFileManager defaultManager];
[manager createDirectoryAtPath:[[self thumbnailPath] stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:nil];
if (!image) {
[manager removeItemAtURL:url error:nil];
return;
}
[UIImagePNGRepresentation(image) writeToURL:url atomically:YES];
}
- (BOOL)isSafe - (BOOL)isSafe
{ {
[self willAccessValueForKey:@"isSafe"]; [self willAccessValueForKey:@"isSafe"];
......
...@@ -91,6 +91,18 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime"; ...@@ -91,6 +91,18 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
return directoryPath; return directoryPath;
} }
- (NSString *)thumbnailFolderPath
{
int directory = NSLibraryDirectory;
NSArray *paths = NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES);
NSString *directoryPath = [paths objectAtIndex:0];
#if DELETE_LIBRARY_ON_EACH_LAUNCH
[[NSFileManager defaultManager] removeItemAtPath:directoryPath error:nil];
#endif
return [directoryPath stringByAppendingPathComponent:@"Thumbnails"];
}
- (NSManagedObjectContext *)managedObjectContext - (NSManagedObjectContext *)managedObjectContext
{ {
if (_managedObjectContext) if (_managedObjectContext)
...@@ -627,19 +639,22 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime"; ...@@ -627,19 +639,22 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
if (!_allowNetworkAccess) { if (!_allowNetworkAccess) {
// Always attempt to fetch // Always attempt to fetch
request = [self fetchRequestForEntity:@"File"]; request = [self fetchRequestForEntity:@"File"];
[request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES && computedThumbnail == nil"]]; [request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES"]];
results = [[self managedObjectContext] executeFetchRequest:request error:nil]; results = [[self managedObjectContext] executeFetchRequest:request error:nil];
for (MLFile *file in results) for (MLFile *file in results) {
[self computeThumbnailForFile:file]; if (!file.computedThumbnail)
[self computeThumbnailForFile:file];
}
return; return;
} }
// Get the thumbnails to compute // Get the thumbnails to compute
request = [self fetchRequestForEntity:@"File"]; request = [self fetchRequestForEntity:@"File"];
[request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES && hasFetchedInfo == 1 && artworkURL == nil && computedThumbnail == nil"]]; [request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES && hasFetchedInfo == 1 && artworkURL == nil"]];
results = [[self managedObjectContext] executeFetchRequest:request error:nil]; results = [[self managedObjectContext] executeFetchRequest:request error:nil];
for (MLFile *file in results) for (MLFile *file in results)
[self computeThumbnailForFile:file]; if (!file.computedThumbnail)
[self computeThumbnailForFile:file];
// Get to fetch meta data // Get to fetch meta data
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
{ {
mediaThumbnailer.delegate = nil; mediaThumbnailer.delegate = nil;
MLLog(@"Finished thumbnail for %@", self.file.title); MLLog(@"Finished thumbnail for %@", self.file.title);
self.file.computedThumbnail = UIImagePNGRepresentation([UIImage imageWithCGImage:thumbnail]); self.file.computedThumbnail = [UIImage imageWithCGImage:thumbnail];
[self endThumbnailing]; [self endThumbnailing];
} }
......
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