diff options
author | ritsuka <[email protected]> | 2014-07-11 18:22:43 +0000 |
---|---|---|
committer | ritsuka <[email protected]> | 2014-07-11 18:22:43 +0000 |
commit | 70f4a8751ea04c69095025394adecff6a2c8edea (patch) | |
tree | 58531bf3ae09e2d508b0f85494b8e6fca9b0ed3f /macosx/HBUtilities.m | |
parent | 2412d4a92123b2f20b43987a65a4fbd645be1443 (diff) |
MacGUI: Expanded the auto name feature to make it as powerful as the WinGUI counterpart.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6228 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBUtilities.m')
-rw-r--r-- | macosx/HBUtilities.m | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/macosx/HBUtilities.m b/macosx/HBUtilities.m new file mode 100644 index 000000000..47666f923 --- /dev/null +++ b/macosx/HBUtilities.m @@ -0,0 +1,101 @@ +/* HBUtilities.m $ + + This file is part of the HandBrake source code. + Homepage: <http://handbrake.fr/>. + It may be used under the terms of the GNU General Public License. */ + +#import "HBUtilities.h" +#include "common.h" + +@implementation HBUtilities + ++ (NSString *)automaticNameForSource:(NSString *)sourceName + title:(NSUInteger)title + chapters:(NSRange)chaptersRange + quality:(NSString *)quality + bitrate:(NSString *)bitrate + videoCodec:(uint32_t *)codec +{ + NSMutableString *name = [[[NSMutableString alloc] init] autorelease]; + // The format array contains the tokens as NSString + NSArray *format = [[NSUserDefaults standardUserDefaults] objectForKey:@"HBAutoNamingFormat"]; + + for (NSString *formatKey in format) + { + if ([formatKey isEqualToString:@"{Source}"]) + { + if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"HBAutoNamingRemoveUnderscore"] boolValue]) + { + sourceName = [sourceName stringByReplacingOccurrencesOfString:@"_" withString:@" "]; + } + if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"HBAutoNamingRemovePunctuation"] boolValue]) + { + sourceName = [sourceName stringByReplacingOccurrencesOfString:@"-" withString:@""]; + sourceName = [sourceName stringByReplacingOccurrencesOfString:@"." withString:@""]; + sourceName = [sourceName stringByReplacingOccurrencesOfString:@"," withString:@""]; + sourceName = [sourceName stringByReplacingOccurrencesOfString:@";" withString:@""]; + } + if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"HBAutoNamingTitleCase"] boolValue]) + { + sourceName = [sourceName capitalizedString]; + } + [name appendString:sourceName]; + } + else if ([formatKey isEqualToString:@"{Title}"]) + { + [name appendFormat:@"%lu", (unsigned long)title]; + } + else if ([formatKey isEqualToString:@"{Date}"]) + { + NSDate *date = [NSDate date]; + NSString *dateString = nil; + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + [formatter setDateStyle:NSDateFormatterShortStyle]; + [formatter setTimeStyle:NSDateFormatterNoStyle]; + dateString = [[formatter stringFromDate:date] stringByReplacingOccurrencesOfString:@"/" withString:@"-"]; + [name appendString:dateString]; + } + else if ([formatKey isEqualToString:@"{Time}"]) + { + NSDate *date = [NSDate date]; + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + [formatter setDateStyle:NSDateFormatterNoStyle]; + [formatter setTimeStyle:NSDateFormatterShortStyle]; + [name appendString:[formatter stringFromDate:date]]; + } + else if ([formatKey isEqualToString:@"{Chapters}"]) + { + if (chaptersRange.location == chaptersRange.length) + { + [name appendFormat:@"%lu", (unsigned long)chaptersRange.location]; + } + else + { + [name appendFormat:@"%lu-%lu", (unsigned long)chaptersRange.location, (unsigned long)chaptersRange.length]; + } + } + else if ([formatKey isEqualToString:@"{Quality/Bitrate}"]) + { + if (quality) + { + // Append the right quality suffix for the selected codec (rf/qp) + [name appendString:[[NSString stringWithUTF8String:hb_video_quality_get_name(codec)] lowercaseString]]; + [name appendString:quality]; + } + else + { + [name appendString:@"abr"]; + [name appendString:bitrate]; + } + } + else + { + [name appendString:formatKey]; + } + } + + return [[name copy] autorelease]; +} + + +@end |