diff options
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/HBPreferencesController.m | 2 | ||||
-rw-r--r-- | macosx/HBTitle.h | 17 | ||||
-rw-r--r-- | macosx/HBTitle.m | 31 | ||||
-rw-r--r-- | macosx/HBUtilities.h | 3 | ||||
-rw-r--r-- | macosx/HBUtilities.m | 44 |
5 files changed, 89 insertions, 8 deletions
diff --git a/macosx/HBPreferencesController.m b/macosx/HBPreferencesController.m index aa02821f6..3f66bd717 100644 --- a/macosx/HBPreferencesController.m +++ b/macosx/HBPreferencesController.m @@ -122,7 +122,7 @@ [self.formatTokenField setTokenizingCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"%%"]]; [self.formatTokenField setCompletionDelay:0.2]; - _buildInFormatTokens = @[@"{Source}", @"{Title}", @"{Date}", @"{Time}", @"{Chapters}", @"{Quality/Bitrate}"]; + _buildInFormatTokens = @[@"{Source}", @"{Title}", @"{Date}", @"{Time}", @"{Creation-Date}", @"{Creation-Time}", @"{Chapters}", @"{Quality/Bitrate}"]; [self.builtInTokenField setTokenizingCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"%%"]]; [self.builtInTokenField setStringValue:[self.buildInFormatTokens componentsJoinedByString:@"%%"]]; diff --git a/macosx/HBTitle.h b/macosx/HBTitle.h index 79869ea20..3979b6d4c 100644 --- a/macosx/HBTitle.h +++ b/macosx/HBTitle.h @@ -11,6 +11,21 @@ NS_ASSUME_NONNULL_BEGIN @class HBChapter; @class HBPreset; +@interface HBMetadata : NSObject + +@property (nonatomic, readonly, nullable) NSString *name; +@property (nonatomic, readonly, nullable) NSString *artist; +@property (nonatomic, readonly, nullable) NSString *composer; +@property (nonatomic, readonly, nullable) NSString *releaseDate; +@property (nonatomic, readonly, nullable) NSString *comment; +@property (nonatomic, readonly, nullable) NSString *album; +@property (nonatomic, readonly, nullable) NSString *albumArtist; +@property (nonatomic, readonly, nullable) NSString *genre; +@property (nonatomic, readonly, nullable) NSString *description; +@property (nonatomic, readonly, nullable) NSString *longDescription; + +@end + /** * HBTitles is an interface to the low-level hb_title_t. * the properties are lazy-loaded. @@ -46,6 +61,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSArray<NSDictionary<NSString *, id> *> *subtitlesTracks; @property (nonatomic, readonly) NSArray<HBChapter *> *chapters; +@property (nonatomic, readonly) HBMetadata *metadata; + @end NS_ASSUME_NONNULL_END diff --git a/macosx/HBTitle.m b/macosx/HBTitle.m index e718624a7..01cf53bca 100644 --- a/macosx/HBTitle.m +++ b/macosx/HBTitle.m @@ -25,12 +25,37 @@ extern NSString *keySubTrackName; extern NSString *keySubTrackLanguageIsoCode; extern NSString *keySubTrackType; +@interface HBMetadata () + +@property (nonatomic, readonly) hb_metadata_t *hb_metadata; +@property (nonatomic, copy) NSString *releaseDate; + +@end + +@implementation HBMetadata +- (instancetype)initWithMetadata:(hb_metadata_t *)data +{ + _hb_metadata = data; + return self; +} + +- (NSString *)releaseDate +{ + if (self.hb_metadata->release_date == nil) + { + return nil; + } + return @(self.hb_metadata->release_date); +} + +@end + @interface HBTitle () @property (nonatomic, readonly) hb_title_t *hb_title; @property (nonatomic, readonly) hb_handle_t *hb_handle; @property (nonatomic, readwrite, copy) NSString *name; - +@property (nonatomic, readwrite) HBMetadata *metadata; @property (nonatomic, readwrite) NSArray *audioTracks; @property (nonatomic, readwrite) NSArray *subtitlesTracks; @property (nonatomic, readwrite) NSArray *chapters; @@ -52,12 +77,14 @@ extern NSString *keySubTrackType; _hb_title = title; _hb_handle = handle; _featured = featured; + + _metadata = [[HBMetadata alloc] initWithMetadata:title->metadata]; } return self; } -- (NSString *)name +- (NSString *)name { if (!_name) { diff --git a/macosx/HBUtilities.h b/macosx/HBUtilities.h index 4b4fa035a..fd8963693 100644 --- a/macosx/HBUtilities.h +++ b/macosx/HBUtilities.h @@ -58,7 +58,8 @@ NS_ASSUME_NONNULL_BEGIN chapters:(NSRange)chaptersRange quality:(double)quality bitrate:(int)bitrate - videoCodec:(uint32_t)codec; + videoCodec:(uint32_t)codec + creationDate:(NSDate *)creationDate; + (NSString *)isoCodeForNativeLang:(NSString *)language; + (NSString *)iso6392CodeFor:(NSString *)language; 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) |