diff --git a/Base.lproj/QueueOptions.xib b/Base.lproj/QueueOptions.xib index 3b387f3..baecd61 100644 --- a/Base.lproj/QueueOptions.xib +++ b/Base.lproj/QueueOptions.xib @@ -1,8 +1,8 @@ - + - + @@ -15,7 +15,7 @@ - + - + @@ -398,9 +398,9 @@ - + - + @@ -440,7 +440,7 @@ - + @@ -488,7 +488,7 @@ - + @@ -513,7 +513,7 @@ - + @@ -536,6 +536,16 @@ + @@ -552,6 +562,7 @@ + @@ -569,9 +580,9 @@ - + @@ -591,6 +602,7 @@ + @@ -601,6 +613,7 @@ + @@ -632,7 +645,7 @@ - + diff --git a/Classes/MP42FileAdditions.swift b/Classes/MP42FileAdditions.swift index b8ff284..0ef4baf 100644 --- a/Classes/MP42FileAdditions.swift +++ b/Classes/MP42FileAdditions.swift @@ -7,6 +7,14 @@ import Foundation +private extension String { + func condensingWhitespace() -> String { + return self.components(separatedBy: .whitespacesAndNewlines) + .filter { !$0.isEmpty } + .joined(separator: " ") + } +} + extension MP42File { enum TrackHDType : Int { @@ -95,6 +103,8 @@ extension MP42File { } } + name = name.trimmingCharacters(in: CharacterSet(charactersIn: ":/")).condensingWhitespace() + return name.isEmpty ? nil : name } } diff --git a/Classes/QueueAction.swift b/Classes/QueueAction.swift index 19a5456..8f67997 100644 --- a/Classes/QueueAction.swift +++ b/Classes/QueueAction.swift @@ -13,6 +13,27 @@ import Foundation // @objc var localizedDescription: String { get } //} +/// An action that set a formatted file name. +@objc(SBQueueSetOutputFilenameAction) class QueueSetOutputFilenameAction: NSObject, SBQueueActionProtocol { + + var localizedDescription: String { return NSLocalizedString("Setting Name", comment: "Action localized description.") } + override var description: String { return NSLocalizedString("Set Name", comment: "Action description.") } + + @objc override init() {} + + func runAction(_ item: SBQueueItem) { + if let formattedName = item.mp4File?.formattedFileName() { + let pathExtension = item.destURL.pathExtension + let destURL = item.destURL.deletingLastPathComponent().appendingPathComponent(formattedName).appendingPathExtension(pathExtension) + item.destURL = destURL + } + } + + func encode(with aCoder: NSCoder) {} + required init?(coder aDecoder: NSCoder) {} + static var supportsSecureCoding: Bool { return true } +} + /// An action that search in the item source directory for additionals srt subtitles. @objc(SBQueueSubtitlesAction) class QueueSubtitlesAction : NSObject, SBQueueActionProtocol { diff --git a/Classes/SBQueueController.m b/Classes/SBQueueController.m index 6465f36..a2e5161 100755 --- a/Classes/SBQueueController.m +++ b/Classes/SBQueueController.m @@ -263,6 +263,10 @@ static void *SBQueueContex = &SBQueueContex; preferredArtwork:[self.options[SBQueueProviderArtwork] unsignedIntegerValue]]]; } + if ([(self.options)[SBQueueSetOutputFilename] boolValue]) { + [item addAction:[[SBQueueSetOutputFilenameAction alloc] init]]; + } + if ([(self.options)[SBQueueSubtitles] boolValue]) { [item addAction:[[SBQueueSubtitlesAction alloc] init]]; } diff --git a/Classes/SBQueuePreferences.h b/Classes/SBQueuePreferences.h index c83e8f0..72dafdf 100644 --- a/Classes/SBQueuePreferences.h +++ b/Classes/SBQueuePreferences.h @@ -34,6 +34,7 @@ extern NSString * const SBQueueMovieProviderLanguage; extern NSString * const SBQueueTVShowProviderLanguage; extern NSString * const SBQueueProviderArtwork; +extern NSString * const SBQueueSetOutputFilename; extern NSString * const SBQueueDestination; @interface SBQueuePreferences : NSObject diff --git a/Classes/SBQueuePreferences.m b/Classes/SBQueuePreferences.m index 66f71bf..9504bc0 100644 --- a/Classes/SBQueuePreferences.m +++ b/Classes/SBQueuePreferences.m @@ -37,6 +37,7 @@ NSString * const SBQueueTVShowProviderLanguage = @"SBQueueTVShowProviderLanguage NSString * const SBQueueProviderArtwork = @"SBQueueProviderArtwork"; NSString * const SBQueueSet = @"SBQueueSet"; +NSString * const SBQueueSetOutputFilename = @"SBQueueSetOutputFilename"; @implementation SBQueuePreferences @@ -45,7 +46,7 @@ NSString * const SBQueueSet = @"SBQueueSet"; if (self) { _options = [[NSMutableDictionary alloc] init]; - NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueApplyColorSpace, SBQueueApplyColorSpaceValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueShowDoneNotification, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork]; + NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueApplyColorSpace, SBQueueApplyColorSpaceValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueShowDoneNotification, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork, SBQueueSetOutputFilename]; [keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { self.options[obj] = [[NSUserDefaults standardUserDefaults] valueForKey:obj]; @@ -84,6 +85,8 @@ NSString * const SBQueueSet = @"SBQueueSet"; SBQueueApplyColorSpace: @NO, SBQueueApplyColorSpaceValue: @1, + SBQueueSetOutputFilename: @NO, + SBQueueAutoStart: @NO, SBQueueOptimize : @YES, SBQueueShowDoneNotification: @YES, @@ -99,7 +102,7 @@ NSString * const SBQueueSet = @"SBQueueSet"; * Save the queue user defaults */ - (void)saveUserDefaults { - NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueApplyColorSpace, SBQueueApplyColorSpaceValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueShowDoneNotification, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork]; + NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueApplyColorSpace, SBQueueApplyColorSpaceValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueShowDoneNotification, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork, SBQueueSetOutputFilename]; [keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [[NSUserDefaults standardUserDefaults] setValue:self.options[obj] forKey:obj];