Add an additional check in TheTVDB.m initialize.

This commit is contained in:
Damiano Galassi committed 2014-01-08 11:50:51 +01:00
1 parent 5b334e60cb
commit b2dfc243a2
5 files changed
+440 -320

No files matched your search

+17 -4
View File
@@ -24,7 +24,13 @@ extern NSString * const MP42GenerateChaptersPreviewTrack;
extern NSString * const MP42CustomChaptersPreviewTrack;
extern NSString * const MP42OrganizeAlternateGroups;
@protocol MP42FileDelegate
typedef enum MP42Status : NSInteger {
MP42StatusLoaded = 0,
MP42StatusReading,
MP42StatusWriting
} MP42Status;
@protocol MP42FileDelegate <NSObject>
@optional
- (void)progressStatus:(CGFloat)progress;
- (void)endSave:(id)sender;
@@ -41,6 +47,8 @@ extern NSString * const MP42OrganizeAlternateGroups;
NSMutableDictionary *_importers;
BOOL _hasFileRepresentation;
MP42Status _status;
BOOL _cancelled;
NSMutableArray *_tracks;
@@ -52,7 +60,7 @@ extern NSString * const MP42OrganizeAlternateGroups;
@property(readonly) NSURL *URL;
@property(readonly) MP42Metadata *metadata;
@property(readonly, copy) NSArray *tracks;
@property(readonly) NSArray *tracks;
@property(readonly) BOOL hasFileRepresentation;
@property(readonly) NSUInteger duration;
@@ -73,12 +81,17 @@ extern NSString * const MP42OrganizeAlternateGroups;
- (void)moveTrackAtIndex:(NSUInteger)index toIndex:(NSUInteger)newIndex;
- (MP42ChapterTrack *)chapters;
/**
* Create a set of alternate group the way iTunes and Apple devices want:
* one alternate group for sound, one for subtitles, a disabled photo-jpeg track,
* a disabled chapter track, and a video track with no alternate group
*/
- (void)organizeAlternateGroups;
- (BOOL)optimize;
- (BOOL)writeToUrl:(NSURL *)url withAttributes:(NSDictionary *)attributes error:(NSError **)outError;
- (BOOL)updateMP4FileWithAttributes:(NSDictionary *)attributes error:(NSError **)outError;
- (BOOL)optimize;
- (void)cancel;
@end
+275 -316
View File
File diff suppressed because it is too large. Load diff
+19
View File
@@ -0,0 +1,19 @@
//
// MP42PreviewGenerator.h
// MP42Foundation
//
// Created by Damiano Galassi on 08/01/14.
// Copyright (c) 2014 Damiano Galassi. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface MP42PreviewGenerator : NSObject
+ (NSArray *)generatePreviewImagesFromChapters:(NSArray *)chapters andFile:(NSURL *)file;
+ (NSArray *)generatePreviewImagesQTKitFromChapters:(NSArray *)chapters andFile:(NSURL *)file;
+ (NSArray *)generatePreviewImagesAVFoundationFromChapters:(NSArray *)chapters andFile:(NSURL *)file;
@end
+117
View File
@@ -0,0 +1,117 @@
//
// MP42PreviewGenerator.m
// MP42Foundation
//
// Created by Damiano Galassi on 08/01/14.
// Copyright (c) 2014 Damiano Galassi. All rights reserved.
//
#import "MP42PreviewGenerator.h"
#import "MP42TextSample.h"
#import <QTKit/QTKit.h>
#if __MAC_OS_X_VERSION_MAX_ALLOWED > 1060
#import <AVFoundation/AVFoundation.h>
#endif
@implementation MP42PreviewGenerator
+ (NSArray *)generatePreviewImagesFromChapters:(NSArray *)chapters andFile:(NSURL *)file {
NSArray *images = nil;
// If we are on 10.7 or later, use AVFoundation, else QTKit
if (NSClassFromString(@"AVAsset")) {
images = [MP42PreviewGenerator generatePreviewImagesAVFoundationFromChapters:chapters andFile:file];
} else {
images = [MP42PreviewGenerator generatePreviewImagesQTKitFromChapters:chapters andFile:file];
}
return images;
}
+ (NSArray *)generatePreviewImagesQTKitFromChapters:(NSArray *)chapters andFile:(NSURL *)file {
__block QTMovie * qtMovie;
// QTMovie objects must always be create on the main thread.
NSDictionary *movieAttributes = @{QTMovieURLAttribute: file,
QTMovieAskUnresolvedDataRefsAttribute: @NO,
@"QTMovieOpenForPlaybackAttribute": @YES,
@"QTMovieOpenAsyncRequiredAttribute": @NO,
@"QTMovieOpenAsyncOKAttribute": @NO,
QTMovieApertureModeAttribute: QTMovieApertureModeClean};
if (dispatch_get_current_queue() != dispatch_get_main_queue()) {
dispatch_sync(dispatch_get_main_queue(), ^{
qtMovie = [[QTMovie alloc] initWithAttributes:movieAttributes error:nil];
});
}
else
qtMovie = [[QTMovie alloc] initWithAttributes:movieAttributes error:nil];
if (!qtMovie)
return nil;
for (QTTrack *qtTrack in [qtMovie tracksOfMediaType:@"sbtl"])
[qtTrack setAttribute:@NO forKey:QTTrackEnabledAttribute];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:QTMovieFrameImageTypeNSImage forKey:QTMovieFrameImageType];
NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:[chapters count]];
for (MP42TextSample *chapter in chapters) {
QTTime chapterTime = {
[chapter timestamp] + 1500, // Add a short offset, hopefully we will get a better image
1000, // if there is a fade
0
};
NSImage *frame = [qtMovie frameImageAtTime:chapterTime withAttributes:attributes error:nil];
if (images)
[images addObject:frame];
}
// Release the movie, we don't want to keep it open while we are writing in it using another library.
// I am not sure if it is safe to release a QTMovie from a background thread, let's do it on the main just to be sure.
if (dispatch_get_current_queue() != dispatch_get_main_queue()) {
dispatch_sync(dispatch_get_main_queue(), ^{
[qtMovie release];
});
}
else
[qtMovie release];
return [images autorelease];
}
+ (NSArray *)generatePreviewImagesAVFoundationFromChapters:(NSArray *)chapters andFile:(NSURL *)file {
NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:[chapters count]];
// If we are on 10.7, use the AVFoundation path
#if __MAC_OS_X_VERSION_MAX_ALLOWED > 1060
AVAsset *asset = [AVAsset assetWithURL:file];
if ([asset tracksWithMediaCharacteristic:AVMediaCharacteristicVisual]) {
AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
generator.appliesPreferredTrackTransform = YES;
generator.apertureMode = AVAssetImageGeneratorApertureModeCleanAperture;
generator.requestedTimeToleranceBefore = kCMTimeZero;
generator.requestedTimeToleranceAfter = kCMTimeZero;
for (MP42TextSample * chapter in chapters) {
CMTime time = CMTimeMake([chapter timestamp] + 1800, 1000);
CGImageRef imgRef = [generator copyCGImageAtTime:time actualTime:NULL error:NULL];
if (imgRef) {
NSSize size = NSMakeSize(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));
NSImage *frame = [[NSImage alloc] initWithCGImage:imgRef size:size];
[images addObject:frame];
[frame release];
}
CGImageRelease(imgRef);
}
}
#endif
return [images autorelease];
}
@end