Added a new SBQueue class in an effort to contain SBQueueController size.
This commit is contained in:
1 parent
42d23c8bdb
commit
dab25ea4b8
3 files changed
+553
No files matched your search
@@ -0,0 +1,73 @@
|
|||||||
|
//
|
||||||
|
// SBQueue.h
|
||||||
|
// Subler
|
||||||
|
//
|
||||||
|
// Created by Damiano Galassi on 27/02/14.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
#import <IOKit/pwr_mgt/IOPMLib.h>
|
||||||
|
|
||||||
|
@class SBQueueItem;
|
||||||
|
@class MP42File;
|
||||||
|
|
||||||
|
typedef NS_ENUM(NSUInteger, SBQueueStatus) {
|
||||||
|
SBQueueStatusUnknown = 0,
|
||||||
|
SBQueueStatusWorking,
|
||||||
|
SBQueueStatusCompleted,
|
||||||
|
SBQueueStatusFailed,
|
||||||
|
SBQueueStatusCancelled,
|
||||||
|
};
|
||||||
|
|
||||||
|
@interface SBQueue : NSObject {
|
||||||
|
@private
|
||||||
|
dispatch_queue_t _queue;
|
||||||
|
SBQueueStatus _status;
|
||||||
|
|
||||||
|
MP42File *_currentMP4;
|
||||||
|
NSMutableArray *_items;
|
||||||
|
NSURL *_URL;
|
||||||
|
NSURL *_destination;
|
||||||
|
|
||||||
|
IOPMAssertionID _assertionID;
|
||||||
|
IOReturn _io_success;
|
||||||
|
BOOL _cancelled;
|
||||||
|
|
||||||
|
BOOL _optimize;
|
||||||
|
BOOL _fetchMetadata;
|
||||||
|
BOOL _organizeGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property (atomic, readonly) SBQueueStatus status;
|
||||||
|
|
||||||
|
@property (atomic, copy) NSURL *destination;
|
||||||
|
@property (atomic) BOOL optimize;
|
||||||
|
@property (atomic) BOOL fetchMetadata;
|
||||||
|
@property (atomic) BOOL organizeGroups;
|
||||||
|
|
||||||
|
- (instancetype)initWithURL:(NSURL *)queueURL;
|
||||||
|
|
||||||
|
- (void)start;
|
||||||
|
- (void)stop;
|
||||||
|
|
||||||
|
- (void)addItem:(SBQueueItem *)item;
|
||||||
|
|
||||||
|
- (NSUInteger)count;
|
||||||
|
- (NSUInteger)readyCount;
|
||||||
|
|
||||||
|
- (SBQueueItem *)itemAtIndex:(NSUInteger)index;
|
||||||
|
- (NSUInteger)indexOfItem:(SBQueueItem *)item;
|
||||||
|
- (NSArray *)itemsAtIndexes:(NSIndexSet *)indexes;
|
||||||
|
|
||||||
|
- (void)insertItem:(SBQueueItem *)anItem atIndex:(NSUInteger)index;
|
||||||
|
|
||||||
|
- (void)removeItemsAtIndexes:(NSIndexSet *)indexes;
|
||||||
|
- (void)removeItem:(SBQueueItem *)item;
|
||||||
|
|
||||||
|
- (NSIndexSet *)removeCompletedItems;
|
||||||
|
|
||||||
|
- (BOOL)saveQueueToDisk;
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,474 @@
|
|||||||
|
//
|
||||||
|
// SBQueue.m
|
||||||
|
// Subler
|
||||||
|
//
|
||||||
|
// Created by Damiano Galassi on 27/02/14.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "SBQueue.h"
|
||||||
|
#import "SBQueueItem.h"
|
||||||
|
|
||||||
|
#import "MetadataImporter.h"
|
||||||
|
|
||||||
|
#import <MP42Foundation/MP42File.h>
|
||||||
|
#import <MP42Foundation/MP42FileImporter.h>
|
||||||
|
#import <MP42Foundation/MP42Image.h>
|
||||||
|
#import <MP42Foundation/MP42Utilities.h>
|
||||||
|
|
||||||
|
static NSString *fileType = @"mp4";
|
||||||
|
|
||||||
|
@interface SBQueue () <MP42FileDelegate>
|
||||||
|
|
||||||
|
@property (atomic) SBQueueStatus status;
|
||||||
|
|
||||||
|
@property (nonatomic, copy) NSURL *URL;
|
||||||
|
@property (nonatomic, retain) NSMutableArray *items;
|
||||||
|
|
||||||
|
@property (nonatomic) dispatch_queue_t queue;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation SBQueue
|
||||||
|
|
||||||
|
@synthesize status = _status, destination = _destination;
|
||||||
|
@synthesize optimize = _optimize, fetchMetadata = _fetchMetadata, organizeGroups = _organizeGroups;
|
||||||
|
@synthesize items = _items, URL = _URL, queue = _queue;
|
||||||
|
|
||||||
|
- (instancetype)initWithURL:(NSURL *)queueURL {
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
_queue = dispatch_queue_create("org.subler.Queue", NULL);
|
||||||
|
|
||||||
|
_URL = [queueURL copy];
|
||||||
|
|
||||||
|
if ([[NSFileManager defaultManager] fileExistsAtPath:[queueURL path]]) {
|
||||||
|
@try {
|
||||||
|
_items = [[NSKeyedUnarchiver unarchiveObjectWithFile:[queueURL path]] retain];
|
||||||
|
} @catch (NSException *exception) {
|
||||||
|
[[NSFileManager defaultManager] removeItemAtURL:queueURL error:nil];
|
||||||
|
_items = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SBQueueItem *item in _items)
|
||||||
|
if (item.status == SBQueueItemStatusWorking)
|
||||||
|
item.status = SBQueueItemStatusFailed;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_items) {
|
||||||
|
_items = [[NSMutableArray alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)saveQueueToDisk {
|
||||||
|
return [NSKeyedArchiver archiveRootObject:self.items toFile:[self.URL path]];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (SBQueueItem *)firstItemInQueue
|
||||||
|
{
|
||||||
|
for (SBQueueItem *item in self.items)
|
||||||
|
if ((item.status != SBQueueItemStatusCompleted) && (item.status != SBQueueItemStatusFailed))
|
||||||
|
return item;
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - item management
|
||||||
|
|
||||||
|
- (void)addItem:(SBQueueItem *)item
|
||||||
|
{
|
||||||
|
[self.items addObject:item];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)count {
|
||||||
|
return [self.items count];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)readyCount {
|
||||||
|
NSUInteger count = 0;
|
||||||
|
for (SBQueueItem *item in self.items)
|
||||||
|
if ([item status] != SBQueueItemStatusCompleted)
|
||||||
|
count++;
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (SBQueueItem *)itemAtIndex:(NSUInteger)index {
|
||||||
|
return [self.items objectAtIndex:index];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray *)itemsAtIndexes:(NSIndexSet *)indexes {
|
||||||
|
return [self.items objectsAtIndexes:indexes];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)indexOfItem:(SBQueueItem *)item {
|
||||||
|
return [self.items indexOfObject:item];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)insertItem:(SBQueueItem *)anItem atIndex:(NSUInteger)index {
|
||||||
|
[self.items insertObject:anItem atIndex:index];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)removeItemsAtIndexes:(NSIndexSet *)indexes {
|
||||||
|
[self.items removeObjectsAtIndexes:indexes];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)removeItem:(SBQueueItem *)item {
|
||||||
|
[self.items removeObject:item];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSIndexSet *)removeCompletedItems {
|
||||||
|
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
|
||||||
|
|
||||||
|
for (SBQueueItem *item in self.items)
|
||||||
|
if ([item status] == SBQueueItemStatusCompleted)
|
||||||
|
[indexes addIndex:[self.items indexOfObject:item]];
|
||||||
|
|
||||||
|
[self.items removeObjectsAtIndexes:indexes];
|
||||||
|
|
||||||
|
return [indexes autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - item preprocessing
|
||||||
|
|
||||||
|
- (NSArray *)loadSubtitles:(NSURL *)url
|
||||||
|
{
|
||||||
|
NSError *outError;
|
||||||
|
NSMutableArray *tracksArray = [[NSMutableArray alloc] init];
|
||||||
|
NSArray *directory = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[url URLByDeletingLastPathComponent]
|
||||||
|
includingPropertiesForKeys:nil
|
||||||
|
options:NSDirectoryEnumerationSkipsSubdirectoryDescendants |
|
||||||
|
NSDirectoryEnumerationSkipsHiddenFiles |
|
||||||
|
NSDirectoryEnumerationSkipsPackageDescendants
|
||||||
|
error:nil];
|
||||||
|
|
||||||
|
for (NSURL *dirUrl in directory) {
|
||||||
|
if ([[dirUrl pathExtension] isEqualToString:@"srt"]) {
|
||||||
|
NSComparisonResult result;
|
||||||
|
NSString *movieFilename = [[url URLByDeletingPathExtension] lastPathComponent];
|
||||||
|
NSString *subtitleFilename = [[dirUrl URLByDeletingPathExtension] lastPathComponent];
|
||||||
|
NSRange range = { 0, [movieFilename length] };
|
||||||
|
|
||||||
|
if ([movieFilename length] <= [subtitleFilename length]) {
|
||||||
|
result = [subtitleFilename compare:movieFilename options:NSCaseInsensitiveSearch range:range];
|
||||||
|
|
||||||
|
if (result == NSOrderedSame) {
|
||||||
|
MP42FileImporter *fileImporter = [[[MP42FileImporter alloc] initWithURL:dirUrl
|
||||||
|
error:&outError] autorelease];
|
||||||
|
|
||||||
|
for (MP42Track *track in fileImporter.tracks) {
|
||||||
|
[tracksArray addObject:track];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [tracksArray autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MP42Image *)loadArtwork:(NSURL *)url
|
||||||
|
{
|
||||||
|
NSData *artworkData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||||
|
if (artworkData && [artworkData length]) {
|
||||||
|
MP42Image *artwork = [[MP42Image alloc] initWithData:artworkData type:MP42_ART_JPEG];
|
||||||
|
if (artwork != nil) {
|
||||||
|
return [artwork autorelease];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MP42Metadata *)searchMetadataForFile:(NSURL *)url
|
||||||
|
{
|
||||||
|
id currentSearcher = nil;
|
||||||
|
MP42Metadata *metadata = nil;
|
||||||
|
|
||||||
|
// Parse FileName and search for metadata
|
||||||
|
NSDictionary *parsed = [MetadataImporter parseFilename:[url lastPathComponent]];
|
||||||
|
NSString *type = (NSString *)[parsed valueForKey:@"type"];
|
||||||
|
if ([@"movie" isEqualToString:type]) {
|
||||||
|
currentSearcher = [MetadataImporter defaultMovieProvider];
|
||||||
|
NSString *language = [MetadataImporter defaultMovieLanguage];
|
||||||
|
NSArray *results = [currentSearcher searchMovie:[parsed valueForKey:@"title"] language:language];
|
||||||
|
if ([results count])
|
||||||
|
metadata = [currentSearcher loadMovieMetadata:[results objectAtIndex:0] language:language];
|
||||||
|
} else if ([@"tv" isEqualToString:type]) {
|
||||||
|
currentSearcher = [MetadataImporter defaultTVProvider];
|
||||||
|
NSString *language = [MetadataImporter defaultTVLanguage];
|
||||||
|
NSArray *results = [currentSearcher searchTVSeries:[parsed valueForKey:@"seriesName"]
|
||||||
|
language:language seasonNum:[parsed valueForKey:@"seasonNum"]
|
||||||
|
episodeNum:[parsed valueForKey:@"episodeNum"]];
|
||||||
|
if ([results count])
|
||||||
|
metadata = [currentSearcher loadTVMetadata:[results objectAtIndex:0] language:language];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadata.artworkThumbURLs && [metadata.artworkThumbURLs count]) {
|
||||||
|
NSURL *artworkURL = nil;
|
||||||
|
if ([type isEqualToString:@"movie"]) {
|
||||||
|
artworkURL = [metadata.artworkFullsizeURLs objectAtIndex:0];
|
||||||
|
} else if ([type isEqualToString:@"tv"]) {
|
||||||
|
if ([metadata.artworkFullsizeURLs count] > 1) {
|
||||||
|
int i = 0;
|
||||||
|
for (NSString *artworkProviderName in metadata.artworkProviderNames) {
|
||||||
|
NSArray *a = [artworkProviderName componentsSeparatedByString:@"|"];
|
||||||
|
if ([a count] > 1 && ![[a objectAtIndex:1] isEqualToString:@"episode"]) {
|
||||||
|
artworkURL = [metadata.artworkFullsizeURLs objectAtIndex:i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
artworkURL = [metadata.artworkFullsizeURLs objectAtIndex:0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MP42Image *artwork = [self loadArtwork:artworkURL];
|
||||||
|
|
||||||
|
if (artwork)
|
||||||
|
[metadata.artworks addObject:artwork];
|
||||||
|
}
|
||||||
|
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MP42File *)prepareQueueItem:(NSURL*)url error:(NSError**)outError {
|
||||||
|
NSString *type;
|
||||||
|
MP42File *mp4File = nil;
|
||||||
|
|
||||||
|
[url getResourceValue:&type forKey:NSURLTypeIdentifierKey error:outError];
|
||||||
|
|
||||||
|
if ([type isEqualToString:@"com.apple.m4a-audio"] || [type isEqualToString:@"com.apple.m4v-video"] || [type isEqualToString:@"public.mpeg-4"]) {
|
||||||
|
mp4File = [[MP42File alloc] initWithExistingFile:url andDelegate:self];
|
||||||
|
} else {
|
||||||
|
mp4File = [[MP42File alloc] initWithDelegate:self];
|
||||||
|
MP42FileImporter *fileImporter = [[MP42FileImporter alloc] initWithURL:url
|
||||||
|
error:outError];
|
||||||
|
|
||||||
|
for (MP42Track *track in fileImporter.tracks) {
|
||||||
|
if ([track.format isEqualToString:MP42AudioFormatAC3]) {
|
||||||
|
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBAudioConvertAC3"] boolValue]) {
|
||||||
|
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBAudioKeepAC3"] boolValue] ||
|
||||||
|
![(MP42AudioTrack *)track fallbackTrack]) {
|
||||||
|
MP42AudioTrack *copy = [track copy];
|
||||||
|
[copy setNeedConversion:YES];
|
||||||
|
[copy setMixdownType:SBDolbyPlIIMixdown];
|
||||||
|
|
||||||
|
[(MP42AudioTrack *)track setFallbackTrack:copy];
|
||||||
|
|
||||||
|
[mp4File addTrack:copy];
|
||||||
|
|
||||||
|
[copy release];
|
||||||
|
} else {
|
||||||
|
track.needConversion = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([track.format isEqualToString:MP42AudioFormatDTS] ||
|
||||||
|
([track.format isEqualToString:MP42SubtitleFormatVobSub] && [[[NSUserDefaults standardUserDefaults] valueForKey:@"SBSubtitleConvertBitmap"] boolValue]))
|
||||||
|
track.needConversion = YES;
|
||||||
|
|
||||||
|
if (isTrackMuxable(track.format) || trackNeedConversion(track.format))
|
||||||
|
[mp4File addTrack:track];
|
||||||
|
}
|
||||||
|
[fileImporter release];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search for external subtitles files
|
||||||
|
NSArray *subtitles = [self loadSubtitles:url];
|
||||||
|
for (MP42SubtitleTrack *subTrack in subtitles) {
|
||||||
|
[mp4File addTrack:subTrack];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search for metadata
|
||||||
|
if (self.fetchMetadata) {
|
||||||
|
MP42Metadata *metadata = [self searchMetadataForFile:url];
|
||||||
|
|
||||||
|
for (MP42Track *track in mp4File.tracks)
|
||||||
|
if ([track isKindOfClass:[MP42VideoTrack class]]) {
|
||||||
|
int hdVideo = isHdVideo([((MP42VideoTrack *) track) trackWidth], [((MP42VideoTrack *) track) trackHeight]);
|
||||||
|
|
||||||
|
if (hdVideo)
|
||||||
|
[mp4File.metadata setTag:@(hdVideo) forKey:@"HD Video"];
|
||||||
|
}
|
||||||
|
|
||||||
|
[[mp4File metadata] mergeMetadata:metadata];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.organizeGroups)
|
||||||
|
[mp4File organizeAlternateGroups];
|
||||||
|
|
||||||
|
return [mp4File autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Queue control
|
||||||
|
|
||||||
|
- (void)disableSleep {
|
||||||
|
CFStringRef reasonForActivity= CFSTR("Subler Queue Started");
|
||||||
|
_io_success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
|
||||||
|
kIOPMAssertionLevelOn, reasonForActivity, &_assertionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)enableSleep {
|
||||||
|
if (_io_success == kIOReturnSuccess) {
|
||||||
|
IOPMAssertionRelease(_assertionID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)start
|
||||||
|
{
|
||||||
|
if (self.status == SBQueueStatusWorking) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
self.status = SBQueueStatusWorking;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable sleep assertion
|
||||||
|
[self disableSleep];
|
||||||
|
|
||||||
|
dispatch_async(self.queue, ^{
|
||||||
|
NSError *outError = nil;
|
||||||
|
BOOL noErr = NO;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
@autoreleasepool {
|
||||||
|
__block SBQueueItem *item = nil;
|
||||||
|
|
||||||
|
// Get the first item available in the queue
|
||||||
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||||
|
item = [[self firstItemInQueue] retain];
|
||||||
|
item.status = SBQueueItemStatusWorking;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (item == nil) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
noErr = [self processItem:item error:&outError];
|
||||||
|
|
||||||
|
// Check results
|
||||||
|
if (_cancelled) {
|
||||||
|
item.status = SBQueueItemStatusCancelled;
|
||||||
|
self.status = SBQueueStatusCancelled;
|
||||||
|
break;
|
||||||
|
} else if (noErr) {
|
||||||
|
if (self.optimize) {
|
||||||
|
noErr = [_currentMP4 optimize];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (noErr) {
|
||||||
|
item.status = SBQueueItemStatusCompleted;
|
||||||
|
} else {
|
||||||
|
item.status = SBQueueItemStatusFailed;
|
||||||
|
if (outError) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[NSApp presentError:outError];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the queue
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self saveQueueToDisk];
|
||||||
|
});
|
||||||
|
|
||||||
|
[item release];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.status == SBQueueStatusCancelled) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable sleep assertion
|
||||||
|
[self enableSleep];
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)processItem:(SBQueueItem *)item error:(NSError **)outError{
|
||||||
|
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
|
||||||
|
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue])
|
||||||
|
[attributes setObject:@YES forKey:MP42GenerateChaptersPreviewTrack];
|
||||||
|
|
||||||
|
#ifdef SB_SANDBOX
|
||||||
|
if([destination respondsToSelector:@selector(startAccessingSecurityScopedResource)])
|
||||||
|
[destination startAccessingSecurityScopedResource];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BOOL noErr = YES;
|
||||||
|
|
||||||
|
_currentMP4 = [item mp4File];
|
||||||
|
[_currentMP4 setDelegate:self];
|
||||||
|
|
||||||
|
// Update the UI
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
/*NSInteger itemIndex = [filesArray indexOfObject:item];
|
||||||
|
[countLabel setStringValue:[NSString stringWithFormat:@"Processing file %ld of %lu.",(long)itemIndex + 1, (unsigned long)[filesArray count]]];
|
||||||
|
[[NSApp dockTile] setBadgeLabel:[NSString stringWithFormat:@"%lu", (unsigned long)[filesArray count] - itemIndex]];
|
||||||
|
[tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] columnIndexes:[NSIndexSet indexSetWithIndex:0]];*/
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set the destination url
|
||||||
|
if (![item destURL]) {
|
||||||
|
if (!_currentMP4 && self.destination /*&& customDestination*/) {
|
||||||
|
item.destURL = [[[self.destination URLByAppendingPathComponent:[item.URL lastPathComponent]] URLByDeletingPathExtension] URLByAppendingPathExtension:fileType];
|
||||||
|
} else {
|
||||||
|
item.destURL = [[item.URL URLByDeletingPathExtension] URLByAppendingPathExtension:fileType];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The file has been added directly to the queue
|
||||||
|
if (!_currentMP4 && item.URL)
|
||||||
|
_currentMP4 = [self prepareQueueItem:item.URL error:outError];
|
||||||
|
|
||||||
|
NSDictionary *dict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[_currentMP4.URL path] error:NULL];
|
||||||
|
NSNumber *freeSpace = [dict objectForKey:NSFileSystemFreeSize];
|
||||||
|
if (freeSpace && [_currentMP4 dataSize] > [freeSpace longLongValue]) {
|
||||||
|
NSLog(@"Not enough disk space");
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have an existing mp4 file, update it
|
||||||
|
if (!_cancelled) {
|
||||||
|
if ([_currentMP4 hasFileRepresentation])
|
||||||
|
noErr = [_currentMP4 updateMP4FileWithAttributes:attributes error:outError];
|
||||||
|
// Write the new file to disk
|
||||||
|
else if (_currentMP4 && item.destURL) {
|
||||||
|
[attributes addEntriesFromDictionary:[item attributes]];
|
||||||
|
noErr = [_currentMP4 writeToUrl:[item destURL]
|
||||||
|
withAttributes:attributes
|
||||||
|
error:outError];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SB_SANDBOX
|
||||||
|
if([destination respondsToSelector:@selector(stopAccessingSecurityScopedResource)])
|
||||||
|
[destination stopAccessingSecurityScopedResource];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
[attributes release];
|
||||||
|
return noErr;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)stop {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
dispatch_release(_queue);
|
||||||
|
|
||||||
|
[_items release];
|
||||||
|
[_URL release];
|
||||||
|
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -57,6 +57,7 @@
|
|||||||
A9D47B5917B239E200900BCA /* EncodeCanceled@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = A9D47B5517B239E200900BCA /* EncodeCanceled@2x.png */; };
|
A9D47B5917B239E200900BCA /* EncodeCanceled@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = A9D47B5517B239E200900BCA /* EncodeCanceled@2x.png */; };
|
||||||
A9D47B5A17B239E200900BCA /* EncodeComplete.png in Resources */ = {isa = PBXBuildFile; fileRef = A9D47B5617B239E200900BCA /* EncodeComplete.png */; };
|
A9D47B5A17B239E200900BCA /* EncodeComplete.png in Resources */ = {isa = PBXBuildFile; fileRef = A9D47B5617B239E200900BCA /* EncodeComplete.png */; };
|
||||||
A9D47B5B17B239E200900BCA /* EncodeComplete@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = A9D47B5717B239E200900BCA /* EncodeComplete@2x.png */; };
|
A9D47B5B17B239E200900BCA /* EncodeComplete@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = A9D47B5717B239E200900BCA /* EncodeComplete@2x.png */; };
|
||||||
|
A9D73C5218BF3F1100C6FFA6 /* SBQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = A9D73C5118BF3F1100C6FFA6 /* SBQueue.m */; };
|
||||||
A9F284A0133C9F6E00F10951 /* close.pdf in Resources */ = {isa = PBXBuildFile; fileRef = A9F2849D133C9F6E00F10951 /* close.pdf */; };
|
A9F284A0133C9F6E00F10951 /* close.pdf in Resources */ = {isa = PBXBuildFile; fileRef = A9F2849D133C9F6E00F10951 /* close.pdf */; };
|
||||||
A9F284A1133C9F6E00F10951 /* close-over.pdf in Resources */ = {isa = PBXBuildFile; fileRef = A9F2849E133C9F6E00F10951 /* close-over.pdf */; };
|
A9F284A1133C9F6E00F10951 /* close-over.pdf in Resources */ = {isa = PBXBuildFile; fileRef = A9F2849E133C9F6E00F10951 /* close-over.pdf */; };
|
||||||
A9F284A2133C9F6E00F10951 /* close-pressed.pdf in Resources */ = {isa = PBXBuildFile; fileRef = A9F2849F133C9F6E00F10951 /* close-pressed.pdf */; };
|
A9F284A2133C9F6E00F10951 /* close-pressed.pdf in Resources */ = {isa = PBXBuildFile; fileRef = A9F2849F133C9F6E00F10951 /* close-pressed.pdf */; };
|
||||||
@@ -207,6 +208,8 @@
|
|||||||
A9D47B5517B239E200900BCA /* EncodeCanceled@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "EncodeCanceled@2x.png"; path = "images/EncodeCanceled@2x.png"; sourceTree = "<group>"; };
|
A9D47B5517B239E200900BCA /* EncodeCanceled@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "EncodeCanceled@2x.png"; path = "images/EncodeCanceled@2x.png"; sourceTree = "<group>"; };
|
||||||
A9D47B5617B239E200900BCA /* EncodeComplete.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = EncodeComplete.png; path = images/EncodeComplete.png; sourceTree = "<group>"; };
|
A9D47B5617B239E200900BCA /* EncodeComplete.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = EncodeComplete.png; path = images/EncodeComplete.png; sourceTree = "<group>"; };
|
||||||
A9D47B5717B239E200900BCA /* EncodeComplete@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "EncodeComplete@2x.png"; path = "images/EncodeComplete@2x.png"; sourceTree = "<group>"; };
|
A9D47B5717B239E200900BCA /* EncodeComplete@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "EncodeComplete@2x.png"; path = "images/EncodeComplete@2x.png"; sourceTree = "<group>"; };
|
||||||
|
A9D73C5018BF3F1100C6FFA6 /* SBQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBQueue.h; path = Classes/SBQueue.h; sourceTree = "<group>"; };
|
||||||
|
A9D73C5118BF3F1100C6FFA6 /* SBQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SBQueue.m; path = Classes/SBQueue.m; sourceTree = "<group>"; };
|
||||||
A9ED7B21180067A2008FD3A8 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
|
A9ED7B21180067A2008FD3A8 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
|
||||||
A9F2849D133C9F6E00F10951 /* close.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = close.pdf; path = images/close.pdf; sourceTree = "<group>"; };
|
A9F2849D133C9F6E00F10951 /* close.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = close.pdf; path = images/close.pdf; sourceTree = "<group>"; };
|
||||||
A9F2849E133C9F6E00F10951 /* close-over.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = "close-over.pdf"; path = "images/close-over.pdf"; sourceTree = "<group>"; };
|
A9F2849E133C9F6E00F10951 /* close-over.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = "close-over.pdf"; path = "images/close-over.pdf"; sourceTree = "<group>"; };
|
||||||
@@ -311,6 +314,8 @@
|
|||||||
A9B46ABE12B79D1C0040517A /* SBDocument.m */,
|
A9B46ABE12B79D1C0040517A /* SBDocument.m */,
|
||||||
A961475F13F567E10068F161 /* SBQueueController.h */,
|
A961475F13F567E10068F161 /* SBQueueController.h */,
|
||||||
A961476013F567E10068F161 /* SBQueueController.m */,
|
A961476013F567E10068F161 /* SBQueueController.m */,
|
||||||
|
A9D73C5018BF3F1100C6FFA6 /* SBQueue.h */,
|
||||||
|
A9D73C5118BF3F1100C6FFA6 /* SBQueue.m */,
|
||||||
A982D0BE140AB66400B92357 /* SBQueueItem.h */,
|
A982D0BE140AB66400B92357 /* SBQueueItem.h */,
|
||||||
A982D0BF140AB66400B92357 /* SBQueueItem.m */,
|
A982D0BF140AB66400B92357 /* SBQueueItem.m */,
|
||||||
A961476113F567E10068F161 /* SBPresetManager.h */,
|
A961476113F567E10068F161 /* SBPresetManager.h */,
|
||||||
@@ -654,6 +659,7 @@
|
|||||||
A9B46ABF12B79D1C0040517A /* SBDocument.m in Sources */,
|
A9B46ABF12B79D1C0040517A /* SBDocument.m in Sources */,
|
||||||
CD71FEA312F1B5AF00F0A98D /* SBMetadataSearchController.m in Sources */,
|
CD71FEA312F1B5AF00F0A98D /* SBMetadataSearchController.m in Sources */,
|
||||||
CD71FF1D12F1C4A900F0A98D /* TheTVDB.m in Sources */,
|
CD71FF1D12F1C4A900F0A98D /* TheTVDB.m in Sources */,
|
||||||
|
A9D73C5218BF3F1100C6FFA6 /* SBQueue.m in Sources */,
|
||||||
A9AB485717F0AEAC000AA72E /* SBSoundViewController.m in Sources */,
|
A9AB485717F0AEAC000AA72E /* SBSoundViewController.m in Sources */,
|
||||||
CD56963212FAAD680029FADB /* SBArtworkSelector.m in Sources */,
|
CD56963212FAAD680029FADB /* SBArtworkSelector.m in Sources */,
|
||||||
A936E03E130BE10200CA5527 /* MAAttachedWindow.m in Sources */,
|
A936E03E130BE10200CA5527 /* MAAttachedWindow.m in Sources */,
|
||||||
|
|||||||
Reference in new issue
Block a user