Convert all the queue actions to Swift.
This commit is contained in:
9 files changed
+246
-416
No files matched your search
@@ -59,8 +59,10 @@ extension SBDocument: ChapterSearchControllerDelegate, MetadataSearchControllerD
|
|||||||
let map = metadata.mediaKind == 9 ? defaults.map(forKey: "SBMetadataMovieResultMap") : defaults.map(forKey: "SBMetadataTvShowResultMap")
|
let map = metadata.mediaKind == 9 ? defaults.map(forKey: "SBMetadataMovieResultMap") : defaults.map(forKey: "SBMetadataTvShowResultMap")
|
||||||
let keepEmptyKeys = defaults.bool(forKey: "SBMetadataKeepEmptyAnnotations")
|
let keepEmptyKeys = defaults.bool(forKey: "SBMetadataKeepEmptyAnnotations")
|
||||||
|
|
||||||
let result = metadata.mappedMetadata(to: map!, keepEmptyKeys: keepEmptyKeys)
|
if let map = map {
|
||||||
mp4.metadata.merge(result)
|
let result = metadata.mappedMetadata(to: map, keepEmptyKeys: keepEmptyKeys)
|
||||||
|
mp4.metadata.merge(result)
|
||||||
|
}
|
||||||
|
|
||||||
if let hdType = mp4.hdType {
|
if let hdType = mp4.hdType {
|
||||||
for item in mp4.metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyHDVideo) {
|
for item in mp4.metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyHDVideo) {
|
||||||
@@ -118,7 +120,6 @@ extension SBDocument: ChapterSearchControllerDelegate, MetadataSearchControllerD
|
|||||||
func didSelect(tracks: [MP42Track], metadata: MP42Metadata?) {
|
func didSelect(tracks: [MP42Track], metadata: MP42Metadata?) {
|
||||||
for track in tracks {
|
for track in tracks {
|
||||||
mp4.addTrack(track)
|
mp4.addTrack(track)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if tracks.isEmpty == false {
|
if tracks.isEmpty == false {
|
||||||
|
|||||||
+229
-3
@@ -7,7 +7,59 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/// An actions that applies a preset to the item.
|
/// SBQueue actions protocol, actions can be run by the queue's items.
|
||||||
|
//@objc(SBQueueActionProtocol) protocol QueueActionProtocol: NSSecureCoding {
|
||||||
|
// @objc func runAction(_ item: SBQueueItem)
|
||||||
|
// @objc var localizedDescription: String { get }
|
||||||
|
//}
|
||||||
|
|
||||||
|
/// An action that search in the item source directory for additionals srt subtitles.
|
||||||
|
@objc(SBQueueSubtitlesAction) class QueueSubtitlesAction : NSObject, SBQueueActionProtocol {
|
||||||
|
|
||||||
|
var localizedDescription: String { return NSLocalizedString("Loading subtitles", comment: "Action localized description.") }
|
||||||
|
override var description: String { return NSLocalizedString("Load Subtitles", comment: "Action description.") }
|
||||||
|
|
||||||
|
@objc override init() {}
|
||||||
|
|
||||||
|
private func loadExternalSubtitles(url: URL) -> [MP42FileImporter] {
|
||||||
|
let movieFilename = url.deletingPathExtension().lastPathComponent
|
||||||
|
var importers: [MP42FileImporter] = Array()
|
||||||
|
if let contents = try? FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil, options: [.skipsSubdirectoryDescendants, .skipsHiddenFiles, .skipsPackageDescendants]) {
|
||||||
|
for url in contents {
|
||||||
|
if url.pathExtension.caseInsensitiveCompare("srt") == ComparisonResult.orderedSame {
|
||||||
|
let subtitleFilename = url.deletingPathExtension().lastPathComponent
|
||||||
|
if movieFilename.count < subtitleFilename.count &&
|
||||||
|
subtitleFilename.compare(subtitleFilename, options: String.CompareOptions.caseInsensitive, range: movieFilename.startIndex..<movieFilename.endIndex, locale: nil) == ComparisonResult.orderedSame {
|
||||||
|
if let importer = try? MP42FileImporter(url: url) {
|
||||||
|
importers.append(importer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return importers
|
||||||
|
}
|
||||||
|
|
||||||
|
func runAction(_ item: SBQueueItem) {
|
||||||
|
let subtitlesImporters = loadExternalSubtitles(url: item.fileURL)
|
||||||
|
|
||||||
|
for importer in subtitlesImporters {
|
||||||
|
for track in importer.tracks {
|
||||||
|
item.mp4File?.addTrack(track)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(with aCoder: NSCoder) {}
|
||||||
|
|
||||||
|
required init?(coder aDecoder: NSCoder) {}
|
||||||
|
|
||||||
|
static var supportsSecureCoding: Bool { return true }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An action that applies a preset to the item.
|
||||||
@objc(SBQueueSetAction) class QueueSetAction : NSObject, SBQueueActionProtocol {
|
@objc(SBQueueSetAction) class QueueSetAction : NSObject, SBQueueActionProtocol {
|
||||||
|
|
||||||
private let preset: MetadataPreset
|
private let preset: MetadataPreset
|
||||||
@@ -55,7 +107,6 @@ import Foundation
|
|||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
guard let preset = aDecoder.decodeObject(of: MetadataPreset.self, forKey: "SBQueueActionSet") else { return nil }
|
guard let preset = aDecoder.decodeObject(of: MetadataPreset.self, forKey: "SBQueueActionSet") else { return nil }
|
||||||
|
|
||||||
self.preset = preset
|
self.preset = preset
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +136,7 @@ extension Array where Element == Artwork {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An actions that fetches metadata online.
|
/// An action that fetches metadata online.
|
||||||
@objc(SBQueueMetadataAction) class QueueMetadataAction : NSObject, SBQueueActionProtocol {
|
@objc(SBQueueMetadataAction) class QueueMetadataAction : NSObject, SBQueueActionProtocol {
|
||||||
|
|
||||||
private let movieLanguage: String
|
private let movieLanguage: String
|
||||||
@@ -222,3 +273,178 @@ extension Array where Element == Artwork {
|
|||||||
static var supportsSecureCoding: Bool { return true }
|
static var supportsSecureCoding: Bool { return true }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An action that organize the item tracks' groups.
|
||||||
|
@objc(SBQueueOrganizeGroupsAction) class QueueOrganizeGroupsAction : NSObject, SBQueueActionProtocol {
|
||||||
|
|
||||||
|
var localizedDescription: String { return NSLocalizedString("Organizing groups", comment: "Organize Groups action local description") }
|
||||||
|
override var description: String { return NSLocalizedString("Organize Groups", comment: "Organize Groups action description") }
|
||||||
|
|
||||||
|
@objc override init() {}
|
||||||
|
|
||||||
|
func runAction(_ item: SBQueueItem) {
|
||||||
|
item.mp4File?.organizeAlternateGroups()
|
||||||
|
item.mp4File?.inferMediaCharacteristics()
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(with aCoder: NSCoder) {}
|
||||||
|
|
||||||
|
required init?(coder aDecoder: NSCoder) {}
|
||||||
|
|
||||||
|
static var supportsSecureCoding: Bool { return true }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An action that fix the item tracks' fallbacks.
|
||||||
|
@objc(SBQueueFixFallbacksAction) class QueueFixFallbacksAction : NSObject, SBQueueActionProtocol {
|
||||||
|
|
||||||
|
var localizedDescription: String { return NSLocalizedString("Fixing Fallbacks", comment: "Action localized description.") }
|
||||||
|
override var description: String { return NSLocalizedString("Fix Fallbacks", comment: "Action description.") }
|
||||||
|
|
||||||
|
@objc override init() {}
|
||||||
|
|
||||||
|
func runAction(_ item: SBQueueItem) {
|
||||||
|
item.mp4File?.setAutoFallback()
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(with aCoder: NSCoder) {}
|
||||||
|
|
||||||
|
required init?(coder aDecoder: NSCoder) {}
|
||||||
|
|
||||||
|
static var supportsSecureCoding: Bool { return true }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An action that set unknown language tracks to preferred one.
|
||||||
|
@objc(SBQueueSetLanguageAction) class QueueSetLanguageAction : NSObject, SBQueueActionProtocol {
|
||||||
|
|
||||||
|
var localizedDescription: String { return NSLocalizedString("Setting tracks language", comment: "Set Language action local description") }
|
||||||
|
override var description: String { return NSLocalizedString("Set tracks language", comment: "Set Language action description") }
|
||||||
|
|
||||||
|
let language: String
|
||||||
|
|
||||||
|
@objc init(language: String) {
|
||||||
|
self.language = language
|
||||||
|
}
|
||||||
|
|
||||||
|
func runAction(_ item: SBQueueItem) {
|
||||||
|
if let tracks = item.mp4File?.tracks {
|
||||||
|
for track in tracks {
|
||||||
|
if track.language == "und" {
|
||||||
|
track.language = language
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(with aCoder: NSCoder) {
|
||||||
|
aCoder.encode(language, forKey: "SBQueueSetLanguageAction")
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder aDecoder: NSCoder) {
|
||||||
|
guard let language = aDecoder.decodeObject(of: NSString.self, forKey: "SBQueueSetLanguageAction") as String?
|
||||||
|
else { return nil }
|
||||||
|
self.language = language
|
||||||
|
}
|
||||||
|
|
||||||
|
static var supportsSecureCoding: Bool { return true }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An action that remove the tracks names.
|
||||||
|
@objc(SBQueueClearTrackNameAction) class QueueClearTrackNameAction : NSObject, SBQueueActionProtocol {
|
||||||
|
|
||||||
|
var localizedDescription: String { return NSLocalizedString("Clearing tracks names", comment: "Action localized description") }
|
||||||
|
override var description: String { return NSLocalizedString("Clear tracks names", comment: "Action description") }
|
||||||
|
|
||||||
|
@objc override init() {}
|
||||||
|
|
||||||
|
func runAction(_ item: SBQueueItem) {
|
||||||
|
if let tracks = item.mp4File?.tracks {
|
||||||
|
for track in tracks {
|
||||||
|
track.name = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(with aCoder: NSCoder) {}
|
||||||
|
|
||||||
|
required init?(coder aDecoder: NSCoder) {}
|
||||||
|
|
||||||
|
static var supportsSecureCoding: Bool { return true }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc(SBQueueColorSpaceActionTag) enum QueueColorSpaceActionTag: UInt16 {
|
||||||
|
case SBQueueColorSpaceActionTagNone = 1
|
||||||
|
case SBQueueColorSpaceActionTagRec601PAL
|
||||||
|
case SBQueueColorSpaceActionTagRec601SMPTEC
|
||||||
|
case SBQueueColorSpaceActionTagRec709
|
||||||
|
case SBQueueColorSpaceActionTagRec2020
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An action that set the video track color space.
|
||||||
|
@objc(SBQueueColorSpaceAction) class QueueColorSpaceAction : NSObject, SBQueueActionProtocol {
|
||||||
|
|
||||||
|
var localizedDescription: String { return NSLocalizedString("Setting color space", comment: "Set track color space action local description") }
|
||||||
|
override var description: String { return NSLocalizedString("Set color space", comment: "Set track color space action description") }
|
||||||
|
|
||||||
|
let colorPrimaries: UInt16;
|
||||||
|
let transferCharacteristics: UInt16;
|
||||||
|
let matrixCoefficients: UInt16;
|
||||||
|
|
||||||
|
@objc init(tag: QueueColorSpaceActionTag) {
|
||||||
|
switch tag {
|
||||||
|
case .SBQueueColorSpaceActionTagNone:
|
||||||
|
self.colorPrimaries = 0
|
||||||
|
self.transferCharacteristics = 0
|
||||||
|
self.matrixCoefficients = 0
|
||||||
|
case .SBQueueColorSpaceActionTagRec601PAL:
|
||||||
|
self.colorPrimaries = 5
|
||||||
|
self.transferCharacteristics = 1
|
||||||
|
self.matrixCoefficients = 6
|
||||||
|
case .SBQueueColorSpaceActionTagRec601SMPTEC:
|
||||||
|
self.colorPrimaries = 6
|
||||||
|
self.transferCharacteristics = 1
|
||||||
|
self.matrixCoefficients = 6
|
||||||
|
case .SBQueueColorSpaceActionTagRec709:
|
||||||
|
self.colorPrimaries = 1
|
||||||
|
self.transferCharacteristics = 1
|
||||||
|
self.matrixCoefficients = 1
|
||||||
|
case .SBQueueColorSpaceActionTagRec2020:
|
||||||
|
self.colorPrimaries = 9
|
||||||
|
self.transferCharacteristics = 1
|
||||||
|
self.matrixCoefficients = 9
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runAction(_ item: SBQueueItem) {
|
||||||
|
if let tracks = item.mp4File?.tracks(withMediaType: kMP42MediaType_Video) as? [MP42VideoTrack] {
|
||||||
|
for track in tracks {
|
||||||
|
if track.format == kMP42VideoCodecType_H264 ||
|
||||||
|
track.format == kMP42VideoCodecType_HEVC ||
|
||||||
|
track.format == kMP42VideoCodecType_HEVC_PSinBitstream ||
|
||||||
|
track.format == kMP42VideoCodecType_MPEG4Video {
|
||||||
|
track.colorPrimaries = colorPrimaries;
|
||||||
|
track.transferCharacteristics = transferCharacteristics;
|
||||||
|
track.matrixCoefficients = matrixCoefficients;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(with aCoder: NSCoder) {
|
||||||
|
aCoder.encode(Int32(colorPrimaries), forKey: "SBQueueColorSpaceActionColorPrimaries")
|
||||||
|
aCoder.encode(Int32(transferCharacteristics), forKey: "SBQueueColorSpaceActionTransferCharacteristics")
|
||||||
|
aCoder.encode(Int32(matrixCoefficients), forKey: "SBQueueColorSpaceActionMatrixCoefficients")
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder aDecoder: NSCoder) {
|
||||||
|
self.colorPrimaries = UInt16(aDecoder.decodeInt32(forKey: "SBQueueColorSpaceActionColorPrimaries"))
|
||||||
|
self.transferCharacteristics = UInt16(aDecoder.decodeInt32(forKey: "SBQueueColorSpaceActionTransferCharacteristics"))
|
||||||
|
self.matrixCoefficients = UInt16(aDecoder.decodeInt32(forKey: "SBQueueColorSpaceActionMatrixCoefficients"))
|
||||||
|
}
|
||||||
|
|
||||||
|
static var supportsSecureCoding: Bool { return true }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
//
|
|
||||||
// SBQueueAction.h
|
|
||||||
// Subler
|
|
||||||
//
|
|
||||||
// Created by Damiano Galassi on 12/03/14.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
|
|
||||||
@class SBQueueItem;
|
|
||||||
@class MP42Metadata;
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SBQueue actions protocol, actions can be run by
|
|
||||||
* the queue's items.
|
|
||||||
*/
|
|
||||||
@protocol SBQueueActionProtocol <NSObject, NSSecureCoding>
|
|
||||||
- (void)runAction:(SBQueueItem *)item;
|
|
||||||
@property (nonatomic, readonly) NSString *localizedDescription;
|
|
||||||
@end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An actions that search in the item source directory for additionals srt subtitles
|
|
||||||
*/
|
|
||||||
@interface SBQueueSubtitlesAction : NSObject <SBQueueActionProtocol>
|
|
||||||
@end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An actions that organize the item tracks' groups.
|
|
||||||
*/
|
|
||||||
@interface SBQueueOrganizeGroupsAction : NSObject <SBQueueActionProtocol>
|
|
||||||
@end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An actions that fix the item tracks' fallbacks.
|
|
||||||
*/
|
|
||||||
@interface SBQueueFixFallbacksAction : NSObject <SBQueueActionProtocol>
|
|
||||||
@end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An actions that remove the tracks names.
|
|
||||||
*/
|
|
||||||
@interface SBQueueClearTrackNameAction : NSObject <SBQueueActionProtocol>
|
|
||||||
@end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An actions that set unknown language tracks to preferred one.
|
|
||||||
*/
|
|
||||||
@interface SBQueueSetLanguageAction : NSObject <SBQueueActionProtocol>
|
|
||||||
- (instancetype)initWithLanguage:(NSString *)language;
|
|
||||||
@end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An actions that set the video track color space.
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef NS_ENUM(NSUInteger, SBQueueColorSpaceActionTag) {
|
|
||||||
SBQueueColorSpaceActionTagNone = 1,
|
|
||||||
SBQueueColorSpaceActionTagRec601PAL,
|
|
||||||
SBQueueColorSpaceActionTagRec601SMPTEC,
|
|
||||||
SBQueueColorSpaceActionTagRec709,
|
|
||||||
SBQueueColorSpaceActionTagRec2020
|
|
||||||
};
|
|
||||||
@interface SBQueueColorSpaceAction : NSObject <SBQueueActionProtocol>
|
|
||||||
- (instancetype)initWithTag:(uint16_t)tag;
|
|
||||||
- (instancetype)initWithColorPrimaries:(uint16_t)colorPrimaries transferCharacteristics:(uint16_t)transferCharacteristics matrixCoefficients:(uint16_t)matrixCoefficients;
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
@@ -1,325 +0,0 @@
|
|||||||
//
|
|
||||||
// SBQueueAction.m
|
|
||||||
// Subler
|
|
||||||
//
|
|
||||||
// Created by Damiano Galassi on 12/03/14.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "SBQueueAction.h"
|
|
||||||
|
|
||||||
#import "SBQueueItem.h"
|
|
||||||
|
|
||||||
#import <MP42Foundation/MP42File.h>
|
|
||||||
#import <MP42Foundation/MP42FileImporter.h>
|
|
||||||
#import <MP42Foundation/MP42Image.h>
|
|
||||||
#import <MP42Foundation/MP42Utilities.h>
|
|
||||||
|
|
||||||
@implementation SBQueueSubtitlesAction
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the subtitles in the parent directory
|
|
||||||
*/
|
|
||||||
- (NSArray<MP42FileImporter *> *)loadSubtitles:(NSURL *)url {
|
|
||||||
NSError *error = nil;
|
|
||||||
NSMutableArray<MP42FileImporter *> *importersArray = [[NSMutableArray alloc] init];
|
|
||||||
NSArray<NSURL *> *directory = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:url.URLByDeletingLastPathComponent
|
|
||||||
includingPropertiesForKeys:nil
|
|
||||||
options:NSDirectoryEnumerationSkipsSubdirectoryDescendants |
|
|
||||||
NSDirectoryEnumerationSkipsHiddenFiles |
|
|
||||||
NSDirectoryEnumerationSkipsPackageDescendants
|
|
||||||
error:nil];
|
|
||||||
|
|
||||||
for (NSURL *dirUrl in directory) {
|
|
||||||
if ([dirUrl.pathExtension caseInsensitiveCompare:@"srt"] == NSOrderedSame) {
|
|
||||||
NSComparisonResult result;
|
|
||||||
NSString *movieFilename = url.URLByDeletingPathExtension.lastPathComponent;
|
|
||||||
NSString *subtitleFilename = dirUrl.URLByDeletingPathExtension.lastPathComponent;
|
|
||||||
NSRange range = { 0, movieFilename.length };
|
|
||||||
|
|
||||||
if (movieFilename.length <= subtitleFilename.length) {
|
|
||||||
result = [subtitleFilename compare:movieFilename options:NSCaseInsensitiveSearch range:range];
|
|
||||||
|
|
||||||
if (result == NSOrderedSame) {
|
|
||||||
MP42FileImporter *fileImporter = [[MP42FileImporter alloc] initWithURL:dirUrl
|
|
||||||
error:&error];
|
|
||||||
if (fileImporter) {
|
|
||||||
[importersArray addObject:fileImporter];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return importersArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)runAction:(SBQueueItem *)item {
|
|
||||||
// Search for external subtitles files
|
|
||||||
NSArray<MP42FileImporter *> *subtitles = [self loadSubtitles:item.fileURL];
|
|
||||||
for (MP42FileImporter *fileImporter in subtitles) {
|
|
||||||
for (MP42SubtitleTrack *subTrack in fileImporter.tracks) {
|
|
||||||
[item.mp4File addTrack:subTrack];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)description {
|
|
||||||
return NSLocalizedString(@"Load Subtitles", @"Action description.");
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)localizedDescription {
|
|
||||||
return NSLocalizedString(@"Loading subtitles", @"Action localized description.");
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (BOOL)supportsSecureCoding {
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
|
||||||
self = [super init];
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder {
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation SBQueueOrganizeGroupsAction
|
|
||||||
|
|
||||||
- (void)runAction:(SBQueueItem *)item {
|
|
||||||
[item.mp4File organizeAlternateGroups];
|
|
||||||
[item.mp4File inferMediaCharacteristics];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)description {
|
|
||||||
return NSLocalizedString(@"Organize Groups", @"Organize Groups action description");
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)localizedDescription {
|
|
||||||
return NSLocalizedString(@"Organizing groups", @"Organize Groups action local description");
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (BOOL)supportsSecureCoding {
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
|
||||||
self = [super init];
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder {}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An actions that fix the item tracks' fallbacks.
|
|
||||||
*/
|
|
||||||
@implementation SBQueueFixFallbacksAction
|
|
||||||
|
|
||||||
- (void)runAction:(SBQueueItem *)item {
|
|
||||||
[item.mp4File setAutoFallback];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)description {
|
|
||||||
return NSLocalizedString(@"Fix Fallbacks", @"Action description.");
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)localizedDescription {
|
|
||||||
return NSLocalizedString(@"Fixing Fallbacks", @"Action localized description.");
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (BOOL)supportsSecureCoding {
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
|
||||||
self = [super init];
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder {}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An actions that remove the tracks names.
|
|
||||||
*/
|
|
||||||
@implementation SBQueueClearTrackNameAction
|
|
||||||
|
|
||||||
- (void)runAction:(SBQueueItem *)item {
|
|
||||||
for (MP42Track *track in item.mp4File.tracks) {
|
|
||||||
track.name = @"";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)description {
|
|
||||||
return NSLocalizedString(@"Clear tracks names", @"Action description.");
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)localizedDescription {
|
|
||||||
return NSLocalizedString(@"Clearing tracks names", @"Action localized description.");
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (BOOL)supportsSecureCoding {
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
|
||||||
self = [super init];
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder {}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An actions that set unknown language tracks to preferred one.
|
|
||||||
*/
|
|
||||||
@interface SBQueueSetLanguageAction ()
|
|
||||||
@property (nonatomic, readonly) NSString *language;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation SBQueueSetLanguageAction
|
|
||||||
|
|
||||||
- (instancetype)initWithLanguage:(NSString *)language {
|
|
||||||
self = [super init];
|
|
||||||
if (self) {
|
|
||||||
_language = [language copy];
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)runAction:(SBQueueItem *)item {
|
|
||||||
for (MP42Track *track in item.mp4File.tracks) {
|
|
||||||
if ([track.language isEqualToString:@"und"]) {
|
|
||||||
track.language = self.language;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)description {
|
|
||||||
return NSLocalizedString(@"Set tracks language", @"Set Language action description");
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)localizedDescription {
|
|
||||||
return NSLocalizedString(@"Setting tracks language", @"Set Language action local description");
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (BOOL)supportsSecureCoding {
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
|
||||||
self = [super init];
|
|
||||||
_language = [coder decodeObjectOfClass:[NSString class] forKey:@"SBQueueSetLanguageAction"];
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder {
|
|
||||||
[coder encodeObject:self.language forKey:@"SBQueueSetLanguageAction"];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface SBQueueColorSpaceAction ()
|
|
||||||
@property(nonatomic, readonly) uint16_t colorPrimaries;
|
|
||||||
@property(nonatomic, readonly) uint16_t transferCharacteristics;
|
|
||||||
@property(nonatomic, readonly) uint16_t matrixCoefficients;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation SBQueueColorSpaceAction
|
|
||||||
|
|
||||||
- (instancetype)initWithTag:(uint16_t)tag {
|
|
||||||
self = [super init];
|
|
||||||
if (self) {
|
|
||||||
switch (tag) {
|
|
||||||
case SBQueueColorSpaceActionTagRec601PAL:
|
|
||||||
_colorPrimaries = 5;
|
|
||||||
_transferCharacteristics = 1;
|
|
||||||
_matrixCoefficients = 6;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SBQueueColorSpaceActionTagRec601SMPTEC:
|
|
||||||
_colorPrimaries = 6;
|
|
||||||
_transferCharacteristics = 1;
|
|
||||||
_matrixCoefficients = 6;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SBQueueColorSpaceActionTagRec709:
|
|
||||||
_colorPrimaries = 1;
|
|
||||||
_transferCharacteristics = 1;
|
|
||||||
_matrixCoefficients = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SBQueueColorSpaceActionTagRec2020:
|
|
||||||
_colorPrimaries = 9;
|
|
||||||
_transferCharacteristics = 1;
|
|
||||||
_matrixCoefficients = 9;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SBQueueColorSpaceActionTagNone:
|
|
||||||
default:
|
|
||||||
_colorPrimaries = 0;
|
|
||||||
_transferCharacteristics = 0;
|
|
||||||
_matrixCoefficients = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithColorPrimaries:(uint16_t)colorPrimaries transferCharacteristics:(uint16_t)transferCharacteristics matrixCoefficients:(uint16_t)matrixCoefficients {
|
|
||||||
self = [super init];
|
|
||||||
if (self) {
|
|
||||||
_colorPrimaries = colorPrimaries;
|
|
||||||
_transferCharacteristics = transferCharacteristics;
|
|
||||||
_matrixCoefficients = matrixCoefficients;
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)runAction:(SBQueueItem *)item {
|
|
||||||
for (MP42VideoTrack *track in [item.mp4File tracksWithMediaType:kMP42MediaType_Video]) {
|
|
||||||
if (track.format == kMP42VideoCodecType_H264 ||
|
|
||||||
track.format == kMP42VideoCodecType_HEVC ||
|
|
||||||
track.format == kMP42VideoCodecType_HEVC_PSinBitstream ||
|
|
||||||
track.format == kMP42VideoCodecType_MPEG4Video) {
|
|
||||||
track.colorPrimaries = self.colorPrimaries;
|
|
||||||
track.transferCharacteristics = self.transferCharacteristics;
|
|
||||||
track.matrixCoefficients = self.matrixCoefficients;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)description {
|
|
||||||
return NSLocalizedString(@"Set color space", @"Set track color space action description");
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)localizedDescription {
|
|
||||||
return NSLocalizedString(@"Setting color space", @"Set track color space action local description");
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (BOOL)supportsSecureCoding {
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
|
||||||
self = [super init];
|
|
||||||
_colorPrimaries = [coder decodeInt32ForKey:@"SBQueueColorSpaceActionColorPrimaries"];
|
|
||||||
_transferCharacteristics = [coder decodeInt32ForKey:@"SBQueueColorSpaceActionTransferCharacteristics"];
|
|
||||||
_matrixCoefficients = [coder decodeInt32ForKey:@"SBQueueColorSpaceActionMatrixCoefficients"];
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder {
|
|
||||||
[coder encodeInt32:self.colorPrimaries forKey:@"SBQueueColorSpaceActionColorPrimaries"];
|
|
||||||
[coder encodeInt32:self.transferCharacteristics forKey:@"SBQueueColorSpaceActionTransferCharacteristics"];
|
|
||||||
[coder encodeInt32:self.matrixCoefficients forKey:@"SBQueueColorSpaceActionMatrixCoefficients"];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
+13
-3
@@ -7,12 +7,22 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "SBQueueAction.h"
|
|
||||||
|
|
||||||
@class MP42File;
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@class MP42File;
|
||||||
|
@class SBQueueItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SBQueue actions protocol, actions can be run by
|
||||||
|
* the queue's items.
|
||||||
|
*/
|
||||||
|
@protocol SBQueueActionProtocol <NSObject, NSSecureCoding>
|
||||||
|
- (void)runAction:(SBQueueItem *)item;
|
||||||
|
@property (nonatomic, readonly) NSString *localizedDescription;
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
typedef NS_ENUM(NSUInteger, SBQueueItemStatus) {
|
typedef NS_ENUM(NSUInteger, SBQueueItemStatus) {
|
||||||
SBQueueItemStatusUnknown = 0,
|
SBQueueItemStatusUnknown = 0,
|
||||||
SBQueueItemStatusReady,
|
SBQueueItemStatusReady,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "SBQueueItem.h"
|
#import "SBQueueItem.h"
|
||||||
#import "SBQueueAction.h"
|
|
||||||
|
|
||||||
#import <MP42Foundation/MP42File.h>
|
#import <MP42Foundation/MP42File.h>
|
||||||
#import <MP42Foundation/MP42FileImporter.h>
|
#import <MP42Foundation/MP42FileImporter.h>
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#import <XCTest/XCTest.h>
|
#import <XCTest/XCTest.h>
|
||||||
|
|
||||||
#import "SBQueueAction.h"
|
|
||||||
|
|
||||||
@interface Subler_Tests : XCTestCase
|
@interface Subler_Tests : XCTestCase
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#import "SBDocument.h"
|
#import "SBDocument.h"
|
||||||
#import "SBQueueItem.h"
|
#import "SBQueueItem.h"
|
||||||
#import "SBQueueAction.h"
|
|
||||||
#import "SBMovieViewController.h"
|
#import "SBMovieViewController.h"
|
||||||
#import "SBMediaTagsController.h"
|
#import "SBMediaTagsController.h"
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,6 @@
|
|||||||
A9AB486817F0AEFD000AA72E /* VideoView.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9AB486217F0AEFD000AA72E /* VideoView.xib */; };
|
A9AB486817F0AEFD000AA72E /* VideoView.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9AB486217F0AEFD000AA72E /* VideoView.xib */; };
|
||||||
A9AE26C01F3B66470041A57D /* SquaredTVArt.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9AE26BD1F3B66470041A57D /* SquaredTVArt.swift */; };
|
A9AE26C01F3B66470041A57D /* SquaredTVArt.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9AE26BD1F3B66470041A57D /* SquaredTVArt.swift */; };
|
||||||
A9AE70E11F2F7B3D001CF27C /* MetadataHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9AE70E01F2F7B3D001CF27C /* MetadataHelper.swift */; };
|
A9AE70E11F2F7B3D001CF27C /* MetadataHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9AE70E01F2F7B3D001CF27C /* MetadataHelper.swift */; };
|
||||||
A9AF6A7518D0496400FAAB08 /* SBQueueAction.m in Sources */ = {isa = PBXBuildFile; fileRef = A9AF6A7418D0496400FAAB08 /* SBQueueAction.m */; };
|
|
||||||
A9B46AA412B79BB10040517A /* Subler.icns in Resources */ = {isa = PBXBuildFile; fileRef = A9B46AA312B79BB10040517A /* Subler.icns */; };
|
A9B46AA412B79BB10040517A /* Subler.icns in Resources */ = {isa = PBXBuildFile; fileRef = A9B46AA312B79BB10040517A /* Subler.icns */; };
|
||||||
A9B46ABF12B79D1C0040517A /* SBDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = A9B46ABE12B79D1C0040517A /* SBDocument.m */; };
|
A9B46ABF12B79D1C0040517A /* SBDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = A9B46ABE12B79D1C0040517A /* SBDocument.m */; };
|
||||||
A9B514191EFC12310055A035 /* TheTVDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B514181EFC12310055A035 /* TheTVDB.swift */; };
|
A9B514191EFC12310055A035 /* TheTVDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B514181EFC12310055A035 /* TheTVDB.swift */; };
|
||||||
@@ -268,8 +267,6 @@
|
|||||||
A9AB485317F0AEAC000AA72E /* SBVideoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SBVideoViewController.m; path = Classes/PropertyView/SBVideoViewController.m; sourceTree = "<group>"; };
|
A9AB485317F0AEAC000AA72E /* SBVideoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SBVideoViewController.m; path = Classes/PropertyView/SBVideoViewController.m; sourceTree = "<group>"; };
|
||||||
A9AE26BD1F3B66470041A57D /* SquaredTVArt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SquaredTVArt.swift; path = Classes/MetadataImporters/SquaredTVArt.swift; sourceTree = "<group>"; };
|
A9AE26BD1F3B66470041A57D /* SquaredTVArt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SquaredTVArt.swift; path = Classes/MetadataImporters/SquaredTVArt.swift; sourceTree = "<group>"; };
|
||||||
A9AE70E01F2F7B3D001CF27C /* MetadataHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MetadataHelper.swift; path = Classes/MetadataImporters/MetadataHelper.swift; sourceTree = "<group>"; };
|
A9AE70E01F2F7B3D001CF27C /* MetadataHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MetadataHelper.swift; path = Classes/MetadataImporters/MetadataHelper.swift; sourceTree = "<group>"; };
|
||||||
A9AF6A7318D0496400FAAB08 /* SBQueueAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBQueueAction.h; path = Classes/SBQueueAction.h; sourceTree = "<group>"; };
|
|
||||||
A9AF6A7418D0496400FAAB08 /* SBQueueAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SBQueueAction.m; path = Classes/SBQueueAction.m; sourceTree = "<group>"; };
|
|
||||||
A9B3411B1679CA3E00E6EE0C /* QTKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QTKit.framework; path = System/Library/Frameworks/QTKit.framework; sourceTree = SDKROOT; };
|
A9B3411B1679CA3E00E6EE0C /* QTKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QTKit.framework; path = System/Library/Frameworks/QTKit.framework; sourceTree = SDKROOT; };
|
||||||
A9B46AA312B79BB10040517A /* Subler.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = Subler.icns; path = images/Subler.icns; sourceTree = "<group>"; };
|
A9B46AA312B79BB10040517A /* Subler.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = Subler.icns; path = images/Subler.icns; sourceTree = "<group>"; };
|
||||||
A9B46ABD12B79D1C0040517A /* SBDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBDocument.h; path = Classes/SBDocument.h; sourceTree = "<group>"; };
|
A9B46ABD12B79D1C0040517A /* SBDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBDocument.h; path = Classes/SBDocument.h; sourceTree = "<group>"; };
|
||||||
@@ -564,8 +561,6 @@
|
|||||||
A9D73C5118BF3F1100C6FFA6 /* SBQueue.m */,
|
A9D73C5118BF3F1100C6FFA6 /* SBQueue.m */,
|
||||||
A982D0BE140AB66400B92357 /* SBQueueItem.h */,
|
A982D0BE140AB66400B92357 /* SBQueueItem.h */,
|
||||||
A982D0BF140AB66400B92357 /* SBQueueItem.m */,
|
A982D0BF140AB66400B92357 /* SBQueueItem.m */,
|
||||||
A9AF6A7318D0496400FAAB08 /* SBQueueAction.h */,
|
|
||||||
A9AF6A7418D0496400FAAB08 /* SBQueueAction.m */,
|
|
||||||
A91B196B1F2B0DCB0008675F /* QueueAction.swift */,
|
A91B196B1F2B0DCB0008675F /* QueueAction.swift */,
|
||||||
A9A8CEF71E43754400BC2AE1 /* SBQueueScriptCommand.h */,
|
A9A8CEF71E43754400BC2AE1 /* SBQueueScriptCommand.h */,
|
||||||
A9A8CEF81E43754400BC2AE1 /* SBQueueScriptCommand.m */,
|
A9A8CEF81E43754400BC2AE1 /* SBQueueScriptCommand.m */,
|
||||||
@@ -856,7 +851,6 @@
|
|||||||
A961476313F567E10068F161 /* SBQueueController.m in Sources */,
|
A961476313F567E10068F161 /* SBQueueController.m in Sources */,
|
||||||
A982D0C0140AB66400B92357 /* SBQueueItem.m in Sources */,
|
A982D0C0140AB66400B92357 /* SBQueueItem.m in Sources */,
|
||||||
A90057C01F99E35300FA4ED1 /* PopUpCellView.swift in Sources */,
|
A90057C01F99E35300FA4ED1 /* PopUpCellView.swift in Sources */,
|
||||||
A9AF6A7518D0496400FAAB08 /* SBQueueAction.m in Sources */,
|
|
||||||
A91B196C1F2B0DCB0008675F /* QueueAction.swift in Sources */,
|
A91B196C1F2B0DCB0008675F /* QueueAction.swift in Sources */,
|
||||||
A956CE651F99E5BB00093992 /* ActivityWindowController.swift in Sources */,
|
A956CE651F99E5BB00093992 /* ActivityWindowController.swift in Sources */,
|
||||||
A99189D11F2F88F700623ED7 /* ChapterSearchController.swift in Sources */,
|
A99189D11F2F88F700623ED7 /* ChapterSearchController.swift in Sources */,
|
||||||
|
|||||||
Reference in new issue
Block a user