summaryrefslogtreecommitdiffstats
path: root/macosx/HBUtilities.m
diff options
context:
space:
mode:
authorMatthew Lazarow <[email protected]>2018-08-13 15:56:01 -0400
committerScott <[email protected]>2018-08-13 20:56:01 +0100
commita9daef1e18b93f793479155210110322234bb655 (patch)
tree0bd762a171c18d9999ec13dfc65f025f1e7db160 /macosx/HBUtilities.m
parent223dc7bd007bfd665948f7e11a9f4681d580cb35 (diff)
Autoname creation date
Adds {creation-date} and {creation-time} templates to autoname preference option.
Diffstat (limited to 'macosx/HBUtilities.m')
-rw-r--r--macosx/HBUtilities.m44
1 files changed, 40 insertions, 4 deletions
diff --git a/macosx/HBUtilities.m b/macosx/HBUtilities.m
index 5794a712b..ae2658444 100644
--- a/macosx/HBUtilities.m
+++ b/macosx/HBUtilities.m
@@ -155,9 +155,29 @@
return mediaURL;
}
++ (nullable NSDate *)getReleaseDate:(HBTitle *)title
+{
+ if ([title.metadata.releaseDate length] == 0){
+ return nil;
+ }
+
+ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
+ NSString *dt = title.metadata.releaseDate;
+ [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
+ NSDate *releaseDate = [dateFormatter dateFromString:dt];
+ return releaseDate;
+}
+
+ (NSString *)automaticNameForJob:(HBJob *)job
{
HBTitle *title = job.title;
+
+ NSDate *releaseDate = [self getReleaseDate: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
@@ -165,7 +185,9 @@
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];
+ videoCodec:job.video.encoder
+ creationDate:releaseDate
+ ];
return fileName;
}
@@ -206,7 +228,6 @@
// use the correct extension based on the container
NSString *ext = [self automaticExtForJob:job];
fileName = [fileName stringByAppendingPathExtension:ext];
-
return fileName;
}
@@ -216,10 +237,12 @@
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 *format = [[NSUserDefaults standardUserDefaults] objectForKey:@"HBAutoNamingFormat"];
+ NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
for (NSString *formatKey in format)
{
@@ -250,7 +273,6 @@
{
NSDate *date = [NSDate date];
NSString *dateString = nil;
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterShortStyle];
[formatter setTimeStyle:NSDateFormatterNoStyle];
dateString = [[formatter stringFromDate:date] stringByReplacingOccurrencesOfString:@"/" withString:@"-"];
@@ -259,11 +281,25 @@
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:@"{Creation-Date}"])
+ {
+ NSString *dateString = nil;
+ [formatter setDateStyle:NSDateFormatterShortStyle];
+ [formatter setTimeStyle:NSDateFormatterNoStyle];
+ dateString = [[formatter stringFromDate:creationDate] stringByReplacingOccurrencesOfString:@"/" withString:@"-"];
+ [name appendString:dateString];
+
+ }
+ else if ([formatKey isEqualToString:@"{Creation-Time}"])
+ {
+ [formatter setDateStyle:NSDateFormatterNoStyle];
+ [formatter setTimeStyle:NSDateFormatterShortStyle];
+ [name appendString:[formatter stringFromDate:creationDate]];
+ }
else if ([formatKey isEqualToString:@"{Chapters}"])
{
if (chaptersRange.location == chaptersRange.length)