Add SBQueueSetOutputFilenameAction action.

This commit is contained in:
Damiano Galassi committed 2017-12-06 14:20:41 +01:00
1 parent 32791b4d5c
commit 477ffe293a
6 files changed
+82 -30

No files matched your search

+10
View File
@@ -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
}
}
+21
View File
@@ -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 {
+4
View File
@@ -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]];
}
+1
View File
@@ -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
+5 -2
View File
@@ -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<NSString *> *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<NSString *> *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueApplyColorSpace, SBQueueApplyColorSpaceValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueShowDoneNotification, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork];
NSArray<NSString *> *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];