Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented scanner to find audio and subtitle languages (downstream code to use this information not implemented yet) Changed HBBPreset to use NSASCIIStringEncoding rather than NSUTF8StringEncoding to avoid awkward retry for random failures
- Loading branch information
Showing
6 changed files
with
163 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+1.82 KB
(100%)
...codeproj/project.xcworkspace/xcuserdata/taglia.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
// | |||
// HBBVideoScan.h | |||
// HandBrakeBatch | |||
// | |||
// Created by Cesare Tagliaferri on 16/01/2012. | |||
// This file is part of the HandBrakeBatch source code. | |||
// Homepage: <http://www.osomac.com/>. | |||
// It may be used under the terms of the GNU General Public License. | |||
// | |||
|
|||
#import <Foundation/Foundation.h> | |||
|
|||
@interface HBBVideoScan : NSObject { | |||
NSString *fileName; | |||
NSMutableArray *audioLanguages; | |||
NSMutableArray *subtitleLanguages; | |||
} | |||
|
|||
@property (assign)NSString *fileName; | |||
@property (readonly)NSArray *audioLanguages; | |||
@property (readonly)NSArray *subtitleLanguages; | |||
|
|||
-(id)initWithFile:(NSString *)path; | |||
-(void)scan; | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,83 @@ | |||
// | |||
// HBBVideoScan.m | |||
// HandBrakeBatch | |||
// | |||
// Created by Cesare Tagliaferri on 16/01/2012. | |||
// This file is part of the HandBrakeBatch source code. | |||
// Homepage: <http://www.osomac.com/>. | |||
// It may be used under the terms of the GNU General Public License. | |||
// | |||
|
|||
#import "HBBVideoScan.h" | |||
|
|||
@implementation HBBVideoScan | |||
|
|||
@synthesize fileName, audioLanguages, subtitleLanguages; | |||
|
|||
-(id)initWithFile:(NSString *)path { | |||
self = [self init]; | |||
|
|||
[self setFileName:path]; | |||
|
|||
return self; | |||
} | |||
|
|||
- (id)init { | |||
self = [super init]; | |||
|
|||
if (self) { | |||
audioLanguages = [[NSMutableArray alloc] init]; | |||
subtitleLanguages = [[NSMutableArray alloc] init]; | |||
} | |||
|
|||
return self; | |||
} | |||
|
|||
-(void)scan { | |||
NSTask *task = [[NSTask alloc] init]; | |||
NSPipe *stdOutPipe = [NSPipe pipe]; | |||
|
|||
[task setStandardOutput:stdOutPipe]; | |||
[task setStandardError: [task standardOutput]]; | |||
|
|||
// No perf issues here, so we always use the 32 bit version | |||
[task setLaunchPath:[[NSBundle mainBundle] pathForResource:@"HandBrakeCLI_32" ofType:@""]]; | |||
|
|||
// Setting arguments | |||
[task setArguments:[NSArray arrayWithObjects:@"--scan", @"-i", fileName, nil]]; | |||
|
|||
// Executing scan | |||
[task launch]; | |||
[task waitUntilExit]; | |||
|
|||
NSData *output = [[stdOutPipe fileHandleForReading] readDataToEndOfFile]; | |||
|
|||
NSString *stringData = [NSString stringWithCString:[output bytes] encoding:NSASCIIStringEncoding]; | |||
|
|||
NSArray *outputLines = [stringData componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]; | |||
|
|||
NSUInteger audioIndex = [outputLines indexOfObject:@" + audio tracks:"]; | |||
NSUInteger subtitleIndex = [outputLines indexOfObject:@" + subtitle tracks:"]; | |||
|
|||
// Reset languages | |||
[audioLanguages removeAllObjects]; | |||
[subtitleLanguages removeAllObjects]; | |||
|
|||
while ([[outputLines objectAtIndex:++audioIndex] characterAtIndex:4] == '+') { | |||
NSRange range = [[outputLines objectAtIndex:audioIndex] rangeOfString:@"iso639-2: "]; | |||
[audioLanguages addObject:[[outputLines objectAtIndex:audioIndex] substringWithRange:NSMakeRange(range.location + range.length, 3)]]; | |||
} | |||
while ([[outputLines objectAtIndex:++subtitleIndex] characterAtIndex:4] == '+') { | |||
NSRange range = [[outputLines objectAtIndex:audioIndex] rangeOfString:@"iso639-2: "]; | |||
[audioLanguages addObject:[[outputLines objectAtIndex:audioIndex] substringWithRange:NSMakeRange(range.location + range.length, 3)]]; | |||
} | |||
|
|||
for (NSString *aLang in audioLanguages) { | |||
NSLog(@"Audio language found: %@", aLang); | |||
} | |||
for (NSString *sLang in subtitleLanguages) { | |||
NSLog(@"Subtitle language found: %@", sLang); | |||
} | |||
} | |||
|
|||
@end |