summaryrefslogtreecommitdiffstats
path: root/macosx/HBUtilities.m
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2019-07-29 07:34:38 +0200
committerDamiano Galassi <[email protected]>2019-07-29 07:34:38 +0200
commit8e2843720a9e6a87670da4e3caccfd570f66389f (patch)
tree9ed0392c6aef95b2f600d948564b030da2293d95 /macosx/HBUtilities.m
parent9446eba9eac07b6b47dc6d6e9f3c2a7331b38aa0 (diff)
MacGui: refactor the preferences keys and autonaming methods; fix the queue when running multiple HandBrake instances; fixed a number of bugs.
Diffstat (limited to 'macosx/HBUtilities.m')
-rw-r--r--macosx/HBUtilities.m193
1 files changed, 1 insertions, 192 deletions
diff --git a/macosx/HBUtilities.m b/macosx/HBUtilities.m
index 8cb5e2507..9099af552 100644
--- a/macosx/HBUtilities.m
+++ b/macosx/HBUtilities.m
@@ -7,34 +7,10 @@
#import "HBUtilities.h"
#import <Cocoa/Cocoa.h>
-#import "HBTitle.h"
-#import "HBJob.h"
-
-#include "common.h"
#include "lang.h"
-static NSDateFormatter *_timeFormatter = nil;
-static NSDateFormatter *_dateFormatter = nil;
-static NSDateFormatter *_releaseDateFormatter = nil;
-
@implementation HBUtilities
-+ (void)initialize
-{
- if (self == [HBUtilities class]) {
- _dateFormatter = [[NSDateFormatter alloc] init];
- [_dateFormatter setDateStyle:NSDateFormatterShortStyle];
- [_dateFormatter setTimeStyle:NSDateFormatterNoStyle];
-
- _timeFormatter = [[NSDateFormatter alloc] init];
- [_timeFormatter setDateStyle:NSDateFormatterNoStyle];
- [_timeFormatter setTimeStyle:NSDateFormatterShortStyle];
-
- _releaseDateFormatter = [[NSDateFormatter alloc] init];
- [_releaseDateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
- }
-}
-
+ (NSString *)handBrakeVersion
{
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
@@ -123,7 +99,7 @@ static NSDateFormatter *_releaseDateFormatter = nil;
NSURL *mediaURL = URL;
// We check to see if the chosen file at path is a package
- if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:URL.path])
+ if ([NSWorkspace.sharedWorkspace isFilePackageAtPath:URL.path])
{
[HBUtilities writeToActivityLog:"trying to open a package at: %s", URL.path.UTF8String];
// We check to see if this is an .eyetv package
@@ -180,173 +156,6 @@ static NSDateFormatter *_releaseDateFormatter = nil;
return mediaURL;
}
-+ (nullable NSDate *)releaseDate:(HBTitle *)title
-{
- if ([title.metadata.releaseDate length] == 0)
- {
- return nil;
- }
- else
- {
- return [_releaseDateFormatter dateFromString:title.metadata.releaseDate];
- }
-}
-
-+ (NSString *)automaticNameForJob:(HBJob *)job
-{
- HBTitle *title = job.title;
-
- NSDate *releaseDate = [self releaseDate:title];
- if (releaseDate == nil)
- {
- NSDictionary* fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:job.fileURL.path error:nil];
- releaseDate = [fileAttribs objectForKey:NSFileCreationDate];
- }
-
- // Generate a new file name
- NSString *fileName = [HBUtilities automaticNameForSource:title.name
- title:title.index
- chapters:NSMakeRange(job.range.chapterStart + 1, job.range.chapterStop + 1)
- quality:job.video.qualityType ? job.video.quality : 0
- bitrate:!job.video.qualityType ? job.video.avgBitrate : 0
- videoCodec:job.video.encoder
- creationDate:releaseDate];
- return fileName;
-}
-
-+ (NSString *)automaticExtForJob:(HBJob *)job
-{
- NSString *extension = @(hb_container_get_default_extension(job.container));
-
- if (job.container & HB_MUX_MASK_MP4)
- {
- BOOL anyCodecAC3 = [job.audio anyCodecMatches:HB_ACODEC_AC3] || [job.audio anyCodecMatches:HB_ACODEC_AC3_PASS];
- // Chapter markers are enabled if the checkbox is ticked and we are doing p2p or we have > 1 chapter
- BOOL chapterMarkers = (job.chaptersEnabled) &&
- (job.range.type != HBRangeTypeChapters || job.range.chapterStart < job.range.chapterStop);
-
- NSString *defaultExtension = [[NSUserDefaults standardUserDefaults] objectForKey:@"DefaultMpegExtension"];
-
- if ([defaultExtension isEqualToString:@".m4v"] ||
- ((YES == anyCodecAC3 || YES == chapterMarkers) && [defaultExtension isEqualToString:@"Auto"]))
- {
- extension = @"m4v";
- }
- }
-
- return extension;
-}
-
-+ (NSString *)defaultNameForJob:(HBJob *)job
-{
- // Generate a new file name
- NSString *fileName = job.title.name;
-
- // If Auto Naming is on. We create an output filename by using the
- // format set int he preferences.
- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"])
- {
- fileName = [self automaticNameForJob:job];
- }
-
- // use the correct extension based on the container
- NSString *ext = [self automaticExtForJob:job];
- fileName = [fileName stringByAppendingPathExtension:ext];
- return fileName;
-}
-
-+ (NSString *)automaticNameForSource:(NSString *)sourceName
- title:(NSUInteger)title
- chapters:(NSRange)chaptersRange
- quality:(double)quality
- bitrate:(int)bitrate
- videoCodec:(uint32_t)codec
- creationDate:(NSDate *)creationDate
-{
- NSMutableString *name = [[NSMutableString alloc] init];
- // The format array contains the tokens as NSString
- NSArray<NSString *> *format = [[NSUserDefaults standardUserDefaults] objectForKey:@"HBAutoNamingFormat"];
-
- for (NSString *formatKey in format)
- {
- if ([formatKey isEqualToString:@"{Source}"])
- {
- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HBAutoNamingRemoveUnderscore"])
- {
- sourceName = [sourceName stringByReplacingOccurrencesOfString:@"_" withString:@" "];
- }
- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HBAutoNamingRemovePunctuation"])
- {
- sourceName = [sourceName stringByReplacingOccurrencesOfString:@"-" withString:@""];
- sourceName = [sourceName stringByReplacingOccurrencesOfString:@"." withString:@""];
- sourceName = [sourceName stringByReplacingOccurrencesOfString:@"," withString:@""];
- sourceName = [sourceName stringByReplacingOccurrencesOfString:@";" withString:@""];
- }
- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HBAutoNamingTitleCase"])
- {
- 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 = [[_dateFormatter stringFromDate:date] stringByReplacingOccurrencesOfString:@"/" withString:@"-"];
- [name appendString:dateString];
- }
- else if ([formatKey isEqualToString:@"{Time}"])
- {
- NSDate *date = [NSDate date];
- [name appendString:[_timeFormatter stringFromDate:date]];
- }
- else if ([formatKey isEqualToString:@"{Creation-Date}"])
- {
- NSString *dateString = [[_dateFormatter stringFromDate:creationDate] stringByReplacingOccurrencesOfString:@"/" withString:@"-"];
- [name appendString:dateString];
-
- }
- else if ([formatKey isEqualToString:@"{Creation-Time}"])
- {
- [name appendString:[_timeFormatter stringFromDate:creationDate]];
- }
- 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 (bitrate)
- {
- [name appendString:@"abr"];
- [name appendString:[NSString stringWithFormat:@"%d", bitrate]];
- }
- else
- {
- // Append the right quality suffix for the selected codec (rf/qp)
- [name appendString:[@(hb_video_quality_get_name(codec)) lowercaseString]];
- [name appendString:[NSString stringWithFormat:@"%0.2f", quality]];
- }
- }
- else
- {
- [name appendString:formatKey];
- }
- }
-
- return [name copy];
-}
-
+ (NSString *)isoCodeForNativeLang:(NSString *)language
{
const iso639_lang_t *lang = lang_get_next(NULL);