Commit 4edb98f3 authored by Pierre's avatar Pierre

Store the thumbnails outside the db.

parent fe503ffc
......@@ -7,6 +7,7 @@
//
#import <CoreData/CoreData.h>
#import <UIKit/UIKit.h>
@class MLShowEpisode;
......@@ -40,13 +41,13 @@ extern NSString *kMLFileTypeTVShowEpisode;
@property (nonatomic, retain) NSNumber *unread;
@property (nonatomic, retain) NSNumber *hasFetchedInfo;
@property (nonatomic, retain) NSNumber *noOnlineMetaData;
@property (nonatomic, retain) NSData * computedThumbnail;
@property (nonatomic, retain) MLShowEpisode *showEpisode;
@property (nonatomic, retain) NSSet *labels;
@property (nonatomic, retain) NSSet *tracks;
@property (nonatomic, retain) NSNumber *isOnDisk;
@property (nonatomic, retain) NSNumber *duration;
@property (nonatomic, retain) UIImage *computedThumbnail;
@property (nonatomic, assign) BOOL isSafe;
@property (nonatomic, assign) BOOL isBeingParsed;
@property (nonatomic, assign) BOOL thumbnailTimeouted;
......
......@@ -23,6 +23,7 @@
// May be internal
- (NSFetchRequest *)fetchRequestForEntity:(NSString *)entity;
- (id)createObjectForEntity:(NSString *)entity;
- (NSString *)thumbnailFolderPath;
- (void)applicationWillStart;
- (void)applicationWillExit;
......
......@@ -14,6 +14,7 @@
#import "MLThumbnailerQueue.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NSString *kMLFileTypeMovie = @"movie";
NSString *kMLFileTypeClip = @"clip";
......@@ -102,13 +103,37 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
@dynamic unread;
@dynamic hasFetchedInfo;
@dynamic noOnlineMetaData;
@dynamic computedThumbnail;
@dynamic showEpisode;
@dynamic labels;
@dynamic tracks;
@dynamic isOnDisk;
@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
{
[self willAccessValueForKey:@"isSafe"];
......
......@@ -91,6 +91,18 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
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
{
if (_managedObjectContext)
......@@ -627,18 +639,21 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
if (!_allowNetworkAccess) {
// Always attempt to fetch
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];
for (MLFile *file in results)
for (MLFile *file in results) {
if (!file.computedThumbnail)
[self computeThumbnailForFile:file];
}
return;
}
// Get the thumbnails to compute
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];
for (MLFile *file in results)
if (!file.computedThumbnail)
[self computeThumbnailForFile:file];
......
......@@ -71,7 +71,7 @@
{
mediaThumbnailer.delegate = nil;
MLLog(@"Finished thumbnail for %@", self.file.title);
self.file.computedThumbnail = UIImagePNGRepresentation([UIImage imageWithCGImage:thumbnail]);
self.file.computedThumbnail = [UIImage imageWithCGImage:thumbnail];
[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