Initial import
This commit is contained in:
commit
fcc318e844
135 files changed
+38844
No files matched your search
Vendored
BIN
Binary file not shown.
Executable
+48
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// MetadataImporter.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2013-05-30.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class SBMetadataSearchController;
|
||||
@class MP42Metadata;
|
||||
|
||||
@interface MetadataImporter : NSObject {
|
||||
SBMetadataSearchController *mCallback;
|
||||
BOOL isCancelled;
|
||||
}
|
||||
|
||||
#pragma mark Helper routines
|
||||
+ (NSDictionary *) parseFilename: (NSString *) filename;
|
||||
+ (NSString *) urlEncoded:(NSString *)s;
|
||||
+ (NSData *) downloadDataOrGetFromCache:(NSURL *)url;
|
||||
|
||||
#pragma mark Static methods
|
||||
+ (NSArray *) languagesForProvider:(NSString *)aProvider;
|
||||
+ (instancetype) importerForProvider:(NSString *)aProviderName;
|
||||
+ (instancetype) defaultMovieProvider;
|
||||
+ (instancetype) defaultTVProvider;
|
||||
+ (NSString *) defaultMovieLanguage;
|
||||
+ (NSString *) defaultTVLanguage;
|
||||
|
||||
#pragma mark Asynchronous searching
|
||||
- (void) searchTVSeries:(NSString *)aSeries language:(NSString *)aLanguage callback:(SBMetadataSearchController *)aCallback;
|
||||
- (void) searchTVSeries:(NSString *)aSeries language:(NSString *)aLanguage seasonNum:(NSString *)aSeasonNum episodeNum:(NSString *)aEpisodeNum callback:(SBMetadataSearchController *)aCallback;
|
||||
- (void) loadTVMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage callback:(SBMetadataSearchController *)aCallback;
|
||||
- (void) searchMovie:(NSString *)aMovieTitle language:(NSString *)aLanguage callback:(SBMetadataSearchController *)aCallback;
|
||||
- (void) loadMovieMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage callback:(SBMetadataSearchController *)aCallback;
|
||||
- (void) cancel;
|
||||
|
||||
#pragma Methods to be overridden
|
||||
- (NSArray *) languages;
|
||||
- (NSArray *) searchTVSeries:(NSString *)aSeriesName language:(NSString *)aLanguage;
|
||||
- (NSArray *) searchTVSeries:(NSString *)aSeriesName language:(NSString *)aLanguage seasonNum:(NSString *)aSeasonNum episodeNum:(NSString *)aEpisodeNum;
|
||||
- (NSArray *) searchMovie:(NSString *)aMovieTitle language:(NSString *)aLanguage;
|
||||
- (MP42Metadata*) loadTVMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage;
|
||||
- (MP42Metadata*) loadMovieMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage;
|
||||
|
||||
@end
|
||||
Executable
+312
@@ -0,0 +1,312 @@
|
||||
//
|
||||
// MetadataImporter.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2013-05-30.
|
||||
//
|
||||
//
|
||||
|
||||
#import <MP42Foundation/MP42Metadata.h>
|
||||
#import <MP42Foundation/MP42Languages.h>
|
||||
#import <MP42Foundation/RegexKitLite.h>
|
||||
|
||||
#import "MetadataImporter.h"
|
||||
|
||||
#import "SBMetadataSearchController.h"
|
||||
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
#import "iTunesStore.h"
|
||||
#import "TheMovieDB3.h"
|
||||
#import "TheTVDB.h"
|
||||
|
||||
|
||||
@implementation MetadataImporter
|
||||
|
||||
#pragma mark Helper routines
|
||||
|
||||
+ (NSDictionary *) parseFilename: (NSString *) filename
|
||||
{
|
||||
NSMutableDictionary *results = nil;
|
||||
|
||||
if (!filename || ![filename length]) {
|
||||
return results;
|
||||
}
|
||||
|
||||
NSString *regexString = @"^\\[(.+)\\](?:(?:\\s|_)+)?([^()]+)(?:(?:\\s|_)+)(?:(?:-\\s|-_|Ep)+)([0-9][0-9]?)";
|
||||
NSDictionary *resultDictionary = [filename dictionaryByMatchingRegex:regexString
|
||||
withKeysAndCaptures:@"fanSubGroup", 1, @"seriesName", 2, @"episodeNumber", 3, nil];
|
||||
|
||||
if (resultDictionary != nil && [resultDictionary count]) {
|
||||
results = [[NSMutableDictionary alloc] initWithCapacity:2];
|
||||
NSString *seriesName = [[resultDictionary valueForKey:@"seriesName"] stringByReplacingOccurrencesOfString:@"_" withString:@" "];
|
||||
NSInteger episodeNumber = [[resultDictionary valueForKey:@"episodeNumber"] integerValue];
|
||||
[results setValue:@"tv" forKey:@"type"];
|
||||
[results setValue:seriesName forKey:@"seriesName"];
|
||||
[results setValue:@"1" forKey:@"seasonNum"];
|
||||
[results setValue:[NSString stringWithFormat:@"%ld", (long) episodeNumber] forKey:@"episodeNum"];
|
||||
|
||||
return [results autorelease];
|
||||
}
|
||||
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
[task setLaunchPath:@"/usr/bin/perl"];
|
||||
|
||||
NSMutableArray *args = [[NSMutableArray alloc] initWithCapacity:3];
|
||||
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"ParseFilename" ofType:@""];
|
||||
[args addObject:[NSString stringWithFormat:@"-I%@/lib", path]];
|
||||
[args addObject:[NSString stringWithFormat:@"%@/ParseFilename.pl", path]];
|
||||
[args addObject:filename];
|
||||
[task setArguments:args];
|
||||
|
||||
NSPipe *stdOut = [[NSPipe alloc] init];
|
||||
NSFileHandle *stdOutWrite = [stdOut fileHandleForWriting];
|
||||
[task setStandardOutput:stdOutWrite];
|
||||
|
||||
[task launch];
|
||||
[task waitUntilExit];
|
||||
[stdOutWrite closeFile];
|
||||
|
||||
NSData *outputData = [[stdOut fileHandleForReading] readDataToEndOfFile];
|
||||
NSString *outputString = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
|
||||
NSArray *lines = [outputString componentsSeparatedByString:@"\n"];
|
||||
|
||||
if ([lines count]) {
|
||||
if ([(NSString *) [lines objectAtIndex:0] isEqualToString:@"tv"]) {
|
||||
if ([lines count] >= 4) {
|
||||
results = [[NSMutableDictionary alloc] initWithCapacity:4];
|
||||
[results setValue:@"tv" forKey:@"type"];
|
||||
NSString *newSeriesName=[[lines objectAtIndex:1]
|
||||
stringByReplacingOccurrencesOfString:@"."
|
||||
withString:@" "];
|
||||
[results setValue:newSeriesName forKey:@"seriesName"];
|
||||
[results setValue:[lines objectAtIndex:2] forKey:@"seasonNum"];
|
||||
[results setValue:[lines objectAtIndex:3] forKey:@"episodeNum"];
|
||||
}
|
||||
} else if ([(NSString *) [lines objectAtIndex:0] isEqualToString:@"movie"]) {
|
||||
if ([lines count] >= 2) {
|
||||
results = [[NSMutableDictionary alloc] initWithCapacity:4];
|
||||
[results setValue:@"movie" forKey:@"type"];
|
||||
NSString *newTitle=[[lines objectAtIndex:1]
|
||||
stringByReplacingOccurrencesOfString:@"."
|
||||
withString:@" "];
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"(" withString:@" "];
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@")" withString:@" "];
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"[" withString:@" "];
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"]" withString:@" "];
|
||||
newTitle = [newTitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
[results setValue:newTitle forKey:@"title"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[outputString release];
|
||||
[stdOut release];
|
||||
[args release];
|
||||
[task release];
|
||||
|
||||
return [results autorelease];
|
||||
}
|
||||
|
||||
+ (NSString *) urlEncoded:(NSString *)s {
|
||||
CFStringRef urlString = CFURLCreateStringByAddingPercentEscapes(
|
||||
NULL,
|
||||
(CFStringRef) s,
|
||||
NULL,
|
||||
(CFStringRef) @"!*'\"();:@&=+$,/?%#[]% ",
|
||||
kCFStringEncodingUTF8);
|
||||
return [(NSString *)urlString autorelease];
|
||||
}
|
||||
|
||||
+ (NSString *) md5String:(NSString *) s {
|
||||
const char *cStr = [s UTF8String];
|
||||
unsigned char result[CC_MD5_DIGEST_LENGTH];
|
||||
CC_MD5(cStr, strlen(cStr), result);
|
||||
NSMutableString *r = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
|
||||
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; ++i) {
|
||||
[r appendFormat:@"%02x", result[i]];
|
||||
}
|
||||
return [NSString stringWithString:r];
|
||||
}
|
||||
|
||||
+ (NSData *)downloadDataOrGetFromCache:(NSURL *)url {
|
||||
NSString *path = nil;
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
if ([paths count]) {
|
||||
NSString *bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
|
||||
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:bundleName];
|
||||
}
|
||||
NSString *filename = [path stringByAppendingPathComponent:[MetadataImporter md5String:[url absoluteString]]];
|
||||
NSString *extension = [[url path] pathExtension];
|
||||
filename = [filename stringByAppendingPathExtension:extension];
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:filename]) {
|
||||
NSDictionary* attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filename error:nil];
|
||||
if (attrs) {
|
||||
NSDate *date = [attrs fileCreationDate];
|
||||
NSTimeInterval oldness = [date timeIntervalSinceNow];
|
||||
// if less than 2 hours old
|
||||
if (([[[[url absoluteString] pathExtension] lowercaseString] isEqualToString:@"jpg"]) || (oldness > -60 * 60 * 2)) {
|
||||
return [NSData dataWithContentsOfFile:filename];
|
||||
}
|
||||
}
|
||||
}
|
||||
NSError *outError = nil;
|
||||
NSData *r = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&outError];
|
||||
|
||||
if (!outError && r)
|
||||
[r writeToFile:filename atomically:NO];
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#pragma mark Static methods
|
||||
|
||||
+ (NSArray *) languagesForProvider:(NSString *)aProvider {
|
||||
MetadataImporter *m = [MetadataImporter importerForProvider:aProvider];
|
||||
NSArray *a = [m languages];
|
||||
return a;
|
||||
}
|
||||
|
||||
+ (instancetype) importerForProvider:(NSString *)aProvider {
|
||||
if ([aProvider isEqualToString:@"iTunes Store"]) {
|
||||
return [[[iTunesStore alloc] init] autorelease];
|
||||
} else if ([aProvider isEqualToString:@"TheMovieDB"]) {
|
||||
return [[[TheMovieDB3 alloc] init] autorelease];
|
||||
} else if ([aProvider isEqualToString:@"TheTVDB"]) {
|
||||
return [[[TheTVDB alloc] init] autorelease];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (instancetype) defaultMovieProvider {
|
||||
return [MetadataImporter importerForProvider:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBMetadataPreference|Movie"]];
|
||||
}
|
||||
|
||||
+ (instancetype) defaultTVProvider {
|
||||
return [MetadataImporter importerForProvider:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBMetadataPreference|TV"]];
|
||||
}
|
||||
|
||||
+ (NSString *) defaultMovieLanguage {
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
return [defaults valueForKey:[NSString stringWithFormat:@"SBMetadataPreference|Movie|%@|Language", [defaults valueForKey:@"SBMetadataPreference|Movie"]]];
|
||||
}
|
||||
|
||||
+ (NSString *) defaultTVLanguage {
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
return [defaults valueForKey:[NSString stringWithFormat:@"SBMetadataPreference|TV|%@|Language", [defaults valueForKey:@"SBMetadataPreference|TV"]]];
|
||||
}
|
||||
|
||||
#pragma mark Asynchronous searching
|
||||
|
||||
- (void) searchTVSeries:(NSString *)aSeries language:(NSString *)aLanguage callback:(SBMetadataSearchController *)aCallback {
|
||||
mCallback = aCallback;
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
@autoreleasepool {
|
||||
NSArray *results = [self searchTVSeries:aSeries language:aLanguage];
|
||||
if (!isCancelled) {
|
||||
[mCallback performSelectorOnMainThread:@selector(searchTVSeriesNameDone:) withObject:results waitUntilDone:YES];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void) searchTVSeries:(NSString *)aSeries language:(NSString *)aLanguage seasonNum:(NSString *)aSeasonNum episodeNum:(NSString *)aEpisodeNum callback:(SBMetadataSearchController *)aCallback {
|
||||
mCallback = aCallback;
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
@autoreleasepool {
|
||||
NSArray *results = [self searchTVSeries:aSeries language:aLanguage seasonNum:aSeasonNum episodeNum:aEpisodeNum];
|
||||
if (!isCancelled) {
|
||||
[mCallback performSelectorOnMainThread:@selector(searchForResultsDone:) withObject:results waitUntilDone:YES];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void) loadTVMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage callback:(SBMetadataSearchController *)aCallback {
|
||||
mCallback = aCallback;
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
@autoreleasepool {
|
||||
[self loadTVMetadata:aMetadata language:aLanguage];
|
||||
if (!isCancelled) {
|
||||
[mCallback performSelectorOnMainThread:@selector(loadAdditionalMetadataDone:) withObject:aMetadata waitUntilDone:YES];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void) searchMovie:(NSString *)aMovieTitle language:(NSString *)aLanguage callback:(SBMetadataSearchController *)aCallback {
|
||||
mCallback = aCallback;
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
@autoreleasepool {
|
||||
NSArray *results = [self searchMovie:aMovieTitle language:aLanguage];
|
||||
if (!isCancelled)
|
||||
[mCallback performSelectorOnMainThread:@selector(searchForResultsDone:) withObject:results waitUntilDone:YES];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void) loadMovieMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage callback:(SBMetadataSearchController *)aCallback {
|
||||
mCallback = aCallback;
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
@autoreleasepool {
|
||||
[self loadMovieMetadata:aMetadata language:aLanguage];
|
||||
if (!isCancelled) {
|
||||
[mCallback performSelectorOnMainThread:@selector(loadAdditionalMetadataDone:) withObject:aMetadata waitUntilDone:YES];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)cancel {
|
||||
@synchronized(self) {
|
||||
isCancelled = YES;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Methods to be overridden
|
||||
|
||||
- (NSArray *) languages {
|
||||
@throw [NSException exceptionWithName:NSInternalInconsistencyException
|
||||
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
- (NSArray *) searchTVSeries:(NSString *)aSeriesName language:(NSString *)aLanguage {
|
||||
TheTVDB *searcher = [[TheTVDB alloc] init];
|
||||
NSArray *a = [searcher searchTVSeries:aSeriesName language:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBMetadataPreference|TV|TheTVDB|Language"]];
|
||||
[searcher release];
|
||||
return a;
|
||||
}
|
||||
|
||||
- (NSArray *) searchTVSeries:(NSString *)aSeriesName language:(NSString *)aLanguage seasonNum:(NSString *)aSeasonNum episodeNum:(NSString *)aEpisodeNum {
|
||||
@throw [NSException exceptionWithName:NSInternalInconsistencyException
|
||||
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
- (MP42Metadata*) loadTVMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage {
|
||||
@throw [NSException exceptionWithName:NSInternalInconsistencyException
|
||||
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
- (NSArray *) searchMovie:(NSString *)aMovieTitle language:(NSString *)aLanguage {
|
||||
@throw [NSException exceptionWithName:NSInternalInconsistencyException
|
||||
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
- (MP42Metadata*) loadMovieMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage {
|
||||
@throw [NSException exceptionWithName:NSInternalInconsistencyException
|
||||
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
#pragma mark Finishing up
|
||||
|
||||
- (void) dealloc {
|
||||
mCallback = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// TheMovieDB3.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2013/05/30.
|
||||
// Copyright 2013 Douglas Stebila. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import "MetadataImporter.h"
|
||||
|
||||
@interface TheMovieDB3 : MetadataImporter
|
||||
|
||||
@end
|
||||
Executable
+193
@@ -0,0 +1,193 @@
|
||||
//
|
||||
// TheMovieDB3.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2013-05-30.
|
||||
//
|
||||
//
|
||||
|
||||
#import <MP42Foundation/MP42Metadata.h>
|
||||
#import <MP42Foundation/MP42Ratings.h>
|
||||
#import <MP42Foundation/MP42Languages.h>
|
||||
#import <MP42Foundation/JSONKit.h>
|
||||
|
||||
#import "SBMetadataSearchController.h"
|
||||
|
||||
#import "TheMovieDB3.h"
|
||||
#import "iTunesStore.h"
|
||||
|
||||
#define API_KEY @"b0073bafb08b4f68df101eb2325f27dc"
|
||||
|
||||
@implementation TheMovieDB3
|
||||
|
||||
- (NSArray *) languages {
|
||||
return [[MP42Languages defaultManager] languages];
|
||||
}
|
||||
|
||||
- (NSArray *) searchMovie:(NSString *)aMovieTitle language:(NSString *)aLanguage {
|
||||
NSString *lang = [MP42Languages iso6391CodeFor:aLanguage];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/search/movie?api_key=%@&query=%@&language=%@", API_KEY, [MetadataImporter urlEncoded:aMovieTitle], lang]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
return [TheMovieDB3 metadataForResults:d];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (MP42Metadata *) artworksForResult:(NSDictionary *)r metadata:(MP42Metadata *)aMetadata {
|
||||
// artwork
|
||||
NSMutableArray *artworkThumbURLs = [[NSMutableArray alloc] initWithCapacity:2];
|
||||
NSMutableArray *artworkFullsizeURLs = [[NSMutableArray alloc] initWithCapacity:1];
|
||||
NSMutableArray *artworkProviderNames = [[NSMutableArray alloc] initWithCapacity:1];
|
||||
|
||||
// add iTunes artwork
|
||||
MP42Metadata *iTunesMetadata = [iTunesStore quickiTunesSearchMovie:[[aMetadata tagsDict] valueForKey:@"Name"]];
|
||||
if (iTunesMetadata && [iTunesMetadata artworkThumbURLs] && [iTunesMetadata artworkFullsizeURLs] && ([[iTunesMetadata artworkThumbURLs] count] == [[iTunesMetadata artworkFullsizeURLs] count])) {
|
||||
[artworkThumbURLs addObjectsFromArray:[iTunesMetadata artworkThumbURLs]];
|
||||
[artworkFullsizeURLs addObjectsFromArray:[iTunesMetadata artworkFullsizeURLs]];
|
||||
[artworkProviderNames addObjectsFromArray:[iTunesMetadata artworkProviderNames]];
|
||||
}
|
||||
|
||||
// load image variables from configuration
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/configuration?api_key=%@", API_KEY]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
NSArray *posters = [r valueForKeyPath:@"images.posters"];
|
||||
|
||||
if (jsonData && posters && [posters isKindOfClass:[NSArray class]]) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *config = [jsonDecoder objectWithData:jsonData];
|
||||
|
||||
if ([config valueForKey:@"images"]) {
|
||||
NSString *imageBaseUrl = [[config valueForKey:@"images"] valueForKey:@"secure_base_url"];
|
||||
NSString *posterThumbnailSize = [[[config valueForKey:@"images"] valueForKey:@"poster_sizes"] objectAtIndex:0];
|
||||
NSString *backdropThumbnailSize = [[[config valueForKey:@"images"] valueForKey:@"backdrop_sizes"] objectAtIndex:0];
|
||||
|
||||
for (NSDictionary *poster in posters) {
|
||||
if ([poster valueForKey:@"file_path"] && ([poster valueForKey:@"file_path"] != [NSNull null])) {
|
||||
[artworkThumbURLs addObject:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", imageBaseUrl, posterThumbnailSize, [poster valueForKey:@"file_path"]]]];
|
||||
[artworkFullsizeURLs addObject:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", imageBaseUrl, @"original", [poster valueForKey:@"file_path"]]]];
|
||||
[artworkProviderNames addObject:@"TheMovieDB|poster"];
|
||||
}
|
||||
}
|
||||
if (![posters count] && [r valueForKey:@"poster_path"] && ([r valueForKey:@"poster_path"] != [NSNull null])) {
|
||||
[artworkThumbURLs addObject:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", imageBaseUrl, posterThumbnailSize, [r valueForKey:@"poster_path"]]]];
|
||||
[artworkFullsizeURLs addObject:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", imageBaseUrl, @"original", [r valueForKey:@"poster_path"]]]];
|
||||
[artworkProviderNames addObject:@"TheMovieDB|poster"];
|
||||
}
|
||||
|
||||
if ([r valueForKey:@"backdrop_path"] && ([r valueForKey:@"backdrop_path"] != [NSNull null])) {
|
||||
[artworkThumbURLs addObject:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", imageBaseUrl, backdropThumbnailSize, [r valueForKey:@"backdrop_path"]]]];
|
||||
[artworkFullsizeURLs addObject:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", imageBaseUrl, @"original", [r valueForKey:@"backdrop_path"]]]];
|
||||
[artworkProviderNames addObject:@"TheMovieDB|backdrop"];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[aMetadata setArtworkThumbURLs:artworkThumbURLs];
|
||||
[aMetadata setArtworkFullsizeURLs:artworkFullsizeURLs];
|
||||
[aMetadata setArtworkProviderNames:artworkProviderNames];
|
||||
[artworkThumbURLs release];
|
||||
[artworkFullsizeURLs release];
|
||||
[artworkProviderNames release];
|
||||
|
||||
return aMetadata;
|
||||
}
|
||||
|
||||
- (MP42Metadata *) loadMovieMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage {
|
||||
NSString *lang = [MP42Languages iso6391CodeFor:aLanguage];
|
||||
NSNumber *theMovieDBID = [[aMetadata tagsDict] valueForKey:@"TheMovieDB ID"];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/movie/%@?api_key=%@&language=%@&append_to_response=casts,releases,images", theMovieDBID, API_KEY, lang]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
MP42Metadata *r = [TheMovieDB3 metadataForResult:d language:lang];
|
||||
if (r) {
|
||||
[aMetadata mergeMetadata:r];
|
||||
}
|
||||
aMetadata = [self artworksForResult:d metadata:aMetadata];
|
||||
}
|
||||
|
||||
return aMetadata;
|
||||
}
|
||||
|
||||
#pragma mark Parse results
|
||||
|
||||
+ (NSString *) commaJoinedSubentriesOf:(NSArray *)aArray forKey:(NSString *)aKey {
|
||||
if (!aArray || ([aArray count] == 0)) {
|
||||
return nil;
|
||||
}
|
||||
NSMutableArray *r = [NSMutableArray arrayWithCapacity:[aArray count]];
|
||||
for (NSDictionary *d in aArray) {
|
||||
if ([d valueForKey:aKey]) {
|
||||
[r addObject:[d valueForKey:aKey]];
|
||||
}
|
||||
}
|
||||
return [r componentsJoinedByString:@", "];
|
||||
}
|
||||
|
||||
+ (NSString *) commaJoinedSubentriesOf:(NSArray *)aArray forKey:(NSString *)aKey withKey:(NSString *)aWithKey equalTo:(NSString *)aEqualTo {
|
||||
if (!aArray || ([aArray count] == 0)) {
|
||||
return nil;
|
||||
}
|
||||
NSMutableArray *r = [NSMutableArray array];
|
||||
for (NSDictionary *d in aArray) {
|
||||
if ([d valueForKey:aKey]) {
|
||||
if ([d valueForKey:aWithKey] && [[d valueForKey:aWithKey] isEqualToString:aEqualTo]) {
|
||||
[r addObject:[d valueForKey:aKey]];
|
||||
}
|
||||
}
|
||||
}
|
||||
return [r componentsJoinedByString:@", "];
|
||||
}
|
||||
|
||||
+ (MP42Metadata *) metadataForResult:(NSDictionary *)r language:(NSString *)aLanguage {
|
||||
MP42Metadata *metadata = [[MP42Metadata alloc] init];
|
||||
metadata.mediaKind = 9; // movie
|
||||
[metadata setTag:[r valueForKey:@"id"] forKey:@"TheMovieDB ID"];
|
||||
[metadata setTag:[r valueForKey:@"title"] forKey:@"Name"];
|
||||
[metadata setTag:[r valueForKey:@"release_date"] forKey:@"Release Date"];
|
||||
[metadata setTag:[TheMovieDB3 commaJoinedSubentriesOf:[r valueForKey:@"genres"] forKey:@"name"] forKey:@"Genre"];
|
||||
[metadata setTag:[r valueForKey:@"overview"] forKey:@"Description"];
|
||||
[metadata setTag:[r valueForKey:@"overview"] forKey:@"Long Description"];
|
||||
[metadata setTag:[TheMovieDB3 commaJoinedSubentriesOf:[r valueForKey:@"production_companies"] forKey:@"name"] forKey:@"Studio"];
|
||||
NSDictionary *casts = [r valueForKey:@"casts"];
|
||||
[metadata setTag:[TheMovieDB3 commaJoinedSubentriesOf:[casts valueForKey:@"cast"] forKey:@"name"] forKey:@"Cast"];
|
||||
[metadata setTag:[TheMovieDB3 commaJoinedSubentriesOf:[casts valueForKey:@"crew"] forKey:@"name" withKey:@"job" equalTo:@"Director"] forKey:@"Director"];
|
||||
[metadata setTag:[TheMovieDB3 commaJoinedSubentriesOf:[casts valueForKey:@"crew"] forKey:@"name" withKey:@"job" equalTo:@"Director"] forKey:@"Artist"];
|
||||
[metadata setTag:[TheMovieDB3 commaJoinedSubentriesOf:[casts valueForKey:@"crew"] forKey:@"name" withKey:@"job" equalTo:@"Producer"] forKey:@"Producers"];
|
||||
[metadata setTag:[TheMovieDB3 commaJoinedSubentriesOf:[casts valueForKey:@"crew"] forKey:@"name" withKey:@"job" equalTo:@"Executive Producer"] forKey:@"Executive Producer"];
|
||||
[metadata setTag:[TheMovieDB3 commaJoinedSubentriesOf:[casts valueForKey:@"crew"] forKey:@"name" withKey:@"department" equalTo:@"Writing"] forKey:@"Screenwriters"];
|
||||
[metadata setTag:[TheMovieDB3 commaJoinedSubentriesOf:[casts valueForKey:@"crew"] forKey:@"name" withKey:@"job" equalTo:@"Original Music Composer"] forKey:@"Composer"];
|
||||
|
||||
if (aLanguage) {
|
||||
NSArray *countries = [[r valueForKey:@"releases"] valueForKey:@"countries"];
|
||||
|
||||
for (NSDictionary *d in countries) {
|
||||
if ([[d valueForKey:@"iso_3166_1"] isEqualToString:@"US"]) {
|
||||
[metadata setTag:[NSNumber numberWithUnsignedInteger:
|
||||
[[MP42Ratings defaultManager] ratingIndexForiTunesCountry:@"USA" media:@"movie" ratingString:[d valueForKey:@"certification"]]] forKey:@"Rating"] ;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [metadata autorelease];
|
||||
}
|
||||
|
||||
+ (NSArray *) metadataForResults:(NSDictionary *)dict {
|
||||
NSArray *resultsArray = [dict valueForKey:@"results"];
|
||||
NSMutableArray *returnArray = [[NSMutableArray alloc] initWithCapacity:[resultsArray count]];
|
||||
for (NSDictionary *r in resultsArray) {
|
||||
if ([r isKindOfClass:[NSDictionary class]]) {
|
||||
MP42Metadata *metadata = [TheMovieDB3 metadataForResult:r language:nil];
|
||||
[returnArray addObject:metadata];
|
||||
}
|
||||
}
|
||||
return [returnArray autorelease];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// TheTVDB.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2013-06-06.
|
||||
//
|
||||
//
|
||||
|
||||
#import "MetadataImporter.h"
|
||||
|
||||
@interface TheTVDB : MetadataImporter
|
||||
|
||||
@end
|
||||
Executable
+225
@@ -0,0 +1,225 @@
|
||||
//
|
||||
// TheTVDB.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2013-06-06.
|
||||
//
|
||||
//
|
||||
|
||||
#import <MP42Foundation/MP42Metadata.h>
|
||||
#import <MP42Foundation/MP42Ratings.h>
|
||||
#import <MP42Foundation/MP42Languages.h>
|
||||
|
||||
#import "TheTVDB.h"
|
||||
|
||||
#import "iTunesStore.h"
|
||||
#import "XMLReader.h"
|
||||
|
||||
#define API_KEY @"3498815BE9484A62"
|
||||
|
||||
@implementation TheTVDB
|
||||
|
||||
- (NSArray *) languages {
|
||||
return [[MP42Languages defaultManager] languages];
|
||||
}
|
||||
|
||||
- (NSArray *) searchTVSeries:(NSString *)aSeriesName language:(NSString *)aLanguage {
|
||||
NSURL *url;
|
||||
// search for series
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/api/GetSeries.php?seriesname=%@", [MetadataImporter urlEncoded:aSeriesName]]];
|
||||
NSData *seriesXML = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
NSDictionary *series = [XMLReader dictionaryForXMLData:seriesXML error:NULL];
|
||||
if (!series) return nil;
|
||||
NSArray *seriesArray = [series retrieveArrayForPath:@"Data.Series"];
|
||||
NSMutableArray *results = [[NSMutableArray alloc] initWithCapacity:[seriesArray count]];
|
||||
for (NSDictionary *s in seriesArray) {
|
||||
[results addObject:[s retrieveForPath:@"SeriesName.text"]];
|
||||
}
|
||||
return [results autorelease];
|
||||
}
|
||||
|
||||
- (NSArray *) searchTVSeries:(NSString *)aSeriesName language:(NSString *)aLanguage seasonNum:(NSString *)aSeasonNum episodeNum:(NSString *)aEpisodeNum {
|
||||
NSString *lang = [MP42Languages iso6391CodeFor:aLanguage];
|
||||
if (!lang) lang = @"en";
|
||||
NSURL *url;
|
||||
|
||||
// search for series
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/api/GetSeries.php?seriesname=%@", [MetadataImporter urlEncoded:aSeriesName]]];
|
||||
NSData *seriesXML = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
NSDictionary *series = [XMLReader dictionaryForXMLData:seriesXML error:NULL];
|
||||
|
||||
if (!series) return nil;
|
||||
|
||||
NSArray *seriesObject = [series retrieveForPath:@"Data.Series"];
|
||||
NSMutableArray *seriesIDs = [[NSMutableArray alloc] init];;
|
||||
if ([seriesObject isKindOfClass:[NSArray class]]) {
|
||||
for (NSDictionary *s in seriesObject)
|
||||
if ([aSeriesName isEqualToString:[s retrieveForPath:@"SeriesName.text"]])
|
||||
[seriesIDs addObject:[s retrieveForPath:@"seriesid.text"]];
|
||||
|
||||
if (![seriesIDs count])
|
||||
[seriesIDs addObject:[series retrieveForPath:@"Data.Series.0.seriesid.text"]];
|
||||
}
|
||||
else {
|
||||
NSString *seriesID = [series retrieveForPath:@"Data.Series.seriesid.text"];
|
||||
if (seriesID)
|
||||
[seriesIDs addObject:seriesID];
|
||||
}
|
||||
NSMutableArray *results = [[NSMutableArray alloc] init];
|
||||
|
||||
if ([seriesIDs count]) {
|
||||
for (NSString *seriesID in seriesIDs) {
|
||||
if (!seriesID || [seriesID isEqualToString:@""])
|
||||
continue;
|
||||
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/api/%@/series/%@/all/%@.xml", API_KEY, seriesID, lang]];
|
||||
NSData *episodesXML = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
NSDictionary *episodes = [XMLReader dictionaryForXMLData:episodesXML error:NULL];
|
||||
|
||||
if (!episodes)
|
||||
continue;
|
||||
|
||||
NSArray *episodesArray = [episodes retrieveArrayForPath:@"Data.Episode"];
|
||||
NSDictionary *thisSeries = [episodes retrieveForPath:@"Data.Series"];
|
||||
|
||||
for (NSDictionary *episode in episodesArray) {
|
||||
if (aSeasonNum && ![aSeasonNum isEqualToString:@""]) {
|
||||
if ([[episode retrieveForPath:@"SeasonNumber.text"] isEqualToString:aSeasonNum]) {
|
||||
if (aEpisodeNum && ![aEpisodeNum isEqualToString:@""]) {
|
||||
if ([[episode retrieveForPath:@"EpisodeNumber.text"] isEqualToString:aEpisodeNum]) {
|
||||
[results addObject:[TheTVDB metadataForEpisode:episode series:thisSeries]];
|
||||
}
|
||||
} else {
|
||||
[results addObject:[TheTVDB metadataForEpisode:episode series:thisSeries]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
[results addObject:[TheTVDB metadataForEpisode:episode series:thisSeries]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[seriesIDs release];
|
||||
|
||||
return [results autorelease];
|
||||
}
|
||||
|
||||
- (MP42Metadata*) loadTVMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage {
|
||||
// add iTunes artwork
|
||||
MP42Metadata *iTunesMetadata = [iTunesStore quickiTunesSearchTV:[[aMetadata tagsDict] valueForKey:@"TV Show"] episodeTitle:[[aMetadata tagsDict] valueForKey:@"Name"]];
|
||||
NSMutableArray * newArtworkThumbURLs = [[[NSMutableArray alloc] init] autorelease];
|
||||
NSMutableArray * newArtworkFullsizeURLs = [[[NSMutableArray alloc] init] autorelease];
|
||||
NSMutableArray * newArtworkProviderNames = [[[NSMutableArray alloc] init] autorelease];
|
||||
if (iTunesMetadata && [iTunesMetadata artworkThumbURLs] && [iTunesMetadata artworkFullsizeURLs] && ([[iTunesMetadata artworkThumbURLs] count] == [[iTunesMetadata artworkFullsizeURLs] count])) {
|
||||
[newArtworkThumbURLs addObjectsFromArray:[iTunesMetadata artworkThumbURLs]];
|
||||
[newArtworkFullsizeURLs addObjectsFromArray:[iTunesMetadata artworkFullsizeURLs]];
|
||||
[newArtworkProviderNames addObjectsFromArray:[iTunesMetadata artworkProviderNames]];
|
||||
}
|
||||
[newArtworkThumbURLs addObjectsFromArray:[aMetadata artworkThumbURLs]];
|
||||
[newArtworkFullsizeURLs addObjectsFromArray:[aMetadata artworkFullsizeURLs]];
|
||||
[newArtworkProviderNames addObjectsFromArray:[aMetadata artworkProviderNames]];
|
||||
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/api/%@/series/%@/banners.xml", API_KEY, [[aMetadata tagsDict] valueForKey:@"TheTVDB Series ID"]]];
|
||||
NSData *bannersXML = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
NSDictionary *banners = [XMLReader dictionaryForXMLData:bannersXML error:NULL];
|
||||
if (!banners) return nil;
|
||||
NSArray *bannersArray = [banners retrieveArrayForPath:@"Banners.Banner"];
|
||||
NSURL *u;
|
||||
for (NSDictionary *banner in bannersArray) {
|
||||
if ([[banner retrieveForPath:@"BannerType.text"] isEqualToString:@"season"] && [[banner retrieveForPath:@"BannerType2.text"] isEqualToString:@"season"] && [[banner retrieveForPath:@"Season.text"] isEqualToString:[[aMetadata tagsDict] valueForKey:@"TV Season"]]) {
|
||||
u = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/banners/%@", [banner retrieveForPath:@"BannerPath.text"]]];
|
||||
[newArtworkThumbURLs addObject:u];
|
||||
[newArtworkFullsizeURLs addObject:u];
|
||||
[newArtworkProviderNames addObject:[NSString stringWithFormat:@"TheTVDB|season %@", [[aMetadata tagsDict] valueForKey:@"TV Season"]]];
|
||||
}
|
||||
}
|
||||
for (NSDictionary *banner in bannersArray) {
|
||||
if ([[banner retrieveForPath:@"BannerType.text"] isEqualToString:@"poster"]) {
|
||||
u = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/banners/%@", [banner retrieveForPath:@"BannerPath.text"]]];
|
||||
[newArtworkThumbURLs addObject:u];
|
||||
[newArtworkFullsizeURLs addObject:u];
|
||||
[newArtworkProviderNames addObject:@"TheTVDB|poster"];
|
||||
}
|
||||
}
|
||||
[aMetadata setArtworkThumbURLs:newArtworkThumbURLs];
|
||||
[aMetadata setArtworkFullsizeURLs:newArtworkFullsizeURLs];
|
||||
[aMetadata setArtworkProviderNames:newArtworkProviderNames];
|
||||
return aMetadata;
|
||||
}
|
||||
|
||||
+ (NSString *) cleanPeopleList:(NSString *)s {
|
||||
NSArray *a = [[[s stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]
|
||||
stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"|"]]
|
||||
componentsSeparatedByString:@"|"];
|
||||
return [a componentsJoinedByString:@", "];
|
||||
}
|
||||
|
||||
+ (MP42Metadata *) metadataForEpisode:(NSDictionary *)aEpisode series:(NSDictionary *)aSeries {
|
||||
MP42Metadata *metadata = [[MP42Metadata alloc] init];
|
||||
metadata.mediaKind = 10; // TV show
|
||||
[metadata setTag:[aSeries retrieveForPath:@"id.text"] forKey:@"TheTVDB Series ID"];
|
||||
[metadata setTag:[aSeries retrieveForPath:@"SeriesName.text"] forKey:@"TV Show"];
|
||||
[metadata setTag:[aSeries retrieveForPath:@"Overview.text"] forKey:@"Series Description"];
|
||||
[metadata setTag:[TheTVDB cleanPeopleList:[aSeries retrieveForPath:@"Genre.text"]] forKey:@"Genre"];
|
||||
|
||||
[metadata setTag:[NSNumber numberWithUnsignedInteger:
|
||||
[[MP42Ratings defaultManager] ratingIndexForiTunesCountry:@"USA" media:@"TV" ratingString:[aSeries retrieveForPath:@"ContentRating.text"]]] forKey:@"Rating"];
|
||||
|
||||
[metadata setTag:[aSeries retrieveForPath:@"Network.text"] forKey:@"TV Network"];
|
||||
[metadata setTag:[aEpisode retrieveForPath:@"SeasonNumber.text"] forKey:@"TV Season"];
|
||||
[metadata setTag:[aEpisode retrieveForPath:@"EpisodeNumber.text"] forKey:@"TV Episode #"];
|
||||
|
||||
NSString *episodeID = [NSString stringWithFormat:@"%ld%02ld", (long)[[aEpisode retrieveForPath:@"SeasonNumber.text"] integerValue],
|
||||
(long)[[aEpisode retrieveForPath:@"EpisodeNumber.text"] integerValue]];
|
||||
[metadata setTag:episodeID forKey:@"TV Episode ID"];
|
||||
|
||||
[metadata setTag:[aEpisode retrieveForPath:@"SeasonNumber.text"] forKey:@"TV Season"];
|
||||
[metadata setTag:[aEpisode retrieveForPath:@"EpisodeName.text"] forKey:@"Name"];
|
||||
[metadata setTag:[aEpisode retrieveForPath:@"FirstAired.text"] forKey:@"Release Date"];
|
||||
[metadata setTag:[aEpisode retrieveForPath:@"Overview.text"] forKey:@"Description"];
|
||||
[metadata setTag:[aEpisode retrieveForPath:@"Overview.text"] forKey:@"Long Description"];
|
||||
[metadata setTag:[aEpisode retrieveForPath:@"EpisodeNumber.text"] forKey:@"Track #"];
|
||||
[metadata setTag:[TheTVDB cleanPeopleList:[aEpisode retrieveForPath:@"Director.text"]] forKey:@"Director"];
|
||||
|
||||
[metadata setTag:[NSString stringWithFormat:@"%@, Season %@", [aSeries retrieveForPath:@"SeriesName.text"], [aEpisode retrieveForPath:@"SeasonNumber.text"]] forKey:@"Album"];
|
||||
[metadata setTag:[aSeries retrieveForPath:@"SeriesName.text"] forKey:@"Artist"];
|
||||
|
||||
[metadata setTag:[TheTVDB cleanPeopleList:[aEpisode retrieveForPath:@"Writer.text"]] forKey:@"Screenwriters"];
|
||||
// cast
|
||||
NSString *actors = [TheTVDB cleanPeopleList:[aSeries retrieveForPath:@"Actors.text"]];
|
||||
NSString *gueststars = [TheTVDB cleanPeopleList:[aEpisode retrieveForPath:@"GuestStars.text"]];
|
||||
if ([actors length]) {
|
||||
if ([gueststars length]) {
|
||||
[metadata setTag:[NSString stringWithFormat:@"%@, %@", actors, gueststars] forKey:@"Cast"];
|
||||
} else {
|
||||
[metadata setTag:actors forKey:@"Cast"];
|
||||
}
|
||||
} else {
|
||||
if ([gueststars length]) {
|
||||
[metadata setTag:gueststars forKey:@"Cast"];
|
||||
}
|
||||
}
|
||||
// artwork
|
||||
NSMutableArray *artworkThumbURLs = [[NSMutableArray alloc] initWithCapacity:10];
|
||||
NSMutableArray *artworkFullsizeURLs = [[NSMutableArray alloc] initWithCapacity:10];
|
||||
NSMutableArray *artworkProviderNames = [[NSMutableArray alloc] initWithCapacity:10];
|
||||
NSURL *u;
|
||||
if ([aEpisode retrieveForPath:@"filename.text"]) {
|
||||
u = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/banners/%@", [aEpisode retrieveForPath:@"filename.text"]]];
|
||||
[artworkThumbURLs addObject:u];
|
||||
[artworkFullsizeURLs addObject:u];
|
||||
[artworkProviderNames addObject:@"TheTVDB|episode"];
|
||||
}
|
||||
[metadata setArtworkThumbURLs: artworkThumbURLs];
|
||||
[metadata setArtworkFullsizeURLs: artworkFullsizeURLs];
|
||||
[metadata setArtworkProviderNames:artworkProviderNames];
|
||||
[artworkThumbURLs release];
|
||||
[artworkFullsizeURLs release];
|
||||
[artworkProviderNames release];
|
||||
// TheTVDB does not provide the following fields normally associated with TV shows in MP42Metadata:
|
||||
// "Copyright", "Comments", "Producers", "Artist"
|
||||
return [metadata autorelease];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// iTunesStore.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2011/01/28.
|
||||
// Copyright 2011 Douglas Stebila. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import "MetadataImporter.h"
|
||||
|
||||
@interface iTunesStore : MetadataImporter
|
||||
|
||||
#pragma mark iTunes stores
|
||||
+ (NSDictionary *) getStoreFor:(NSString *)aLanguageString;
|
||||
|
||||
#pragma mark Quick iTunes search for metadata
|
||||
+ (MP42Metadata *) quickiTunesSearchTV:(NSString *)aSeriesName episodeTitle:(NSString *)aEpisodeTitle;
|
||||
+ (MP42Metadata *) quickiTunesSearchMovie:(NSString *)aMovieName;
|
||||
|
||||
#pragma mark Parse results
|
||||
+ (NSArray *) readPeople:(NSString *)aPeople fromXML:(NSXMLDocument *)aXml;
|
||||
+ (NSArray *) metadataForResults:(NSDictionary *)dict store:(NSDictionary *)store;
|
||||
|
||||
@end
|
||||
Executable
+384
@@ -0,0 +1,384 @@
|
||||
//
|
||||
// iTunesStore.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2011/01/28.
|
||||
// Copyright 2011 Douglas Stebila. All rights reserved.
|
||||
//
|
||||
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
#import <MP42Foundation/MP42Ratings.h>
|
||||
#import <MP42Foundation/JSONKit.h>
|
||||
|
||||
#import "iTunesStore.h"
|
||||
#import "SBMetadataSearchController.h"
|
||||
|
||||
@implementation iTunesStore
|
||||
|
||||
#pragma mark iTunes stores
|
||||
|
||||
- (NSArray *) languages {
|
||||
NSString* iTunesStoresJSON = [[NSBundle mainBundle] pathForResource:@"iTunesStores" ofType:@"json"];
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSArray *iTunesStores = [jsonDecoder objectWithData:[NSData dataWithContentsOfFile:iTunesStoresJSON]];
|
||||
NSMutableArray *results = [[NSMutableArray alloc] initWithCapacity:[iTunesStores count]];
|
||||
for (NSDictionary *store in iTunesStores) {
|
||||
[results addObject:[NSString stringWithFormat:@"%@ (%@)", [store valueForKey:@"country"], [store valueForKey:@"language"]]];
|
||||
}
|
||||
return [results autorelease];
|
||||
}
|
||||
|
||||
+ (NSDictionary *) getStoreFor:(NSString *)aLanguageString {
|
||||
NSString* iTunesStoresJSON = [[NSBundle mainBundle] pathForResource:@"iTunesStores" ofType:@"json"];
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSArray *iTunesStores = [jsonDecoder objectWithData:[NSData dataWithContentsOfFile:iTunesStoresJSON]];
|
||||
for (NSDictionary *store in iTunesStores) {
|
||||
if (aLanguageString && [aLanguageString isEqualToString:[NSString stringWithFormat:@"%@ (%@)", [store valueForKey:@"country"], [store valueForKey:@"language"]]]) {
|
||||
return store;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark Search for TV episode metadata
|
||||
|
||||
NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
{
|
||||
int v1 = [[[((MP42Metadata *) ep1) tagsDict] valueForKey:@"TV Episode #"] intValue];
|
||||
int v2 = [[[((MP42Metadata *) ep2) tagsDict] valueForKey:@"TV Episode #"] intValue];
|
||||
|
||||
int s1 = [[[((MP42Metadata *) ep1) tagsDict] valueForKey:@"TV Season"] intValue];
|
||||
int s2 = [[[((MP42Metadata *) ep2) tagsDict] valueForKey:@"TV Season"] intValue];
|
||||
|
||||
if (s1 == s2) {
|
||||
if (v1 < v2)
|
||||
return NSOrderedAscending;
|
||||
else if (v1 > v2)
|
||||
return NSOrderedDescending;
|
||||
}
|
||||
|
||||
if (s1 < s2)
|
||||
return NSOrderedAscending;
|
||||
else if (s1 > s2)
|
||||
return NSOrderedDescending;
|
||||
else
|
||||
return NSOrderedSame;
|
||||
}
|
||||
|
||||
- (NSArray *)filterResult:(NSArray *)results tvSeries:(NSString *)aSeriesName seasonNum:(NSString *)aSeasonNum episodeNum:(NSString *)aEpisodeNum {
|
||||
NSMutableArray *r = [[NSMutableArray alloc] init];
|
||||
for (MP42Metadata *m in results) {
|
||||
if (!aSeriesName || [[[m tagsDict] valueForKey:@"TV Show"] isEqualToString:aSeriesName]) {
|
||||
// Episode Number and Season Number
|
||||
if ((aEpisodeNum && [aEpisodeNum length]) && (aSeasonNum && [aSeasonNum length])) {
|
||||
if ([[[[m tagsDict] valueForKey:@"TV Episode #"] stringValue] isEqualToString:aEpisodeNum] &&
|
||||
[[[m tagsDict] valueForKey:@"TV Season"] integerValue] == [aSeasonNum integerValue]) {
|
||||
[r addObject:m];
|
||||
}
|
||||
|
||||
}
|
||||
// Episode Number only
|
||||
else if ((aEpisodeNum && [aEpisodeNum length]) && !(aSeasonNum && [aSeasonNum length])) {
|
||||
if ([[[[m tagsDict] valueForKey:@"TV Episode #"] stringValue] isEqualToString:aEpisodeNum]) {
|
||||
[r addObject:m];
|
||||
}
|
||||
|
||||
}
|
||||
// Season Number only
|
||||
else if (!(aEpisodeNum && [aEpisodeNum length]) && (aSeasonNum && [aSeasonNum length])) {
|
||||
if ([[[m tagsDict] valueForKey:@"TV Season"] integerValue] == [aSeasonNum integerValue]) {
|
||||
[r addObject:m];
|
||||
}
|
||||
}
|
||||
else if (!(aEpisodeNum && [aEpisodeNum length]) && !(aSeasonNum && [aSeasonNum length])) {
|
||||
[r addObject:m];
|
||||
}
|
||||
}
|
||||
}
|
||||
return [r autorelease];
|
||||
}
|
||||
|
||||
- (NSArray *) searchTVSeries:(NSString *)aSeriesName language:(NSString *)aLanguage seasonNum:(NSString *)aSeasonNum episodeNum:(NSString *)aEpisodeNum
|
||||
{
|
||||
NSString *country = @"US";
|
||||
NSString *language = @"EN";
|
||||
NSString *season = @"season";
|
||||
NSDictionary *store = [iTunesStore getStoreFor:aLanguage];
|
||||
if (store) {
|
||||
country = [store valueForKey:@"country2"];
|
||||
language = [store valueForKey:@"language2"];
|
||||
if ([store valueForKey:@"season"] && ![[store valueForKey:@"season"] isEqualToString:@""]) {
|
||||
season = [[store valueForKey:@"season"] lowercaseString];
|
||||
}
|
||||
}
|
||||
|
||||
NSURL *url;
|
||||
if (aSeasonNum && [aSeasonNum length]) {
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&attribute=tvSeasonTerm&entity=tvEpisode&limit=200", country, [language lowercaseString], [MetadataImporter urlEncoded:[NSString stringWithFormat:@"%@ %@ %@", aSeriesName, season, aSeasonNum]]]];
|
||||
} else {
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&attribute=showTerm&entity=tvEpisode&limit=200", country, [language lowercaseString], [MetadataImporter urlEncoded:aSeriesName]]];
|
||||
}
|
||||
NSData *jsonData = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
NSArray *results = [iTunesStore metadataForResults:d store:store];
|
||||
if (([results count] == 0) && ![aLanguage isEqualToString:@"USA (English)"]) {
|
||||
return [self searchTVSeries:aSeriesName language:@"USA (English)" seasonNum:aSeasonNum episodeNum:aEpisodeNum];
|
||||
}
|
||||
if (([results count] == 0) && aSeasonNum) {
|
||||
return [self searchTVSeries:aSeriesName language:@"USA (English)" seasonNum:nil episodeNum:aEpisodeNum];
|
||||
}
|
||||
|
||||
// Filter results
|
||||
NSArray *r = [self filterResult:results tvSeries:aSeriesName seasonNum:aSeasonNum episodeNum:aEpisodeNum];
|
||||
|
||||
// If we don't have any result for the exact series name, relax the filter
|
||||
if (![r count]) {
|
||||
r = [self filterResult:results tvSeries:nil seasonNum:aSeasonNum episodeNum:aEpisodeNum];
|
||||
}
|
||||
|
||||
NSArray *resultsSorted = [r sortedArrayUsingFunction:sortMP42Metadata context:NULL];
|
||||
return resultsSorted;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark Quick iTunes search for metadata
|
||||
|
||||
+ (MP42Metadata *) quickiTunesSearchTV:(NSString *)aSeriesName episodeTitle:(NSString *)aEpisodeTitle {
|
||||
NSDictionary *store = [iTunesStore getStoreFor:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBMetadataPreference|TV|iTunes Store|Language"]];
|
||||
if (!store) {
|
||||
return nil;
|
||||
}
|
||||
NSString *country = [store valueForKey:@"country2"];
|
||||
NSString *language = [store valueForKey:@"language2"];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=tvEpisode", country, [language lowercaseString], [MetadataImporter urlEncoded:[NSString stringWithFormat:@"%@ %@", aSeriesName, aEpisodeTitle]]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
NSArray *results = [iTunesStore metadataForResults:d store:store];
|
||||
if ([results count] > 0) {
|
||||
return [results objectAtIndex:0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (MP42Metadata *) quickiTunesSearchMovie:(NSString *)aMovieName {
|
||||
NSDictionary *store = [iTunesStore getStoreFor:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBMetadataPreference|Movie|iTunes Store|Language"]];
|
||||
if (!store) {
|
||||
return nil;
|
||||
}
|
||||
NSString *country = [store valueForKey:@"country2"];
|
||||
NSString *language = [store valueForKey:@"language2"];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=movie", country, language, [MetadataImporter urlEncoded:aMovieName]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
NSArray *results = [iTunesStore metadataForResults:d store:store];
|
||||
if ([results count] > 0) {
|
||||
return [results objectAtIndex:0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark Search for movie metadata
|
||||
|
||||
- (NSArray *) searchMovie:(NSString *)aMovieTitle language:(NSString *)aLanguage
|
||||
{
|
||||
NSString *country = @"US";
|
||||
NSString *language = @"EN";
|
||||
NSDictionary *store = [iTunesStore getStoreFor:aLanguage];
|
||||
if (store) {
|
||||
country = [store valueForKey:@"country2"];
|
||||
language = [store valueForKey:@"language2"];
|
||||
}
|
||||
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=movie&limit=150", country, language, [MetadataImporter urlEncoded:aMovieTitle]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
return [iTunesStore metadataForResults:d store:store];
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark Load additional metadata
|
||||
|
||||
- (MP42Metadata *) loadTVMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage {
|
||||
NSDictionary *store = [iTunesStore getStoreFor:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBMetadataPreference|TV|iTunes Store|Language"]];
|
||||
if (!store) {
|
||||
return nil;
|
||||
}
|
||||
NSString *country = [store valueForKey:@"country2"];
|
||||
NSString *language = [store valueForKey:@"language2"];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?country=%@&lang=%@&id=%@", country, [language lowercaseString], [[aMetadata tagsDict] valueForKey:@"playlistID"]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
NSArray *resultsArray = [d valueForKey:@"results"];
|
||||
if ([resultsArray count] > 0) {
|
||||
NSDictionary *r = [resultsArray objectAtIndex:0];
|
||||
[aMetadata setTag:[r valueForKey:@"longDescription"] forKey:@"Series Description"];
|
||||
}
|
||||
}
|
||||
}
|
||||
return aMetadata;
|
||||
}
|
||||
|
||||
- (MP42Metadata *) loadMovieMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage {
|
||||
NSData *xmlData = [MetadataImporter downloadDataOrGetFromCache:[NSURL URLWithString:[[aMetadata tagsDict] valueForKey:@"iTunes URL"]]];
|
||||
if (xmlData) {
|
||||
NSXMLDocument *xml = [[NSXMLDocument alloc] initWithData:xmlData options:NSXMLDocumentTidyHTML error:NULL];
|
||||
NSArray *p = [iTunesStore readPeople:@"Actor" fromXML:xml];
|
||||
if (p && [p count]) [aMetadata setTag:[p componentsJoinedByString:@", "] forKey:@"Cast"];
|
||||
p = [iTunesStore readPeople:@"Director" fromXML:xml];
|
||||
if (p && [p count]) [aMetadata setTag:[p componentsJoinedByString:@", "] forKey:@"Director"];
|
||||
if (p && [p count]) [aMetadata setTag:[p componentsJoinedByString:@", "] forKey:@"Artist"];
|
||||
p = [iTunesStore readPeople:@"Producer" fromXML:xml];
|
||||
if (p && [p count]) [aMetadata setTag:[p componentsJoinedByString:@", "] forKey:@"Producers"];
|
||||
p = [iTunesStore readPeople:@"Screenwriter" fromXML:xml];
|
||||
if (p && [p count]) [aMetadata setTag:[p componentsJoinedByString:@", "] forKey:@"Screenwriters"];
|
||||
NSArray *nodes = [xml nodesForXPath:[NSString stringWithFormat:@"//li[@class='copyright']"] error:NULL];
|
||||
for (NSXMLNode *n in nodes) {
|
||||
NSString *copyright = [n stringValue];
|
||||
copyright = [copyright stringByReplacingOccurrencesOfString:@". All Rights Reserved." withString:@""];
|
||||
copyright = [copyright stringByReplacingOccurrencesOfString:@". All rights reserved." withString:@""];
|
||||
copyright = [copyright stringByReplacingOccurrencesOfString:@". All Rights Reserved" withString:@""];
|
||||
copyright = [copyright stringByReplacingOccurrencesOfString:@". All rights reserved" withString:@""];
|
||||
copyright = [copyright stringByReplacingOccurrencesOfString:@" by " withString:@" "];
|
||||
[aMetadata setTag:copyright forKey:@"Copyright"];
|
||||
}
|
||||
[xml release];
|
||||
}
|
||||
|
||||
return aMetadata;
|
||||
}
|
||||
|
||||
#pragma mark Parse results
|
||||
|
||||
/* Scrape people from iTunes Store website HTML */
|
||||
+ (NSArray *) readPeople:(NSString *)aPeople fromXML:(NSXMLDocument *)aXml {
|
||||
if (aXml) {
|
||||
NSArray *nodes = [aXml nodesForXPath:[NSString stringWithFormat:@"//div[starts-with(@metrics-loc,'Titledbox_%@')]", aPeople] error:NULL];
|
||||
for (NSXMLNode *n in nodes) {
|
||||
NSXMLDocument *subXML = [[NSXMLDocument alloc] initWithXMLString:[n XMLString] options:0 error:NULL];
|
||||
if (subXML) {
|
||||
NSArray *subNodes = [subXML nodesForXPath:@"//a" error:NULL];
|
||||
NSMutableArray *r = [[NSMutableArray alloc] initWithCapacity:[subNodes count]];
|
||||
for (NSXMLNode *sub in subNodes) {
|
||||
[r addObject:[sub stringValue]];
|
||||
}
|
||||
[subXML release];
|
||||
return [r autorelease];
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSArray *) metadataForResults:(NSDictionary *)dict store:(NSDictionary *)store {
|
||||
NSMutableArray *returnArray = [[NSMutableArray alloc] initWithCapacity:[[dict valueForKey:@"resultCount"] integerValue]];
|
||||
NSArray *resultsArray = [dict valueForKey:@"results"];
|
||||
for (int i = 0; i < [resultsArray count]; i++) {
|
||||
NSDictionary *r = [resultsArray objectAtIndex:i];
|
||||
|
||||
// Skip if the result is not a track (for example an artist or a collection)
|
||||
if (![[r valueForKey:@"wrapperType"] isEqualToString:@"track"])
|
||||
continue;
|
||||
|
||||
MP42Metadata *metadata = [[MP42Metadata alloc] init];
|
||||
if ([[r valueForKey:@"kind"] isEqualToString:@"feature-movie"]) {
|
||||
metadata.mediaKind = 9; // movie
|
||||
[metadata setTag:[r valueForKey:@"trackName"] forKey:@"Name"];
|
||||
[metadata setTag:[r valueForKey:@"artistName"] forKey:@"Director"];
|
||||
[metadata setTag:[r valueForKey:@"artistName"] forKey:@"Artist"];
|
||||
} else if ([[r valueForKey:@"kind"] isEqualToString:@"tv-episode"]) {
|
||||
metadata.mediaKind = 10; // TV show
|
||||
[metadata setTag:[r valueForKey:@"artistName"] forKey:@"TV Show"];
|
||||
[metadata setTag:[r valueForKey:@"artistName"] forKey:@"Artist"];
|
||||
NSString *s = [r valueForKey:@"collectionName"];
|
||||
NSString *season = nil;
|
||||
if (![[store valueForKey:@"season"] isEqualToString:@""]) {
|
||||
NSArray *sa = [[s lowercaseString] componentsSeparatedByString:[NSString stringWithFormat:@", %@ ", [store valueForKey:@"season"]]];
|
||||
if ([sa count] > 1) {
|
||||
season = [sa objectAtIndex:1];
|
||||
} else {
|
||||
season = @"1";
|
||||
}
|
||||
}
|
||||
if (season) {
|
||||
[metadata setTag:season forKey:@"TV Season"];
|
||||
NSString *episodeID = [NSString stringWithFormat:@"%ld%02ld", (long)[season integerValue],
|
||||
(long)[[r valueForKey:@"trackNumber"] integerValue]];
|
||||
[metadata setTag:episodeID forKey:@"TV Episode ID"];
|
||||
[metadata setTag:[NSString stringWithFormat:@"%@, Season %@", [r valueForKey:@"artistName"], season] forKey:@"Album"];
|
||||
}
|
||||
[metadata setTag:[r valueForKey:@"trackNumber"] forKey:@"TV Episode #"];
|
||||
[metadata setTag:[r valueForKey:@"trackName"] forKey:@"Name"];
|
||||
[metadata setTag:[NSString stringWithFormat:@"%@/%@", [r valueForKey:@"trackNumber"], [r valueForKey:@"trackCount"]] forKey:@"Track #"];
|
||||
[metadata setTag:[r valueForKey:@"artistId"] forKey:@"artistID"];
|
||||
[metadata setTag:[r valueForKey:@"collectionId"] forKey:@"playlistID"];
|
||||
}
|
||||
// metadata common to both TV episodes and movies
|
||||
[metadata setTag:[(NSString *) [r valueForKey:@"releaseDate"] substringToIndex:10] forKey:@"Release Date"];
|
||||
if ([r valueForKey:@"shortDescription"])
|
||||
[metadata setTag:[r valueForKey:@"shortDescription"] forKey:@"Description"];
|
||||
else
|
||||
[metadata setTag:[r valueForKey:@"longDescription"] forKey:@"Description"];
|
||||
[metadata setTag:[r valueForKey:@"longDescription"] forKey:@"Long Description"];
|
||||
[metadata setTag:[r valueForKey:@"primaryGenreName"] forKey:@"Genre"];
|
||||
[metadata setTag:[NSNumber numberWithUnsignedInteger:[[MP42Ratings defaultManager] ratingIndexForiTunesCountry:[store valueForKey:@"country"] media:(metadata.mediaKind == 9 ? @"movie" : @"TV") ratingString:[r valueForKey:@"contentAdvisoryRating"]]] forKey:@"Rating"];
|
||||
[metadata setTag:[r valueForKey:@"trackViewUrl"] forKey:@"iTunes URL"];
|
||||
if ([store valueForKey:@"storeCode"]) {
|
||||
[metadata setTag:[[store valueForKey:@"storeCode"] stringValue] forKey:@"iTunes Country"];
|
||||
}
|
||||
NSString *trackExplicitness = [r valueForKey:@"trackExplicitness"];
|
||||
[metadata setTag:[r valueForKey:@"trackId"] forKey:@"contentID"];
|
||||
if ([trackExplicitness isEqualToString:@"explicit"]) {
|
||||
[metadata setContentRating:4];
|
||||
} else if ([trackExplicitness isEqualToString:@"cleaned"]) {
|
||||
[metadata setContentRating:2];
|
||||
}
|
||||
// artwork
|
||||
NSString *artworkString = [r valueForKey:@"artworkUrl100"];
|
||||
if (artworkString) {
|
||||
NSMutableArray *artworkThumbURLs = [[NSMutableArray alloc] initWithCapacity:1];
|
||||
[artworkThumbURLs addObject:[NSURL URLWithString:artworkString]];
|
||||
[metadata setArtworkThumbURLs: artworkThumbURLs];
|
||||
[artworkThumbURLs release];
|
||||
artworkString = [artworkString stringByReplacingOccurrencesOfString:@"100x100-75." withString:@""];
|
||||
NSMutableArray *artworkFullsizeURLs = [[NSMutableArray alloc] initWithCapacity:1];
|
||||
[artworkFullsizeURLs addObject:[NSURL URLWithString:artworkString]];
|
||||
[metadata setArtworkFullsizeURLs: artworkFullsizeURLs];
|
||||
[artworkFullsizeURLs release];
|
||||
NSMutableArray *artworkProviderNames = [[NSMutableArray alloc] initWithCapacity:1];
|
||||
[artworkProviderNames addObject:@"iTunes"];
|
||||
[metadata setArtworkProviderNames:artworkProviderNames];
|
||||
[artworkProviderNames release];
|
||||
}
|
||||
|
||||
// add to array
|
||||
[returnArray addObject:metadata];
|
||||
[metadata release];
|
||||
|
||||
}
|
||||
return [returnArray autorelease];
|
||||
}
|
||||
|
||||
@end
|
||||
+912
@@ -0,0 +1,912 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
|
||||
<data>
|
||||
<int key="IBDocument.SystemTarget">1060</int>
|
||||
<string key="IBDocument.SystemVersion">13A603</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">4511</string>
|
||||
<string key="IBDocument.AppKitVersion">1265</string>
|
||||
<string key="IBDocument.HIToolboxVersion">695.00</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="NS.object.0">4511</string>
|
||||
</object>
|
||||
<array key="IBDocument.IntegratedClassDependencies">
|
||||
<string>NSButton</string>
|
||||
<string>NSButtonCell</string>
|
||||
<string>NSCustomObject</string>
|
||||
<string>NSCustomView</string>
|
||||
<string>NSScrollView</string>
|
||||
<string>NSScroller</string>
|
||||
<string>NSTabView</string>
|
||||
<string>NSTabViewItem</string>
|
||||
<string>NSTableColumn</string>
|
||||
<string>NSTableHeaderView</string>
|
||||
<string>NSTableView</string>
|
||||
<string>NSTextFieldCell</string>
|
||||
<string>NSView</string>
|
||||
</array>
|
||||
<array key="IBDocument.PluginDependencies">
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
</array>
|
||||
<object class="NSMutableDictionary" key="IBDocument.Metadata">
|
||||
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
|
||||
<integer value="1" key="NS.object.0"/>
|
||||
</object>
|
||||
<array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
|
||||
<object class="NSCustomObject" id="1001">
|
||||
<string key="NSClassName">SBChapterViewController</string>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="1003">
|
||||
<string key="NSClassName">FirstResponder</string>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="1004">
|
||||
<string key="NSClassName">NSApplication</string>
|
||||
</object>
|
||||
<object class="NSCustomView" id="1005">
|
||||
<reference key="NSNextResponder"/>
|
||||
<int key="NSvFlags">268</int>
|
||||
<array class="NSMutableArray" key="NSSubviews">
|
||||
<object class="NSTabView" id="980212840">
|
||||
<reference key="NSNextResponder" ref="1005"/>
|
||||
<int key="NSvFlags">274</int>
|
||||
<string key="NSFrame">{{-11, -12}, {502, 279}}</string>
|
||||
<reference key="NSSuperview" ref="1005"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="900859224"/>
|
||||
<array class="NSMutableArray" key="NSTabViewItems">
|
||||
<object class="NSTabViewItem" id="561234673">
|
||||
<string key="NSIdentifier">1</string>
|
||||
<object class="NSView" key="NSView" id="900859224">
|
||||
<reference key="NSNextResponder" ref="980212840"/>
|
||||
<int key="NSvFlags">274</int>
|
||||
<array class="NSMutableArray" key="NSSubviews">
|
||||
<object class="NSScrollView" id="86220922">
|
||||
<reference key="NSNextResponder" ref="900859224"/>
|
||||
<int key="NSvFlags">274</int>
|
||||
<array class="NSMutableArray" key="NSSubviews">
|
||||
<object class="NSClipView" id="399023230">
|
||||
<reference key="NSNextResponder" ref="86220922"/>
|
||||
<int key="NSvFlags">2322</int>
|
||||
<array class="NSMutableArray" key="NSSubviews">
|
||||
<object class="NSTableView" id="999266526">
|
||||
<reference key="NSNextResponder" ref="399023230"/>
|
||||
<int key="NSvFlags">256</int>
|
||||
<string key="NSFrameSize">{446, 181}</string>
|
||||
<reference key="NSSuperview" ref="399023230"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="477814729"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
|
||||
<bool key="NSControlAllowsExpansionToolTips">YES</bool>
|
||||
<object class="NSTableHeaderView" key="NSHeaderView" id="888415462">
|
||||
<reference key="NSNextResponder" ref="188370008"/>
|
||||
<int key="NSvFlags">256</int>
|
||||
<string key="NSFrameSize">{446, 17}</string>
|
||||
<reference key="NSSuperview" ref="188370008"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="399023230"/>
|
||||
<reference key="NSTableView" ref="999266526"/>
|
||||
</object>
|
||||
<object class="_NSCornerView" key="NSCornerView">
|
||||
<nil key="NSNextResponder"/>
|
||||
<int key="NSvFlags">-2147483392</int>
|
||||
<string key="NSFrame">{{-22, 0}, {12, 17}}</string>
|
||||
</object>
|
||||
<array class="NSMutableArray" key="NSTableColumns">
|
||||
<object class="NSTableColumn" id="891606345">
|
||||
<string key="NSIdentifier">time</string>
|
||||
<double key="NSWidth">96</double>
|
||||
<double key="NSMinWidth">40</double>
|
||||
<double key="NSMaxWidth">1000</double>
|
||||
<object class="NSTableHeaderCell" key="NSHeaderCell">
|
||||
<int key="NSCellFlags">75497536</int>
|
||||
<int key="NSCellFlags2">2048</int>
|
||||
<string key="NSContents">Time</string>
|
||||
<object class="NSFont" key="NSSupport" id="26">
|
||||
<string key="NSName">.LucidaGrandeUI</string>
|
||||
<double key="NSSize">11</double>
|
||||
<int key="NSfFlags">3100</int>
|
||||
</object>
|
||||
<object class="NSColor" key="NSBackgroundColor" id="120863768">
|
||||
<int key="NSColorSpace">3</int>
|
||||
<bytes key="NSWhite">MC4zMzMzMzI5OQA</bytes>
|
||||
</object>
|
||||
<object class="NSColor" key="NSTextColor" id="1034872520">
|
||||
<int key="NSColorSpace">6</int>
|
||||
<string key="NSCatalogName">System</string>
|
||||
<string key="NSColorName">headerTextColor</string>
|
||||
<object class="NSColor" key="NSColor" id="68887631">
|
||||
<int key="NSColorSpace">3</int>
|
||||
<bytes key="NSWhite">MAA</bytes>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSTextFieldCell" key="NSDataCell" id="350676877">
|
||||
<int key="NSCellFlags">337641536</int>
|
||||
<int key="NSCellFlags2">133120</int>
|
||||
<string key="NSContents">Text Cell</string>
|
||||
<reference key="NSSupport" ref="26"/>
|
||||
<reference key="NSControlView" ref="999266526"/>
|
||||
<object class="NSColor" key="NSBackgroundColor" id="315001162">
|
||||
<int key="NSColorSpace">6</int>
|
||||
<string key="NSCatalogName">System</string>
|
||||
<string key="NSColorName">controlBackgroundColor</string>
|
||||
<object class="NSColor" key="NSColor" id="79804590">
|
||||
<int key="NSColorSpace">3</int>
|
||||
<bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSColor" key="NSTextColor" id="492112684">
|
||||
<int key="NSColorSpace">6</int>
|
||||
<string key="NSCatalogName">System</string>
|
||||
<string key="NSColorName">controlTextColor</string>
|
||||
<reference key="NSColor" ref="68887631"/>
|
||||
</object>
|
||||
<array key="NSAllowedInputLocales">
|
||||
<string>ti_ER</string>
|
||||
<string>ar_LY</string>
|
||||
<string>kok_IN</string>
|
||||
<string>mk_MK</string>
|
||||
<string>eo</string>
|
||||
<string>fr_CH</string>
|
||||
<string>sw</string>
|
||||
<string>so_ET</string>
|
||||
<string>gv</string>
|
||||
<string>ar_BH</string>
|
||||
<string>hy_AM_REVISED</string>
|
||||
<string>it_IT</string>
|
||||
<string>bg_BG</string>
|
||||
<string>ro</string>
|
||||
<string>es_HN</string>
|
||||
<string>en_BE</string>
|
||||
<string>is</string>
|
||||
<string>kw_GB</string>
|
||||
<string>kl</string>
|
||||
<string>ga_IE</string>
|
||||
<string>nl_NL</string>
|
||||
<string>uk</string>
|
||||
<string>fr_CA</string>
|
||||
<string>sk_SK</string>
|
||||
<string>es_AR</string>
|
||||
<string>en_MT</string>
|
||||
<string>fr_BE</string>
|
||||
<string>ca</string>
|
||||
<string>cs_CZ</string>
|
||||
<string>fr_FR</string>
|
||||
<string>en_ZA</string>
|
||||
<string>sl</string>
|
||||
<string>fa</string>
|
||||
<string>so</string>
|
||||
<string>pt</string>
|
||||
<string>et_EE</string>
|
||||
<string>eu_ES</string>
|
||||
<string>fi</string>
|
||||
<string>de_CH</string>
|
||||
<string>or</string>
|
||||
<string>gu_IN</string>
|
||||
<string>mt_MT</string>
|
||||
<string>nb</string>
|
||||
<string>ms</string>
|
||||
<string>es_CR</string>
|
||||
<string>as_IN</string>
|
||||
<string>ar_SA</string>
|
||||
<string>am</string>
|
||||
<string>pl</string>
|
||||
<string>hu</string>
|
||||
<string>lv</string>
|
||||
<string>ar_DZ</string>
|
||||
<string>ur</string>
|
||||
<string>pt_PT</string>
|
||||
<string>eu</string>
|
||||
<string>so_DJ</string>
|
||||
<string>de</string>
|
||||
<string>en_IN</string>
|
||||
<string>hr_HR</string>
|
||||
<string>ar_AE</string>
|
||||
<string>gu</string>
|
||||
<string>lt</string>
|
||||
<string>te_IN</string>
|
||||
<string>ar_KW</string>
|
||||
<string>sr_Latn</string>
|
||||
<string>de_AT</string>
|
||||
<string>en_US</string>
|
||||
<string>es_PR</string>
|
||||
<string>pl_PL</string>
|
||||
<string>uz_Cyrl_UZ</string>
|
||||
<string>ar_EG</string>
|
||||
<string>it_CH</string>
|
||||
<string>nl</string>
|
||||
<string>haw_US</string>
|
||||
<string>is_IS</string>
|
||||
<string>en_IE</string>
|
||||
<string>kl_GL</string>
|
||||
<string>ps</string>
|
||||
<string>zh_Hans_CN</string>
|
||||
<string>ar</string>
|
||||
<string>ru_UA</string>
|
||||
<string>th_TH</string>
|
||||
<string>fr_LU</string>
|
||||
<string>uz_Latn_UZ</string>
|
||||
<string>az</string>
|
||||
<string>bn_IN</string>
|
||||
<string>es_MX</string>
|
||||
<string>kk_KZ</string>
|
||||
<string>en_US_POSIX</string>
|
||||
<string>el_GR</string>
|
||||
<string>he</string>
|
||||
<string>es_UY</string>
|
||||
<string>nn_NO</string>
|
||||
<string>sr</string>
|
||||
<string>sk</string>
|
||||
<string>ur_PK</string>
|
||||
<string>es_PA</string>
|
||||
<string>sv_FI</string>
|
||||
<string>zh</string>
|
||||
<string>es_DO</string>
|
||||
<string>en_CA</string>
|
||||
<string>en_BW</string>
|
||||
<string>de_DE</string>
|
||||
<string>haw</string>
|
||||
<string>pa_IN</string>
|
||||
<string>sq</string>
|
||||
<string>kw</string>
|
||||
<string>ga</string>
|
||||
<string>ml</string>
|
||||
<string>mt</string>
|
||||
<string>af_ZA</string>
|
||||
<string>az_Latn</string>
|
||||
<string>ko_KR</string>
|
||||
<string>fa_AF</string>
|
||||
<string>ps_AF</string>
|
||||
<string>be_BY</string>
|
||||
<string>bn</string>
|
||||
<string>it</string>
|
||||
<string>sr_Latn_CS</string>
|
||||
<string>zh_Hans</string>
|
||||
<string>as</string>
|
||||
<string>ms_MY</string>
|
||||
<string>be</string>
|
||||
<string>sl_SI</string>
|
||||
<string>fa_IR</string>
|
||||
<string>es_EC</string>
|
||||
<string>kok</string>
|
||||
<string>es_PY</string>
|
||||
<string>ta_IN</string>
|
||||
<string>am_ET</string>
|
||||
<string>es_CO</string>
|
||||
<string>uz_Latn</string>
|
||||
<string>el</string>
|
||||
<string>zh_Hant_MO</string>
|
||||
<string>kk</string>
|
||||
<string>kn</string>
|
||||
<string>zh_Hant</string>
|
||||
<string>en</string>
|
||||
<string>es_PE</string>
|
||||
<string>pt_BR</string>
|
||||
<string>ar_LB</string>
|
||||
<string>en_NZ</string>
|
||||
<string>es_ES</string>
|
||||
<string>en_HK</string>
|
||||
<string>es_BO</string>
|
||||
<string>hu_HU</string>
|
||||
<string>sr_Cyrl</string>
|
||||
<string>nb_NO</string>
|
||||
<string>sv</string>
|
||||
<string>vi</string>
|
||||
<string>ti_ET</string>
|
||||
<string>bg</string>
|
||||
<string>om</string>
|
||||
<string>de_LU</string>
|
||||
<string>en_SG</string>
|
||||
<string>id_ID</string>
|
||||
<string>ur_IN</string>
|
||||
<string>uz</string>
|
||||
<string>da</string>
|
||||
<string>ru_RU</string>
|
||||
<string>es_US</string>
|
||||
<string>es_VE</string>
|
||||
<string>ko</string>
|
||||
<string>ja</string>
|
||||
<string>af</string>
|
||||
<string>ar_YE</string>
|
||||
<string>lt_LT</string>
|
||||
<string>om_KE</string>
|
||||
<string>zh_Hans_SG</string>
|
||||
<string>es_NI</string>
|
||||
<string>he_IL</string>
|
||||
<string>en_PK</string>
|
||||
<string>en_PH</string>
|
||||
<string>az_Cyrl_AZ</string>
|
||||
<string>en_AU</string>
|
||||
<string>az_Cyrl</string>
|
||||
<string>ta</string>
|
||||
<string>ar_MA</string>
|
||||
<string>sw_KE</string>
|
||||
<string>tr_TR</string>
|
||||
<string>zh_Hant_HK</string>
|
||||
<string>en_ZW</string>
|
||||
<string>de_BE</string>
|
||||
<string>mk</string>
|
||||
<string>pa</string>
|
||||
<string>da_DK</string>
|
||||
<string>es_GT</string>
|
||||
<string>es</string>
|
||||
<string>ar_IQ</string>
|
||||
<string>az_Latn_AZ</string>
|
||||
<string>so_SO</string>
|
||||
<string>lv_LV</string>
|
||||
<string>mr</string>
|
||||
<string>te</string>
|
||||
<string>sq_AL</string>
|
||||
<string>ml_IN</string>
|
||||
<string>uk_UA</string>
|
||||
<string>hi_IN</string>
|
||||
<string>ca_ES</string>
|
||||
<string>ar_TN</string>
|
||||
<string>id</string>
|
||||
<string>om_ET</string>
|
||||
<string>cs</string>
|
||||
<string>fo_FO</string>
|
||||
<string>hy_AM</string>
|
||||
<string>en_GB</string>
|
||||
<string>sr_Cyrl_CS</string>
|
||||
<string>gl_ES</string>
|
||||
<string>sw_TZ</string>
|
||||
<string>ro_RO</string>
|
||||
<string>cy</string>
|
||||
<string>fr</string>
|
||||
<string>ms_BN</string>
|
||||
<string>so_KE</string>
|
||||
<string>tr</string>
|
||||
<string>gl</string>
|
||||
<string>cy_GB</string>
|
||||
<string>ar_OM</string>
|
||||
<string>fo</string>
|
||||
<string>es_CL</string>
|
||||
<string>sv_SE</string>
|
||||
<string>ar_JO</string>
|
||||
<string>uz_Cyrl</string>
|
||||
<string>zh_Hant_TW</string>
|
||||
<string>et</string>
|
||||
<string>hi</string>
|
||||
<string>fi_FI</string>
|
||||
<string>nn</string>
|
||||
<string>th</string>
|
||||
<string>ar_SY</string>
|
||||
<string>ja_JP</string>
|
||||
<string>gv_GB</string>
|
||||
<string>hy</string>
|
||||
<string>en_VI</string>
|
||||
<string>kn_IN</string>
|
||||
<string>ti</string>
|
||||
<string>ar_QA</string>
|
||||
<string>es_SV</string>
|
||||
<string>hr</string>
|
||||
<string>ru</string>
|
||||
<string>ar_SD</string>
|
||||
<string>mr_IN</string>
|
||||
<string>vi_VN</string>
|
||||
<string>nl_BE</string>
|
||||
<string>or_IN</string>
|
||||
</array>
|
||||
</object>
|
||||
<int key="NSResizingMask">3</int>
|
||||
<bool key="NSIsResizeable">YES</bool>
|
||||
<bool key="NSIsEditable">YES</bool>
|
||||
<reference key="NSTableView" ref="999266526"/>
|
||||
</object>
|
||||
<object class="NSTableColumn" id="729273205">
|
||||
<string key="NSIdentifier">title</string>
|
||||
<double key="NSWidth">344</double>
|
||||
<double key="NSMinWidth">40</double>
|
||||
<double key="NSMaxWidth">2000</double>
|
||||
<object class="NSTableHeaderCell" key="NSHeaderCell">
|
||||
<int key="NSCellFlags">75497536</int>
|
||||
<int key="NSCellFlags2">2048</int>
|
||||
<string key="NSContents">Title</string>
|
||||
<reference key="NSSupport" ref="26"/>
|
||||
<reference key="NSBackgroundColor" ref="120863768"/>
|
||||
<reference key="NSTextColor" ref="1034872520"/>
|
||||
</object>
|
||||
<object class="NSTextFieldCell" key="NSDataCell" id="283838781">
|
||||
<int key="NSCellFlags">337641536</int>
|
||||
<int key="NSCellFlags2">133120</int>
|
||||
<string key="NSContents">Text Cell</string>
|
||||
<reference key="NSSupport" ref="26"/>
|
||||
<reference key="NSControlView" ref="999266526"/>
|
||||
<reference key="NSBackgroundColor" ref="315001162"/>
|
||||
<reference key="NSTextColor" ref="492112684"/>
|
||||
</object>
|
||||
<int key="NSResizingMask">3</int>
|
||||
<bool key="NSIsResizeable">YES</bool>
|
||||
<bool key="NSIsEditable">YES</bool>
|
||||
<reference key="NSTableView" ref="999266526"/>
|
||||
</object>
|
||||
</array>
|
||||
<double key="NSIntercellSpacingWidth">3</double>
|
||||
<double key="NSIntercellSpacingHeight">2</double>
|
||||
<object class="NSColor" key="NSBackgroundColor">
|
||||
<int key="NSColorSpace">3</int>
|
||||
<bytes key="NSWhite">MQA</bytes>
|
||||
</object>
|
||||
<object class="NSColor" key="NSGridColor">
|
||||
<int key="NSColorSpace">6</int>
|
||||
<string key="NSCatalogName">System</string>
|
||||
<string key="NSColorName">gridColor</string>
|
||||
<object class="NSColor" key="NSColor">
|
||||
<int key="NSColorSpace">3</int>
|
||||
<bytes key="NSWhite">MC41AA</bytes>
|
||||
</object>
|
||||
</object>
|
||||
<double key="NSRowHeight">14</double>
|
||||
<int key="NSTvFlags">-155189248</int>
|
||||
<reference key="NSDelegate"/>
|
||||
<reference key="NSDataSource"/>
|
||||
<int key="NSGridStyleMask">1</int>
|
||||
<int key="NSColumnAutoresizingStyle">4</int>
|
||||
<int key="NSDraggingSourceMaskForLocal">15</int>
|
||||
<int key="NSDraggingSourceMaskForNonLocal">0</int>
|
||||
<bool key="NSAllowsTypeSelect">YES</bool>
|
||||
<int key="NSTableViewDraggingDestinationStyle">0</int>
|
||||
<int key="NSTableViewGroupRowStyle">1</int>
|
||||
</object>
|
||||
</array>
|
||||
<string key="NSFrame">{{1, 17}, {446, 181}}</string>
|
||||
<reference key="NSSuperview" ref="86220922"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="999266526"/>
|
||||
<reference key="NSDocView" ref="999266526"/>
|
||||
<reference key="NSBGColor" ref="315001162"/>
|
||||
<int key="NScvFlags">4</int>
|
||||
</object>
|
||||
<object class="NSScroller" id="477814729">
|
||||
<reference key="NSNextResponder" ref="86220922"/>
|
||||
<int key="NSvFlags">-2147483392</int>
|
||||
<string key="NSFrame">{{412, 17}, {11, 176}}</string>
|
||||
<reference key="NSSuperview" ref="86220922"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="827247503"/>
|
||||
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
|
||||
<int key="NSsFlags">256</int>
|
||||
<reference key="NSTarget" ref="86220922"/>
|
||||
<string key="NSAction">_doScroller:</string>
|
||||
<double key="NSCurValue">37</double>
|
||||
<double key="NSPercent">0.19473679999999999</double>
|
||||
</object>
|
||||
<object class="NSScroller" id="827247503">
|
||||
<reference key="NSNextResponder" ref="86220922"/>
|
||||
<int key="NSvFlags">-2147483392</int>
|
||||
<string key="NSFrame">{{1, 193}, {411, 11}}</string>
|
||||
<reference key="NSSuperview" ref="86220922"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="665589373"/>
|
||||
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
|
||||
<int key="NSsFlags">257</int>
|
||||
<reference key="NSTarget" ref="86220922"/>
|
||||
<string key="NSAction">_doScroller:</string>
|
||||
<double key="NSPercent">0.99763599999999997</double>
|
||||
</object>
|
||||
<object class="NSClipView" id="188370008">
|
||||
<reference key="NSNextResponder" ref="86220922"/>
|
||||
<int key="NSvFlags">2338</int>
|
||||
<array class="NSMutableArray" key="NSSubviews">
|
||||
<reference ref="888415462"/>
|
||||
</array>
|
||||
<string key="NSFrame">{{1, 0}, {446, 17}}</string>
|
||||
<reference key="NSSuperview" ref="86220922"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="888415462"/>
|
||||
<reference key="NSDocView" ref="888415462"/>
|
||||
<reference key="NSBGColor" ref="315001162"/>
|
||||
<int key="NScvFlags">4</int>
|
||||
</object>
|
||||
</array>
|
||||
<string key="NSFrame">{{17, 36}, {448, 199}}</string>
|
||||
<reference key="NSSuperview" ref="900859224"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="188370008"/>
|
||||
<int key="NSsFlags">133682</int>
|
||||
<reference key="NSVScroller" ref="477814729"/>
|
||||
<reference key="NSHScroller" ref="827247503"/>
|
||||
<reference key="NSContentView" ref="399023230"/>
|
||||
<reference key="NSHeaderClipView" ref="188370008"/>
|
||||
<bytes key="NSScrollAmts">QSAAAEEgAABBgAAAQYAAAA</bytes>
|
||||
<double key="NSMinMagnification">0.25</double>
|
||||
<double key="NSMaxMagnification">4</double>
|
||||
<double key="NSMagnification">1</double>
|
||||
</object>
|
||||
<object class="NSButton" id="900292374">
|
||||
<reference key="NSNextResponder" ref="900859224"/>
|
||||
<int key="NSvFlags">292</int>
|
||||
<string key="NSFrame">{{40, 7}, {24, 22}}</string>
|
||||
<reference key="NSSuperview" ref="900859224"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSButtonCell" key="NSCell" id="7436524">
|
||||
<int key="NSCellFlags">603979776</int>
|
||||
<int key="NSCellFlags2">134217728</int>
|
||||
<string key="NSContents"/>
|
||||
<object class="NSFont" key="NSSupport" id="555068703">
|
||||
<string key="NSName">.LucidaGrandeUI</string>
|
||||
<double key="NSSize">13</double>
|
||||
<int key="NSfFlags">1044</int>
|
||||
</object>
|
||||
<reference key="NSControlView" ref="900292374"/>
|
||||
<int key="NSButtonFlags">-2030288896</int>
|
||||
<int key="NSButtonFlags2">162</int>
|
||||
<object class="NSCustomResource" key="NSNormalImage">
|
||||
<string key="NSClassName">NSImage</string>
|
||||
<string key="NSResourceName">NSRemoveTemplate</string>
|
||||
</object>
|
||||
<string key="NSAlternateContents"/>
|
||||
<string key="NSKeyEquivalent"/>
|
||||
<int key="NSPeriodicDelay">200</int>
|
||||
<int key="NSPeriodicInterval">25</int>
|
||||
</object>
|
||||
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
|
||||
</object>
|
||||
<object class="NSButton" id="665589373">
|
||||
<reference key="NSNextResponder" ref="900859224"/>
|
||||
<int key="NSvFlags">292</int>
|
||||
<string key="NSFrame">{{17, 7}, {24, 22}}</string>
|
||||
<reference key="NSSuperview" ref="900859224"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="900292374"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSButtonCell" key="NSCell" id="19812870">
|
||||
<int key="NSCellFlags">67108864</int>
|
||||
<int key="NSCellFlags2">134217728</int>
|
||||
<string key="NSContents"/>
|
||||
<reference key="NSSupport" ref="555068703"/>
|
||||
<reference key="NSControlView" ref="665589373"/>
|
||||
<int key="NSButtonFlags">-2030288896</int>
|
||||
<int key="NSButtonFlags2">162</int>
|
||||
<object class="NSCustomResource" key="NSNormalImage">
|
||||
<string key="NSClassName">NSImage</string>
|
||||
<string key="NSResourceName">NSAddTemplate</string>
|
||||
</object>
|
||||
<string key="NSAlternateContents"/>
|
||||
<string key="NSKeyEquivalent"/>
|
||||
<int key="NSPeriodicDelay">200</int>
|
||||
<int key="NSPeriodicInterval">25</int>
|
||||
</object>
|
||||
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
|
||||
</object>
|
||||
</array>
|
||||
<string key="NSFrame">{{10, 25}, {482, 241}}</string>
|
||||
<reference key="NSSuperview" ref="980212840"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="86220922"/>
|
||||
</object>
|
||||
<string key="NSLabel">Chapters</string>
|
||||
<object class="NSColor" key="NSColor">
|
||||
<int key="NSColorSpace">6</int>
|
||||
<string key="NSCatalogName">System</string>
|
||||
<string key="NSColorName">controlColor</string>
|
||||
<reference key="NSColor" ref="79804590"/>
|
||||
</object>
|
||||
<reference key="NSTabView" ref="980212840"/>
|
||||
</object>
|
||||
</array>
|
||||
<reference key="NSSelectedTabViewItem" ref="561234673"/>
|
||||
<reference key="NSFont" ref="26"/>
|
||||
<int key="NSTvFlags">134217728</int>
|
||||
<bool key="NSAllowTruncatedLabels">YES</bool>
|
||||
<bool key="NSDrawsBackground">YES</bool>
|
||||
<array class="NSMutableArray" key="NSSubviews">
|
||||
<reference ref="900859224"/>
|
||||
</array>
|
||||
</object>
|
||||
</array>
|
||||
<string key="NSFrameSize">{480, 272}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="980212840"/>
|
||||
<string key="NSClassName">NSView</string>
|
||||
</object>
|
||||
</array>
|
||||
<object class="IBObjectContainer" key="IBDocument.Objects">
|
||||
<bool key="usesAutoincrementingIDs">NO</bool>
|
||||
<array class="NSMutableArray" key="connectionRecords">
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">view</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="1005"/>
|
||||
</object>
|
||||
<string key="id">2</string>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">removeChapter</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="900292374"/>
|
||||
</object>
|
||||
<string key="id">47</string>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">removeChapter:</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="900292374"/>
|
||||
</object>
|
||||
<string key="id">48</string>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">addChapter:</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="665589373"/>
|
||||
</object>
|
||||
<string key="id">50</string>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">chapterTableView</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="999266526"/>
|
||||
</object>
|
||||
<string key="id">49</string>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">delegate</string>
|
||||
<reference key="source" ref="999266526"/>
|
||||
<reference key="destination" ref="1001"/>
|
||||
</object>
|
||||
<string key="id">29</string>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">dataSource</string>
|
||||
<reference key="source" ref="999266526"/>
|
||||
<reference key="destination" ref="1001"/>
|
||||
</object>
|
||||
<string key="id">28</string>
|
||||
</object>
|
||||
</array>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<array key="orderedObjects">
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">0</string>
|
||||
<array key="object" id="0"/>
|
||||
<reference key="children" ref="1000"/>
|
||||
<nil key="parent"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">-2</string>
|
||||
<reference key="object" ref="1001"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">File's Owner</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">-1</string>
|
||||
<reference key="object" ref="1003"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">First Responder</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">-3</string>
|
||||
<reference key="object" ref="1004"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">Application</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">1</string>
|
||||
<reference key="object" ref="1005"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="980212840"/>
|
||||
</array>
|
||||
<reference key="parent" ref="0"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">10</string>
|
||||
<reference key="object" ref="980212840"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="561234673"/>
|
||||
</array>
|
||||
<reference key="parent" ref="1005"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">11</string>
|
||||
<reference key="object" ref="561234673"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="900859224"/>
|
||||
</array>
|
||||
<reference key="parent" ref="980212840"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">12</string>
|
||||
<reference key="object" ref="900859224"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="86220922"/>
|
||||
<reference ref="900292374"/>
|
||||
<reference ref="665589373"/>
|
||||
</array>
|
||||
<reference key="parent" ref="561234673"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">19</string>
|
||||
<reference key="object" ref="86220922"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="477814729"/>
|
||||
<reference ref="827247503"/>
|
||||
<reference ref="888415462"/>
|
||||
<reference ref="999266526"/>
|
||||
</array>
|
||||
<reference key="parent" ref="900859224"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">20</string>
|
||||
<reference key="object" ref="477814729"/>
|
||||
<reference key="parent" ref="86220922"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">21</string>
|
||||
<reference key="object" ref="827247503"/>
|
||||
<reference key="parent" ref="86220922"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">23</string>
|
||||
<reference key="object" ref="888415462"/>
|
||||
<reference key="parent" ref="86220922"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">31</string>
|
||||
<reference key="object" ref="900292374"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="7436524"/>
|
||||
</array>
|
||||
<reference key="parent" ref="900859224"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">32</string>
|
||||
<reference key="object" ref="7436524"/>
|
||||
<reference key="parent" ref="900292374"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">42</string>
|
||||
<reference key="object" ref="665589373"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="19812870"/>
|
||||
</array>
|
||||
<reference key="parent" ref="900859224"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">43</string>
|
||||
<reference key="object" ref="19812870"/>
|
||||
<reference key="parent" ref="665589373"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">22</string>
|
||||
<reference key="object" ref="999266526"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="891606345"/>
|
||||
<reference ref="729273205"/>
|
||||
</array>
|
||||
<reference key="parent" ref="86220922"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">24</string>
|
||||
<reference key="object" ref="891606345"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="350676877"/>
|
||||
</array>
|
||||
<reference key="parent" ref="999266526"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">25</string>
|
||||
<reference key="object" ref="729273205"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="283838781"/>
|
||||
</array>
|
||||
<reference key="parent" ref="999266526"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">26</string>
|
||||
<reference key="object" ref="283838781"/>
|
||||
<reference key="parent" ref="729273205"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">27</string>
|
||||
<reference key="object" ref="350676877"/>
|
||||
<reference key="parent" ref="891606345"/>
|
||||
</object>
|
||||
</array>
|
||||
</object>
|
||||
<dictionary class="NSMutableDictionary" key="flattenedProperties">
|
||||
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="10.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="11.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="12.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="19.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="20.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="21.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="22.CustomClassName">SBTableView</string>
|
||||
<string key="22.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="23.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="24.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="25.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="26.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="27.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="31.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="32.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="42.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="43.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
</dictionary>
|
||||
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
|
||||
<nil key="activeLocalization"/>
|
||||
<dictionary class="NSMutableDictionary" key="localizations"/>
|
||||
<nil key="sourceID"/>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">SBChapterViewController</string>
|
||||
<string key="superclassName">NSViewController</string>
|
||||
<dictionary class="NSMutableDictionary" key="actions">
|
||||
<string key="addChapter:">id</string>
|
||||
<string key="removeChapter:">id</string>
|
||||
</dictionary>
|
||||
<dictionary class="NSMutableDictionary" key="actionInfosByName">
|
||||
<object class="IBActionInfo" key="addChapter:">
|
||||
<string key="name">addChapter:</string>
|
||||
<string key="candidateClassName">id</string>
|
||||
</object>
|
||||
<object class="IBActionInfo" key="removeChapter:">
|
||||
<string key="name">removeChapter:</string>
|
||||
<string key="candidateClassName">id</string>
|
||||
</object>
|
||||
</dictionary>
|
||||
<dictionary class="NSMutableDictionary" key="outlets">
|
||||
<string key="chapterTableView">SBTableView</string>
|
||||
<string key="removeChapter">NSButton</string>
|
||||
</dictionary>
|
||||
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
|
||||
<object class="IBToOneOutletInfo" key="chapterTableView">
|
||||
<string key="name">chapterTableView</string>
|
||||
<string key="candidateClassName">SBTableView</string>
|
||||
</object>
|
||||
<object class="IBToOneOutletInfo" key="removeChapter">
|
||||
<string key="name">removeChapter</string>
|
||||
<string key="candidateClassName">NSButton</string>
|
||||
</object>
|
||||
</dictionary>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">./Classes/SBChapterViewController.h</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">SBTableView</string>
|
||||
<string key="superclassName">NSTableView</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">./Classes/SBTableView.h</string>
|
||||
</object>
|
||||
</object>
|
||||
</array>
|
||||
</object>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
|
||||
<bool key="IBDocument.previouslyAttemptedUpgradeToXcode5">YES</bool>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
|
||||
<real value="1060" key="NS.object.0"/>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
|
||||
<integer value="4600" key="NS.object.0"/>
|
||||
</object>
|
||||
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
|
||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
||||
<dictionary class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
|
||||
<string key="NSAddTemplate">{8, 8}</string>
|
||||
<string key="NSRemoveTemplate">{8, 8}</string>
|
||||
</dictionary>
|
||||
</data>
|
||||
</archive>
|
||||
+256
@@ -0,0 +1,256 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
|
||||
<data>
|
||||
<int key="IBDocument.SystemTarget">1060</int>
|
||||
<string key="IBDocument.SystemVersion">13A603</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">4511</string>
|
||||
<string key="IBDocument.AppKitVersion">1265</string>
|
||||
<string key="IBDocument.HIToolboxVersion">695.00</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="NS.object.0">4511</string>
|
||||
</object>
|
||||
<array key="IBDocument.IntegratedClassDependencies">
|
||||
<string>NSCustomObject</string>
|
||||
<string>NSCustomView</string>
|
||||
<string>NSTabView</string>
|
||||
<string>NSTabViewItem</string>
|
||||
<string>NSTextField</string>
|
||||
<string>NSTextFieldCell</string>
|
||||
<string>NSView</string>
|
||||
</array>
|
||||
<array key="IBDocument.PluginDependencies">
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
</array>
|
||||
<object class="NSMutableDictionary" key="IBDocument.Metadata">
|
||||
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
|
||||
<integer value="1" key="NS.object.0"/>
|
||||
</object>
|
||||
<array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
|
||||
<object class="NSCustomObject" id="1001">
|
||||
<string key="NSClassName">SBEmptyViewController</string>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="1003">
|
||||
<string key="NSClassName">FirstResponder</string>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="1004">
|
||||
<string key="NSClassName">NSApplication</string>
|
||||
</object>
|
||||
<object class="NSCustomView" id="1005">
|
||||
<reference key="NSNextResponder"/>
|
||||
<int key="NSvFlags">268</int>
|
||||
<array class="NSMutableArray" key="NSSubviews">
|
||||
<object class="NSTabView" id="919391344">
|
||||
<reference key="NSNextResponder" ref="1005"/>
|
||||
<int key="NSvFlags">274</int>
|
||||
<string key="NSFrame">{{-11, -12}, {502, 279}}</string>
|
||||
<reference key="NSSuperview" ref="1005"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="936155568"/>
|
||||
<array class="NSMutableArray" key="NSTabViewItems">
|
||||
<object class="NSTabViewItem" id="381230830">
|
||||
<string key="NSIdentifier">1</string>
|
||||
<object class="NSView" key="NSView" id="936155568">
|
||||
<reference key="NSNextResponder" ref="919391344"/>
|
||||
<int key="NSvFlags">274</int>
|
||||
<array class="NSMutableArray" key="NSSubviews">
|
||||
<object class="NSTextField" id="173710471">
|
||||
<reference key="NSNextResponder" ref="936155568"/>
|
||||
<int key="NSvFlags">301</int>
|
||||
<string key="NSFrame">{{176, 112}, {129, 17}}</string>
|
||||
<reference key="NSSuperview" ref="936155568"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSTextFieldCell" key="NSCell" id="1034784350">
|
||||
<int key="NSCellFlags">68157504</int>
|
||||
<int key="NSCellFlags2">272630784</int>
|
||||
<string key="NSContents">Nothing to see here</string>
|
||||
<object class="NSFont" key="NSSupport">
|
||||
<string key="NSName">.LucidaGrandeUI</string>
|
||||
<double key="NSSize">13</double>
|
||||
<int key="NSfFlags">1044</int>
|
||||
</object>
|
||||
<reference key="NSControlView" ref="173710471"/>
|
||||
<object class="NSColor" key="NSBackgroundColor" id="290017160">
|
||||
<int key="NSColorSpace">6</int>
|
||||
<string key="NSCatalogName">System</string>
|
||||
<string key="NSColorName">controlColor</string>
|
||||
<object class="NSColor" key="NSColor">
|
||||
<int key="NSColorSpace">3</int>
|
||||
<bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSColor" key="NSTextColor">
|
||||
<int key="NSColorSpace">6</int>
|
||||
<string key="NSCatalogName">System</string>
|
||||
<string key="NSColorName">controlTextColor</string>
|
||||
<object class="NSColor" key="NSColor">
|
||||
<int key="NSColorSpace">3</int>
|
||||
<bytes key="NSWhite">MAA</bytes>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
|
||||
<int key="NSTextFieldAlignmentRectInsetsVersion">1</int>
|
||||
</object>
|
||||
</array>
|
||||
<string key="NSFrame">{{10, 25}, {482, 241}}</string>
|
||||
<reference key="NSSuperview" ref="919391344"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="173710471"/>
|
||||
</object>
|
||||
<string key="NSLabel">Empty</string>
|
||||
<reference key="NSColor" ref="290017160"/>
|
||||
<reference key="NSTabView" ref="919391344"/>
|
||||
</object>
|
||||
</array>
|
||||
<reference key="NSSelectedTabViewItem" ref="381230830"/>
|
||||
<object class="NSFont" key="NSFont">
|
||||
<string key="NSName">.LucidaGrandeUI</string>
|
||||
<double key="NSSize">11</double>
|
||||
<int key="NSfFlags">3100</int>
|
||||
</object>
|
||||
<int key="NSTvFlags">134217728</int>
|
||||
<bool key="NSAllowTruncatedLabels">YES</bool>
|
||||
<bool key="NSDrawsBackground">YES</bool>
|
||||
<array class="NSMutableArray" key="NSSubviews">
|
||||
<reference ref="936155568"/>
|
||||
</array>
|
||||
</object>
|
||||
</array>
|
||||
<string key="NSFrameSize">{480, 272}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="919391344"/>
|
||||
<string key="NSClassName">NSView</string>
|
||||
</object>
|
||||
</array>
|
||||
<object class="IBObjectContainer" key="IBDocument.Objects">
|
||||
<bool key="usesAutoincrementingIDs">NO</bool>
|
||||
<array class="NSMutableArray" key="connectionRecords">
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">view</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="1005"/>
|
||||
</object>
|
||||
<string key="id">4</string>
|
||||
</object>
|
||||
</array>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<array key="orderedObjects">
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">0</string>
|
||||
<array key="object" id="0"/>
|
||||
<reference key="children" ref="1000"/>
|
||||
<nil key="parent"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">-2</string>
|
||||
<reference key="object" ref="1001"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">File's Owner</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">-1</string>
|
||||
<reference key="object" ref="1003"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">First Responder</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">-3</string>
|
||||
<reference key="object" ref="1004"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">Application</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">1</string>
|
||||
<reference key="object" ref="1005"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="919391344"/>
|
||||
</array>
|
||||
<reference key="parent" ref="0"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">5</string>
|
||||
<reference key="object" ref="919391344"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="381230830"/>
|
||||
</array>
|
||||
<reference key="parent" ref="1005"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">6</string>
|
||||
<reference key="object" ref="381230830"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="936155568"/>
|
||||
</array>
|
||||
<reference key="parent" ref="919391344"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">9</string>
|
||||
<reference key="object" ref="936155568"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="173710471"/>
|
||||
</array>
|
||||
<reference key="parent" ref="381230830"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">2</string>
|
||||
<reference key="object" ref="173710471"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="1034784350"/>
|
||||
</array>
|
||||
<reference key="parent" ref="936155568"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<string key="id">3</string>
|
||||
<reference key="object" ref="1034784350"/>
|
||||
<reference key="parent" ref="173710471"/>
|
||||
</object>
|
||||
</array>
|
||||
</object>
|
||||
<dictionary class="NSMutableDictionary" key="flattenedProperties">
|
||||
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="5.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="9.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
</dictionary>
|
||||
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
|
||||
<nil key="activeLocalization"/>
|
||||
<dictionary class="NSMutableDictionary" key="localizations"/>
|
||||
<nil key="sourceID"/>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">SBEmptyViewController</string>
|
||||
<string key="superclassName">NSViewController</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">./Classes/SBEmptyViewController.h</string>
|
||||
</object>
|
||||
</object>
|
||||
</array>
|
||||
</object>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
|
||||
<bool key="IBDocument.previouslyAttemptedUpgradeToXcode5">YES</bool>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
|
||||
<real value="1060" key="NS.object.0"/>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
|
||||
<integer value="4600" key="NS.object.0"/>
|
||||
</object>
|
||||
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
|
||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
||||
</data>
|
||||
</archive>
|
||||
+3021
File diff suppressed because it is too large.
Load diff
+1047
File diff suppressed because it is too large.
Load diff
+2384
File diff suppressed because it is too large.
Load diff
+28
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// ChapterViewController.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 06/02/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
#import <MP42Foundation/MP42ChapterTrack.h>
|
||||
|
||||
@class SBTableView;
|
||||
|
||||
@interface SBChapterViewController : NSViewController {
|
||||
MP42ChapterTrack *track;
|
||||
|
||||
NSDictionary *detailBoldAttr;
|
||||
|
||||
IBOutlet SBTableView *chapterTableView;
|
||||
IBOutlet NSButton *removeChapter;
|
||||
}
|
||||
|
||||
- (void) setTrack:(MP42ChapterTrack *)track;
|
||||
- (IBAction) addChapter: (id) sender;
|
||||
- (IBAction) removeChapter: (id) sender;
|
||||
|
||||
@end
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// ChapterViewController.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 06/02/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBChapterViewController.h"
|
||||
|
||||
#import <MP42Foundation/MP42Utilities.h>
|
||||
|
||||
@implementation SBChapterViewController
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
NSMutableParagraphStyle * ps = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
|
||||
[ps setHeadIndent: -10.0];
|
||||
[ps setAlignment:NSRightTextAlignment];
|
||||
|
||||
detailBoldAttr = [[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSFont boldSystemFontOfSize:11.0], NSFontAttributeName,
|
||||
ps, NSParagraphStyleAttributeName,
|
||||
[NSColor grayColor], NSForegroundColorAttributeName,
|
||||
nil] retain];
|
||||
}
|
||||
|
||||
- (void)setTrack:(MP42ChapterTrack *)chapterTrack
|
||||
{
|
||||
track = chapterTrack;
|
||||
}
|
||||
|
||||
- (NSAttributedString *)boldString:(NSString *)string
|
||||
{
|
||||
return [[[NSAttributedString alloc] initWithString:string attributes:detailBoldAttr] autorelease];
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfRowsInTableView:(NSTableView *)t
|
||||
{
|
||||
return [track chapterCount];
|
||||
}
|
||||
|
||||
- (id) tableView:(NSTableView *)tableView
|
||||
objectValueForTableColumn:(NSTableColumn *)tableColumn
|
||||
row:(NSInteger)rowIndex
|
||||
{
|
||||
MP42TextSample * chapter = [track chapterAtIndex:rowIndex];
|
||||
if ([tableColumn.identifier isEqualToString:@"time"])
|
||||
return [self boldString:SMPTEStringFromTime(chapter.timestamp, 1000)];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"title"])
|
||||
return chapter.title;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)tableView:(NSTableView *)tableView
|
||||
setObjectValue:(id)anObject
|
||||
forTableColumn:(NSTableColumn *)tableColumn
|
||||
row:(NSInteger)rowIndex
|
||||
{
|
||||
MP42TextSample * chapter = [track chapterAtIndex:rowIndex];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"title"]) {
|
||||
if (![chapter.title isEqualToString:anObject]) {
|
||||
[track setTitle:anObject forChapter:chapter];
|
||||
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
else if ([tableColumn.identifier isEqualToString:@"time"]) {
|
||||
MP42Duration timestamp = TimeFromSMPTEString(anObject, 1000);
|
||||
if (!(chapter.timestamp == timestamp)) {
|
||||
[track setTimestamp:timestamp forChapter:chapter];
|
||||
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
|
||||
{
|
||||
if ([chapterTableView selectedRow] != -1)
|
||||
[removeChapter setEnabled:YES];
|
||||
else
|
||||
[removeChapter setEnabled:NO];
|
||||
}
|
||||
|
||||
- (IBAction)removeChapter:(id)sender {
|
||||
NSUInteger current_index = [chapterTableView selectedRow];
|
||||
if (current_index < [track chapterCount]) {
|
||||
[track removeChapterAtIndex:current_index];
|
||||
|
||||
[chapterTableView reloadData];
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)addChapter:(id)sender {
|
||||
[track addChapter:@"Chapter" duration:0];
|
||||
|
||||
[chapterTableView reloadData];
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[detailBoldAttr release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// PropertyViewController.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 06/02/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
@interface SBEmptyViewController : NSViewController {
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// PropertyViewController.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 06/02/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBEmptyViewController.h"
|
||||
|
||||
|
||||
@implementation SBEmptyViewController
|
||||
|
||||
|
||||
@end
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// MovieViewController.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 06/02/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Quartz/Quartz.h>
|
||||
|
||||
@class MP42File;
|
||||
@class MP42Metadata;
|
||||
@class SBTableView;
|
||||
@class SBImageBrowserView;
|
||||
|
||||
@interface SBMovieViewController : NSViewController {
|
||||
MP42Metadata *metadata;
|
||||
|
||||
IBOutlet NSPopUpButton *tagList;
|
||||
IBOutlet NSPopUpButton *setList;
|
||||
|
||||
IBOutlet SBTableView *tagsTableView;
|
||||
|
||||
IBOutlet NSPopUpButton *mediaKind;
|
||||
IBOutlet NSPopUpButton *contentRating;
|
||||
IBOutlet NSPopUpButton *hdVideo;
|
||||
IBOutlet NSButton *gapless;
|
||||
IBOutlet NSButton *podcast;
|
||||
|
||||
IBOutlet NSButton *removeTag;
|
||||
|
||||
IBOutlet NSWindow *saveWindow;
|
||||
IBOutlet NSTextField *presetName;
|
||||
|
||||
NSPopUpButtonCell *ratingCell;
|
||||
NSComboBoxCell *genreCell;
|
||||
|
||||
NSDictionary *tags;
|
||||
NSArray *tagsArray;
|
||||
NSArray *tagsMenu;
|
||||
NSDictionary *detailBoldAttr;
|
||||
|
||||
NSMutableDictionary *dct;
|
||||
NSTableColumn *tabCol;
|
||||
CGFloat width;
|
||||
|
||||
IBOutlet SBImageBrowserView *imageBrowser;
|
||||
|
||||
IBOutlet NSButton *addArtwork;
|
||||
IBOutlet NSButton *removeArtwork;
|
||||
}
|
||||
|
||||
- (void) setFile: (MP42File *)file;
|
||||
- (void) setMetadata: (MP42Metadata *)data;
|
||||
|
||||
- (IBAction) addTag: (id) sender;
|
||||
- (IBAction) removeTag: (id) sender;
|
||||
|
||||
- (IBAction) addMetadataSet: (id)sender;
|
||||
|
||||
- (IBAction) showSaveSet: (id)sender;
|
||||
- (IBAction) closeSaveSheet: (id) sender;
|
||||
- (IBAction) saveSet: (id)sender;
|
||||
|
||||
- (IBAction) changeMediaKind: (id) sender;
|
||||
- (IBAction) changecContentRating: (id) sender;
|
||||
- (IBAction) changeGapless: (id) sender;
|
||||
- (IBAction) changePodcast: (id) sender;
|
||||
- (IBAction) changehdVideo: (id) sender;
|
||||
|
||||
- (IBAction) zoomSliderDidChange:(id)sender;
|
||||
|
||||
- (IBAction) selectArtwork: (id) sender;
|
||||
- (IBAction) removeArtwork: (id) sender;
|
||||
|
||||
@end
|
||||
Executable
+823
@@ -0,0 +1,823 @@
|
||||
//
|
||||
// MovieViewController.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 06/02/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
NSString *MetadataPBoardType = @"MetadataPBoardType";
|
||||
|
||||
#import "SBMovieViewController.h"
|
||||
#import "SBTableView.h"
|
||||
#import "SBPresetManager.h"
|
||||
#import "SBTableView.h"
|
||||
#import "SBImageBrowserView.h"
|
||||
|
||||
#import <MP42Foundation/MP42Ratings.h>
|
||||
#import <MP42Foundation/MP42Image.h>
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
|
||||
@interface SBMovieViewController () <SBTableViewDelegate, SBImageBrowserViewDelegate>
|
||||
- (void) updateSetsMenu: (id)sender;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBMovieViewController
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[self updateSetsMenu:self];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(updateSetsMenu:)
|
||||
name:@"SBPresetManagerUpdatedNotification" object:nil];
|
||||
|
||||
tagsMenu = [[metadata writableMetadata] retain];
|
||||
for (id tag in tagsMenu)
|
||||
[tagList addItemWithTitle:tag];
|
||||
|
||||
ratingCell = [[NSPopUpButtonCell alloc] init];
|
||||
[ratingCell setAutoenablesItems:NO];
|
||||
[ratingCell setFont:[NSFont systemFontOfSize:11]];
|
||||
[ratingCell setControlSize:NSSmallControlSize];
|
||||
[ratingCell setBordered:NO];
|
||||
NSArray *ratings = [[MP42Ratings defaultManager] ratings];
|
||||
for (NSString *rating in ratings) {
|
||||
[[ratingCell menu] addItem:[[[NSMenuItem alloc] initWithTitle:rating action:NULL keyEquivalent:@""] autorelease]];
|
||||
}
|
||||
|
||||
genreCell = [[NSComboBoxCell alloc] init];
|
||||
[genreCell setCompletes:YES];
|
||||
[genreCell setFont:[NSFont systemFontOfSize:11]];
|
||||
[genreCell setDrawsBackground:NO];
|
||||
[genreCell setBezeled:NO];
|
||||
[genreCell setButtonBordered:NO];
|
||||
[genreCell setControlSize:NSSmallControlSize];
|
||||
[genreCell setIntercellSpacing:NSMakeSize(1.0, 1.0)];
|
||||
[genreCell setEditable:YES];
|
||||
[genreCell addItemsWithObjectValues:[metadata availableGenres]];
|
||||
|
||||
NSMutableParagraphStyle * ps = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
|
||||
[ps setHeadIndent: -10.0];
|
||||
[ps setAlignment:NSRightTextAlignment];
|
||||
|
||||
detailBoldAttr = [[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSFont boldSystemFontOfSize:11.0], NSFontAttributeName,
|
||||
ps, NSParagraphStyleAttributeName,
|
||||
[NSColor grayColor], NSForegroundColorAttributeName,
|
||||
nil] retain];
|
||||
|
||||
[mediaKind selectItemWithTag:metadata.mediaKind];
|
||||
[contentRating selectItemWithTag:metadata.contentRating];
|
||||
[hdVideo selectItemWithTag:metadata.hdVideo];
|
||||
[gapless setState:metadata.gapless];
|
||||
[podcast setState:metadata.podcast];
|
||||
|
||||
tabCol = [[[tagsTableView tableColumns] objectAtIndex:1] retain];
|
||||
width = [tabCol width];
|
||||
|
||||
[self updateTagsArray];
|
||||
|
||||
[tagsTableView setDoubleAction:@selector(doubleClickAction:)];
|
||||
[tagsTableView setTarget:self];
|
||||
[tagsTableView set_pasteboardTypes:[NSArray arrayWithObject:MetadataPBoardType]];
|
||||
|
||||
dct = [[NSMutableDictionary alloc] init];
|
||||
|
||||
[imageBrowser set_pasteboardTypes:[NSArray arrayWithObjects: NSPasteboardTypeTIFF, NSPasteboardTypePNG, nil]];
|
||||
[imageBrowser setZoomValue:1.0];
|
||||
[imageBrowser reloadData];
|
||||
}
|
||||
|
||||
- (void) setFile: (MP42File *)file
|
||||
{
|
||||
metadata = file.metadata;
|
||||
tags = metadata.tagsDict;
|
||||
}
|
||||
|
||||
- (void) setMetadata: (MP42Metadata *)data
|
||||
{
|
||||
metadata = data;
|
||||
tags = data.tagsDict;
|
||||
}
|
||||
|
||||
- (void) updateTagsArray
|
||||
{
|
||||
[tagsArray autorelease];
|
||||
NSArray *context = [metadata availableMetadata];
|
||||
tagsArray = [[tags allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
|
||||
NSInteger right = [context indexOfObject:obj2];
|
||||
NSInteger left = [context indexOfObject:obj1];
|
||||
|
||||
if (right < left)
|
||||
return NSOrderedDescending;
|
||||
else
|
||||
return NSOrderedAscending;
|
||||
}];
|
||||
[tagsArray retain];
|
||||
}
|
||||
|
||||
- (void) add:(NSDictionary *) data
|
||||
{
|
||||
NSArray *metadataKeys = [data allKeys];
|
||||
|
||||
for (NSString *key in metadataKeys) {
|
||||
[metadata setTag:[data valueForKey:key] forKey:key];
|
||||
}
|
||||
NSUndoManager *undo = [[self view] undoManager];
|
||||
[[undo prepareWithInvocationTarget:self] remove:data];
|
||||
|
||||
if (![undo isUndoing]) {
|
||||
[undo setActionName:@"Insert"];
|
||||
}
|
||||
|
||||
[self updateTagsArray];
|
||||
[tagsTableView reloadData];
|
||||
}
|
||||
|
||||
- (void) remove:(NSDictionary *) data
|
||||
{
|
||||
NSArray *metadataKeys = [data allKeys];
|
||||
|
||||
for (NSString *key in metadataKeys) {
|
||||
[metadata removeTagForKey:key];
|
||||
}
|
||||
NSUndoManager *undo = [[self view] undoManager];
|
||||
[[undo prepareWithInvocationTarget:self] add:data];
|
||||
|
||||
if (![undo isUndoing]) {
|
||||
[undo setActionName:@"Delete"];
|
||||
}
|
||||
|
||||
[self updateTagsArray];
|
||||
[tagsTableView reloadData];
|
||||
}
|
||||
|
||||
- (IBAction) addTag: (id) sender
|
||||
{
|
||||
NSString *tagName = [[sender selectedItem] title];
|
||||
|
||||
if (![metadata.tagsDict valueForKey:tagName])
|
||||
[self add:[NSDictionary dictionaryWithObject:@"" forKey:tagName]];
|
||||
}
|
||||
|
||||
- (IBAction) removeTag: (id) sender {
|
||||
NSIndexSet *rowIndexes = [tagsTableView selectedRowIndexes];
|
||||
NSUInteger current_index = [rowIndexes lastIndex];
|
||||
NSMutableDictionary *tagDict = [[[NSMutableDictionary alloc] init] autorelease];
|
||||
|
||||
while (current_index != NSNotFound) {
|
||||
if ([tagsTableView editedRow] == -1) {
|
||||
NSString *tagName = [tagsArray objectAtIndex:current_index];
|
||||
[tagDict setObject:[metadata.tagsDict valueForKey:tagName] forKey:tagName];
|
||||
}
|
||||
current_index = [rowIndexes indexLessThanIndex: current_index];
|
||||
}
|
||||
[self remove:tagDict];
|
||||
}
|
||||
|
||||
- (void) updateMetadata:(id)value forKey:(NSString *)key
|
||||
{
|
||||
NSString *oldValue = [[[metadata tagsDict] valueForKey:key] retain];
|
||||
|
||||
if ([metadata setTag:value forKey:key]) {
|
||||
|
||||
[tagsTableView noteHeightOfRowsWithIndexesChanged:
|
||||
[NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [tagsTableView numberOfRows])]];
|
||||
|
||||
NSUndoManager *undo = [[self view] undoManager];
|
||||
[[undo prepareWithInvocationTarget:self] updateMetadata:oldValue
|
||||
forKey:key];
|
||||
if (![undo isUndoing]) {
|
||||
[undo setActionName:@"Editing"];
|
||||
}
|
||||
}
|
||||
[oldValue release];
|
||||
}
|
||||
|
||||
- (NSArray *) allSet
|
||||
{
|
||||
return [metadata writableMetadata];
|
||||
}
|
||||
|
||||
- (NSArray *) tvShowSet
|
||||
{
|
||||
return [NSArray arrayWithObjects: @"Name", @"Artist", @"Album", @"Release Date", @"Track #", @"Disk #", @"TV Show", @"TV Episode #", @"TV Network", @"TV Episode ID", @"TV Season", @"Genre", @"Description", @"Long Description", nil];
|
||||
}
|
||||
|
||||
- (NSArray *) movieSet
|
||||
{
|
||||
return [NSArray arrayWithObjects: @"Name", @"Artist", @"Album", @"Genre", @"Release Date", @"Track #", @"Disk #", @"Cast", @"Director", @"Screenwriters", @"Genre", @"Description", @"Long Description", @"Rating", @"Copyright", nil];
|
||||
}
|
||||
|
||||
- (IBAction) addMetadataSet: (id)sender
|
||||
{
|
||||
NSArray *metadataKeys = nil;
|
||||
if ([sender tag] == 0)
|
||||
metadataKeys = [self allSet];
|
||||
else if ([sender tag] == 1) {
|
||||
metadataKeys = [self movieSet];
|
||||
metadata.mediaKind = 9;
|
||||
[mediaKind selectItemWithTag:metadata.mediaKind];
|
||||
}
|
||||
else if ([sender tag] == 2) {
|
||||
metadataKeys = [self tvShowSet];
|
||||
metadata.mediaKind = 10;
|
||||
[mediaKind selectItemWithTag:metadata.mediaKind];
|
||||
}
|
||||
|
||||
NSMutableDictionary *tagDict = [[[NSMutableDictionary alloc] init] autorelease];
|
||||
for (NSString *key in metadataKeys) {
|
||||
if (![[metadata tagsDict] valueForKey:key])
|
||||
[tagDict setValue:@"" forKey:key];
|
||||
}
|
||||
|
||||
[self add:tagDict];
|
||||
}
|
||||
|
||||
- (void) applySet: (id)sender
|
||||
{
|
||||
NSInteger tag = [sender tag];
|
||||
SBPresetManager *presetManager = [SBPresetManager sharedManager];
|
||||
|
||||
MP42Metadata *newTags = [[presetManager presets] objectAtIndex:tag];
|
||||
|
||||
NSArray *metadataKeys = [[newTags tagsDict] allKeys];
|
||||
|
||||
NSMutableDictionary *tagDict = [[[NSMutableDictionary alloc] init] autorelease];
|
||||
for (NSString *key in metadataKeys) {
|
||||
[tagDict setValue:[[newTags tagsDict] valueForKey:key] forKey:key];
|
||||
}
|
||||
|
||||
[metadata.artworks addObjectsFromArray:newTags.artworks];
|
||||
[metadata setIsArtworkEdited:YES];
|
||||
[imageBrowser reloadData];
|
||||
|
||||
metadata.mediaKind = newTags.mediaKind;
|
||||
[mediaKind selectItemWithTag:metadata.mediaKind];
|
||||
|
||||
metadata.hdVideo = newTags.hdVideo;
|
||||
[hdVideo selectItemWithTag:metadata.hdVideo];
|
||||
|
||||
metadata.gapless = newTags.gapless;
|
||||
[gapless setState:metadata.gapless];
|
||||
|
||||
metadata.podcast = newTags.podcast;
|
||||
[podcast setState:metadata.podcast];
|
||||
|
||||
metadata.contentRating = newTags.contentRating;
|
||||
[contentRating selectItemWithTag:metadata.contentRating];
|
||||
|
||||
[self add:tagDict];
|
||||
}
|
||||
|
||||
- (void) updateSetsMenu: (id)sender
|
||||
{
|
||||
SBPresetManager *presetManager = [SBPresetManager sharedManager];
|
||||
NSMenu * setListMenu = [setList menu];
|
||||
|
||||
while ([setListMenu numberOfItems] > 1)
|
||||
[setListMenu removeItemAtIndex: 1];
|
||||
|
||||
NSMenuItem *newItem = [[[NSMenuItem alloc] initWithTitle:@"Save Set" action:@selector(showSaveSet:) keyEquivalent:@""] autorelease];
|
||||
[newItem setTarget:self];
|
||||
[setListMenu addItem:newItem];
|
||||
|
||||
[setListMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
newItem = [[[NSMenuItem alloc] initWithTitle:@"All" action:@selector(addMetadataSet:) keyEquivalent:@""] autorelease];
|
||||
[newItem setTarget:self];
|
||||
[newItem setTag: 0];
|
||||
[setListMenu addItem:newItem];
|
||||
|
||||
newItem = [[[NSMenuItem alloc] initWithTitle:@"Movie" action:@selector(addMetadataSet:) keyEquivalent:@""] autorelease];
|
||||
[newItem setTarget:self];
|
||||
[newItem setTag: 1];
|
||||
[setListMenu addItem:newItem];
|
||||
|
||||
newItem = [[[NSMenuItem alloc] initWithTitle:@"TV Show" action:@selector(addMetadataSet:) keyEquivalent:@""] autorelease];
|
||||
[newItem setTarget:self];
|
||||
[newItem setTag: 2];
|
||||
[setListMenu addItem:newItem];
|
||||
|
||||
if ([[presetManager presets] count])
|
||||
[setListMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
NSUInteger i = 0;
|
||||
|
||||
for (MP42Metadata *set in [presetManager presets]) {
|
||||
newItem = [[NSMenuItem alloc] initWithTitle:[set presetName] action:@selector(applySet:) keyEquivalent:@""];
|
||||
if (i < 9)
|
||||
[newItem setKeyEquivalent:[NSString stringWithFormat:@"%lu", (unsigned long)i+1]];
|
||||
|
||||
[newItem setTarget:self];
|
||||
[newItem setTag:i++];
|
||||
|
||||
[setListMenu addItem:newItem];
|
||||
[newItem release];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction) showSaveSet: (id)sender
|
||||
{
|
||||
[NSApp beginSheet:saveWindow modalForWindow:[[self view]window]
|
||||
modalDelegate:nil didEndSelector:NULL contextInfo:nil];
|
||||
}
|
||||
|
||||
- (IBAction) saveSet: (id) sender
|
||||
{
|
||||
SBPresetManager *presetManager = [SBPresetManager sharedManager];
|
||||
|
||||
[metadata setPresetName:[presetName stringValue]];
|
||||
[presetManager newSetFromExistingMetadata: metadata];
|
||||
|
||||
[NSApp endSheet: saveWindow];
|
||||
[saveWindow orderOut:self];
|
||||
}
|
||||
|
||||
- (IBAction) closeSaveSheet: (id) sender
|
||||
{
|
||||
[NSApp endSheet: saveWindow];
|
||||
[saveWindow orderOut:self];
|
||||
}
|
||||
|
||||
/* NSTableView additions for copy & paste and more */
|
||||
|
||||
- (IBAction)doubleClickAction:(id)sender
|
||||
{
|
||||
// make sure they clicked a real cell and not a header or empty row
|
||||
if ([sender clickedRow] != -1 && [sender clickedColumn] == 1) {
|
||||
// edit the cell
|
||||
[sender editColumn:[sender clickedColumn]
|
||||
row:[sender clickedRow]
|
||||
withEvent:nil
|
||||
select:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_deleteSelectionFromTableView:(NSTableView *)tableView;
|
||||
{
|
||||
[self removeTag:tableView];
|
||||
}
|
||||
|
||||
- (void)_copySelectionFromTableView:(NSTableView *)tableView;
|
||||
{
|
||||
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
||||
NSIndexSet *rowIndexes = [tableView selectedRowIndexes];
|
||||
NSUInteger current_index = [rowIndexes lastIndex];
|
||||
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
|
||||
NSString *string = @"";
|
||||
|
||||
while (current_index != NSNotFound) {
|
||||
NSString *tagName = [tagsArray objectAtIndex:current_index];
|
||||
NSString *tagValue = [tags objectForKey:tagName];
|
||||
string = [string stringByAppendingFormat:@"%@: %@\n",tagName, tagValue];
|
||||
[data setValue:tagValue forKey:tagName];
|
||||
|
||||
current_index = [rowIndexes indexLessThanIndex: current_index];
|
||||
}
|
||||
|
||||
NSArray *types = [NSArray arrayWithObjects:
|
||||
MetadataPBoardType, NSStringPboardType, nil];
|
||||
[pb declareTypes:types owner:nil];
|
||||
[pb setString:string forType: NSStringPboardType];
|
||||
[pb setData:[NSArchiver archivedDataWithRootObject:data] forType:MetadataPBoardType];
|
||||
[data release];
|
||||
}
|
||||
|
||||
- (void)_cutSelectionFromTableView:(NSTableView *)tableView;
|
||||
{
|
||||
[self _copySelectionFromTableView:tableView];
|
||||
[self removeTag:tableView];
|
||||
}
|
||||
|
||||
- (void)_pasteToTableView:(NSTableView *)tableView
|
||||
{
|
||||
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
||||
NSData *archivedData = [pb dataForType:MetadataPBoardType];
|
||||
NSMutableDictionary *data = [NSUnarchiver unarchiveObjectWithData:archivedData];
|
||||
|
||||
[self add:data];
|
||||
}
|
||||
|
||||
- (void)_pasteToImageBrowserView:(IKImageBrowserView *)ImageBrowserView
|
||||
{
|
||||
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
|
||||
|
||||
NSArray *classes = [NSArray arrayWithObjects:[NSURL class], [NSImage class], nil];
|
||||
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSImage imageTypes]
|
||||
forKey:NSPasteboardURLReadingContentsConformToTypesKey];
|
||||
NSArray *copiedItems = [pasteboard readObjectsForClasses:classes options:options];
|
||||
|
||||
if (copiedItems != nil) {
|
||||
for (id item in copiedItems)
|
||||
[self addArtwork:item];
|
||||
|
||||
metadata.isArtworkEdited = YES;
|
||||
metadata.isEdited = YES;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
[imageBrowser reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSAttributedString *) boldString: (NSString *) string
|
||||
{
|
||||
return [[[NSAttributedString alloc] initWithString:string attributes:detailBoldAttr] autorelease];
|
||||
}
|
||||
|
||||
/* TableView delegate methods */
|
||||
|
||||
- (NSInteger) numberOfRowsInTableView: (NSTableView *) t
|
||||
{
|
||||
return [[metadata tagsDict] count];
|
||||
}
|
||||
|
||||
- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
|
||||
{
|
||||
NSCell *cell = nil;
|
||||
NSString *tagName = nil;
|
||||
if (tableColumn != nil)
|
||||
tagName= [tagsArray objectAtIndex:row];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"name"]) {
|
||||
cell = [tableColumn dataCell];
|
||||
}
|
||||
else if ([tableColumn.identifier isEqualToString:@"value"]) {
|
||||
if ([tagName isEqualToString:@"Rating"]) {
|
||||
cell = ratingCell;
|
||||
}
|
||||
else if ([tagName isEqualToString:@"Genre"]) {
|
||||
cell = genreCell;
|
||||
}
|
||||
else
|
||||
cell = [tableColumn dataCell];
|
||||
}
|
||||
else
|
||||
cell = nil;
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (id) tableView:(NSTableView *)tableView
|
||||
objectValueForTableColumn:(NSTableColumn *)tableColumn
|
||||
row:(NSInteger)rowIndex
|
||||
{
|
||||
if ([tableColumn.identifier isEqualToString:@"name"])
|
||||
return [self boldString:[tagsArray objectAtIndex:rowIndex]];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"value"])
|
||||
return [tags objectForKey:[tagsArray objectAtIndex:rowIndex]];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) tableView: (NSTableView *) tableView
|
||||
setObjectValue: (id) anObject
|
||||
forTableColumn: (NSTableColumn *) tableColumn
|
||||
row: (NSInteger) rowIndex
|
||||
{
|
||||
NSString *tagName = [tagsArray objectAtIndex:rowIndex];
|
||||
[dct removeAllObjects];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"value"]) {
|
||||
[self updateMetadata:anObject forKey:tagName];
|
||||
}
|
||||
}
|
||||
|
||||
- (CGFloat) tableView: (NSTableView *) tableView
|
||||
heightOfRow: (NSInteger) rowIndex
|
||||
{
|
||||
NSString *key = [tagsArray objectAtIndex:rowIndex];
|
||||
CGFloat height;
|
||||
|
||||
if (!(height = [[dct objectForKey:key] floatValue])) {
|
||||
//calculate new row height
|
||||
NSRect r = NSMakeRect(0,0,width,1000.0);
|
||||
NSTextFieldCell *cell = [tabCol dataCellForRow:rowIndex];
|
||||
[cell setObjectValue:[tags objectForKey:[tagsArray objectAtIndex:rowIndex]]];
|
||||
height = [cell cellSizeForBounds:r].height; // Slow, but we cache it.
|
||||
[dct setObject:@(height) forKey:key];
|
||||
}
|
||||
|
||||
if (height < 14.0)
|
||||
return 14.0;
|
||||
else
|
||||
return height;
|
||||
}
|
||||
|
||||
- (NSString *) tableView: (NSTableView *) aTableView
|
||||
toolTipForCell: (NSCell *) aCell
|
||||
rect: (NSRectPointer) rect
|
||||
tableColumn: (NSTableColumn *) aTableColumn
|
||||
row: (NSInteger) row
|
||||
mouseLocation: (NSPoint) mouseLocation
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)tableViewColumnDidResize: (NSNotification* )notification
|
||||
{
|
||||
[dct removeAllObjects];
|
||||
width = [tabCol width];
|
||||
[tagsTableView noteHeightOfRowsWithIndexesChanged:
|
||||
[NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [tagsTableView numberOfRows])]];
|
||||
}
|
||||
|
||||
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
|
||||
{
|
||||
if ([tagsTableView selectedRow] != -1)
|
||||
[removeTag setEnabled:YES];
|
||||
else
|
||||
[removeTag setEnabled:NO];
|
||||
}
|
||||
|
||||
- (IBAction) changeMediaKind: (id) sender
|
||||
{
|
||||
uint8_t tagName = [[sender selectedItem] tag];
|
||||
|
||||
if (metadata.mediaKind != tagName) {
|
||||
metadata.mediaKind = tagName;
|
||||
metadata.isEdited = YES;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction) changecContentRating: (id) sender
|
||||
{
|
||||
uint8_t tagName = [[sender selectedItem] tag];
|
||||
|
||||
if (metadata.contentRating != tagName) {
|
||||
metadata.contentRating = tagName;
|
||||
metadata.isEdited = YES;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction) changeGapless: (id) sender
|
||||
{
|
||||
uint8_t newValue;
|
||||
if (sender == gapless)
|
||||
newValue = [gapless state];
|
||||
else {
|
||||
newValue = ![gapless state];
|
||||
[gapless setState:newValue];
|
||||
}
|
||||
|
||||
if (metadata.gapless != newValue) {
|
||||
metadata.gapless = newValue;
|
||||
metadata.isEdited = YES;
|
||||
}
|
||||
|
||||
NSUndoManager *undo = [[self view] undoManager];
|
||||
[[undo prepareWithInvocationTarget:self] changeGapless: self];
|
||||
|
||||
if (![undo isUndoing]) {
|
||||
[undo setActionName:@"Check Gapless"];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction) changePodcast: (id) sender
|
||||
{
|
||||
uint8_t newValue;
|
||||
if (sender == podcast)
|
||||
newValue = [podcast state];
|
||||
else {
|
||||
newValue = ![podcast state];
|
||||
[podcast setState:newValue];
|
||||
}
|
||||
|
||||
if (metadata.podcast != newValue) {
|
||||
metadata.podcast = newValue;
|
||||
metadata.isEdited = YES;
|
||||
}
|
||||
|
||||
NSUndoManager *undo = [[self view] undoManager];
|
||||
[[undo prepareWithInvocationTarget:self] changePodcast: self];
|
||||
|
||||
if (![undo isUndoing]) {
|
||||
[undo setActionName:@"Check Podast"];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction) changehdVideo: (id) sender
|
||||
{
|
||||
uint8_t tagName = [[sender selectedItem] tag];
|
||||
|
||||
if (metadata.hdVideo != tagName) {
|
||||
metadata.hdVideo = tagName;
|
||||
metadata.isEdited = YES;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark IKImageBrowserDataSource
|
||||
|
||||
- (NSUInteger)numberOfItemsInImageBrowser:(IKImageBrowserView *) aBrowser
|
||||
{
|
||||
return [metadata.artworks count];
|
||||
}
|
||||
|
||||
- (id)imageBrowser:(IKImageBrowserView *) aBrowser itemAtIndex:(NSUInteger)index
|
||||
{
|
||||
return [metadata.artworks objectAtIndex:index];
|
||||
}
|
||||
|
||||
- (BOOL)imageBrowser:(IKImageBrowserView *) aBrowser moveItemsAtIndexes: (NSIndexSet *)indexes toIndex:(NSUInteger)destinationIndex
|
||||
{
|
||||
destinationIndex -= [indexes countOfIndexesInRange:NSMakeRange(0, destinationIndex)];;
|
||||
|
||||
NSArray *objects = [metadata.artworks objectsAtIndexes:indexes];
|
||||
[metadata.artworks removeObjectsAtIndexes:indexes];
|
||||
|
||||
for (id object in [objects reverseObjectEnumerator])
|
||||
[metadata.artworks insertObject:object atIndex:destinationIndex];
|
||||
|
||||
metadata.isEdited = YES;
|
||||
metadata.isArtworkEdited = YES;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSUInteger)imageBrowser:(IKImageBrowserView *) aBrowser writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard:(NSPasteboard *)pasteboard
|
||||
{
|
||||
NSInteger index;
|
||||
[pasteboard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil];
|
||||
|
||||
for (index = [itemIndexes lastIndex]; index != NSNotFound; index = [itemIndexes indexLessThanIndex:index]) {
|
||||
NSArray *representations = [[[metadata.artworks objectAtIndex:index] image] representations];
|
||||
NSData *bitmapData = [NSBitmapImageRep representationOfImageRepsInArray:representations
|
||||
usingType:NSTIFFFileType properties:nil];
|
||||
|
||||
[pasteboard setData:bitmapData forType:NSTIFFPboardType];
|
||||
}
|
||||
|
||||
return [itemIndexes count];
|
||||
}
|
||||
|
||||
- (void)imageBrowser:(IKImageBrowserView *) aBrowser removeItemsAtIndexes:(NSIndexSet *) indexes
|
||||
{
|
||||
[metadata.artworks removeObjectsAtIndexes:indexes];
|
||||
|
||||
metadata.isEdited = YES;
|
||||
metadata.isArtworkEdited = YES;
|
||||
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark IKImageBrowserDelegate
|
||||
|
||||
- (void)imageBrowser:(IKImageBrowserView *) aBrowser cellWasDoubleClickedAtIndex:(NSUInteger) index
|
||||
{
|
||||
}
|
||||
|
||||
- (void)imageBrowserSelectionDidChange:(IKImageBrowserView *) aBrowser
|
||||
{
|
||||
NSIndexSet *rowIndexes = [aBrowser selectionIndexes];
|
||||
|
||||
if ([rowIndexes count])
|
||||
[removeArtwork setEnabled:YES];
|
||||
else
|
||||
[removeArtwork setEnabled:NO];
|
||||
}
|
||||
|
||||
- (IBAction) zoomSliderDidChange:(id)sender {
|
||||
[imageBrowser setZoomValue:[sender floatValue]];
|
||||
[imageBrowser setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
- (IBAction) removeArtwork:(id) sender {
|
||||
NSIndexSet *rowIndexes = [imageBrowser selectionIndexes];
|
||||
|
||||
metadata.isEdited = YES;
|
||||
metadata.isArtworkEdited = YES;
|
||||
|
||||
[metadata.artworks removeObjectsAtIndexes: rowIndexes];
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
|
||||
[imageBrowser reloadData];
|
||||
}
|
||||
|
||||
- (BOOL)addArtwork:(id)item
|
||||
{
|
||||
NSString *type;
|
||||
NSError *error;
|
||||
|
||||
if ([item isKindOfClass:[NSURL class]]) {
|
||||
if ([item getResourceValue:&type forKey:NSURLTypeIdentifierKey error:&error]) {
|
||||
if (UTTypeConformsTo((CFStringRef)type, (CFStringRef)@"public.jpeg")) {
|
||||
MP42Image *artwork = [[MP42Image alloc] initWithData:[NSData dataWithContentsOfURL:item] type:MP42_ART_JPEG];
|
||||
[metadata.artworks addObject:artwork];
|
||||
[artwork release];
|
||||
}
|
||||
else {
|
||||
NSImage * artworkImage = [[NSImage alloc] initWithContentsOfURL:item];
|
||||
MP42Image *artwork = [[MP42Image alloc] initWithImage:artworkImage];
|
||||
[metadata.artworks addObject:artwork];
|
||||
|
||||
[artwork release];
|
||||
[artworkImage release];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
else if ([item isKindOfClass:[NSImage class]]) {
|
||||
MP42Image *artwork = [[MP42Image alloc] initWithImage:item];
|
||||
[metadata.artworks addObject:artwork];
|
||||
[artwork release];
|
||||
return YES;
|
||||
}
|
||||
else if ([item isKindOfClass:[MP42Image class]]) {
|
||||
[metadata.artworks addObject:item];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (IBAction)selectArtwork:(id)sender
|
||||
{
|
||||
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
||||
panel.allowsMultipleSelection = YES;
|
||||
panel.canChooseFiles = YES;
|
||||
panel.canChooseDirectories = NO;
|
||||
[panel setAllowedFileTypes:[NSArray arrayWithObject:@"public.image"]];
|
||||
|
||||
[panel beginSheetModalForWindow: [[self view] window] completionHandler:^(NSInteger result) {
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
|
||||
for (NSURL *url in [panel URLs])
|
||||
[self addArtwork:url];
|
||||
|
||||
metadata.isArtworkEdited = YES;
|
||||
metadata.isEdited = YES;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
[imageBrowser reloadData];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender
|
||||
{
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender
|
||||
{
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
- (BOOL)performDragOperation:(id)sender
|
||||
{
|
||||
BOOL edited = NO;
|
||||
NSPasteboard *pasteboard = [sender draggingPasteboard];
|
||||
|
||||
NSArray *classes = [NSArray arrayWithObjects:[NSURL class], [NSImage class], nil];
|
||||
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSImage imageTypes]
|
||||
forKey:NSPasteboardURLReadingContentsConformToTypesKey];
|
||||
NSArray *draggedItems = [pasteboard readObjectsForClasses:classes options:options];
|
||||
|
||||
if (draggedItems) {
|
||||
for (id dragItem in draggedItems)
|
||||
edited = [self addArtwork:dragItem];
|
||||
|
||||
if (edited) {
|
||||
metadata.isArtworkEdited = YES;
|
||||
metadata.isEdited = YES;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
[imageBrowser reloadData];
|
||||
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)concludeDragOperation:(id < NSDraggingInfo >)sender
|
||||
{
|
||||
[imageBrowser reloadData];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
|
||||
[imageBrowser setDataSource:nil];
|
||||
[imageBrowser setDelegate:nil];
|
||||
[tagsTableView setDataSource:nil];
|
||||
[tagsTableView setDelegate:nil];
|
||||
|
||||
[tagsArray release];
|
||||
[tagsMenu release];
|
||||
[tabCol release];
|
||||
[detailBoldAttr release];
|
||||
[ratingCell release];
|
||||
[genreCell release];
|
||||
[dct release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// PropertyViewController.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 06/02/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class MP42AudioTrack;
|
||||
@class MP42File;
|
||||
|
||||
@interface SBSoundViewController : NSViewController {
|
||||
MP42AudioTrack *track;
|
||||
MP42File *mp4file;
|
||||
|
||||
NSMutableArray *_fallbacks;
|
||||
NSMutableArray *_follows;
|
||||
|
||||
IBOutlet NSSlider *volume;
|
||||
IBOutlet NSPopUpButton *alternateGroup;
|
||||
IBOutlet NSPopUpButton *fallback;
|
||||
IBOutlet NSPopUpButton *follows;
|
||||
}
|
||||
|
||||
- (void)setTrack:(MP42AudioTrack *)soundTrack;
|
||||
- (void)setFile:(MP42File *)mp4;
|
||||
|
||||
- (IBAction)setTrackVolume:(id)sender;
|
||||
- (IBAction)setAltenateGroup:(id)sender;
|
||||
- (IBAction)setFallbackTrack:(id)sender;
|
||||
- (IBAction)setFollowsTrack:(id)sender;
|
||||
|
||||
@end
|
||||
Executable
+149
@@ -0,0 +1,149 @@
|
||||
//
|
||||
// PropertyViewController.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 06/02/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBSoundViewController.h"
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
|
||||
@implementation SBSoundViewController
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[alternateGroup selectItemAtIndex:track.alternate_group];
|
||||
|
||||
_fallbacks = [[NSMutableArray alloc] init];
|
||||
|
||||
if ([[track format] isEqualToString:MP42AudioFormatAC3]) {
|
||||
NSInteger i = 1;
|
||||
NSInteger selectedItem = 0;
|
||||
|
||||
for (MP42AudioTrack *fileTrack in [mp4file tracksWithMediaType:MP42MediaTypeAudio]) {
|
||||
if ([[fileTrack format] isEqualToString:MP42AudioFormatAAC]) {
|
||||
NSMenuItem *newItem = [[[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%@ - %@ - %@",
|
||||
fileTrack.Id ? [NSString stringWithFormat:@"%d", fileTrack.Id] : @"na",
|
||||
fileTrack.name,
|
||||
fileTrack.language]
|
||||
action:@selector(setFallbackTrack:)
|
||||
keyEquivalent:@""] autorelease];
|
||||
[newItem setTarget:self];
|
||||
[newItem setTag:i];
|
||||
[[fallback menu] addItem:newItem];
|
||||
[_fallbacks addObject:fileTrack];
|
||||
|
||||
if (track.fallbackTrack == fileTrack)
|
||||
selectedItem = i;
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
[fallback selectItemWithTag:selectedItem];
|
||||
}
|
||||
else {
|
||||
[fallback setEnabled:NO];
|
||||
}
|
||||
|
||||
_follows = [[NSMutableArray alloc] init];
|
||||
|
||||
NSInteger i = 1;
|
||||
NSInteger selectedItem = 0;
|
||||
|
||||
for (MP42SubtitleTrack *fileTrack in [mp4file tracksWithMediaType:MP42MediaTypeSubtitle]) {
|
||||
NSMenuItem *newItem = [[[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%@ - %@ - %@",
|
||||
fileTrack.Id ? [NSString stringWithFormat:@"%d", fileTrack.Id] : @"na",
|
||||
fileTrack.name,
|
||||
fileTrack.language]
|
||||
action:@selector(setFollowsTrack:)
|
||||
keyEquivalent:@""] autorelease];
|
||||
[newItem setTarget:self];
|
||||
[newItem setTag:i];
|
||||
[[follows menu] addItem:newItem];
|
||||
[_follows addObject:fileTrack];
|
||||
|
||||
if (track.followsTrack == fileTrack)
|
||||
selectedItem = i;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
[follows selectItemWithTag:selectedItem];
|
||||
|
||||
[volume setFloatValue:track.volume * 100];
|
||||
}
|
||||
|
||||
- (void)setFile:(MP42File *)mp4
|
||||
{
|
||||
mp4file = mp4;
|
||||
}
|
||||
|
||||
- (void)setTrack:(MP42AudioTrack *)soundTrack
|
||||
{
|
||||
track = soundTrack;
|
||||
}
|
||||
|
||||
- (IBAction)setTrackVolume:(id)sender
|
||||
{
|
||||
float value = [sender doubleValue] / 100;
|
||||
if (track.volume != value) {
|
||||
track.volume = value;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)setFallbackTrack:(id)sender
|
||||
{
|
||||
NSInteger index = [sender tag];
|
||||
|
||||
if (index) {
|
||||
MP42AudioTrack *audioTrack = [_fallbacks objectAtIndex:index-1];
|
||||
|
||||
if (audioTrack != track.fallbackTrack) {
|
||||
track.fallbackTrack = audioTrack;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
else {
|
||||
track.fallbackTrack = nil;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)setFollowsTrack:(id)sender
|
||||
{
|
||||
NSInteger index = [sender tag];
|
||||
|
||||
if (index) {
|
||||
MP42SubtitleTrack *subTrack = [_follows objectAtIndex:index-1];
|
||||
|
||||
if (subTrack != track.followsTrack) {
|
||||
track.followsTrack = subTrack;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
} }
|
||||
else {
|
||||
track.followsTrack = nil;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)setAltenateGroup:(id)sender
|
||||
{
|
||||
uint8_t tagName = [[sender selectedItem] tag];
|
||||
|
||||
if (track.alternate_group != tagName) {
|
||||
track.alternate_group = tagName;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_fallbacks release];
|
||||
[_follows release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// PropertyViewController.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 06/02/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class MP42File;
|
||||
@class MP42VideoTrack;
|
||||
@class MP42SubtitleTrack;
|
||||
|
||||
@interface SBVideoViewController : NSViewController {
|
||||
MP42VideoTrack *track;
|
||||
MP42File *mp4file;
|
||||
|
||||
IBOutlet NSTextField *sampleWidth;
|
||||
IBOutlet NSTextField *sampleHeight;
|
||||
|
||||
IBOutlet NSTextField *trackWidth;
|
||||
IBOutlet NSTextField *trackHeight;
|
||||
|
||||
IBOutlet NSTextField *hSpacing;
|
||||
IBOutlet NSTextField *vSpacing;
|
||||
|
||||
IBOutlet NSTextField *offsetX;
|
||||
IBOutlet NSTextField *offsetY;
|
||||
|
||||
IBOutlet NSPopUpButton *alternateGroup;
|
||||
|
||||
IBOutlet NSPopUpButton *videoProfile;
|
||||
IBOutlet NSTextField *videoProfileLabel;
|
||||
IBOutlet NSTextField *videoProfileDescription;
|
||||
|
||||
IBOutlet NSPopUpButton *forcedSubs;
|
||||
IBOutlet NSTextField *forcedSubsLabel;
|
||||
|
||||
IBOutlet NSPopUpButton *forced;
|
||||
IBOutlet NSTextField *forcedLabel;
|
||||
|
||||
IBOutlet NSButton *preserveAspectRatio;
|
||||
|
||||
IBOutlet NSMenuItem *profileLevelUnchanged;
|
||||
|
||||
NSMutableArray *_forced;
|
||||
}
|
||||
|
||||
- (void)setTrack:(MP42VideoTrack *)videoTrack;
|
||||
- (void)setFile:(MP42File *)mp4;
|
||||
|
||||
- (IBAction)setSize:(id)sender;
|
||||
- (IBAction)setPixelAspect:(id)sender;
|
||||
- (IBAction)setAltenateGroup:(id)sender;
|
||||
|
||||
- (IBAction)setProfileLevel:(id)sender;
|
||||
|
||||
- (IBAction)setForcedSubtitles:(id)sender;
|
||||
- (IBAction)setForcedTrack:(id)sender;
|
||||
|
||||
@end
|
||||
Executable
+320
@@ -0,0 +1,320 @@
|
||||
//
|
||||
// PropertyViewController.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 06/02/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBVideoViewController.h"
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
|
||||
@implementation SBVideoViewController
|
||||
|
||||
static NSString *getProfileName(uint8_t profile) {
|
||||
switch (profile) {
|
||||
case 66:
|
||||
return @"Baseline";
|
||||
case 77:
|
||||
return @"Main";
|
||||
case 88:
|
||||
return @"Extended";
|
||||
case 100:
|
||||
return @"High";
|
||||
case 110:
|
||||
return @"High 10";
|
||||
case 122:
|
||||
return @"High 4:2:2";
|
||||
case 144:
|
||||
return @"High 4:4:4";
|
||||
default:
|
||||
return @"Unknown profile";
|
||||
}
|
||||
}
|
||||
|
||||
static NSString *getLevelName(uint8_t level) {
|
||||
switch (level) {
|
||||
case 10:
|
||||
case 20:
|
||||
case 30:
|
||||
case 40:
|
||||
case 50:
|
||||
return [NSString stringWithFormat:@"%u", level/10];
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 21:
|
||||
case 22:
|
||||
case 31:
|
||||
case 32:
|
||||
case 41:
|
||||
case 42:
|
||||
case 51:
|
||||
return [NSString stringWithFormat:@"%u.%u", level/10, level % 10];
|
||||
default:
|
||||
return [NSString stringWithFormat:@"unknown level %x", level];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[sampleWidth setStringValue: [NSString stringWithFormat:@"%lld", track.width]];
|
||||
[sampleHeight setStringValue: [NSString stringWithFormat:@"%lld", track.height]];
|
||||
|
||||
[trackWidth setStringValue: [NSString stringWithFormat:@"%d", (uint16_t)track.trackWidth]];
|
||||
[trackHeight setStringValue: [NSString stringWithFormat:@"%d", (uint16_t)track.trackHeight]];
|
||||
|
||||
[hSpacing setStringValue: [NSString stringWithFormat:@"%lld", track.hSpacing]];
|
||||
[vSpacing setStringValue: [NSString stringWithFormat:@"%lld", track.vSpacing]];
|
||||
|
||||
[offsetX setStringValue: [NSString stringWithFormat:@"%d", track.offsetX]];
|
||||
[offsetY setStringValue: [NSString stringWithFormat:@"%d", track.offsetY]];
|
||||
|
||||
[alternateGroup selectItemAtIndex:track.alternate_group];
|
||||
|
||||
if ([track.format isEqualToString:MP42VideoFormatH264] && track.origProfile && track.origLevel) {
|
||||
[profileLevelUnchanged setTitle:[NSString stringWithFormat:@"Current profile: %@ @ %@",
|
||||
getProfileName(track.origProfile), getLevelName(track.origLevel)]];
|
||||
if ((track.origProfile == track.newProfile) && (track.origLevel == track.newLevel)) {
|
||||
[videoProfile selectItemWithTag:1];
|
||||
} else {
|
||||
if ((track.newProfile == 66) && (track.newLevel == 21)) {
|
||||
[videoProfile selectItemWithTag:6621];
|
||||
} else if ((track.newProfile == 77) && (track.newLevel == 31)) {
|
||||
[videoProfile selectItemWithTag:7731];
|
||||
} else if ((track.newProfile == 100) && (track.newLevel == 31)) {
|
||||
[videoProfile selectItemWithTag:10031];
|
||||
} else if ((track.newProfile == 100) && (track.newLevel == 41)) {
|
||||
[videoProfile selectItemWithTag:10041];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
[videoProfile setEnabled:NO];
|
||||
[videoProfile setHidden:YES];
|
||||
[videoProfileLabel setHidden:YES];
|
||||
[videoProfileDescription setHidden:YES];
|
||||
}
|
||||
|
||||
if ([track isKindOfClass:[MP42SubtitleTrack class]]) {
|
||||
[forcedSubs setEnabled:YES];
|
||||
[forcedSubs setHidden:NO];
|
||||
[forcedSubsLabel setHidden:NO];
|
||||
|
||||
[forced setHidden:NO];
|
||||
[forcedLabel setHidden:NO];
|
||||
|
||||
MP42SubtitleTrack * subTrack = (MP42SubtitleTrack*)track;
|
||||
|
||||
if (!subTrack.someSamplesAreForced && !subTrack.allSamplesAreForced) {
|
||||
[forcedSubs selectItemWithTag:0];
|
||||
} else if (subTrack.someSamplesAreForced && !subTrack.allSamplesAreForced) {
|
||||
[forcedSubs selectItemWithTag:1];
|
||||
} else if (subTrack.allSamplesAreForced) {
|
||||
[forcedSubs selectItemWithTag:2];
|
||||
}
|
||||
|
||||
_forced = [[NSMutableArray alloc] init];
|
||||
|
||||
NSInteger i = 1;
|
||||
NSInteger selectedItem = 0;
|
||||
for (MP42SubtitleTrack *fileTrack in [mp4file tracksWithMediaType:MP42MediaTypeSubtitle]) {
|
||||
NSMenuItem *newItem = [[[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%@ - %@ - %@",
|
||||
fileTrack.Id ? [NSString stringWithFormat:@"%d", fileTrack.Id] : @"NA",
|
||||
fileTrack.name,
|
||||
fileTrack.language]
|
||||
action:@selector(setForcedTrack:)
|
||||
keyEquivalent:@""] autorelease];
|
||||
[newItem setTarget:self];
|
||||
[newItem setTag:i];
|
||||
[[forced menu] addItem:newItem];
|
||||
[_forced addObject:fileTrack];
|
||||
|
||||
if (((MP42SubtitleTrack *)track).forcedTrack == fileTrack)
|
||||
selectedItem = i;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
[forced selectItemWithTag:selectedItem];
|
||||
}
|
||||
else {
|
||||
[forcedSubs setEnabled:NO];
|
||||
[forcedSubs setHidden:YES];
|
||||
[forcedSubsLabel setHidden:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTrack:(MP42VideoTrack *)videoTrack
|
||||
{
|
||||
track = videoTrack;
|
||||
}
|
||||
|
||||
- (void)setFile:(MP42File *)mp4
|
||||
{
|
||||
mp4file = mp4;
|
||||
}
|
||||
|
||||
- (IBAction)setSize:(id)sender
|
||||
{
|
||||
NSInteger i;
|
||||
|
||||
if (sender == trackWidth) {
|
||||
i = [trackWidth integerValue];
|
||||
if (track.trackWidth != i) {
|
||||
if ([preserveAspectRatio state] == NSOnState) {
|
||||
track.trackHeight = (track.trackHeight / track.trackWidth) * i;
|
||||
[trackHeight setIntegerValue:track.trackHeight];
|
||||
}
|
||||
track.trackWidth = i;
|
||||
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
track.isEdited = YES;
|
||||
}
|
||||
}
|
||||
else if (sender == trackHeight) {
|
||||
i = [trackHeight integerValue];
|
||||
if (track.trackHeight != i) {
|
||||
track.trackHeight = i;
|
||||
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
track.isEdited = YES;
|
||||
}
|
||||
}
|
||||
else if (sender == offsetX) {
|
||||
i = [offsetX integerValue];
|
||||
if (track.offsetX != i) {
|
||||
track.offsetX = i;
|
||||
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
track.isEdited = YES;
|
||||
}
|
||||
}
|
||||
else if (sender == offsetY) {
|
||||
i = [offsetY integerValue];
|
||||
if (track.offsetY != i) {
|
||||
track.offsetY = i;
|
||||
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
track.isEdited = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)setPixelAspect:(id)sender
|
||||
{
|
||||
NSInteger i;
|
||||
|
||||
if (sender == hSpacing) {
|
||||
i = [hSpacing integerValue];
|
||||
if (track.hSpacing != i) {
|
||||
track.hSpacing = i;
|
||||
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
track.isEdited = YES;
|
||||
}
|
||||
}
|
||||
else if (sender == vSpacing) {
|
||||
i = [vSpacing integerValue];
|
||||
if (track.vSpacing != i) {
|
||||
track.vSpacing = i;
|
||||
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
track.isEdited = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (IBAction)setAltenateGroup:(id)sender
|
||||
{
|
||||
uint8_t tagName = [[sender selectedItem] tag];
|
||||
|
||||
if (track.alternate_group != tagName) {
|
||||
track.alternate_group = tagName;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)setProfileLevel:(id)sender
|
||||
{
|
||||
NSInteger tagName = [[sender selectedItem] tag];
|
||||
switch (tagName) {
|
||||
case 1:
|
||||
track.newProfile = track.origProfile;
|
||||
track.newLevel = track.origLevel;
|
||||
return;
|
||||
case 6621:
|
||||
track.newProfile = 66;
|
||||
track.newLevel = 21;
|
||||
break;
|
||||
case 7731:
|
||||
track.newProfile = 77;
|
||||
track.newLevel = 31;
|
||||
break;
|
||||
case 10031:
|
||||
track.newProfile = 100;
|
||||
track.newLevel = 31;
|
||||
break;
|
||||
case 10041:
|
||||
track.newProfile = 100;
|
||||
track.newLevel = 41;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
|
||||
- (IBAction)setForcedSubtitles:(id)sender
|
||||
{
|
||||
if ([track isKindOfClass:[MP42SubtitleTrack class]]) {
|
||||
MP42SubtitleTrack *subTrack = (MP42SubtitleTrack *)track;
|
||||
NSInteger tagName = [[sender selectedItem] tag];
|
||||
|
||||
switch (tagName) {
|
||||
case 0:
|
||||
subTrack.someSamplesAreForced = NO;
|
||||
subTrack.allSamplesAreForced = NO;
|
||||
break;
|
||||
case 1:
|
||||
subTrack.someSamplesAreForced = YES;
|
||||
subTrack.allSamplesAreForced = NO;
|
||||
break;
|
||||
case 2:
|
||||
subTrack.someSamplesAreForced = YES;
|
||||
subTrack.allSamplesAreForced = YES;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)setForcedTrack:(id)sender
|
||||
{
|
||||
NSInteger index = [sender tag];
|
||||
|
||||
if (index) {
|
||||
MP42SubtitleTrack *subTrack = [_forced objectAtIndex:index-1];
|
||||
|
||||
if (subTrack != ((MP42SubtitleTrack *)track).forcedTrack) {
|
||||
((MP42SubtitleTrack *)track).forcedTrack = subTrack;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
else {
|
||||
((MP42SubtitleTrack *)track).forcedTrack = nil;
|
||||
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_forced release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// SBAppDelegate.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 29/01/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class SBPrefsController;
|
||||
@class MP42File;
|
||||
|
||||
@interface SBDocumentController : NSDocumentController
|
||||
|
||||
@end
|
||||
|
||||
@interface SBAppDelegate : NSObject {
|
||||
SBPrefsController *prefController;
|
||||
SBDocumentController *documentController;
|
||||
}
|
||||
|
||||
- (IBAction) showBatchWindow: (id) sender;
|
||||
- (IBAction) showPrefsWindow: (id) sender;
|
||||
- (IBAction) donate:(id)sender;
|
||||
- (IBAction) help:(id)sender;
|
||||
|
||||
- (IBAction) linkDonate: (id) sender;
|
||||
|
||||
@end
|
||||
|
||||
Executable
+172
@@ -0,0 +1,172 @@
|
||||
//
|
||||
// SBAppDelegate.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 29/01/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBAppDelegate.h"
|
||||
#import "SBDocument.h"
|
||||
#import "SBPresetManager.h"
|
||||
#import "SBQueueController.h"
|
||||
#import "SBPrefsController.h"
|
||||
|
||||
#define DONATE_NAG_TIME (60 * 60 * 24 * 7)
|
||||
|
||||
@implementation SBAppDelegate
|
||||
|
||||
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
|
||||
{
|
||||
documentController = [[SBDocumentController alloc] init];
|
||||
|
||||
[SBPrefsController registerUserDefaults];
|
||||
|
||||
if ([[NSUserDefaults standardUserDefaults] valueForKey:@"SBShowQueueWindow"])
|
||||
[[SBQueueController sharedManager] showWindow:self];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)notification {
|
||||
SBPresetManager *presetManager = [SBPresetManager sharedManager];
|
||||
[presetManager savePresets];
|
||||
|
||||
if ([[[SBQueueController sharedManager] window] isVisible])
|
||||
[[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"SBShowQueueWindow"];
|
||||
else
|
||||
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:@"SBShowQueueWindow"];
|
||||
|
||||
if (![[SBQueueController sharedManager] saveQueueToDisk])
|
||||
if ([[NSUserDefaults standardUserDefaults] valueForKey:@"Debug"])
|
||||
NSLog(@"Failed to save queue to disk!");
|
||||
}
|
||||
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app
|
||||
{
|
||||
SBQueueStatus status= [[SBQueueController sharedManager] status];
|
||||
NSInteger result;
|
||||
if (status == SBQueueStatusWorking) {
|
||||
result = NSRunCriticalAlertPanel(
|
||||
NSLocalizedString(@"Are you sure you want to quit Subler?", nil),
|
||||
NSLocalizedString(@"Your current queue will be lost. Do you want to quit anyway?", nil),
|
||||
NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil);
|
||||
|
||||
if (result == NSAlertDefaultReturn)
|
||||
return NSTerminateNow;
|
||||
else
|
||||
return NSTerminateCancel;
|
||||
}
|
||||
|
||||
return NSTerminateNow;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
||||
{
|
||||
BOOL firstLaunch = YES;
|
||||
|
||||
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FirstLaunch"])
|
||||
firstLaunch = NO;
|
||||
|
||||
if (![[NSUserDefaults standardUserDefaults] valueForKey:@"WarningDonate"]) {
|
||||
NSDate * lastDonateDate = [[NSUserDefaults standardUserDefaults] valueForKey:@"DonateAskDate"];
|
||||
const BOOL timePassed = !lastDonateDate || (-1 * [lastDonateDate timeIntervalSinceNow]) >= DONATE_NAG_TIME;
|
||||
|
||||
if (!firstLaunch && timePassed) {
|
||||
[[NSUserDefaults standardUserDefaults] setValue:[NSDate date] forKey:@"DonateAskDate"];
|
||||
|
||||
NSAlert * alert = [[NSAlert alloc] init];
|
||||
[alert setMessageText: NSLocalizedString(@"Support Subler", "Donation -> title")];
|
||||
|
||||
NSString * donateMessage = [NSString stringWithFormat: @"%@",
|
||||
NSLocalizedString(@" A lot of time and effort have gone into development, coding, and refinement."
|
||||
" If you enjoy using it, please consider showing your appreciation with a donation.", "Donation -> message")];
|
||||
|
||||
[alert setInformativeText:donateMessage];
|
||||
[alert setAlertStyle: NSInformationalAlertStyle];
|
||||
|
||||
[alert addButtonWithTitle: NSLocalizedString(@"Donate", "Donation -> button")];
|
||||
NSButton * noDonateButton = [alert addButtonWithTitle: NSLocalizedString(@"Nope", "Donation -> button")];
|
||||
[noDonateButton setKeyEquivalent:@"\e"]; //escape key
|
||||
|
||||
const BOOL allowNeverAgain = lastDonateDate != nil; //hide the "don't show again" check the first time - give them time to try the app
|
||||
[alert setShowsSuppressionButton:allowNeverAgain];
|
||||
if (allowNeverAgain)
|
||||
[[alert suppressionButton] setTitle:NSLocalizedString(@"Don't ask me about this ever again.", "Donation -> button")];
|
||||
|
||||
const NSInteger donateResult = [alert runModal];
|
||||
if (donateResult == NSAlertFirstButtonReturn)
|
||||
[self linkDonate:self];
|
||||
|
||||
if (allowNeverAgain)
|
||||
[[NSUserDefaults standardUserDefaults] setBool:([[alert suppressionButton] state] != NSOnState) forKey:@"WarningDonate"];
|
||||
|
||||
[alert release];
|
||||
}
|
||||
}
|
||||
|
||||
if (firstLaunch)
|
||||
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FirstLaunch"];
|
||||
|
||||
[SBQueueController sharedManager];
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (IBAction) showBatchWindow: (id) sender
|
||||
{
|
||||
[[SBQueueController sharedManager] showWindow:self];
|
||||
}
|
||||
|
||||
- (IBAction) showPrefsWindow: (id) sender
|
||||
{
|
||||
if (!prefController) {
|
||||
prefController = [[SBPrefsController alloc] init];
|
||||
}
|
||||
[prefController showWindow:self];
|
||||
}
|
||||
|
||||
- (IBAction) donate:(id)sender
|
||||
{
|
||||
[self linkDonate:sender];
|
||||
}
|
||||
|
||||
- (IBAction) help:(id)sender
|
||||
{
|
||||
[[NSWorkspace sharedWorkspace] openURL: [NSURL
|
||||
URLWithString:@"http://code.google.com/p/subler/wiki/Documentation"]];
|
||||
}
|
||||
|
||||
- (IBAction) linkDonate:(id)sender
|
||||
{
|
||||
[[NSWorkspace sharedWorkspace] openURL: [NSURL
|
||||
URLWithString:@"https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YKZHVC6HG6AFQ&lc=GB&item_name=Subler¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBDocumentController
|
||||
|
||||
- (id) init
|
||||
{
|
||||
return [super init];
|
||||
}
|
||||
|
||||
- (id)openDocumentWithContentsOfURL:(NSURL *)absoluteURL display:(BOOL)displayDocument error:(NSError **)outError {
|
||||
SBDocument *doc = nil;
|
||||
|
||||
if ([[[absoluteURL path] pathExtension] caseInsensitiveCompare: @"mkv"] == NSOrderedSame ||
|
||||
[[[absoluteURL path] pathExtension] caseInsensitiveCompare: @"mka"] == NSOrderedSame ||
|
||||
[[[absoluteURL path] pathExtension] caseInsensitiveCompare: @"mks"] == NSOrderedSame ||
|
||||
[[[absoluteURL path] pathExtension] caseInsensitiveCompare: @"mov"] == NSOrderedSame) {
|
||||
doc = [self openUntitledDocumentAndDisplay:displayDocument error:outError];
|
||||
[doc performSelectorOnMainThread:@selector(showImportSheet:) withObject:[NSArray arrayWithObject:absoluteURL] waitUntilDone:NO];
|
||||
return doc;
|
||||
}
|
||||
else {
|
||||
return [super openDocumentWithContentsOfURL:absoluteURL display:displayDocument error:outError];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// ArtworkSelector.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2011/02/03.
|
||||
// Copyright 2011 Douglas Stebila. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Quartz/Quartz.h>
|
||||
|
||||
@protocol SBArtworkSelectorDelegate <NSObject>
|
||||
- (void)selectArtworkDone:(NSURL *)url;
|
||||
@end
|
||||
|
||||
@interface SBArtworkSelector : NSWindowController {
|
||||
id <SBArtworkSelectorDelegate> delegate;
|
||||
IBOutlet IKImageBrowserView *imageBrowser;
|
||||
IBOutlet NSSlider *slider;
|
||||
IBOutlet NSButton *addArtworkButton;
|
||||
IBOutlet NSButton *loadMoreArtworkButton;
|
||||
NSMutableArray *imageURLsUnloaded;
|
||||
NSMutableArray *images;
|
||||
NSArray *artworkProviderNames;
|
||||
}
|
||||
|
||||
#pragma mark Initialization
|
||||
- (instancetype)initWithDelegate:(id <SBArtworkSelectorDelegate>)del imageURLs:(NSArray *)imageURLs artworkProviderNames:(NSArray *)artworkProviderNames;
|
||||
|
||||
#pragma mark Load images
|
||||
- (IBAction) loadMoreArtwork:(id)sender;
|
||||
|
||||
#pragma mark User interface
|
||||
- (IBAction) zoomSliderDidChange:(id)sender;
|
||||
|
||||
#pragma mark Finishing up
|
||||
- (IBAction) addArtwork:(id)sender;
|
||||
- (IBAction) addNoArtwork:(id)sender;
|
||||
|
||||
@end
|
||||
Executable
+175
@@ -0,0 +1,175 @@
|
||||
//
|
||||
// ArtworkSelector.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2011/02/03.
|
||||
// Copyright 2011 Douglas Stebila. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBArtworkSelector.h"
|
||||
#import "MetadataImporter.h"
|
||||
#import <MP42Foundation/MP42Image.h>
|
||||
|
||||
#pragma mark IKImageBrowserItem data source objects
|
||||
|
||||
@interface myImageObject : NSObject{
|
||||
NSURL *_url;
|
||||
NSString *_urlString;
|
||||
NSString *_artworkProviderName;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation myImageObject
|
||||
|
||||
- (void) dealloc {
|
||||
[_url release];
|
||||
[_urlString release];
|
||||
[_artworkProviderName release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) setURL:(NSURL *)url {
|
||||
if(_url != url){
|
||||
[_url release];
|
||||
[_urlString release];
|
||||
_url = [url retain];
|
||||
_urlString = [[url absoluteString] retain];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSURL *) url {
|
||||
return _url;
|
||||
}
|
||||
|
||||
- (void) setArtworkProviderName:(NSString *)artworkProviderName {
|
||||
_artworkProviderName = [artworkProviderName retain];
|
||||
}
|
||||
|
||||
- (NSString *) imageRepresentationType {
|
||||
return IKImageBrowserNSDataRepresentationType;
|
||||
}
|
||||
|
||||
- (id) imageRepresentation {
|
||||
return [MetadataImporter downloadDataOrGetFromCache:_url];
|
||||
}
|
||||
|
||||
- (NSString *) imageUID {
|
||||
return _urlString;
|
||||
}
|
||||
|
||||
- (NSString *) imageTitle {
|
||||
NSArray *a = [_artworkProviderName componentsSeparatedByString:@"|"];
|
||||
if ([a count] > 0) {
|
||||
return [a objectAtIndex:0];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString *) imageSubtitle {
|
||||
NSArray *a = [_artworkProviderName componentsSeparatedByString:@"|"];
|
||||
if ([a count] > 1) {
|
||||
return [a objectAtIndex:1];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation SBArtworkSelector
|
||||
|
||||
#pragma mark Initialization
|
||||
|
||||
- (instancetype)initWithDelegate:(id <SBArtworkSelectorDelegate>)del imageURLs:(NSArray *)imageURLs artworkProviderNames:(NSArray *)aArtworkProviderNames {
|
||||
if ((self = [super initWithWindowNibName:@"ArtworkSelector"])) {
|
||||
delegate = del;
|
||||
imageURLsUnloaded = [[NSMutableArray alloc] initWithArray:imageURLs];
|
||||
artworkProviderNames = [aArtworkProviderNames retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark Load images
|
||||
|
||||
- (void)awakeFromNib {
|
||||
images = [[NSMutableArray alloc] initWithCapacity:[imageURLsUnloaded count]];
|
||||
myImageObject *m;
|
||||
for (int i = 0; (i < 10) && ([imageURLsUnloaded count] > 0); i++) {
|
||||
m = [[myImageObject alloc] init];
|
||||
[m setURL:[imageURLsUnloaded objectAtIndex:0]];
|
||||
[m setArtworkProviderName:[artworkProviderNames objectAtIndex:[images count]]];
|
||||
[imageURLsUnloaded removeObjectAtIndex:0];
|
||||
[images addObject:m];
|
||||
[m release];
|
||||
}
|
||||
[loadMoreArtworkButton setEnabled:([imageURLsUnloaded count] > 0)];
|
||||
[imageBrowser reloadData];
|
||||
[imageBrowser setSelectionIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
|
||||
}
|
||||
|
||||
- (IBAction) loadMoreArtwork:(id)sender {
|
||||
myImageObject *m;
|
||||
for (int i = 0; (i < 10) && ([imageURLsUnloaded count] > 0); i++) {
|
||||
m = [[myImageObject alloc] init];
|
||||
[m setURL:[imageURLsUnloaded objectAtIndex:0]];
|
||||
[m setArtworkProviderName:[artworkProviderNames objectAtIndex:[images count]]];
|
||||
[imageURLsUnloaded removeObjectAtIndex:0];
|
||||
[images addObject:m];
|
||||
[m release];
|
||||
}
|
||||
[loadMoreArtworkButton setEnabled:([imageURLsUnloaded count] > 0)];
|
||||
[imageBrowser reloadData];
|
||||
}
|
||||
|
||||
#pragma mark User interface
|
||||
|
||||
- (IBAction) zoomSliderDidChange:(id)sender {
|
||||
[imageBrowser setZoomValue:[slider floatValue]];
|
||||
[imageBrowser setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
#pragma mark Finishing up
|
||||
|
||||
- (IBAction) addArtwork:(id)sender {
|
||||
[delegate performSelector:@selector(selectArtworkDone:) withObject:[[[imageBrowser selectionIndexes] retain] autorelease]];
|
||||
}
|
||||
|
||||
- (IBAction) addNoArtwork:(id)sender {
|
||||
[delegate performSelector:@selector(selectArtworkDone:) withObject:nil];
|
||||
}
|
||||
|
||||
- (void) dealloc {
|
||||
[images release];
|
||||
[imageURLsUnloaded release];
|
||||
[artworkProviderNames release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark IKImageBrowserDataSource
|
||||
|
||||
- (NSUInteger) numberOfItemsInImageBrowser:(IKImageBrowserView *) aBrowser {
|
||||
return [images count];
|
||||
}
|
||||
|
||||
- (id) imageBrowser:(IKImageBrowserView *) aBrowser itemAtIndex:(NSUInteger)index {
|
||||
return [images objectAtIndex:index];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark IKImageBrowserDelegate
|
||||
|
||||
- (void) imageBrowser:(IKImageBrowserView *) aBrowser cellWasDoubleClickedAtIndex:(NSUInteger) index {
|
||||
[self addArtwork:nil];
|
||||
}
|
||||
|
||||
- (void) imageBrowserSelectionDidChange:(IKImageBrowserView *) aBrowser {
|
||||
if ([[aBrowser selectionIndexes] count]) {
|
||||
[addArtworkButton setEnabled:YES];
|
||||
} else {
|
||||
[addArtworkButton setEnabled:NO];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+74
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// SBDocument.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 29/01/09.
|
||||
// Copyright Damiano Galassi 2009 . All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class MP42File;
|
||||
|
||||
@interface SBDocument : NSDocument <NSTableViewDelegate> {
|
||||
MP42File *mp4File;
|
||||
IBOutlet NSWindow *documentWindow;
|
||||
|
||||
IBOutlet NSTableView *fileTracksTable;
|
||||
IBOutlet NSSplitView *splitView;
|
||||
|
||||
IBOutlet NSWindow *savingWindow;
|
||||
IBOutlet NSTextField *saveOperationName;
|
||||
|
||||
NSSavePanel *_currentSavePanel;
|
||||
IBOutlet NSView *saveView;
|
||||
IBOutlet NSPopUpButton *fileFormat;
|
||||
IBOutlet NSProgressIndicator *optBar;
|
||||
|
||||
IBOutlet NSToolbarItem *addTracks;
|
||||
IBOutlet NSToolbarItem *deleteTrack;
|
||||
IBOutlet NSToolbarItem *searchMetadata;
|
||||
IBOutlet NSToolbarItem *sendToQueue;
|
||||
|
||||
NSMutableArray *languages;
|
||||
|
||||
NSViewController *propertyView;
|
||||
IBOutlet NSView *targetView;
|
||||
id importWindow;
|
||||
|
||||
IBOutlet NSWindow *offsetWindow;
|
||||
IBOutlet NSTextField *offset;
|
||||
|
||||
IBOutlet NSButton *cancelSave;
|
||||
IBOutlet NSButton *_64bit_data;
|
||||
IBOutlet NSButton *_64bit_time;
|
||||
BOOL _optimize;
|
||||
}
|
||||
|
||||
- (IBAction)selectFile:(id)sender;
|
||||
- (IBAction)deleteTrack:(id)sender;
|
||||
- (IBAction)sendToQueue:(id)sender;
|
||||
- (IBAction)searchMetadata:(id)sender;
|
||||
|
||||
- (IBAction)showTrackOffsetSheet:(id)sender;
|
||||
- (IBAction)setTrackOffset:(id)sender;
|
||||
- (IBAction)closeOffsetSheet:(id)sender;
|
||||
|
||||
- (IBAction)setSaveFormat:(id)sender;
|
||||
- (IBAction)cancelSaveOperation:(id)sender;
|
||||
- (IBAction)sendToExternalApp:(id)sender;
|
||||
|
||||
- (IBAction)saveAndOptimize:(id)sender;
|
||||
|
||||
- (IBAction)selectMetadataFile:(id)sender;
|
||||
- (IBAction)addChaptersEvery:(id)sender;
|
||||
- (IBAction)iTunesFriendlyTrackGroups:(id)sender;
|
||||
|
||||
- (IBAction)export:(id)sender;
|
||||
|
||||
- (void)showImportSheet:(NSArray *)fileURLs;
|
||||
|
||||
- (MP42File *)mp4File;
|
||||
- (void)setMp4File:(MP42File *)mp4;
|
||||
|
||||
@end
|
||||
Executable
+946
@@ -0,0 +1,946 @@
|
||||
//
|
||||
// SBDocument.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 29/01/09.
|
||||
// Copyright Damiano Galassi 2009 . All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBDocument.h"
|
||||
#import "SBQueueController.h"
|
||||
#import "SBQueueItem.h"
|
||||
#import "SBFileImport.h"
|
||||
|
||||
#import "SBEmptyViewController.h"
|
||||
#import "SBMovieViewController.h"
|
||||
#import "SBVideoViewController.h"
|
||||
#import "SBSoundViewController.h"
|
||||
#import "SBChapterViewController.h"
|
||||
|
||||
#import "SBMetadataSearchController.h"
|
||||
#import "SBArtworkSelector.h"
|
||||
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
#import <MP42Foundation/MP42Languages.h>
|
||||
#import <MP42Foundation/MP42Utilities.h>
|
||||
|
||||
#define SublerTableViewDataType @"SublerTableViewDataType"
|
||||
|
||||
@interface SBDocument () <MP42FileDelegate, SBFileImportDelegate>
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBDocument
|
||||
|
||||
- (NSString *)windowNibName
|
||||
{
|
||||
return @"SBDocument";
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"rememberWindowSize"] integerValue]) {
|
||||
[documentWindow setFrameAutosaveName:@"documentSave"];
|
||||
[documentWindow setFrameUsingName:@"documentSave"];
|
||||
[splitView setAutosaveName:@"splitViewSave"];
|
||||
}
|
||||
|
||||
[optBar setUsesThreadedAnimation:NO];
|
||||
}
|
||||
|
||||
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
|
||||
{
|
||||
[super windowControllerDidLoadNib:aController];
|
||||
|
||||
languages = [[[MP42Languages defaultManager] languages] copy];
|
||||
|
||||
SBMovieViewController *controller = [[SBMovieViewController alloc] initWithNibName:@"MovieView" bundle:nil];
|
||||
[controller setFile:mp4File];
|
||||
if (controller !=nil){
|
||||
propertyView = controller;
|
||||
[[propertyView view] setAutoresizingMask:( NSViewWidthSizable | NSViewHeightSizable )];
|
||||
[[propertyView view] setFrame:[targetView bounds]];
|
||||
[targetView addSubview: [propertyView view]];
|
||||
}
|
||||
|
||||
[documentWindow recalculateKeyViewLoop];
|
||||
|
||||
[fileTracksTable registerForDraggedTypes:[NSArray arrayWithObjects:SublerTableViewDataType, nil]];
|
||||
[documentWindow registerForDraggedTypes:[NSArray arrayWithObjects:
|
||||
NSColorPboardType, NSFilenamesPboardType, nil]];
|
||||
|
||||
_optimize = NO;
|
||||
|
||||
[sendToQueue setImage:[NSImage imageNamed:NSImageNameShareTemplate]];
|
||||
}
|
||||
|
||||
- (id)initWithType:(NSString *)typeName error:(NSError **)outError
|
||||
{
|
||||
if (self = [super initWithType:typeName error:outError])
|
||||
mp4File = [[MP42File alloc] initWithDelegate:self];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (BOOL)canConcurrentlyReadDocumentsOfType:(NSString *)type
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isEntireFileLoaded
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark Read methods
|
||||
|
||||
- (void)reloadFile:(NSURL *)absoluteURL
|
||||
{
|
||||
if (absoluteURL) {
|
||||
MP42File *newFile = [[MP42File alloc] initWithExistingFile:absoluteURL andDelegate:self];
|
||||
if (newFile) {
|
||||
[mp4File autorelease];
|
||||
mp4File = newFile;
|
||||
[fileTracksTable reloadData];
|
||||
[self tableViewSelectionDidChange:nil];
|
||||
}
|
||||
else
|
||||
[self close];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
|
||||
{
|
||||
mp4File = [[MP42File alloc] initWithExistingFile:absoluteURL andDelegate:self];
|
||||
|
||||
if ( outError != NULL && !mp4File ) {
|
||||
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)revertToContentsOfURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
|
||||
{
|
||||
[mp4File release];
|
||||
mp4File = [[MP42File alloc] initWithExistingFile:absoluteURL andDelegate:self];
|
||||
|
||||
[fileTracksTable reloadData];
|
||||
[self tableViewSelectionDidChange:nil];
|
||||
[self updateChangeCount:NSChangeCleared];
|
||||
|
||||
if ( outError != NULL && !mp4File ) {
|
||||
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
|
||||
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
+ (BOOL)autosavesInPlace
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark Save methods
|
||||
|
||||
- (BOOL)saveDidComplete:(NSError **)outError URL:(NSURL *)absoluteURL
|
||||
{
|
||||
[NSApp endSheet: savingWindow];
|
||||
[savingWindow orderOut:self];
|
||||
[optBar stopAnimation:self];
|
||||
|
||||
if (*outError) {
|
||||
[self presentError:*outError
|
||||
modalForWindow:documentWindow
|
||||
delegate:nil
|
||||
didPresentSelector:NULL
|
||||
contextInfo:NULL];
|
||||
|
||||
[*outError release];
|
||||
}
|
||||
|
||||
[self reloadFile:absoluteURL];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)endSave:(id)sender {
|
||||
/* Post an event so our event loop wakes up */
|
||||
[NSApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined location:NSZeroPoint modifierFlags:0 timestamp:0 windowNumber:0 context:NULL subtype:0 data1:0 data2:0] atStart:NO];
|
||||
}
|
||||
|
||||
- (BOOL)writeSafelyToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName
|
||||
forSaveOperation:(NSSaveOperationType)saveOperation error:(NSError **)outError;
|
||||
{
|
||||
__block BOOL success = NO;
|
||||
__block int32_t done = 0;
|
||||
__block NSError *inError = NULL;
|
||||
|
||||
NSMutableDictionary * attributes = [[NSMutableDictionary alloc] init];
|
||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue])
|
||||
[attributes setObject:@YES forKey:MP42GenerateChaptersPreviewTrack];
|
||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBOrganizeAlternateGroups"] boolValue])
|
||||
[attributes setObject:@YES forKey:MP42OrganizeAlternateGroups];
|
||||
|
||||
|
||||
[optBar setIndeterminate:YES];
|
||||
[optBar startAnimation:self];
|
||||
[saveOperationName setStringValue:@"Saving…"];
|
||||
[NSApp beginSheet:savingWindow modalForWindow:documentWindow
|
||||
modalDelegate:nil didEndSelector:NULL contextInfo:nil];
|
||||
|
||||
IOPMAssertionID assertionID;
|
||||
// Enable sleep assertion
|
||||
CFStringRef reasonForActivity= CFSTR("Subler Save Operation");
|
||||
IOReturn io_success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
|
||||
kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
switch (saveOperation) {
|
||||
case NSSaveOperation:
|
||||
// movie file already exists, so we'll just update
|
||||
// the movie resource
|
||||
success = [mp4File updateMP4FileWithAttributes:attributes error:&inError];
|
||||
break;
|
||||
case NSSaveAsOperation:
|
||||
if ([_64bit_data state]) [attributes setObject:@YES forKey:MP4264BitData];
|
||||
if ([_64bit_time state]) [attributes setObject:@YES forKey:MP4264BitTime];
|
||||
success = [mp4File writeToUrl:absoluteURL withAttributes:attributes error:&inError];
|
||||
break;
|
||||
case NSSaveToOperation:
|
||||
// not implemented
|
||||
break;
|
||||
}
|
||||
if (_optimize) {
|
||||
[saveOperationName setStringValue:@"Optimizing…"];
|
||||
[mp4File optimize];
|
||||
_optimize = NO;
|
||||
}
|
||||
|
||||
done = 1;
|
||||
[inError retain];
|
||||
});
|
||||
|
||||
while (!done) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@try {
|
||||
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES];
|
||||
if (event) [NSApp sendEvent:event];
|
||||
}
|
||||
@catch (NSException *localException) {
|
||||
NSLog(@"Exception thrown during save: %@", localException);
|
||||
}
|
||||
@finally {
|
||||
[pool drain];
|
||||
}
|
||||
}
|
||||
|
||||
if (io_success == kIOReturnSuccess)
|
||||
IOPMAssertionRelease(assertionID);
|
||||
|
||||
*outError = [inError autorelease];
|
||||
|
||||
[attributes release];
|
||||
[self saveDidComplete:outError URL:absoluteURL];
|
||||
return success;
|
||||
}
|
||||
|
||||
- (BOOL)prepareSavePanel:(NSSavePanel *)savePanel
|
||||
{
|
||||
_currentSavePanel = savePanel;
|
||||
[savePanel setExtensionHidden:NO];
|
||||
[savePanel setAccessoryView:saveView];
|
||||
|
||||
NSArray *formats = [self writableTypesForSaveOperation:NSSaveAsOperation];
|
||||
[fileFormat removeAllItems];
|
||||
for (id format in formats)
|
||||
[fileFormat addItemWithTitle:format];
|
||||
|
||||
[fileFormat selectItemAtIndex:[[[NSUserDefaults standardUserDefaults] valueForKey:@"defaultSaveFormat"] integerValue]];
|
||||
if ([[NSUserDefaults standardUserDefaults] valueForKey:@"SBSaveFormat"])
|
||||
[_currentSavePanel setAllowedFileTypes:[NSArray arrayWithObject:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBSaveFormat"]]];
|
||||
|
||||
NSString *filename = nil;
|
||||
for (NSUInteger i = 0; i < [mp4File tracksCount]; i++) {
|
||||
MP42Track *track = [mp4File trackAtIndex:i];
|
||||
if ([track sourceURL]) {
|
||||
filename = [[[track sourceURL] lastPathComponent] stringByDeletingPathExtension];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (filename)
|
||||
[savePanel performSelector:@selector(setNameFieldStringValue:) withObject:filename];
|
||||
|
||||
if (mp4File.dataSize > 4200000000)
|
||||
[_64bit_data setState:NSOnState];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (IBAction)setSaveFormat:(id)sender
|
||||
{
|
||||
NSString *requiredFileType = nil;
|
||||
NSInteger index = [sender indexOfSelectedItem];
|
||||
switch (index) {
|
||||
case 0:
|
||||
requiredFileType = MP42FileTypeM4V;
|
||||
break;
|
||||
case 1:
|
||||
requiredFileType = MP42FileTypeMP4;
|
||||
break;
|
||||
case 2:
|
||||
requiredFileType = MP42FileTypeM4A;
|
||||
break;
|
||||
default:
|
||||
requiredFileType = MP42FileTypeM4V;
|
||||
break;
|
||||
}
|
||||
|
||||
[_currentSavePanel setAllowedFileTypes:[NSArray arrayWithObject:requiredFileType]];
|
||||
[[NSUserDefaults standardUserDefaults] setObject:requiredFileType forKey:@"SBSaveFormat"];
|
||||
}
|
||||
|
||||
- (IBAction)cancelSaveOperation:(id)sender
|
||||
{
|
||||
[cancelSave setEnabled:NO];
|
||||
[mp4File cancel];
|
||||
}
|
||||
|
||||
- (IBAction)saveAndOptimize:(id)sender
|
||||
{
|
||||
_optimize = YES;
|
||||
[self saveDocument:sender];
|
||||
}
|
||||
|
||||
- (IBAction)sendToExternalApp:(id)sender
|
||||
{
|
||||
/* send to itunes after save */
|
||||
NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource:
|
||||
[NSString stringWithFormat:@"%@%@%@", @"tell application \"iTunes\" to open (POSIX file \"", [[self fileURL] path], @"\")"]];
|
||||
|
||||
[myScript executeAndReturnError: nil];
|
||||
[myScript release];
|
||||
}
|
||||
|
||||
#pragma mark Interface validation
|
||||
|
||||
- (void)progressStatus:(CGFloat)progress
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[optBar setIndeterminate:NO];
|
||||
[optBar setDoubleValue:progress];
|
||||
});
|
||||
}
|
||||
|
||||
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem
|
||||
{
|
||||
SEL action = [anItem action];
|
||||
|
||||
if (action == @selector(saveDocument:))
|
||||
if ([self isDocumentEdited])
|
||||
return YES;
|
||||
|
||||
if (action == @selector(saveDocumentAs:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(revertDocumentToSaved:))
|
||||
if ([self isDocumentEdited])
|
||||
return YES;
|
||||
|
||||
if (action == @selector(saveAndOptimize:))
|
||||
if (![self isDocumentEdited] && [mp4File hasFileRepresentation])
|
||||
return YES;
|
||||
|
||||
if (action == @selector(selectMetadataFile:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(selectFile:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(deleteTrack:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(searchMetadata:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(sendToQueue:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(sendToExternalApp:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(showTrackOffsetSheet:) && [fileTracksTable selectedRow] != -1)
|
||||
return YES;
|
||||
|
||||
if (action == @selector(addChaptersEvery:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(iTunesFriendlyTrackGroups:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(export:) && [fileTracksTable selectedRow] != -1)
|
||||
if ([[mp4File trackAtIndex:[fileTracksTable selectedRow]] respondsToSelector:@selector(exportToURL:error:)] &&
|
||||
[[mp4File trackAtIndex:[fileTracksTable selectedRow]] muxed])
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem
|
||||
{
|
||||
if (toolbarItem == addTracks)
|
||||
return YES;
|
||||
|
||||
else if (toolbarItem == deleteTrack)
|
||||
if ([fileTracksTable selectedRow] != -1 && [NSApp isActive])
|
||||
return YES;
|
||||
|
||||
if (toolbarItem == searchMetadata)
|
||||
return YES;
|
||||
|
||||
if (toolbarItem == sendToQueue)
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark table datasource
|
||||
|
||||
- (NSInteger)numberOfRowsInTableView:(NSTableView *)t
|
||||
{
|
||||
if (!mp4File)
|
||||
return 0;
|
||||
|
||||
return [mp4File tracksCount];
|
||||
}
|
||||
|
||||
- (id)tableView:(NSTableView *)tableView
|
||||
objectValueForTableColumn:(NSTableColumn *)tableColumn
|
||||
row:(NSInteger)rowIndex
|
||||
{
|
||||
MP42Track *track = [mp4File trackAtIndex:rowIndex];
|
||||
|
||||
if (!track)
|
||||
return nil;
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackId"]) {
|
||||
if ([track Id] == 0)
|
||||
return @"na";
|
||||
else
|
||||
return [NSString stringWithFormat:@"%d", [track Id]];
|
||||
}
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackName"])
|
||||
return track.name;
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackInfo"])
|
||||
return track.formatSummary;
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackEnabled"])
|
||||
return @(track.enabled);
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackDuration"])
|
||||
return track.timeString;
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackLanguage"])
|
||||
return track.language;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)tableView:(NSTableView *)tableView
|
||||
setObjectValue:(id)anObject
|
||||
forTableColumn:(NSTableColumn *)tableColumn
|
||||
row:(NSInteger)rowIndex
|
||||
{
|
||||
MP42Track *track = [mp4File trackAtIndex:rowIndex];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackLanguage"]) {
|
||||
if (![track.language isEqualToString:anObject]) {
|
||||
track.language = anObject;
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
else if ([tableColumn.identifier isEqualToString:@"trackName"]) {
|
||||
if (![track.name isEqualToString:anObject]) {
|
||||
track.name = anObject;
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
else if ([tableColumn.identifier isEqualToString:@"trackEnabled"]) {
|
||||
if (!(track.enabled == [anObject integerValue])) {
|
||||
track.enabled = [anObject integerValue];
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
|
||||
{
|
||||
if ([propertyView view] != nil)
|
||||
[[propertyView view] removeFromSuperview]; // remove the current view
|
||||
|
||||
[[self undoManager] removeAllActionsWithTarget:propertyView]; // remove the undo items from the dealloced view
|
||||
|
||||
if (propertyView != nil)
|
||||
[propertyView release]; // remove the current view controller
|
||||
|
||||
NSInteger row = [fileTracksTable selectedRow];
|
||||
if (row == -1)
|
||||
{
|
||||
SBMovieViewController *controller = [[SBMovieViewController alloc] initWithNibName:@"MovieView" bundle:nil];
|
||||
[controller setFile:mp4File];
|
||||
if (controller !=nil)
|
||||
propertyView = controller;
|
||||
}
|
||||
else if (row != -1 && [[mp4File trackAtIndex:row] isMemberOfClass:[MP42ChapterTrack class]])
|
||||
{
|
||||
SBChapterViewController *controller = [[SBChapterViewController alloc] initWithNibName:@"ChapterView" bundle:nil];
|
||||
[controller setTrack:(MP42ChapterTrack *)[mp4File trackAtIndex:row]];
|
||||
if (controller !=nil)
|
||||
propertyView = controller;
|
||||
}
|
||||
else if (row != -1 && [[mp4File trackAtIndex:row] isKindOfClass:[MP42VideoTrack class]])
|
||||
{
|
||||
SBVideoViewController *controller = [[SBVideoViewController alloc] initWithNibName:@"VideoView" bundle:nil];
|
||||
[controller setTrack:(MP42VideoTrack *)[mp4File trackAtIndex:row]];
|
||||
[controller setFile:mp4File];
|
||||
if (controller !=nil)
|
||||
propertyView = controller;
|
||||
}
|
||||
else if (row != -1 && [[mp4File trackAtIndex:row] isKindOfClass:[MP42AudioTrack class]])
|
||||
{
|
||||
SBSoundViewController *controller = [[SBSoundViewController alloc] initWithNibName:@"SoundView" bundle:nil];
|
||||
[controller setTrack:(MP42AudioTrack *)[mp4File trackAtIndex:row]];
|
||||
[controller setFile:mp4File];
|
||||
if (controller !=nil)
|
||||
propertyView = controller;
|
||||
}
|
||||
else
|
||||
{
|
||||
SBEmptyViewController *controller = [[SBEmptyViewController alloc] initWithNibName:@"EmptyView" bundle:nil];
|
||||
if (controller !=nil)
|
||||
propertyView = controller;
|
||||
}
|
||||
|
||||
// embed the current view to our host view
|
||||
[targetView addSubview: [propertyView view]];
|
||||
[documentWindow recalculateKeyViewLoop];
|
||||
|
||||
// make sure we automatically resize the controller's view to the current window size
|
||||
[[propertyView view] setFrame: [targetView bounds]];
|
||||
[[propertyView view] setAutoresizingMask:( NSViewWidthSizable | NSViewHeightSizable )];
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
|
||||
{
|
||||
// Copy the row numbers to the pasteboard.
|
||||
if ([[mp4File trackAtIndex:[rowIndexes firstIndex]] muxed])
|
||||
return NO;
|
||||
|
||||
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
|
||||
[pboard declareTypes:[NSArray arrayWithObject:SublerTableViewDataType] owner:self];
|
||||
[pboard setData:data forType:SublerTableViewDataType];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSDragOperation)tableView:(NSTableView*)tv
|
||||
validateDrop:(id <NSDraggingInfo>)info
|
||||
proposedRow:(NSInteger)row
|
||||
proposedDropOperation:(NSTableViewDropOperation)op
|
||||
{
|
||||
if (op == NSTableViewDropAbove && row < [mp4File tracksCount]) {
|
||||
if(![[mp4File trackAtIndex:row] muxed])
|
||||
return NSDragOperationEvery;
|
||||
}
|
||||
else if (op == NSTableViewDropAbove && row == [mp4File tracksCount])
|
||||
return NSDragOperationEvery;
|
||||
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
|
||||
row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
|
||||
{
|
||||
NSPasteboard* pboard = [info draggingPasteboard];
|
||||
NSData* rowData = [pboard dataForType:SublerTableViewDataType];
|
||||
NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
|
||||
NSInteger dragRow = [rowIndexes firstIndex];
|
||||
|
||||
[mp4File moveTrackAtIndex:dragRow toIndex:row];
|
||||
[fileTracksTable reloadData];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)canDragRowsWithIndexes:(NSIndexSet *)rowIndexes atPoint:(NSPoint)mouseDownPoint
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
/* NSComboBoxCell dataSource */
|
||||
|
||||
- (NSInteger)numberOfItemsInComboBoxCell:(NSComboBoxCell *)comboBoxCell
|
||||
{
|
||||
return [languages count];
|
||||
}
|
||||
|
||||
- (id)comboBoxCell:(NSComboBoxCell *)comboBoxCell objectValueForItemAtIndex:(NSInteger)index {
|
||||
return [languages objectAtIndex:index];
|
||||
}
|
||||
|
||||
- (NSUInteger)comboBoxCell:(NSComboBoxCell *)comboBoxCell indexOfItemWithStringValue:(NSString *)string {
|
||||
return [languages indexOfObject: string];
|
||||
}
|
||||
|
||||
#pragma mark Various things
|
||||
|
||||
- (IBAction)sendToQueue:(id)sender
|
||||
{
|
||||
SBQueueController *queue = [SBQueueController sharedManager];
|
||||
if ([mp4File hasFileRepresentation]) {
|
||||
SBQueueItem *item = [SBQueueItem itemWithMP4:mp4File];
|
||||
[queue addItem:item];
|
||||
[self close];
|
||||
}
|
||||
else {
|
||||
NSSavePanel * panel = [NSSavePanel savePanel];
|
||||
[self prepareSavePanel:panel];
|
||||
|
||||
[panel setPrompt:@"Send To Queue"];
|
||||
|
||||
[panel beginSheetModalForWindow:documentWindow completionHandler:^(NSInteger result) {
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
|
||||
if ([_64bit_data state]) [attributes setObject:@YES forKey:MP4264BitData];
|
||||
if ([_64bit_time state]) [attributes setObject:@YES forKey:MP4264BitTime];
|
||||
|
||||
SBQueueItem *item = [SBQueueItem itemWithMP4:mp4File url:[panel URL] attributes:attributes];
|
||||
[queue addItem:item];
|
||||
|
||||
[attributes release];
|
||||
[self close];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)searchMetadata:(id)sender
|
||||
{
|
||||
importWindow = [[SBMetadataSearchController alloc] initWithDelegate:self];
|
||||
|
||||
[NSApp beginSheet:[importWindow window] modalForWindow:documentWindow
|
||||
modalDelegate:nil didEndSelector:NULL contextInfo:nil];
|
||||
}
|
||||
|
||||
- (IBAction)showTrackOffsetSheet:(id)sender
|
||||
{
|
||||
[offset setStringValue:[NSString stringWithFormat:@"%lld",
|
||||
[[[mp4File tracks] objectAtIndex:[fileTracksTable selectedRow]] startOffset]]];
|
||||
|
||||
[NSApp beginSheet:offsetWindow modalForWindow:documentWindow
|
||||
modalDelegate:nil didEndSelector:NULL contextInfo:nil];
|
||||
}
|
||||
|
||||
- (IBAction)setTrackOffset:(id)sender
|
||||
{
|
||||
MP42Track *selectedTrack = [[mp4File tracks] objectAtIndex:[fileTracksTable selectedRow]];
|
||||
[selectedTrack setStartOffset:[offset integerValue]];
|
||||
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
|
||||
[NSApp endSheet: offsetWindow];
|
||||
[offsetWindow orderOut:self];
|
||||
}
|
||||
|
||||
- (IBAction)closeOffsetSheet:(id)sender
|
||||
{
|
||||
[NSApp endSheet: offsetWindow];
|
||||
[offsetWindow orderOut:self];
|
||||
}
|
||||
|
||||
- (IBAction)deleteTrack:(id)sender
|
||||
{
|
||||
if ([fileTracksTable selectedRow] == -1 || [fileTracksTable editedRow] != -1)
|
||||
return;
|
||||
|
||||
[mp4File removeTrackAtIndex:[fileTracksTable selectedRow]];
|
||||
|
||||
[mp4File organizeAlternateGroups];
|
||||
|
||||
[fileTracksTable reloadData];
|
||||
[self tableViewSelectionDidChange:nil];
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
|
||||
// Import tracks from file
|
||||
|
||||
- (void)addChapterTrack:(NSURL *)fileURL
|
||||
{
|
||||
[mp4File addTrack:[MP42ChapterTrack chapterTrackFromFile:fileURL]];
|
||||
|
||||
[fileTracksTable reloadData];
|
||||
[self tableViewSelectionDidChange:nil];
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
|
||||
- (IBAction)selectFile:(id)sender
|
||||
{
|
||||
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
||||
panel.allowsMultipleSelection = NO;
|
||||
panel.canChooseFiles = YES;
|
||||
panel.canChooseDirectories = NO;
|
||||
[panel setAllowedFileTypes:supportedFileFormat()];
|
||||
|
||||
[panel beginSheetModalForWindow:documentWindow completionHandler:^(NSInteger result) {
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
NSString *fileExtension = [[panel.URLs objectAtIndex: 0] pathExtension];
|
||||
|
||||
if ([fileExtension caseInsensitiveCompare: @"txt"] == NSOrderedSame)
|
||||
[self addChapterTrack:[panel.URLs objectAtIndex: 0]];
|
||||
else
|
||||
[self performSelectorOnMainThread:@selector(showImportSheet:)
|
||||
withObject:panel.URLs waitUntilDone: NO];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)showImportSheet:(NSArray *)fileURLs
|
||||
{
|
||||
NSError *error = nil;
|
||||
|
||||
importWindow = [[SBFileImport alloc] initWithDelegate:self andFiles:fileURLs error:&error];
|
||||
|
||||
if (importWindow)
|
||||
[NSApp beginSheet:[importWindow window] modalForWindow:documentWindow
|
||||
modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:importWindow];
|
||||
else if (error)
|
||||
[self presentError:error modalForWindow:documentWindow delegate:nil didPresentSelector:NULL contextInfo:nil];
|
||||
}
|
||||
|
||||
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;{
|
||||
[importWindow autorelease], importWindow = nil;
|
||||
|
||||
// IKImageBrowserView is a bit problematic, do the refresh at the end of the run loop
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[fileTracksTable reloadData];
|
||||
[self tableViewSelectionDidChange:nil];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)importDoneWithTracks:(NSArray *)tracksToBeImported andMetadata:(MP42Metadata *)metadata
|
||||
{
|
||||
if (tracksToBeImported) {
|
||||
for (id track in tracksToBeImported)
|
||||
[mp4File addTrack:track];
|
||||
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBOrganizeAlternateGroups"] boolValue])
|
||||
[mp4File organizeAlternateGroups];
|
||||
}
|
||||
|
||||
if (metadata) {
|
||||
[mp4File.metadata mergeMetadata:metadata];
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)metadataImportDone:(MP42Metadata *)metadataToBeImported
|
||||
{
|
||||
if (metadataToBeImported) {
|
||||
[mp4File.metadata mergeMetadata:metadataToBeImported];
|
||||
|
||||
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"];
|
||||
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
[NSApp endSheet:[importWindow window]];
|
||||
[[importWindow window] orderOut:self];
|
||||
[importWindow autorelease], importWindow = nil;
|
||||
|
||||
if (metadataToBeImported) {
|
||||
[self tableViewSelectionDidChange:nil];
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)addMetadata:(NSURL *)URL
|
||||
{
|
||||
if ([[URL pathExtension] isEqualToString:@"xml"] || [[URL pathExtension] isEqualToString:@"nfo"]) {
|
||||
MP42Metadata *xmlMetadata = [[MP42Metadata alloc] initWithFileURL:URL];
|
||||
[mp4File.metadata mergeMetadata:xmlMetadata];
|
||||
[xmlMetadata release];
|
||||
}
|
||||
else {
|
||||
MP42File *file = nil;
|
||||
if ((file = [[MP42File alloc] initWithExistingFile:URL andDelegate:self])) {
|
||||
[mp4File.metadata mergeMetadata:file.metadata];
|
||||
[file release];
|
||||
}
|
||||
}
|
||||
|
||||
[self tableViewSelectionDidChange:nil];
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
|
||||
- (IBAction)selectMetadataFile:(id)sender
|
||||
{
|
||||
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
||||
panel.allowsMultipleSelection = NO;
|
||||
panel.canChooseFiles = YES;
|
||||
panel.canChooseDirectories = NO;
|
||||
[panel setAllowedFileTypes:[NSArray arrayWithObjects:@"mp4", @"m4v", @"m4a", @"xml", @"nfo", nil]];
|
||||
|
||||
[panel beginSheetModalForWindow:documentWindow completionHandler:^(NSInteger result) {
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
[self addMetadata:[panel URL]];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (IBAction)export:(id)sender
|
||||
{
|
||||
NSInteger row = [fileTracksTable selectedRow];
|
||||
NSSavePanel * panel = [NSSavePanel savePanel];
|
||||
NSString *filename = [[[[self fileURL] path] stringByDeletingPathExtension] lastPathComponent];
|
||||
|
||||
if (row != -1 && [[mp4File trackAtIndex:row] isKindOfClass:[MP42SubtitleTrack class]]) {
|
||||
[panel setAllowedFileTypes:[NSArray arrayWithObject: @"srt"]];
|
||||
filename = [filename stringByAppendingFormat:@".%@", [[mp4File trackAtIndex:row] language]];
|
||||
}
|
||||
else if (row != -1 ) {
|
||||
filename = [filename stringByAppendingString:@" - Chapters"];
|
||||
[panel setAllowedFileTypes:[NSArray arrayWithObject: @"txt"]];
|
||||
}
|
||||
|
||||
[panel setCanSelectHiddenExtension: YES];
|
||||
[panel setNameFieldStringValue:filename];
|
||||
|
||||
[panel beginSheetModalForWindow:documentWindow completionHandler:^(NSInteger result) {
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
id track = [mp4File trackAtIndex:[fileTracksTable selectedRow]];
|
||||
|
||||
if (![track exportToURL: [panel URL] error: nil]) {
|
||||
NSAlert * alert = [[NSAlert alloc] init];
|
||||
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Export alert panel -> button")];
|
||||
[alert setMessageText: NSLocalizedString(@"File Could Not Be Saved", "Export alert panel -> title")];
|
||||
[alert setInformativeText: [NSString stringWithFormat:
|
||||
NSLocalizedString(@"There was a problem creating the file \"%@\".",
|
||||
"Export alert panel -> message"), [[[panel URL] path] lastPathComponent]]];
|
||||
[alert setAlertStyle: NSWarningAlertStyle];
|
||||
|
||||
[alert runModal];
|
||||
[alert release];
|
||||
}
|
||||
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (IBAction)addChaptersEvery:(id)sender
|
||||
{
|
||||
MP42ChapterTrack *chapterTrack = [mp4File chapters];
|
||||
NSInteger minutes = [sender tag] * 60 * 1000;
|
||||
NSInteger i, y = 1;
|
||||
|
||||
if (!chapterTrack) {
|
||||
chapterTrack = [[MP42ChapterTrack alloc] init];
|
||||
[chapterTrack setDuration:mp4File.duration];
|
||||
[mp4File addTrack:chapterTrack];
|
||||
[chapterTrack release];
|
||||
}
|
||||
|
||||
if (minutes)
|
||||
for (i = 0, y = 1; i < mp4File.duration; i += minutes, y++) {
|
||||
[chapterTrack addChapter:[NSString stringWithFormat:@"Chapter %ld", (long)y]
|
||||
duration:i];
|
||||
}
|
||||
else
|
||||
[chapterTrack addChapter:@"Chapter 1"
|
||||
duration:mp4File.duration];
|
||||
|
||||
[fileTracksTable reloadData];
|
||||
[self tableViewSelectionDidChange:nil];
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
|
||||
- (IBAction)iTunesFriendlyTrackGroups:(id)sender
|
||||
{
|
||||
[mp4File organizeAlternateGroups];
|
||||
[fileTracksTable reloadData];
|
||||
[self tableViewSelectionDidChange:nil];
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
|
||||
// Drag & Drop
|
||||
|
||||
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
|
||||
NSPasteboard *pboard = [sender draggingPasteboard];
|
||||
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
|
||||
|
||||
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
|
||||
if (sourceDragMask & NSDragOperationCopy) {
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
}
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
|
||||
NSPasteboard *pboard = [sender draggingPasteboard];
|
||||
|
||||
if ( [[pboard types] containsObject:NSURLPboardType] ) {
|
||||
NSArray *items = [pboard readObjectsForClasses:
|
||||
[NSArray arrayWithObject: [NSURL class]] options: nil];
|
||||
NSMutableArray *supItems = [[[NSMutableArray alloc] init] autorelease];
|
||||
|
||||
for (NSURL *file in items) {
|
||||
if ([[file pathExtension] caseInsensitiveCompare: @"txt"] == NSOrderedSame)
|
||||
[self addChapterTrack:file];
|
||||
else if ([[file pathExtension] caseInsensitiveCompare: @"xml"] == NSOrderedSame ||
|
||||
[[file pathExtension] caseInsensitiveCompare: @"nfo"] == NSOrderedSame)
|
||||
[self addMetadata:file];
|
||||
else if (isFileFormatSupported([file pathExtension])) {
|
||||
[supItems addObject:file];
|
||||
}
|
||||
}
|
||||
|
||||
if ([supItems count])
|
||||
[self showImportSheet:supItems];
|
||||
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (MP42File *)mp4File {
|
||||
return mp4File;
|
||||
}
|
||||
|
||||
- (void)setMp4File:(MP42File *)mp4 {
|
||||
[mp4File autorelease];
|
||||
mp4File = [mp4 retain];
|
||||
[fileTracksTable reloadData];
|
||||
[self tableViewSelectionDidChange:nil];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[propertyView release];
|
||||
[languages release];
|
||||
|
||||
[mp4File release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// FileImport.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 31/01/10.
|
||||
// Copyright 2010. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class MP42FileImporter;
|
||||
@class MP42Metadata;
|
||||
|
||||
@protocol SBFileImportDelegate
|
||||
- (void)importDoneWithTracks:(NSArray *)tracksToBeImported andMetadata:(MP42Metadata *)metadata;
|
||||
@end
|
||||
|
||||
@interface SBFileImport : NSWindowController <NSTableViewDelegate> {
|
||||
NSArray *_fileURLs;
|
||||
NSMutableArray *_fileImporters;
|
||||
NSMutableArray *_tracks;
|
||||
|
||||
NSMutableArray *_importCheckArray;
|
||||
NSMutableArray *_actionArray;
|
||||
|
||||
id delegate;
|
||||
IBOutlet NSTableView *tableView;
|
||||
IBOutlet NSButton *addTracksButton;
|
||||
IBOutlet NSButton *importMetadata;
|
||||
IBOutlet NSProgressIndicator *loadProgressBar;
|
||||
}
|
||||
|
||||
- (instancetype)initWithDelegate:(id <SBFileImportDelegate>)del andFiles:(NSArray *)files error:(NSError **)outError;
|
||||
|
||||
- (IBAction)closeWindow:(id)sender;
|
||||
- (IBAction)addTracks:(id)sender;
|
||||
|
||||
@end
|
||||
Executable
+377
@@ -0,0 +1,377 @@
|
||||
//
|
||||
// FileImport.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 31/01/10.
|
||||
// Copyright 2010. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBFileImport.h"
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
#import <MP42Foundation/MP42FileImporter.h>
|
||||
#import <MP42Foundation/MP42Utilities.h>
|
||||
|
||||
@implementation SBFileImport
|
||||
|
||||
- (instancetype)initWithDelegate:(id <SBFileImportDelegate>)del andFiles:(NSArray *)files error:(NSError **)outError
|
||||
{
|
||||
if ((self = [super initWithWindowNibName:@"FileImport"])) {
|
||||
delegate = del;
|
||||
_fileURLs = [files retain];
|
||||
_fileImporters = [[NSMutableArray alloc] initWithCapacity:[files count]];
|
||||
_tracks = [[NSMutableArray alloc] init];
|
||||
|
||||
for (NSURL *file in files) {
|
||||
MP42FileImporter *importer = [[MP42FileImporter alloc] initWithURL:file error:outError];
|
||||
if (importer) {
|
||||
[_tracks addObject:[file lastPathComponent]];
|
||||
[_fileImporters addObject:importer];
|
||||
[importer release];
|
||||
[_tracks addObjectsFromArray:importer.tracks];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
_importCheckArray = [[NSMutableArray alloc] initWithCapacity:[_tracks count]];
|
||||
_actionArray = [[NSMutableArray alloc] initWithCapacity:[_tracks count]];
|
||||
|
||||
for (id object in _tracks) {
|
||||
if ([object isKindOfClass:[MP42Track class]]) {
|
||||
if (isTrackMuxable([object format]) || trackNeedConversion([object format]))
|
||||
[_importCheckArray addObject:@YES];
|
||||
else
|
||||
[_importCheckArray addObject:@NO];
|
||||
|
||||
if ([[object format] isEqualToString:MP42AudioFormatAC3] &&
|
||||
[[[NSUserDefaults standardUserDefaults] valueForKey:@"SBAudioConvertAC3"] boolValue]) {
|
||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBAudioKeepAC3"] boolValue] &&
|
||||
[object fallbackTrack] == nil)
|
||||
[_actionArray addObject:@6];
|
||||
else if ([object fallbackTrack])
|
||||
[_actionArray addObject:@0];
|
||||
else
|
||||
[_actionArray addObject:@([[[NSUserDefaults standardUserDefaults]
|
||||
valueForKey:@"SBAudioMixdown"] integerValue])];
|
||||
}
|
||||
else if ([[object format] isEqualToString:MP42AudioFormatDTS])
|
||||
[_actionArray addObject:@1];
|
||||
else if ([[object format] isEqualToString:MP42SubtitleFormatVobSub] &&
|
||||
[[[NSUserDefaults standardUserDefaults] valueForKey:@"SBSubtitleConvertBitmap"] boolValue])
|
||||
[_actionArray addObject:@1];
|
||||
else if (!trackNeedConversion([object format]))
|
||||
[_actionArray addObject:@0];
|
||||
else if ([object isMemberOfClass:[MP42AudioTrack class]])
|
||||
[_actionArray addObject:@([[[NSUserDefaults standardUserDefaults]
|
||||
valueForKey:@"SBAudioMixdown"] integerValue])];
|
||||
else if ([object isMemberOfClass:[MP42ChapterTrack class]])
|
||||
[_actionArray addObject:@0];
|
||||
else
|
||||
[_actionArray addObject:@1];
|
||||
|
||||
}
|
||||
else {
|
||||
[_importCheckArray addObject:@YES];
|
||||
[_actionArray addObject:@0];
|
||||
}
|
||||
}
|
||||
|
||||
if ([[_fileImporters objectAtIndex:0] metadata])
|
||||
[importMetadata setEnabled:YES];
|
||||
else
|
||||
[importMetadata setEnabled:NO];
|
||||
|
||||
[addTracksButton setEnabled:YES];
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfRowsInTableView:(NSTableView *)t
|
||||
{
|
||||
return [_tracks count];
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(NSTableView *)tableView isGroupRow:(NSInteger)row
|
||||
{
|
||||
id object = [_tracks objectAtIndex:row];
|
||||
if ([object isKindOfClass:[MP42Track class]])
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
|
||||
{
|
||||
NSCell *cell = nil;
|
||||
MP42Track *track = [_tracks objectAtIndex:rowIndex];
|
||||
|
||||
if ([track isKindOfClass:[MP42Track class]]) {
|
||||
if ([tableColumn.identifier isEqualToString:@"check"]) {
|
||||
NSButtonCell *buttonCell = [[NSButtonCell alloc] init];
|
||||
[buttonCell setButtonType:NSSwitchButton];
|
||||
[buttonCell setControlSize:NSSmallControlSize];
|
||||
[buttonCell setTitle:@""];
|
||||
|
||||
return [buttonCell autorelease];
|
||||
}
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackAction"]) {
|
||||
NSPopUpButtonCell *actionCell = [[NSPopUpButtonCell alloc] init];
|
||||
[actionCell setAutoenablesItems:NO];
|
||||
[actionCell setFont:[NSFont systemFontOfSize:11]];
|
||||
[actionCell setControlSize:NSSmallControlSize];
|
||||
[actionCell setBordered:NO];
|
||||
|
||||
if ([track isMemberOfClass:[MP42VideoTrack class]]) {
|
||||
if ([[track.sourceURL pathExtension] caseInsensitiveCompare: @"264"] == NSOrderedSame ||
|
||||
[[track.sourceURL pathExtension] caseInsensitiveCompare: @"h264"] == NSOrderedSame) {
|
||||
NSInteger i = 0;
|
||||
NSArray *formatArray = [NSArray arrayWithObjects:@"23.976", @"24", @"25", @"29.97", @"30", @"50", @"59.96", @"60", nil];
|
||||
NSInteger tags[8] = {2398, 24, 25, 2997, 30, 50, 5994, 60};
|
||||
|
||||
for (NSString* format in formatArray) {
|
||||
NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:format action:NULL keyEquivalent:@""] autorelease];
|
||||
[item setTag:tags[i++]];
|
||||
[item setEnabled:YES];
|
||||
[[actionCell menu] addItem:item];
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:@"Passthru" action:NULL keyEquivalent:@""] autorelease];
|
||||
[item setTag:0];
|
||||
[item setEnabled:YES];
|
||||
[[actionCell menu] addItem:item];
|
||||
|
||||
if (isTrackMuxable(track.format))
|
||||
[item setEnabled:YES];
|
||||
else
|
||||
[item setEnabled:NO];
|
||||
}
|
||||
}
|
||||
else if ([track isMemberOfClass:[MP42SubtitleTrack class]]) {
|
||||
NSInteger tag = 0;
|
||||
NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:@"Passthru" action:NULL keyEquivalent:@""] autorelease];
|
||||
[item setTag:tag++];
|
||||
if (!trackNeedConversion(track.format))
|
||||
[item setEnabled:YES];
|
||||
else
|
||||
[item setEnabled:NO];
|
||||
[[actionCell menu] addItem:item];
|
||||
|
||||
NSArray *formatArray = [NSArray arrayWithObjects:MP42SubtitleFormatTx3g, nil];
|
||||
for (NSString* format in formatArray) {
|
||||
item = [[[NSMenuItem alloc] initWithTitle:format action:NULL keyEquivalent:@""] autorelease];
|
||||
[item setTag:tag++];
|
||||
[item setEnabled:YES];
|
||||
[[actionCell menu] addItem:item];
|
||||
}
|
||||
}
|
||||
else if ([track isMemberOfClass:[MP42AudioTrack class]]) {
|
||||
NSInteger tag = 0;
|
||||
NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:@"Passthru" action:NULL keyEquivalent:@""] autorelease];
|
||||
[item setTag:tag++];
|
||||
if (!trackNeedConversion(track.format))
|
||||
[item setEnabled:YES];
|
||||
else
|
||||
[item setEnabled:NO];
|
||||
[[actionCell menu] addItem:item];
|
||||
|
||||
NSArray *formatArray = [NSArray arrayWithObjects:@"AAC - Dolby Pro Logic II", @"AAC - Dolby Pro Logic", @"AAC - Stereo", @"AAC - Mono", @"AAC - Multi-channel", @"AAC + AC-3", nil];
|
||||
for (NSString* format in formatArray) {
|
||||
item = [[[NSMenuItem alloc] initWithTitle:format action:NULL keyEquivalent:@""] autorelease];
|
||||
[item setTag:tag++];
|
||||
[item setEnabled:YES];
|
||||
[[actionCell menu] addItem:item];
|
||||
}
|
||||
}
|
||||
else if ([track isMemberOfClass:[MP42ChapterTrack class]]) {
|
||||
NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:@"Passthru" action:NULL keyEquivalent:@""] autorelease];
|
||||
[item setTag:0];
|
||||
[item setEnabled:YES];
|
||||
[[actionCell menu] addItem:item];
|
||||
}
|
||||
cell = actionCell;
|
||||
|
||||
return [cell autorelease];
|
||||
}
|
||||
}
|
||||
|
||||
return [tableColumn dataCell];
|
||||
}
|
||||
|
||||
- (id)tableView:(NSTableView *)tableView
|
||||
objectValueForTableColumn:(NSTableColumn *)tableColumn
|
||||
row:(NSInteger)rowIndex
|
||||
{
|
||||
id object = [_tracks objectAtIndex:rowIndex];
|
||||
|
||||
if (!object)
|
||||
return nil;
|
||||
|
||||
if ([object isKindOfClass:[MP42Track class]]) {
|
||||
if( [tableColumn.identifier isEqualToString: @"check"] )
|
||||
return [_importCheckArray objectAtIndex:rowIndex];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackId"])
|
||||
return [NSString stringWithFormat:@"%d", [object Id]];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackName"])
|
||||
return [object name];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackInfo"])
|
||||
return [object format];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackDuration"])
|
||||
return [object timeString];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackLanguage"])
|
||||
return [object language];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"trackAction"])
|
||||
return [_actionArray objectAtIndex:rowIndex];
|
||||
}
|
||||
else if ([tableColumn.identifier isEqualToString:@"trackName"])
|
||||
return object;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)tableView:(NSTableView *)tableView
|
||||
setObjectValue:(id)anObject
|
||||
forTableColumn:(NSTableColumn *)tableColumn
|
||||
row:(NSInteger)rowIndex
|
||||
{
|
||||
if ([tableColumn.identifier isEqualToString: @"check"])
|
||||
[_importCheckArray replaceObjectAtIndex:rowIndex withObject:anObject];
|
||||
if ([tableColumn.identifier isEqualToString:@"trackAction"])
|
||||
[_actionArray replaceObjectAtIndex:rowIndex withObject:anObject];
|
||||
}
|
||||
|
||||
- (IBAction)closeWindow:(id)sender
|
||||
{
|
||||
[tableView setDelegate:nil];
|
||||
[tableView setDataSource:nil];
|
||||
[NSApp endSheet:[self window] returnCode:NSOKButton];
|
||||
[[self window] orderOut:self];
|
||||
}
|
||||
|
||||
- (IBAction)addTracks:(id)sender
|
||||
{
|
||||
NSMutableArray *tracks = [[NSMutableArray alloc] init];
|
||||
NSInteger i = 0;
|
||||
|
||||
for (MP42Track *track in _tracks) {
|
||||
if ([track isKindOfClass:[MP42Track class]]) {
|
||||
if ([[_importCheckArray objectAtIndex: i] boolValue]) {
|
||||
NSUInteger conversion = [[_actionArray objectAtIndex:i] integerValue];
|
||||
|
||||
if ([track isMemberOfClass:[MP42AudioTrack class]]) {
|
||||
if (conversion == 6) {
|
||||
MP42AudioTrack *copy = [track copy];
|
||||
[copy setNeedConversion:YES];
|
||||
[copy setMixdownType:SBDolbyPlIIMixdown];
|
||||
|
||||
[(MP42AudioTrack *)track setFallbackTrack:copy];
|
||||
|
||||
[tracks addObject:copy];
|
||||
[copy release];
|
||||
}
|
||||
else if (conversion)
|
||||
[track setNeedConversion:YES];
|
||||
|
||||
switch (conversion) {
|
||||
case 6:
|
||||
[track setEnabled:NO];
|
||||
break;
|
||||
case 5:
|
||||
[(MP42AudioTrack *)track setMixdownType:nil];
|
||||
break;
|
||||
case 4:
|
||||
[(MP42AudioTrack *)track setMixdownType:SBMonoMixdown];
|
||||
break;
|
||||
case 3:
|
||||
[(MP42AudioTrack *)track setMixdownType:SBStereoMixdown];
|
||||
break;
|
||||
case 2:
|
||||
[(MP42AudioTrack *)track setMixdownType:SBDolbyMixdown];
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
[(MP42AudioTrack *)track setMixdownType:SBDolbyPlIIMixdown];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ([track isMemberOfClass:[MP42SubtitleTrack class]]) {
|
||||
if (conversion)
|
||||
[track setNeedConversion:YES];
|
||||
}
|
||||
else if ([track isMemberOfClass:[MP42VideoTrack class]]) {
|
||||
if ([[track.sourceURL pathExtension] caseInsensitiveCompare:@"264"] == NSOrderedSame ||
|
||||
[[track.sourceURL pathExtension] caseInsensitiveCompare:@"h264"] == NSOrderedSame) {
|
||||
switch(conversion) {
|
||||
case 0:
|
||||
[track setId:2398];
|
||||
break;
|
||||
case 1:
|
||||
[track setId:24];
|
||||
break;
|
||||
case 2:
|
||||
[track setId:25];
|
||||
break;
|
||||
case 3:
|
||||
[track setId:2997];
|
||||
break;
|
||||
case 4:
|
||||
[track setId:30];
|
||||
break;
|
||||
case 5:
|
||||
[track setId:50];
|
||||
break;
|
||||
case 6:
|
||||
[track setId:5994];
|
||||
break;
|
||||
case 7:
|
||||
[track setId:60];
|
||||
break;
|
||||
default:
|
||||
[track setId:2398];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[tracks addObject:track];
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
MP42Metadata *metadata = nil;
|
||||
if ([importMetadata state])
|
||||
metadata = [[[(MP42FileImporter *)[_fileImporters objectAtIndex:0] metadata] retain] autorelease];
|
||||
|
||||
[delegate importDoneWithTracks:tracks andMetadata: metadata];
|
||||
|
||||
[tracks release];
|
||||
|
||||
[tableView setDelegate:nil];
|
||||
[tableView setDataSource:nil];
|
||||
[NSApp endSheet:[self window] returnCode:NSOKButton];
|
||||
[[self window] orderOut:self];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_fileURLs release];
|
||||
[_fileImporters release];
|
||||
[_tracks release];
|
||||
|
||||
[_importCheckArray release];
|
||||
[_actionArray release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// SBImageBrowserView.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 02/09/13.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Quartz/Quartz.h>
|
||||
|
||||
@protocol SBImageBrowserViewDelegate
|
||||
@optional
|
||||
- (void)_pasteToImageBrowserView:(IKImageBrowserView *)ImageBrowserView;
|
||||
@end
|
||||
|
||||
@interface SBImageBrowserView : IKImageBrowserView <SBImageBrowserViewDelegate> {
|
||||
NSArray *_pasteboardTypes;
|
||||
}
|
||||
|
||||
@property(readwrite, retain) NSArray* _pasteboardTypes;
|
||||
|
||||
@end
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// SBImageBrowserView.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 02/09/13.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SBImageBrowserView.h"
|
||||
|
||||
@implementation SBImageBrowserView
|
||||
|
||||
@synthesize _pasteboardTypes;
|
||||
|
||||
- (BOOL)validateMenuItem:(NSMenuItem *)item
|
||||
{
|
||||
id delegate = [self delegate];
|
||||
SEL action = [item action];
|
||||
|
||||
if (action == @selector(paste:)) {
|
||||
if (![self pasteboardHasSupportedType] || ![delegate respondsToSelector:@selector(_pasteToImageBrowserView:)])
|
||||
return NO;
|
||||
else
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
return [super validateMenuItem:item];
|
||||
}
|
||||
|
||||
- (IBAction)paste:(id)sender
|
||||
{
|
||||
if ([[self delegate] respondsToSelector:@selector(_pasteToImageBrowserView:)])
|
||||
[(SBImageBrowserView *)[self delegate] _pasteToImageBrowserView:self];
|
||||
}
|
||||
|
||||
- (BOOL)pasteboardHasSupportedType {
|
||||
// has the pasteboard got a type we support?
|
||||
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
||||
NSString *bestType = [pb availableTypeFromArray:_pasteboardTypes];
|
||||
return (bestType != nil);
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_pasteboardTypes release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+94
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// MetadataImportController.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2011/01/27.
|
||||
// Copyright 2011 Douglas Stebila. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class SBTableView;
|
||||
@class SBArtworkSelector;
|
||||
@class MP42Metadata;
|
||||
|
||||
@protocol SBMetadataSearchControllerDelegate
|
||||
- (void)metadataImportDone:(MP42Metadata *)metadataToBeImported;
|
||||
@end
|
||||
|
||||
@interface SBMetadataSearchController : NSWindowController <NSTableViewDelegate> {
|
||||
id delegate;
|
||||
NSDictionary *detailBoldAttr;
|
||||
|
||||
IBOutlet NSTabView *searchMode;
|
||||
|
||||
IBOutlet NSTextField *movieName;
|
||||
IBOutlet NSPopUpButton *movieLanguage;
|
||||
IBOutlet NSPopUpButton *movieMetadataProvider;
|
||||
|
||||
IBOutlet NSComboBox *tvSeriesName;
|
||||
NSMutableArray *tvSeriesNameSearchArray;
|
||||
IBOutlet NSTextField *tvSeasonNum;
|
||||
IBOutlet NSTextField *tvEpisodeNum;
|
||||
IBOutlet NSPopUpButton *tvLanguage;
|
||||
IBOutlet NSPopUpButton *tvMetadataProvider;
|
||||
|
||||
IBOutlet NSButton *searchButton;
|
||||
id currentSearcher;
|
||||
|
||||
NSArray *resultsArray;
|
||||
IBOutlet NSTableView *resultsTable;
|
||||
MP42Metadata *selectedResult;
|
||||
NSDictionary *selectedResultTags;
|
||||
NSArray *selectedResultTagsArray;
|
||||
IBOutlet SBTableView *metadataTable;
|
||||
|
||||
IBOutlet NSButton *addButton;
|
||||
|
||||
id artworkSelectorWindow;
|
||||
|
||||
IBOutlet NSProgressIndicator *progress;
|
||||
IBOutlet NSTextField *progressText;
|
||||
|
||||
}
|
||||
|
||||
#pragma mark Initialization
|
||||
- (instancetype)initWithDelegate:(id)del;
|
||||
|
||||
#pragma mark Metadata provider
|
||||
- (void) createLanguageMenus;
|
||||
- (void) metadataProvidersSelectDefaultLanguage;
|
||||
- (IBAction) metadataProviderLanguageSelected:(id)sender;
|
||||
- (IBAction) metadataProviderSelected:(id)sender;
|
||||
|
||||
#pragma mark Search input fields
|
||||
- (void) updateSearchButtonVisibility;
|
||||
- (void) searchTVSeriesNameDone:(NSMutableArray *)seriesArray;
|
||||
|
||||
#pragma mark Search for metadata
|
||||
- (IBAction) searchForResults:(id)sender;
|
||||
- (void) searchForResultsDone:(NSArray *)metadataArray;
|
||||
|
||||
#pragma mark Load additional metadata
|
||||
- (IBAction) loadAdditionalMetadata:(id)sender;
|
||||
- (void) loadAdditionalMetadataDone:(MP42Metadata *)metadata;
|
||||
|
||||
#pragma mark Select artwork
|
||||
- (void) selectArtwork;
|
||||
- (void) selectArtworkDone:(NSIndexSet *)indexes;
|
||||
|
||||
#pragma mark Load artwork
|
||||
- (void) loadArtworks:(NSIndexSet *)indexes;
|
||||
|
||||
#pragma mark Finishing up
|
||||
- (void) addMetadata;
|
||||
- (IBAction) closeWindow: (id) sender;
|
||||
|
||||
#pragma mark Miscellaneous
|
||||
- (NSAttributedString *) boldString: (NSString *) string;
|
||||
|
||||
#pragma mark Static methods
|
||||
+ (void) clearRecentSearches;
|
||||
+ (void) deleteCachedMetadata;
|
||||
|
||||
@end
|
||||
Executable
+579
@@ -0,0 +1,579 @@
|
||||
//
|
||||
// MetadataImportController.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Douglas Stebila on 2011/01/27.
|
||||
// Copyright 2011 Douglas Stebila. All rights reserved.
|
||||
//
|
||||
#import <MP42Foundation/MP42Image.h>
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
#import <MP42Foundation/MP42Languages.h>
|
||||
|
||||
#import <MP42Foundation/RegexKitLite.h>
|
||||
|
||||
#import "SBMetadataSearchController.h"
|
||||
#import "SBArtworkSelector.h"
|
||||
#import "SBDocument.h"
|
||||
#import "MetadataImporter.h"
|
||||
|
||||
@interface SBMetadataSearchController () <SBArtworkSelectorDelegate>
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBMetadataSearchController
|
||||
|
||||
#pragma mark Initialization
|
||||
|
||||
- (instancetype)initWithDelegate:(id)del
|
||||
{
|
||||
if ((self = [super initWithWindowNibName:@"MetadataSearch"])) {
|
||||
delegate = del;
|
||||
|
||||
NSMutableParagraphStyle * ps = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
|
||||
[ps setHeadIndent: -10.0];
|
||||
[ps setAlignment:NSRightTextAlignment];
|
||||
detailBoldAttr = [[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]], NSFontAttributeName,
|
||||
ps, NSParagraphStyleAttributeName,
|
||||
[NSColor grayColor], NSForegroundColorAttributeName,
|
||||
nil] retain];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)windowDidLoad {
|
||||
|
||||
[super windowDidLoad];
|
||||
|
||||
[[self window] makeFirstResponder:movieName];
|
||||
|
||||
// metadata provider preferences
|
||||
[movieMetadataProvider selectItemWithTitle:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBMetadataPreference|Movie"]];
|
||||
[tvMetadataProvider selectItemWithTitle:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBMetadataPreference|TV"]];
|
||||
[self metadataProviderSelected:movieMetadataProvider];
|
||||
[self metadataProviderSelected:tvMetadataProvider];
|
||||
|
||||
MP42File *mp4File = [((SBDocument *) delegate) mp4File];
|
||||
|
||||
NSString *filename = nil;
|
||||
for (NSUInteger i = 0; i < [mp4File tracksCount]; i++) {
|
||||
MP42Track *track = [mp4File trackAtIndex:i];
|
||||
if ([track sourceURL]) {
|
||||
filename = [[track sourceURL] lastPathComponent];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!filename) return;
|
||||
|
||||
NSDictionary *parsed = [MetadataImporter parseFilename:filename];
|
||||
if (!parsed) return;
|
||||
|
||||
if ([@"movie" isEqualToString:(NSString *) [parsed valueForKey:@"type"]]) {
|
||||
[searchMode selectTabViewItemAtIndex:0];
|
||||
if ([parsed valueForKey:@"title"]) [movieName setStringValue:[parsed valueForKey:@"title"]];
|
||||
} else if ([@"tv" isEqualToString:(NSString *) [parsed valueForKey:@"type"]]) {
|
||||
[searchMode selectTabViewItemAtIndex:1];
|
||||
[[self window] makeFirstResponder:tvSeriesName];
|
||||
if ([parsed valueForKey:@"seriesName"]) [((NSTextField *) tvSeriesName) setStringValue:[parsed valueForKey:@"seriesName"]];
|
||||
if ([parsed valueForKey:@"seasonNum"]) [tvSeasonNum setStringValue:[parsed valueForKey:@"seasonNum"]];
|
||||
if ([parsed valueForKey:@"episodeNum"]) [tvEpisodeNum setStringValue:[parsed valueForKey:@"episodeNum"]];
|
||||
// just in case this is actually a movie, set the text in the movie field for the user's convenience
|
||||
[movieName setStringValue:[filename stringByDeletingPathExtension]];
|
||||
}
|
||||
[self updateSearchButtonVisibility];
|
||||
if ([searchButton isEnabled]) {
|
||||
[self searchForResults:nil];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#pragma mark Metadata provider
|
||||
|
||||
- (void) createLanguageMenus {
|
||||
[movieLanguage removeAllItems];
|
||||
NSArray *langs = [MetadataImporter languagesForProvider:[[movieMetadataProvider selectedItem] title]];
|
||||
for (NSString *lang in langs) {
|
||||
[movieLanguage addItemWithTitle:lang];
|
||||
}
|
||||
[tvLanguage removeAllItems];
|
||||
langs = [MetadataImporter languagesForProvider:[[tvMetadataProvider selectedItem] title]];
|
||||
for (NSString *lang in langs) {
|
||||
[tvLanguage addItemWithTitle:lang];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) metadataProvidersSelectDefaultLanguage {
|
||||
[movieLanguage selectItemWithTitle:[[NSUserDefaults standardUserDefaults] valueForKey:[NSString stringWithFormat:@"SBMetadataPreference|Movie|%@|Language", [[movieMetadataProvider selectedItem] title]]]];
|
||||
[tvLanguage selectItemWithTitle:[[NSUserDefaults standardUserDefaults] valueForKey:[NSString stringWithFormat:@"SBMetadataPreference|TV|%@|Language", [[tvMetadataProvider selectedItem] title]]]];
|
||||
}
|
||||
|
||||
- (IBAction) metadataProviderLanguageSelected:(id)sender {
|
||||
if (sender == movieLanguage) {
|
||||
[[NSUserDefaults standardUserDefaults] setValue:[[movieLanguage selectedItem] title] forKey:[NSString stringWithFormat:@"SBMetadataPreference|Movie|%@|Language", [[movieMetadataProvider selectedItem] title]]];
|
||||
} else if (sender == tvLanguage) {
|
||||
[[NSUserDefaults standardUserDefaults] setValue:[[tvLanguage selectedItem] title] forKey:[NSString stringWithFormat:@"SBMetadataPreference|TV|%@|Language", [[tvMetadataProvider selectedItem] title]]];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction) metadataProviderSelected:(id)sender {
|
||||
if (sender == movieMetadataProvider) {
|
||||
[[NSUserDefaults standardUserDefaults] setValue:[[movieMetadataProvider selectedItem] title] forKey:@"SBMetadataPreference|Movie"];
|
||||
} else if (sender == tvMetadataProvider) {
|
||||
[[NSUserDefaults standardUserDefaults] setValue:[[tvMetadataProvider selectedItem] title] forKey:@"SBMetadataPreference|TV"];
|
||||
}
|
||||
|
||||
[self createLanguageMenus];
|
||||
[self metadataProvidersSelectDefaultLanguage];
|
||||
[self searchForResults:nil];
|
||||
}
|
||||
|
||||
#pragma mark Search input fields
|
||||
|
||||
- (void)updateSearchButtonVisibility {
|
||||
if ([[[searchMode selectedTabViewItem] label] isEqualToString:@"Movie"]) {
|
||||
if ([[movieName stringValue] length] > 0) {
|
||||
[searchButton setEnabled:YES];
|
||||
return;
|
||||
}
|
||||
} else if ([[[searchMode selectedTabViewItem] label] isEqualToString:@"TV Episode"]) {
|
||||
if ([[tvSeriesName stringValue] length] > 0) {
|
||||
if (([[tvSeasonNum stringValue] length] == 0) && ([[tvEpisodeNum stringValue] length] > 0)) {
|
||||
[searchButton setEnabled:NO];
|
||||
return;
|
||||
} else {
|
||||
[searchButton setEnabled:YES];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
[searchButton setEnabled:NO];
|
||||
}
|
||||
|
||||
- (void)controlTextDidChange:(NSNotification *)aNotification {
|
||||
[self updateSearchButtonVisibility];
|
||||
[addButton setKeyEquivalent:@""];
|
||||
[searchButton setKeyEquivalent:@"\r"];
|
||||
}
|
||||
|
||||
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem {
|
||||
[self updateSearchButtonVisibility];
|
||||
}
|
||||
|
||||
- (void) searchTVSeriesNameDone:(NSMutableArray *)seriesArray {
|
||||
if (tvSeriesNameSearchArray)
|
||||
[tvSeriesNameSearchArray release];
|
||||
|
||||
tvSeriesNameSearchArray = [seriesArray retain];
|
||||
[tvSeriesNameSearchArray sortUsingSelector:@selector(compare:)];
|
||||
[tvSeriesName noteNumberOfItemsChanged];
|
||||
[tvSeriesName reloadData];
|
||||
|
||||
currentSearcher = nil;
|
||||
}
|
||||
|
||||
#pragma mark Search for results
|
||||
|
||||
- (IBAction) searchForResults: (id) sender {
|
||||
if (currentSearcher) {
|
||||
[currentSearcher cancel];
|
||||
currentSearcher = nil;
|
||||
}
|
||||
|
||||
if ([[[searchMode selectedTabViewItem] label] isEqualToString:@"Movie"] && [[movieName stringValue] length]) {
|
||||
[progress startAnimation:self];
|
||||
[progress setHidden:NO];
|
||||
[progressText setStringValue:[NSString stringWithFormat:@"Searching %@ for movie information…",
|
||||
[[movieMetadataProvider selectedItem] title]]];
|
||||
[progressText setHidden:NO];
|
||||
currentSearcher = [MetadataImporter importerForProvider:[[movieMetadataProvider selectedItem] title]];
|
||||
[currentSearcher searchMovie:[movieName stringValue] language:[movieLanguage titleOfSelectedItem] callback:self];
|
||||
} else if ([[[searchMode selectedTabViewItem] label] isEqualToString:@"TV Episode"] && [[tvSeriesName stringValue] length]) {
|
||||
[progress startAnimation:self];
|
||||
[progress setHidden:NO];
|
||||
[progressText setStringValue:[NSString stringWithFormat:@"Searching %@ for episode information…",
|
||||
[[tvMetadataProvider selectedItem] title]]];
|
||||
[progressText setHidden:NO];
|
||||
currentSearcher = [MetadataImporter importerForProvider:[[tvMetadataProvider selectedItem] title]];
|
||||
[currentSearcher searchTVSeries:[tvSeriesName stringValue] language:[tvLanguage titleOfSelectedItem] seasonNum:[tvSeasonNum stringValue] episodeNum:[tvEpisodeNum stringValue] callback:self];
|
||||
}
|
||||
else {
|
||||
// Nothing to search, reset the table view
|
||||
[resultsArray release];
|
||||
resultsArray = nil;
|
||||
selectedResult = nil;
|
||||
[resultsTable reloadData];
|
||||
[metadataTable reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) searchForResultsDone:(NSArray *)_resultsArray {
|
||||
if (resultsArray)
|
||||
[resultsArray release];
|
||||
|
||||
[progressText setHidden:YES];
|
||||
[progress setHidden:YES];
|
||||
[progress stopAnimation:self];
|
||||
resultsArray = [_resultsArray retain];
|
||||
selectedResult = nil;
|
||||
[resultsTable reloadData];
|
||||
[metadataTable reloadData];
|
||||
[self tableViewSelectionDidChange:[NSNotification notificationWithName:@"tableViewSelectionDidChange" object:resultsTable]];
|
||||
[[self window] makeFirstResponder:resultsTable];
|
||||
currentSearcher = nil;
|
||||
}
|
||||
|
||||
#pragma mark Load additional metadata
|
||||
|
||||
- (IBAction) loadAdditionalMetadata:(id) sender {
|
||||
if (currentSearcher) {
|
||||
[currentSearcher cancel];
|
||||
currentSearcher = nil;
|
||||
}
|
||||
|
||||
[addButton setEnabled:NO];
|
||||
if ([[[searchMode selectedTabViewItem] label] isEqualToString:@"Movie"]) {
|
||||
[progress startAnimation:self];
|
||||
[progress setHidden:NO];
|
||||
[progressText setStringValue:@"Downloading additional movie metadata…"];
|
||||
[progressText setHidden:NO];
|
||||
currentSearcher = [MetadataImporter importerForProvider:[[movieMetadataProvider selectedItem] title]];
|
||||
[currentSearcher loadMovieMetadata:selectedResult language:[[movieLanguage selectedItem] title] callback:self];
|
||||
} else if ([[[searchMode selectedTabViewItem] label] isEqualToString:@"TV Episode"]) {
|
||||
[progress startAnimation:self];
|
||||
[progress setHidden:NO];
|
||||
[progressText setStringValue:@"Downloading additional TV metadata…"];
|
||||
[progressText setHidden:NO];
|
||||
currentSearcher = [MetadataImporter importerForProvider:[[tvMetadataProvider selectedItem] title]];
|
||||
[currentSearcher loadTVMetadata:selectedResult language:[[tvLanguage selectedItem] title] callback:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) loadAdditionalMetadataDone:(MP42Metadata *)metadata {
|
||||
[progress setHidden:YES];
|
||||
[progressText setHidden:YES];
|
||||
[progress stopAnimation:self];
|
||||
selectedResult = metadata;
|
||||
[self selectArtwork];
|
||||
currentSearcher = nil;
|
||||
}
|
||||
|
||||
#pragma mark Select artwork
|
||||
|
||||
- (void) selectArtwork {
|
||||
if (selectedResult.artworkThumbURLs && [selectedResult.artworkThumbURLs count]) {
|
||||
if ([selectedResult.artworkThumbURLs count] == 1) {
|
||||
[self loadArtworks:[NSIndexSet indexSetWithIndex:0]];
|
||||
} else {
|
||||
artworkSelectorWindow = [[SBArtworkSelector alloc] initWithDelegate:self imageURLs:selectedResult.artworkThumbURLs artworkProviderNames:selectedResult.artworkProviderNames];
|
||||
[NSApp beginSheet:[artworkSelectorWindow window] modalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:nil];
|
||||
}
|
||||
} else {
|
||||
[self addMetadata];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) selectArtworkDone:(NSIndexSet *)indexes {
|
||||
[NSApp endSheet:[artworkSelectorWindow window]];
|
||||
[[artworkSelectorWindow window] orderOut:self];
|
||||
[artworkSelectorWindow autorelease]; artworkSelectorWindow = nil;
|
||||
|
||||
[self loadArtworks:indexes];
|
||||
}
|
||||
|
||||
#pragma mark Load artwork
|
||||
|
||||
- (void) loadArtworks:(NSIndexSet *)indexes {
|
||||
if (indexes) {
|
||||
[progress startAnimation:self];
|
||||
[progress setHidden:NO];
|
||||
[progressText setStringValue:@"Downloading artwork…"];
|
||||
[progressText setHidden:NO];
|
||||
[tvSeriesName setEnabled:NO];
|
||||
[tvSeasonNum setEnabled:NO];
|
||||
[tvEpisodeNum setEnabled:NO];
|
||||
[movieName setEnabled:NO];
|
||||
[searchButton setEnabled:NO];
|
||||
[resultsTable setEnabled:NO];
|
||||
[metadataTable setEnabled:NO];
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
dispatch_group_t group = dispatch_group_create();
|
||||
|
||||
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
|
||||
dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
|
||||
NSData *artworkData = [MetadataImporter downloadDataOrGetFromCache:[selectedResult.artworkFullsizeURLs objectAtIndex:idx]];
|
||||
|
||||
// Hack, download smaller iTunes version if big iTunes version is not available
|
||||
if (!artworkData) {
|
||||
NSString *provider = [selectedResult.artworkProviderNames objectAtIndex:idx];
|
||||
if ([provider isEqualToString:@"iTunes"]) {
|
||||
NSURL *url = [selectedResult.artworkFullsizeURLs objectAtIndex:idx];
|
||||
url = [[url URLByDeletingPathExtension] URLByAppendingPathExtension:@"600x600-75.jpg"];
|
||||
artworkData = [MetadataImporter downloadDataOrGetFromCache:url];
|
||||
}
|
||||
}
|
||||
|
||||
// Add artwork to metadata object
|
||||
if (artworkData && [artworkData length]) {
|
||||
MP42Image *artwork = [[MP42Image alloc] initWithData:artworkData type:MP42_ART_JPEG];
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
[selectedResult.artworks addObject:artwork];
|
||||
});
|
||||
[artwork release];
|
||||
}
|
||||
});
|
||||
}];
|
||||
|
||||
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
|
||||
dispatch_release(group);
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
[self addMetadata];
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
[self addMetadata];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Finishing up
|
||||
|
||||
- (void) addMetadata {
|
||||
// save TV series name in user preferences
|
||||
if ([[[searchMode selectedTabViewItem] label] isEqualToString:@"TV Episode"]) {
|
||||
NSArray *previousTVseries = [[NSUserDefaults standardUserDefaults] arrayForKey:@"Previously used TV series"];
|
||||
NSMutableArray *newTVseries;
|
||||
NSString *formattedTVshowName = [selectedResultTags objectForKey:@"TV Show"];
|
||||
if (previousTVseries == nil) {
|
||||
newTVseries = [NSMutableArray arrayWithCapacity:1];
|
||||
[newTVseries addObject:formattedTVshowName];
|
||||
[[NSUserDefaults standardUserDefaults] setObject:newTVseries forKey:@"Previously used TV series"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
} else {
|
||||
if ([previousTVseries indexOfObject:formattedTVshowName] == NSNotFound) {
|
||||
newTVseries = [NSMutableArray arrayWithArray:previousTVseries];
|
||||
[newTVseries addObject:formattedTVshowName];
|
||||
[[NSUserDefaults standardUserDefaults] setObject:newTVseries forKey:@"Previously used TV series"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ([delegate respondsToSelector:@selector(metadataImportDone:)]) {
|
||||
[delegate performSelector:@selector(metadataImportDone:) withObject:selectedResult];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction) closeWindow: (id) sender
|
||||
{
|
||||
if (currentSearcher)
|
||||
[currentSearcher cancel];
|
||||
|
||||
if ([delegate respondsToSelector:@selector(metadataImportDone:)]) {
|
||||
[delegate performSelector:@selector(metadataImportDone:) withObject:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[detailBoldAttr release];
|
||||
|
||||
[selectedResultTagsArray release];
|
||||
[tvSeriesNameSearchArray release];
|
||||
[resultsArray release];
|
||||
|
||||
if (currentSearcher) {
|
||||
[currentSearcher cancel];
|
||||
}
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
#pragma mark Privacy
|
||||
|
||||
+ (void) clearRecentSearches {
|
||||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Previously used TV series"];
|
||||
}
|
||||
|
||||
+ (void) deleteCachedMetadata {
|
||||
NSString *path = nil;
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
if ([paths count]) {
|
||||
NSString *bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
|
||||
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:bundleName];
|
||||
}
|
||||
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
|
||||
for (NSString *filename in contents) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:[path stringByAppendingPathComponent:filename] error:nil];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Miscellaneous
|
||||
|
||||
- (NSAttributedString *) boldString: (NSString *) string {
|
||||
return [[[NSAttributedString alloc] initWithString:string attributes:detailBoldAttr] autorelease];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
#pragma mark NSComboBox delegates and protocols
|
||||
|
||||
- (NSString *)comboBox:(NSComboBox *)comboBox completedString:(NSString *)uncompletedString {
|
||||
if (!uncompletedString || ([uncompletedString length] < 1)) return nil;
|
||||
if (comboBox == tvSeriesName) {
|
||||
NSArray *previousTVseries = [[NSUserDefaults standardUserDefaults] arrayForKey:@"Previously used TV series"];
|
||||
if (previousTVseries == nil) return nil;
|
||||
NSEnumerator *previousTVseriesEnum = [previousTVseries objectEnumerator];
|
||||
NSString *s;
|
||||
while ((s = (NSString *) [previousTVseriesEnum nextObject])) {
|
||||
if ([[s lowercaseString] hasPrefix:[uncompletedString lowercaseString]]) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)comboBoxWillPopUp:(NSNotification *)notification {
|
||||
if ([notification object] == tvSeriesName) {
|
||||
if ([[tvSeriesName stringValue] length] == 0) {
|
||||
[tvSeriesNameSearchArray release];
|
||||
tvSeriesNameSearchArray = [[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"Previously used TV series"]];
|
||||
[tvSeriesNameSearchArray sortUsingSelector:@selector(compare:)];
|
||||
[tvSeriesName reloadData];
|
||||
} else if ([[tvSeriesName stringValue] length] > 3) {
|
||||
[tvSeriesNameSearchArray release];
|
||||
tvSeriesNameSearchArray = [[NSMutableArray alloc] initWithCapacity:1];
|
||||
[tvSeriesNameSearchArray addObject:@"searching…"];
|
||||
[tvSeriesName reloadData];
|
||||
[currentSearcher cancel];
|
||||
currentSearcher = [MetadataImporter defaultTVProvider];
|
||||
[currentSearcher searchTVSeries:[tvSeriesName stringValue] language:[[tvLanguage selectedItem] title] callback:self];
|
||||
} else {
|
||||
tvSeriesNameSearchArray = nil;
|
||||
[tvSeriesName reloadData];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)comboBox {
|
||||
// for some unknown reason, the number of items displayed won't be correct unless these member variables get accessed
|
||||
// bug to fix!
|
||||
//NSLog(@"in numberOfItemsInComboBox; box numberOfVisibleItems = %d, cell numberOfVisibleItems = %d", (int) [comboBox numberOfVisibleItems], (int) [[comboBox cell] numberOfVisibleItems]);
|
||||
if (comboBox == tvSeriesName) {
|
||||
if (tvSeriesNameSearchArray != nil) {
|
||||
return [tvSeriesNameSearchArray count];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (id)comboBox:(NSComboBox *)comboBox objectValueForItemAtIndex:(NSInteger)index {
|
||||
if (comboBox == tvSeriesName) {
|
||||
if (tvSeriesNameSearchArray != nil) {
|
||||
return [tvSeriesNameSearchArray objectAtIndex:index];
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
#pragma mark NSTableView delegates and protocols
|
||||
|
||||
- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView {
|
||||
if (tableView == resultsTable) {
|
||||
if (resultsArray != nil) {
|
||||
return [resultsArray count];
|
||||
}
|
||||
} else if (tableView == (NSTableView *) metadataTable) {
|
||||
if (selectedResult != nil) {
|
||||
return [selectedResultTagsArray count];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex {
|
||||
if (tableView == resultsTable) {
|
||||
if (resultsArray != nil) {
|
||||
MP42Metadata *result = [resultsArray objectAtIndex:rowIndex];
|
||||
if ((result.mediaKind == 10) && ([resultsArray count] > 1)) { // TV show
|
||||
return [NSString stringWithFormat:@"%@x%@ - %@", [result.tagsDict valueForKey:@"TV Season"], [result.tagsDict valueForKey:@"TV Episode #"], [result.tagsDict valueForKey:@"Name"]];
|
||||
} else {
|
||||
return [result.tagsDict valueForKey:@"Name"];
|
||||
}
|
||||
}
|
||||
} else if (tableView == (NSTableView *) metadataTable) {
|
||||
if (selectedResult != nil) {
|
||||
if ([tableColumn.identifier isEqualToString:@"name"]) {
|
||||
return [self boldString:[selectedResultTagsArray objectAtIndex:rowIndex]];
|
||||
}
|
||||
if ([tableColumn.identifier isEqualToString:@"value"]) {
|
||||
return [selectedResultTags objectForKey:[selectedResultTagsArray objectAtIndex:rowIndex]];
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
static NSInteger sortFunction (id ldict, id rdict, void *context) {
|
||||
NSComparisonResult rc;
|
||||
|
||||
NSInteger right = [(NSArray*) context indexOfObject:rdict];
|
||||
NSInteger left = [(NSArray*) context indexOfObject:ldict];
|
||||
|
||||
if (right < left)
|
||||
rc = NSOrderedDescending;
|
||||
else
|
||||
rc = NSOrderedAscending;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification {
|
||||
if ([aNotification object] == resultsTable || [aNotification object] == metadataTable) {
|
||||
if (/*resultsArray && */[resultsArray count] > 0) {
|
||||
selectedResult = [resultsArray objectAtIndex:[resultsTable selectedRow]];
|
||||
selectedResultTags = selectedResult.tagsDict;
|
||||
if (selectedResultTagsArray) [selectedResultTagsArray release];
|
||||
selectedResultTagsArray = [[[selectedResultTags allKeys] sortedArrayUsingFunction:sortFunction context:[selectedResult availableMetadata]] retain];
|
||||
[metadataTable reloadData];
|
||||
[addButton setEnabled:YES];
|
||||
[addButton setKeyEquivalent:@"\r"];
|
||||
[searchButton setKeyEquivalent:@""];
|
||||
}
|
||||
} else {
|
||||
[addButton setEnabled:NO];
|
||||
[addButton setKeyEquivalent:@""];
|
||||
[searchButton setKeyEquivalent:@"\r"];
|
||||
}
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row {
|
||||
if (tableView != (NSTableView *) metadataTable) return [tableView rowHeight];
|
||||
|
||||
// It is important to use a constant value when calculating the height. Querying the tableColumn width will not work, since it dynamically changes as the user resizes -- however, we don't get a notification that the user "did resize" it until after the mouse is let go. We use the latter as a hook for telling the table that the heights changed. We must return the same height from this method every time, until we tell the table the heights have changed. Not doing so will quicly cause drawing problems.
|
||||
NSTableColumn *tableColumnToWrap = (NSTableColumn *) [[tableView tableColumns] objectAtIndex:1];
|
||||
NSInteger columnToWrap = [tableView.tableColumns indexOfObject:tableColumnToWrap];
|
||||
|
||||
// Grab the fully prepared cell with our content filled in. Note that in IB the cell's Layout is set to Wraps.
|
||||
NSCell *cell = [tableView preparedCellAtColumn:columnToWrap row:row];
|
||||
|
||||
// See how tall it naturally would want to be if given a restricted with, but unbound height
|
||||
NSRect constrainedBounds = NSMakeRect(0, 0, [tableColumnToWrap width], CGFLOAT_MAX);
|
||||
NSSize naturalSize = [cell cellSizeForBounds:constrainedBounds];
|
||||
|
||||
// Make sure we have a minimum height -- use the table's set height as the minimum.
|
||||
if (naturalSize.height > [tableView rowHeight]) {
|
||||
return naturalSize.height;
|
||||
} else {
|
||||
return [tableView rowHeight];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// SBPrefsController.h
|
||||
//
|
||||
// Created by Damiano Galassi on 13/05/08.
|
||||
// Copyright 2008 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class SBMovieViewController;
|
||||
@class SBTableView;
|
||||
|
||||
@interface SBPrefsController : NSWindowController <NSToolbarDelegate, NSWindowDelegate> {
|
||||
IBOutlet NSView *generalView, *advancedView, *setsView;
|
||||
|
||||
id _popover;
|
||||
SBMovieViewController *_controller;
|
||||
NSInteger _currentRow;
|
||||
|
||||
IBOutlet SBTableView *tableView;
|
||||
IBOutlet NSButton *removeSet;
|
||||
}
|
||||
|
||||
+ (void)registerUserDefaults;
|
||||
|
||||
- (instancetype)init;
|
||||
- (IBAction)clearRecentSearches:(id) sender;
|
||||
- (IBAction)deleteCachedMetadata:(id) sender;
|
||||
- (IBAction)toggleInfoWindow:(id) sender;
|
||||
|
||||
- (IBAction)deletePreset:(id) sender;
|
||||
|
||||
- (IBAction)updateRatingsCountry:(id)sender;
|
||||
|
||||
@end
|
||||
Executable
+293
@@ -0,0 +1,293 @@
|
||||
//
|
||||
// SBPrefsController.m
|
||||
//
|
||||
// Created by Damiano Galassi on 13/05/08.
|
||||
// Copyright 2008 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <MP42Foundation/MP42Metadata.h>
|
||||
#import <MP42Foundation/MP42Ratings.h>
|
||||
|
||||
#import "SBPrefsController.h"
|
||||
#import "SBMetadataSearchController.h"
|
||||
#import "SBPresetManager.h"
|
||||
#import "SBTableView.h"
|
||||
#import "SBMovieViewController.h"
|
||||
|
||||
#import "MAAttachedWindow.h"
|
||||
|
||||
#define TOOLBAR_GENERAL @"TOOLBAR_GENERAL"
|
||||
#define TOOLBAR_ADVANCED @"TOOLBAR_ADVANCED"
|
||||
#define TOOLBAR_SETS @"TOOLBAR_SETS"
|
||||
|
||||
@interface SBPrefsController ()
|
||||
- (NSArray *)ratingsCountries;
|
||||
|
||||
- (void)setPrefView:(id)sender;
|
||||
- (NSToolbarItem *)toolbarItemWithIdentifier:(NSString *)identifier
|
||||
label:(NSString *)label
|
||||
image:(NSImage *)image;
|
||||
@end
|
||||
|
||||
@implementation SBPrefsController
|
||||
|
||||
+ (void)registerUserDefaults
|
||||
{
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"m4v", @"SBSaveFormat",
|
||||
@"0", @"defaultSaveFormat",
|
||||
@"YES", @"SBQueueOptimize",
|
||||
@"YES", @"SBOrganizeAlternateGroups",
|
||||
@"1", @"SBAudioMixdown",
|
||||
@"96", @"SBAudioBitrate",
|
||||
@"YES", @"SBAudioConvertAC3",
|
||||
@"YES", @"SBAudioKeepAC3",
|
||||
@"YES", @"SBSubtitleConvertBitmap",
|
||||
@"All countries", @"SBRatingsCountry",
|
||||
@"m4v", @"SBSaveFormat",
|
||||
@"NO", @"mp464bitOffset",
|
||||
@"YES", @"chaptersPreviewTrack",
|
||||
@"TheMovieDB", @"SBMetadataPreference|Movie",
|
||||
@"USA (English)", @"SBMetadataPreference|Movie|iTunes Store|Language",
|
||||
@"English", @"SBMetadataPreference|Movie|TheMovieDB|Language",
|
||||
@"TheTVDB", @"SBMetadataPreference|TV",
|
||||
@"USA (English)", @"SBMetadataPreference|TV|iTunes Store|Language",
|
||||
@"English", @"SBMetadataPreference|TV|TheTVDB|Language",
|
||||
nil]];
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if ((self = [super initWithWindowNibName:@"Prefs"])) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(updateTableView:)
|
||||
name:@"SBPresetManagerUpdatedNotification" object:nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"] autorelease];
|
||||
[toolbar setDelegate:self];
|
||||
[toolbar setAllowsUserCustomization:NO];
|
||||
[toolbar setDisplayMode:NSToolbarDisplayModeIconAndLabel];
|
||||
[toolbar setSizeMode:NSToolbarSizeModeRegular];
|
||||
[[self window] setToolbar:toolbar];
|
||||
|
||||
[toolbar setSelectedItemIdentifier:TOOLBAR_GENERAL];
|
||||
[self setPrefView:nil];
|
||||
}
|
||||
|
||||
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
|
||||
itemForItemIdentifier:(NSString *)ident
|
||||
willBeInsertedIntoToolbar:(BOOL)flag
|
||||
{
|
||||
if ([ident isEqualToString:TOOLBAR_GENERAL]) {
|
||||
return [self toolbarItemWithIdentifier:ident
|
||||
label:NSLocalizedString(@"General", @"Preferences General Toolbar Item")
|
||||
image:[NSImage imageNamed:NSImageNamePreferencesGeneral]];
|
||||
}
|
||||
else if ([ident isEqualToString:TOOLBAR_ADVANCED]) {
|
||||
return [self toolbarItemWithIdentifier:ident
|
||||
label:NSLocalizedString(@"Advanced", @"Preferences Audio Toolbar Item")
|
||||
image:[NSImage imageNamed:NSImageNameAdvanced]];
|
||||
}
|
||||
else if ([ident isEqualToString:TOOLBAR_SETS]) {
|
||||
return [self toolbarItemWithIdentifier:ident
|
||||
label:NSLocalizedString(@"Sets", @"Preferences Sets Toolbar Item")
|
||||
image:[NSImage imageNamed:NSImageNameFolderSmart]];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
|
||||
{
|
||||
return [self toolbarDefaultItemIdentifiers: toolbar];
|
||||
}
|
||||
|
||||
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
|
||||
{
|
||||
return [self toolbarAllowedItemIdentifiers: toolbar];
|
||||
}
|
||||
|
||||
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
|
||||
{
|
||||
return [NSArray arrayWithObjects: TOOLBAR_GENERAL, TOOLBAR_SETS, TOOLBAR_ADVANCED, nil];
|
||||
}
|
||||
|
||||
- (IBAction)clearRecentSearches:(id)sender {
|
||||
[SBMetadataSearchController clearRecentSearches];
|
||||
}
|
||||
|
||||
- (IBAction)deleteCachedMetadata:(id)sender {
|
||||
[SBMetadataSearchController deleteCachedMetadata];
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
|
||||
SBPresetManager *presetManager = [SBPresetManager sharedManager];
|
||||
return [[presetManager presets] count];
|
||||
}
|
||||
|
||||
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn
|
||||
row:(NSInteger)rowIndex {
|
||||
if ([aTableColumn.identifier isEqualToString:@"name"]) {
|
||||
SBPresetManager *presetManager = [SBPresetManager sharedManager];
|
||||
return [[[presetManager presets] objectAtIndex:rowIndex] presetName];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (IBAction)deletePreset:(id)sender
|
||||
{
|
||||
[self closePopOver:self];
|
||||
|
||||
NSInteger rowIndex = [tableView selectedRow];
|
||||
SBPresetManager *presetManager = [SBPresetManager sharedManager];
|
||||
[presetManager removePresetAtIndex:rowIndex];
|
||||
[tableView reloadData];
|
||||
}
|
||||
|
||||
- (IBAction)closePopOver:(id)sender
|
||||
{
|
||||
if(_popover) {
|
||||
if (!NSClassFromString(@"NSPopover")) {
|
||||
[[self window] removeChildWindow:_popover];
|
||||
[_popover orderOut:self];
|
||||
}
|
||||
else
|
||||
[_popover close];
|
||||
|
||||
[_popover release];
|
||||
_popover = nil;
|
||||
[_controller release];
|
||||
_controller = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)toggleInfoWindow:(id)sender
|
||||
{
|
||||
if (_currentRow == [tableView clickedRow] && _popover)
|
||||
[self closePopOver:sender];
|
||||
else {
|
||||
_currentRow = [tableView clickedRow];
|
||||
[self closePopOver:sender];
|
||||
|
||||
SBPresetManager *presetManager = [SBPresetManager sharedManager];
|
||||
_controller = [[SBMovieViewController alloc] initWithNibName:@"MovieView" bundle:nil];
|
||||
[_controller setMetadata:[[presetManager presets] objectAtIndex:_currentRow]];
|
||||
|
||||
if (NSClassFromString(@"NSPopover")) {
|
||||
_popover = [[NSPopover alloc] init];
|
||||
((NSPopover *)_popover).contentViewController = _controller;
|
||||
((NSPopover *)_popover).contentSize = NSMakeSize(480.0f, 500.0f);
|
||||
|
||||
[_popover showRelativeToRect:[tableView frameOfCellAtColumn:1 row:_currentRow] ofView:tableView preferredEdge:NSMaxYEdge];
|
||||
}
|
||||
else {
|
||||
NSInteger row = [tableView selectedRow];
|
||||
|
||||
NSRect cellFrame = [tableView frameOfCellAtColumn:1 row:row];
|
||||
NSRect tableFrame = [[[tableView superview] superview]frame];
|
||||
|
||||
NSPoint windowPoint = NSMakePoint(NSMidX(cellFrame) + 20,
|
||||
NSHeight(tableFrame) + tableFrame.origin.y - cellFrame.origin.y - (cellFrame.size.height / 2) - 8);
|
||||
|
||||
_popover = [[MAAttachedWindow alloc] initWithView:[_controller view]
|
||||
attachedToPoint:windowPoint
|
||||
inWindow:[self window]
|
||||
onSide:MAPositionBottom
|
||||
atDistance:0];
|
||||
|
||||
[_popover setBackgroundColor:[NSColor colorWithCalibratedRed:0.98 green:0.98 blue:1 alpha:0.9]];
|
||||
[_popover setDelegate:self];
|
||||
[(MAAttachedWindow *)_popover setCornerRadius:6];
|
||||
|
||||
[[self window] addChildWindow:_popover ordered:NSWindowAbove];
|
||||
|
||||
[_popover setAlphaValue:0.0];
|
||||
|
||||
[NSAnimationContext beginGrouping];
|
||||
[[NSAnimationContext currentContext] setDuration:0.2];
|
||||
[_popover makeKeyAndOrderFront:self];
|
||||
[[_popover animator] setAlphaValue:1.0];
|
||||
[NSAnimationContext endGrouping];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateTableView:(id)sender
|
||||
{
|
||||
[tableView reloadData];
|
||||
}
|
||||
|
||||
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
|
||||
{
|
||||
if ([tableView selectedRow] != -1)
|
||||
[removeSet setEnabled:YES];
|
||||
else
|
||||
[removeSet setEnabled:NO];
|
||||
}
|
||||
|
||||
- (NSArray *)ratingsCountries {
|
||||
return [[MP42Ratings defaultManager] ratingsCountries];
|
||||
}
|
||||
|
||||
- (IBAction) updateRatingsCountry:(id)sender {
|
||||
[[MP42Ratings defaultManager] updateRatingsCountry];
|
||||
}
|
||||
|
||||
- (void)setPrefView:(id)sender
|
||||
{
|
||||
NSView *view = generalView;
|
||||
if (sender) {
|
||||
NSString *identifier = [sender itemIdentifier];
|
||||
if ([identifier isEqualToString: TOOLBAR_ADVANCED])
|
||||
view = advancedView;
|
||||
else if ([identifier isEqualToString: TOOLBAR_SETS])
|
||||
view = setsView;
|
||||
}
|
||||
|
||||
NSWindow *window = [self window];
|
||||
if ([window contentView] == view)
|
||||
return;
|
||||
|
||||
NSRect windowRect = [window frame];
|
||||
CGFloat difference = ([view frame].size.height - [[window contentView] frame].size.height);
|
||||
windowRect.origin.y -= difference;
|
||||
windowRect.size.height += difference;
|
||||
|
||||
[view setHidden:YES];
|
||||
[window setContentView:view];
|
||||
[window setFrame:windowRect display:YES animate:YES];
|
||||
[view setHidden:NO];
|
||||
|
||||
//set title label
|
||||
if (sender)
|
||||
[window setTitle:[sender label]];
|
||||
else {
|
||||
NSToolbar *toolbar = [window toolbar];
|
||||
NSString *itemIdentifier = [toolbar selectedItemIdentifier];
|
||||
for (NSToolbarItem *item in [toolbar items])
|
||||
if ([[item itemIdentifier] isEqualToString:itemIdentifier]) {
|
||||
[window setTitle: [item label]];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSToolbarItem *)toolbarItemWithIdentifier:(NSString *)identifier
|
||||
label:(NSString *)label
|
||||
image:(NSImage *)image
|
||||
{
|
||||
NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:identifier];
|
||||
[item setLabel:label];
|
||||
[item setImage:image];
|
||||
[item setAction:@selector(setPrefView:)];
|
||||
[item setAutovalidates:NO];
|
||||
return [item autorelease];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// SBPresetManager.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 02/01/11.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class MP42Metadata;
|
||||
|
||||
extern NSString *SBPresetManagerUpdatedNotification;
|
||||
|
||||
@interface SBPresetManager : NSObject {
|
||||
NSMutableArray *_presets;
|
||||
}
|
||||
|
||||
+ (SBPresetManager *)sharedManager;
|
||||
|
||||
- (void)newSetFromExistingMetadata:(MP42Metadata *)set;
|
||||
- (BOOL)savePresets;
|
||||
|
||||
- (BOOL)removePresetAtIndex:(NSUInteger)index;
|
||||
|
||||
@property(readonly) NSArray *presets;
|
||||
|
||||
@end
|
||||
Executable
+154
@@ -0,0 +1,154 @@
|
||||
//
|
||||
// SBPresetManager.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 02/01/11.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBPresetManager.h"
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
|
||||
/// Notification sent to update presets lists.
|
||||
NSString *SBPresetManagerUpdatedNotification = @"SBPresetManagerUpdatedNotification";
|
||||
|
||||
@interface SBPresetManager ()
|
||||
- (BOOL)loadPresets;
|
||||
- (BOOL)savePresets;
|
||||
- (NSString *)appSupportPath;
|
||||
- (BOOL)removePresetWithName:(NSString*)name;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBPresetManager
|
||||
|
||||
+ (SBPresetManager *)sharedManager
|
||||
{
|
||||
static dispatch_once_t pred;
|
||||
static SBPresetManager *sharedPresetManager = nil;
|
||||
|
||||
dispatch_once(&pred, ^{ sharedPresetManager = [[self alloc] init]; });
|
||||
return sharedPresetManager;
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
if ((self = [super init])) {
|
||||
_presets = [[NSMutableArray alloc] init];
|
||||
|
||||
[self loadPresets];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)updateNotification
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SBPresetManagerUpdatedNotification object:self];
|
||||
}
|
||||
|
||||
- (void)newSetFromExistingMetadata:(MP42Metadata *)set
|
||||
{
|
||||
id newSet = [set copy];
|
||||
[_presets addObject:newSet];
|
||||
[newSet release];
|
||||
|
||||
[self savePresets];
|
||||
[self updateNotification];
|
||||
}
|
||||
|
||||
- (NSString *)appSupportPath
|
||||
{
|
||||
NSString *appSupportPath = nil;
|
||||
|
||||
NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,
|
||||
NSUserDomainMask,
|
||||
YES);
|
||||
if ([allPaths count])
|
||||
appSupportPath = [[allPaths objectAtIndex:0] stringByAppendingPathComponent:@"Subler"];
|
||||
|
||||
return appSupportPath;
|
||||
}
|
||||
|
||||
- (BOOL)loadPresets
|
||||
{
|
||||
NSString *file;
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString *appSupportPath = [self appSupportPath];
|
||||
MP42Metadata *newPreset;
|
||||
|
||||
if (!appSupportPath)
|
||||
return NO;
|
||||
|
||||
NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:appSupportPath];
|
||||
while ((file = [dirEnum nextObject])) {
|
||||
if ([[file pathExtension] isEqualToString:@"sbpreset"]) {
|
||||
@try {
|
||||
newPreset = [NSKeyedUnarchiver unarchiveObjectWithFile:[appSupportPath stringByAppendingPathComponent:file]];
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
continue;
|
||||
}
|
||||
|
||||
newPreset.isEdited = NO;
|
||||
[_presets addObject:newPreset];
|
||||
}
|
||||
}
|
||||
|
||||
if (![_presets count])
|
||||
return NO;
|
||||
else
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)savePresets
|
||||
{
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString *appSupportPath = [self appSupportPath];
|
||||
BOOL noErr = YES;
|
||||
|
||||
|
||||
if (!appSupportPath)
|
||||
return NO;
|
||||
|
||||
if (![fileManager fileExistsAtPath:appSupportPath])
|
||||
[fileManager createDirectoryAtPath:appSupportPath withIntermediateDirectories:noErr attributes:nil error:NULL];
|
||||
|
||||
for (MP42Metadata *object in _presets) {
|
||||
if ([object isEdited]) {
|
||||
NSString *saveLocation = [NSString stringWithFormat:@"%@/%@.sbpreset", appSupportPath, [object presetName]];
|
||||
noErr = [NSKeyedArchiver archiveRootObject:object
|
||||
toFile:saveLocation];
|
||||
}
|
||||
}
|
||||
return noErr;
|
||||
}
|
||||
|
||||
- (BOOL)removePresetAtIndex:(NSUInteger)index
|
||||
{
|
||||
NSString *name = [[_presets objectAtIndex:index] presetName];
|
||||
[_presets removeObjectAtIndex:index];
|
||||
|
||||
[self updateNotification];
|
||||
|
||||
return [self removePresetWithName:name];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)removePresetWithName:(NSString *)name
|
||||
{
|
||||
BOOL err = NO;
|
||||
NSString *appSupportPath = [self appSupportPath];
|
||||
|
||||
if (!appSupportPath)
|
||||
return NO;
|
||||
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
err = [fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/%@.sbpreset", appSupportPath, name]
|
||||
error:NULL];
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@synthesize presets = _presets;
|
||||
|
||||
@end
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// SBQueueController.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 12/08/11.
|
||||
// Copyright 2011 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <IOKit/pwr_mgt/IOPMLib.h>
|
||||
|
||||
@class SBQueueItem;
|
||||
@class SBTableView;
|
||||
@class MP42File;
|
||||
|
||||
typedef enum SBQueueStatus : NSUInteger {
|
||||
SBQueueStatusUnknown = 0,
|
||||
SBQueueStatusWorking,
|
||||
SBQueueStatusCompleted,
|
||||
SBQueueStatusFailed,
|
||||
SBQueueStatusCancelled,
|
||||
} SBQueueStatus;
|
||||
|
||||
@interface SBQueueController : NSWindowController {
|
||||
IBOutlet NSButton *start;
|
||||
IBOutlet NSButton *open;
|
||||
|
||||
IBOutlet NSTextField *countLabel;
|
||||
IBOutlet NSProgressIndicator *progressIndicator;
|
||||
|
||||
IBOutlet NSButton *OptimizeOption;
|
||||
IBOutlet NSButton *MetadataOption;
|
||||
IBOutlet NSButton *ITunesGroupsOption;
|
||||
IBOutlet NSButton *AutoStartOption;
|
||||
IBOutlet NSBox *optionsBox;
|
||||
BOOL optionsStatus;
|
||||
|
||||
IBOutlet NSScrollView *tableScrollView;
|
||||
IBOutlet SBTableView *tableView;
|
||||
|
||||
NSURL *destination;
|
||||
BOOL customDestination;
|
||||
IBOutlet NSPopUpButton *destButton;
|
||||
|
||||
NSImage *docImg;
|
||||
|
||||
dispatch_queue_t queue;
|
||||
MP42File *_currentMP4;
|
||||
|
||||
NSMutableArray *filesArray;
|
||||
SBQueueStatus status;
|
||||
|
||||
IOPMAssertionID _assertionID;
|
||||
BOOL _cancelled;
|
||||
}
|
||||
|
||||
@property(readonly) SBQueueStatus status;
|
||||
|
||||
+ (SBQueueController *)sharedManager;
|
||||
|
||||
- (void)start:(id)sender;
|
||||
- (void)stop:(id)sender;
|
||||
|
||||
- (void)addItem:(SBQueueItem*)item;
|
||||
|
||||
- (BOOL)saveQueueToDisk;
|
||||
|
||||
- (IBAction)removeSelectedItems:(id)sender;
|
||||
- (IBAction)removeCompletedItems:(id)sender;
|
||||
|
||||
- (IBAction)edit:(id)sender;
|
||||
- (IBAction)showInFinder:(id)sender;
|
||||
|
||||
- (IBAction)toggleStartStop:(id)sender;
|
||||
- (IBAction)toggleOptions:(id)sender;
|
||||
|
||||
- (IBAction)open:(id)sender;
|
||||
- (IBAction)chooseDestination:(id)sender;
|
||||
- (IBAction)destination:(id)sender;
|
||||
|
||||
@end
|
||||
Executable
+1002
File diff suppressed because it is too large.
Load diff
Executable
+48
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// SBQueueItem.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 16/08/11.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class MP42File;
|
||||
|
||||
typedef enum SBQueueItemStatus : NSInteger {
|
||||
SBQueueItemtatusUnknown = 0,
|
||||
SBQueueItemStatusReady,
|
||||
SBQueueItemStatusWorking,
|
||||
SBQueueItemStatusCompleted,
|
||||
SBQueueItemStatusFailed,
|
||||
SBQueueItemStatusCancelled,
|
||||
} SBQueueItemStatus;
|
||||
|
||||
@interface SBQueueItem : NSObject <NSCoding> {
|
||||
MP42File *mp4File;
|
||||
NSURL *fileURL;
|
||||
NSURL *destURL;
|
||||
NSDictionary *attributes;
|
||||
|
||||
SBQueueItemStatus status;
|
||||
BOOL humanEdited;
|
||||
}
|
||||
|
||||
@property (atomic, readonly) MP42File *mp4File;
|
||||
@property (atomic, readonly) NSDictionary *attributes;
|
||||
@property (atomic, readonly) NSURL *URL;
|
||||
@property (atomic, retain, readwrite) NSURL *destURL;
|
||||
|
||||
@property (atomic, readwrite) SBQueueItemStatus status;
|
||||
|
||||
- (instancetype)initWithURL:(NSURL *)URL;
|
||||
+ (instancetype)itemWithURL:(NSURL *)URL;
|
||||
|
||||
- (instancetype)initWithMP4:(MP42File *)MP4;
|
||||
- (instancetype)initWithMP4:(MP42File *)MP4 url:(NSURL *)URL attributes:(NSDictionary *)dict;
|
||||
|
||||
+ (instancetype)itemWithMP4:(MP42File *)MP4;
|
||||
+ (instancetype)itemWithMP4:(MP42File *)MP4 url:(NSURL *)URL attributes:(NSDictionary *)dict;
|
||||
|
||||
@end
|
||||
Executable
+152
@@ -0,0 +1,152 @@
|
||||
//
|
||||
// SBQueueItem.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 16/08/11.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBQueueItem.h"
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
|
||||
@implementation SBQueueItem
|
||||
|
||||
@synthesize attributes;
|
||||
@synthesize URL = fileURL;
|
||||
@synthesize destURL;
|
||||
@synthesize mp4File;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithURL:(NSURL*)URL {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
fileURL = [URL retain];
|
||||
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
unsigned long long originalFileSize = [[[fileManager attributesOfItemAtPath:[fileURL path] error:nil] valueForKey:NSFileSize] unsignedLongLongValue];
|
||||
if (originalFileSize > 4200000000) {
|
||||
attributes = [[NSDictionary alloc] initWithObjectsAndKeys:@YES, MP4264BitData, nil];
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype)itemWithURL:(NSURL*)URL
|
||||
{
|
||||
return [[[SBQueueItem alloc] initWithURL:URL] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithMP4:(MP42File*)MP4 {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
mp4File = [MP4 retain];
|
||||
|
||||
if ([MP4 URL])
|
||||
fileURL = [[MP4 URL] retain];
|
||||
else {
|
||||
for (NSUInteger i = 0; i < [mp4File tracksCount]; i++) {
|
||||
MP42Track *track = [mp4File trackAtIndex:i];
|
||||
if ([track sourceURL]) {
|
||||
fileURL = [[track sourceURL] retain];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
status = SBQueueItemStatusReady;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype)itemWithMP4:(MP42File*)MP4
|
||||
{
|
||||
return [[[SBQueueItem alloc] initWithMP4:MP4] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithMP4:(MP42File*)MP4 url:(NSURL*)URL attributes:(NSDictionary*)dict
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
mp4File = [MP4 retain];
|
||||
fileURL = [URL retain];
|
||||
destURL = [URL retain];
|
||||
attributes = [dict retain];
|
||||
|
||||
status = SBQueueItemStatusReady;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype)itemWithMP4:(MP42File*)MP4 url:(NSURL*)URL attributes:(NSDictionary*)dict
|
||||
{
|
||||
return [[[SBQueueItem alloc] initWithMP4:MP4 url:URL attributes:dict] autorelease];
|
||||
}
|
||||
|
||||
- (SBQueueItemStatus)status
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
- (void) setStatus:(SBQueueItemStatus)itemStatus
|
||||
{
|
||||
status = itemStatus;
|
||||
if (status == SBQueueItemStatusCompleted) {
|
||||
if (mp4File) {
|
||||
[mp4File release];
|
||||
mp4File = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[attributes release];
|
||||
[fileURL release];
|
||||
[destURL release];
|
||||
[mp4File release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
[coder encodeInt:1 forKey:@"SBQueueItemTagEncodeVersion"];
|
||||
|
||||
[coder encodeObject:mp4File forKey:@"SBQueueItemMp4File"];
|
||||
[coder encodeObject:fileURL forKey:@"SBQueueItemFileURL"];
|
||||
[coder encodeObject:destURL forKey:@"SBQueueItemDestURL"];
|
||||
[coder encodeObject:attributes forKey:@"SBQueueItemAttributes"];
|
||||
|
||||
[coder encodeInt:status forKey:@"SBQueueItemStatus"];
|
||||
[coder encodeInt:humanEdited forKey:@"SBQueueItemHumanEdited"];
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)decoder
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
mp4File = [[decoder decodeObjectForKey:@"SBQueueItemMp4File"] retain];
|
||||
|
||||
fileURL = [[decoder decodeObjectForKey:@"SBQueueItemFileURL"] retain];
|
||||
destURL = [[decoder decodeObjectForKey:@"SBQueueItemDestURL"] retain];
|
||||
attributes = [[decoder decodeObjectForKey:@"SBQueueItemAttributes"] retain];
|
||||
|
||||
status = [decoder decodeIntForKey:@"SBQueueItemStatus"];
|
||||
humanEdited = [decoder decodeIntForKey:@"SBQueueItemHumanEdited"];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// SBTableView.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 17/06/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@protocol SBTableViewDelegate
|
||||
@optional
|
||||
- (void)_deleteSelectionFromTableView:(NSTableView *)tableView;
|
||||
- (void)_copySelectionFromTableView:(NSTableView *)tableView;
|
||||
- (void)_cutSelectionFromTableView:(NSTableView *)tableView;
|
||||
- (void)_pasteToTableView:(NSTableView *)tableView;
|
||||
@end
|
||||
|
||||
@interface SBTableView : NSTableView<SBTableViewDelegate> {
|
||||
NSArray *_pasteboardTypes;
|
||||
}
|
||||
- (void)keyDown:(NSEvent *)event;
|
||||
@property(readwrite, retain) NSArray* _pasteboardTypes;
|
||||
@end
|
||||
|
||||
Executable
+102
@@ -0,0 +1,102 @@
|
||||
//
|
||||
// SBTableView.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 17/06/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBTableView.h"
|
||||
|
||||
|
||||
@implementation SBTableView
|
||||
|
||||
- (void)keyDown:(NSEvent *)event
|
||||
{
|
||||
id delegate = [self delegate];
|
||||
|
||||
unichar key = [[event charactersIgnoringModifiers] characterAtIndex:0];
|
||||
if (key == NSEnterCharacter || key == NSCarriageReturnCharacter)
|
||||
[self editColumn:1 row:[self selectedRow] withEvent:nil select:YES];
|
||||
else if ((key == NSDeleteCharacter || key == NSDeleteFunctionKey) && [delegate respondsToSelector:@selector(_deleteSelectionFromTableView:)]) {
|
||||
if ([self selectedRow] == -1)
|
||||
NSBeep();
|
||||
else
|
||||
[delegate _deleteSelectionFromTableView:self];
|
||||
return;
|
||||
}
|
||||
else if (key == 27) {
|
||||
[self deselectAll:self];
|
||||
return;
|
||||
}
|
||||
else
|
||||
[super keyDown:event];
|
||||
}
|
||||
|
||||
- (IBAction)delete:(id)sender
|
||||
{
|
||||
if ([self selectedRow] == -1)
|
||||
return;
|
||||
else if ([[self delegate] respondsToSelector:@selector(_deleteSelectionFromTableView:)])
|
||||
[(SBTableView *)[self delegate] _deleteSelectionFromTableView:self];
|
||||
}
|
||||
|
||||
- (IBAction)copy:(id)sender {
|
||||
if ([self selectedRow] == -1)
|
||||
return;
|
||||
else if ([[self delegate] respondsToSelector:@selector(_copySelectionFromTableView:)])
|
||||
[(SBTableView *)[self delegate] _copySelectionFromTableView:self];
|
||||
}
|
||||
|
||||
- (IBAction)cut:(id)sender {
|
||||
if ([self selectedRow] == -1)
|
||||
return;
|
||||
else if ([[self delegate] respondsToSelector:@selector(_cutSelectionFromTableView:)])
|
||||
[(SBTableView *)[self delegate] _cutSelectionFromTableView:self];
|
||||
}
|
||||
|
||||
- (IBAction)paste:(id)sender {
|
||||
if ([[self delegate] respondsToSelector:@selector(_pasteToTableView:)])
|
||||
[(SBTableView *)[self delegate] _pasteToTableView:self];
|
||||
}
|
||||
|
||||
- (BOOL)pasteboardHasSupportedType {
|
||||
// has the pasteboard got a type we support?
|
||||
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
||||
NSString *bestType = [pb availableTypeFromArray:_pasteboardTypes];
|
||||
return (bestType != nil);
|
||||
}
|
||||
|
||||
- (BOOL)validateMenuItem:(NSMenuItem *)item
|
||||
{
|
||||
id delegate = [self delegate];
|
||||
SEL action = [item action];
|
||||
|
||||
if (action == @selector(delete:))
|
||||
if ([self selectedRow] == -1 || ![delegate respondsToSelector:@selector(_deleteSelectionFromTableView:)])
|
||||
return NO;
|
||||
|
||||
if (action == @selector(copy:))
|
||||
if ([self selectedRow] == -1 || ![delegate respondsToSelector:@selector(_copySelectionFromTableView:)])
|
||||
return NO;
|
||||
|
||||
if (action == @selector(cut:))
|
||||
if ([self selectedRow] == -1 || ![delegate respondsToSelector:@selector(_cutSelectionFromTableView:)])
|
||||
return NO;
|
||||
|
||||
if (action == @selector(paste:))
|
||||
if (![self pasteboardHasSupportedType] || ![delegate respondsToSelector:@selector(_pasteToTableView:)])
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[_pasteboardTypes release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@synthesize _pasteboardTypes;
|
||||
|
||||
@end
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// SBView.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 17/06/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
@interface SBView : NSView {
|
||||
IBOutlet NSViewController *viewController;
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// SBView.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 17/06/09.
|
||||
// Copyright 2009 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SBView.h"
|
||||
|
||||
|
||||
@implementation SBView
|
||||
|
||||
- (void)setViewController:(NSViewController *)newController
|
||||
{
|
||||
if (viewController)
|
||||
{
|
||||
NSResponder *controllerNextResponder = [viewController nextResponder];
|
||||
[super setNextResponder:controllerNextResponder];
|
||||
[viewController setNextResponder:nil];
|
||||
}
|
||||
|
||||
viewController = newController;
|
||||
|
||||
if (newController)
|
||||
{
|
||||
NSResponder *ownNextResponder = [self nextResponder];
|
||||
[super setNextResponder: viewController];
|
||||
[viewController setNextResponder:ownNextResponder];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setNextResponder:(NSResponder *)newNextResponder
|
||||
{
|
||||
if (viewController)
|
||||
{
|
||||
[viewController setNextResponder:newNextResponder];
|
||||
return;
|
||||
}
|
||||
|
||||
[super setNextResponder:newNextResponder];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user