Quite incomplete and untested ssa parser.
This commit is contained in:
6 files changed
+685
-1
No files matched your search
@@ -10,6 +10,7 @@
|
||||
#import "MP42MkvImporter.h"
|
||||
#import "MP42Mp4Importer.h"
|
||||
#import "MP42SrtImporter.h"
|
||||
#import "MP42SSAImporter.h"
|
||||
#import "MP42CCImporter.h"
|
||||
#import "MP42AC3Importer.h"
|
||||
#import "MP42AACImporter.h"
|
||||
@@ -55,7 +56,8 @@ static NSArray<NSString *> *_supportedFileFormats;
|
||||
[MP42H264Importer class],
|
||||
[MP42VobSubImporter class],
|
||||
[MP42AVFImporter class],
|
||||
[MP42AC3Importer class]];
|
||||
[MP42AC3Importer class],
|
||||
[MP42SSAImporter class],];
|
||||
|
||||
NSMutableArray<NSString *> *formats = [[NSMutableArray alloc] init];
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// MP42SrtImporter.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 31/01/10.
|
||||
// Copyright 2010 Damiano Galassi All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "MP42FileImporter.h"
|
||||
|
||||
|
||||
@interface MP42SSAImporter : MP42FileImporter
|
||||
@end
|
||||
@@ -0,0 +1,174 @@
|
||||
//
|
||||
// MP42SrtImporter.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 31/01/10.
|
||||
// Copyright 2010 Damiano Galassi All rights reserved.
|
||||
//
|
||||
|
||||
#import "MP42SSAImporter.h"
|
||||
#import "MP42FileImporter+Private.h"
|
||||
|
||||
#import "MP42File.h"
|
||||
#import "MP42SSAParser.h"
|
||||
#import "MP42SubUtilities.h"
|
||||
#import "MP42Languages.h"
|
||||
|
||||
#import "mp4v2.h"
|
||||
#import "MP42PrivateUtilities.h"
|
||||
#import "MP42Track+Private.h"
|
||||
|
||||
@interface MP42SSAImporter ()
|
||||
|
||||
@property (nonatomic, readonly) MP42SSAParser *parser;
|
||||
@property (nonatomic, readonly) SBSubSerializer *ss;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MP42SSAImporter
|
||||
|
||||
+ (NSArray<NSString *> *)supportedFileFormats {
|
||||
return @[@"ssa", @"ass"];
|
||||
}
|
||||
|
||||
- (instancetype)initWithURL:(NSURL *)fileURL error:(NSError **)outError
|
||||
{
|
||||
if ((self = [super initWithURL:fileURL])) {
|
||||
MP42SubtitleTrack *newTrack = [[MP42SubtitleTrack alloc] init];
|
||||
|
||||
newTrack.format = kMP42SubtitleCodecType_3GText;
|
||||
newTrack.URL = self.fileURL;
|
||||
newTrack.alternateGroup = 2;
|
||||
newTrack.language = getFilenameLanguage((__bridge CFStringRef)self.fileURL.path);
|
||||
|
||||
NSString *stringFromFileAtURL = [NSString stringWithContentsOfURL:fileURL encoding:NSUTF8StringEncoding error:NULL];
|
||||
|
||||
// Check if a 10.10 only class is available, NSLinguisticTagger crashes on 10.9
|
||||
// if the string contains some characters.
|
||||
if ([newTrack.language isEqualToString:@"und"] && NSClassFromString(@"NSVisualEffectView")) {
|
||||
// we couldn't deduce language from the fileURL
|
||||
// -> Let's look into the file itself
|
||||
|
||||
if (stringFromFileAtURL) { // try auto determining
|
||||
NSArray *tagschemes = @[NSLinguisticTagSchemeLanguage];
|
||||
NSCountedSet *languagesSet = [NSCountedSet new];
|
||||
NSLinguisticTagger *tagger = [[NSLinguisticTagger alloc] initWithTagSchemes:tagschemes options:0];
|
||||
|
||||
[stringFromFileAtURL enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) {
|
||||
|
||||
if (line.length > 1) {
|
||||
|
||||
tagger.string = line;
|
||||
|
||||
NSOrthography *ortho = [tagger orthographyAtIndex:0 effectiveRange:NULL];
|
||||
NSString *dominantLanguage = ortho.dominantLanguage;
|
||||
|
||||
if (dominantLanguage && ![dominantLanguage isEqualToString:@"und"]) {
|
||||
[languagesSet addObject:dominantLanguage];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
NSArray *sortedValues = [languagesSet.allObjects sortedArrayUsingComparator:^(id obj1, id obj2) {
|
||||
NSUInteger n = [languagesSet countForObject:obj1];
|
||||
NSUInteger m = [languagesSet countForObject:obj2];
|
||||
return (n <= m)? (n < m)? NSOrderedAscending : NSOrderedSame : NSOrderedDescending;
|
||||
}];
|
||||
|
||||
NSString *language = sortedValues.lastObject;
|
||||
|
||||
if (language) {
|
||||
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en"];
|
||||
NSString *languageName = [locale displayNameForKey:NSLocaleLanguageCode
|
||||
value:language];
|
||||
|
||||
if (languageName) {
|
||||
newTrack.language = [MP42Languages.defaultManager extendedTagForLang:languageName];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_parser = [[MP42SSAParser alloc] initWithString:stringFromFileAtURL];
|
||||
|
||||
if (!_parser.lines.count) {
|
||||
if (outError) {
|
||||
*outError = MP42Error(MP42LocalizedString(@"The file could not be opened.", @"ssa error message"),
|
||||
MP42LocalizedString(@"The file is not a ssa file, or it does not contain any subtitles.", @"ssa error message"), 100);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
_ss = [[SBSubSerializer alloc] init];
|
||||
[_ss setSSA:YES];
|
||||
|
||||
for (MP42SSALine *line in _parser.lines) {
|
||||
SBSubLine *sl = [[SBSubLine alloc] initWithLine:line.text start:line.start end: line.end];
|
||||
[_ss addLine:sl];
|
||||
}
|
||||
[_ss setFinished:YES];
|
||||
|
||||
if ([_ss forced]) {
|
||||
newTrack.someSamplesAreForced = YES;
|
||||
}
|
||||
|
||||
newTrack.duration = _parser.lines.lastObject.end;
|
||||
|
||||
[self addTrack:newTrack];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable NSData *)magicCookieForTrack:(MP42Track *)track
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSUInteger)timescaleForTrack:(MP42Track *)track
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
|
||||
- (NSSize)sizeForTrack:(MP42Track *)track
|
||||
{
|
||||
return NSMakeSize([(MP42SubtitleTrack *)track trackWidth], [(MP42SubtitleTrack *) track trackHeight]);
|
||||
}
|
||||
|
||||
- (void)demux
|
||||
{
|
||||
@autoreleasepool {
|
||||
MP42SampleBuffer *sample;
|
||||
|
||||
for (MP42SubtitleTrack *track in self.inputTracks) {
|
||||
CGSize trackSize;
|
||||
trackSize.width = track.trackWidth;
|
||||
trackSize.height = track.trackHeight;
|
||||
|
||||
while (!_ss.isEmpty && !self.isCancelled) {
|
||||
SBSubLine *sl = [_ss getSerializedPacket];
|
||||
|
||||
if ([sl->line isEqualToString:@"\n"]) {
|
||||
sample = copyEmptySubtitleSample(track.sourceId, sl->end_time - sl->begin_time, NO);
|
||||
}
|
||||
else {
|
||||
int top = (sl->top == INT_MAX) ? trackSize.height : sl->top;
|
||||
sample = copySubtitleSample(track.sourceId, sl->line, sl->end_time - sl->begin_time, sl->forced, NO, YES, trackSize, top);
|
||||
}
|
||||
|
||||
[self enqueue:sample];
|
||||
}
|
||||
}
|
||||
|
||||
self.progress = 100.0;
|
||||
|
||||
[self setDone];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return @"SRT demuxer";
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// MP42SSAParser.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 02/10/2017.
|
||||
// Copyright © 2017 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface MP42SSALine : NSObject
|
||||
|
||||
@property (nonatomic, readwrite) unsigned start;
|
||||
@property (nonatomic, readwrite) unsigned end;
|
||||
@property (nonatomic, readwrite) NSString *text;
|
||||
|
||||
@end
|
||||
|
||||
@interface MP42SSAParser : NSObject
|
||||
|
||||
- (instancetype)initWithString:(NSString *)string;
|
||||
- (instancetype)initWithHeader:(NSString *)header;
|
||||
|
||||
@property (nonatomic, readonly) NSArray<MP42SSALine *> *lines;
|
||||
|
||||
- (void)addLine:(NSString *)line;
|
||||
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,441 @@
|
||||
//
|
||||
// MP42SSAParser.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 02/10/2017.
|
||||
// Copyright © 2017 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MP42SSAParser.h"
|
||||
|
||||
@interface MP42SSAStyle : NSObject
|
||||
|
||||
- (instancetype)initWith:(NSArray<NSString *> *)style formats:(NSArray<NSString *> *)format;
|
||||
|
||||
@property (nonatomic, readwrite) NSString *name;
|
||||
@property (nonatomic, readwrite) NSString *fontName;
|
||||
@property (nonatomic, readwrite) int fontSize;
|
||||
@property (nonatomic, readwrite) long primaryColour;
|
||||
@property (nonatomic, readwrite) long secondaryColour;
|
||||
@property (nonatomic, readwrite) long outlineColour;
|
||||
@property (nonatomic, readwrite) long backColour;
|
||||
@property (nonatomic, readwrite) BOOL bold;
|
||||
@property (nonatomic, readwrite) BOOL italic;
|
||||
@property (nonatomic, readwrite) BOOL underline;
|
||||
@property (nonatomic, readwrite) BOOL strikeOut;
|
||||
@property (nonatomic, readwrite) float scaleX;
|
||||
@property (nonatomic, readwrite) float scaleY;
|
||||
@property (nonatomic, readwrite) int spacing;
|
||||
@property (nonatomic, readwrite) float angle;
|
||||
@property (nonatomic, readwrite) short borderStyle;
|
||||
@property (nonatomic, readwrite) short outline;
|
||||
@property (nonatomic, readwrite) short shadow;
|
||||
@property (nonatomic, readwrite) short alignment;
|
||||
@property (nonatomic, readwrite) int marginL;
|
||||
@property (nonatomic, readwrite) int marginR;
|
||||
@property (nonatomic, readwrite) int marginV;
|
||||
@property (nonatomic, readwrite) int alphaLevel;
|
||||
@property (nonatomic, readwrite) int encoding;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MP42SSAStyle
|
||||
|
||||
- (instancetype)initWith:(NSArray<NSString *> *)style formats:(NSArray<NSString *> *)format
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSUInteger stylesCount = style.count;
|
||||
NSUInteger formatsCount = format.count;
|
||||
|
||||
for (NSUInteger index = 0; index < stylesCount && index < formatsCount; index += 1) {
|
||||
NSString *value = style[index];
|
||||
NSString *formatName = format[index];
|
||||
|
||||
if ([formatName isEqualToString:@"Name"]) {
|
||||
_name = value;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Fontname"]) {
|
||||
_fontName = value;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Fontsize"]) {
|
||||
_fontSize = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"PrimaryColour"]) {
|
||||
_primaryColour = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"SecondaryColour"]) {
|
||||
_secondaryColour = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"TertiaryColour"] ||
|
||||
[formatName isEqualToString:@"OutlineColour"] ||
|
||||
[formatName isEqualToString:@"OutlineColor"]) {
|
||||
_outlineColour = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"BackColour"]) {
|
||||
_backColour = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Bold"]) {
|
||||
_bold = value.intValue == -1 ? YES : NO;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Italic"]) {
|
||||
_italic = value.intValue == -1 ? YES : NO;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Underline"]) {
|
||||
_underline = value.intValue == -1 ? YES : NO;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"StrikeOut"]) {
|
||||
_strikeOut = value.intValue == -1 ? YES : NO;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"ScaleX"]) {
|
||||
_scaleX = value.floatValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"ScaleY"]) {
|
||||
_scaleY = value.floatValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Spacing"]) {
|
||||
_spacing = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Angle"]) {
|
||||
_angle = value.floatValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"BorderStyle"]) {
|
||||
_borderStyle = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Outline"]) {
|
||||
_outline = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Shadow"]) {
|
||||
_shadow = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Alignment"]) {
|
||||
_alignment = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"MarginL"]) {
|
||||
_marginL = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"MarginR"]) {
|
||||
_marginR = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"MarginV"]) {
|
||||
_marginV = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"AlphaLevel"]) {
|
||||
_alphaLevel = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Encoding"]) {
|
||||
_encoding = value.intValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface MP42SSALine ()
|
||||
|
||||
- (instancetype)initWithString:(NSString *)string format:(NSArray<NSString *> *)format;
|
||||
|
||||
@property (nonatomic, readwrite) int layer;
|
||||
@property (nonatomic, readwrite) NSString *style;
|
||||
@property (nonatomic, readwrite) NSString *name;
|
||||
@property (nonatomic, readwrite) int marginL;
|
||||
@property (nonatomic, readwrite) int marginR;
|
||||
@property (nonatomic, readwrite) int marginV;
|
||||
@property (nonatomic, readwrite) NSString *effect;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MP42SSALine
|
||||
|
||||
- (instancetype)initWithString:(NSString *)string format:(NSArray<NSString *> *)format
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSUInteger formatsCount = format.count;
|
||||
NSArray<NSString *> *values = [self parse:string count:formatsCount];
|
||||
NSUInteger valuesCount = values.count;
|
||||
|
||||
for (NSUInteger index = 0; index < valuesCount && index < formatsCount; index += 1) {
|
||||
NSString *value = values[index];
|
||||
NSString *formatName = format[index];
|
||||
|
||||
if ([formatName isEqualToString:@"Layer"]) {
|
||||
_layer = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Start"]) {
|
||||
_start = ParseSubTime(value.UTF8String, 1000, NO);
|
||||
}
|
||||
else if ([formatName isEqualToString:@"End"]) {
|
||||
_end = ParseSubTime(value.UTF8String, 1000, NO);
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Style"]) {
|
||||
_style = value;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Name"]) {
|
||||
_name = value;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"MarginL"]) {
|
||||
_marginL = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"MarginR"]) {
|
||||
_marginR = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"MarginV"]) {
|
||||
_marginV = value.intValue;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Effect"]) {
|
||||
_effect = value;
|
||||
}
|
||||
else if ([formatName isEqualToString:@"Text"]) {
|
||||
_text = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSArray<NSString *> *)parse:(NSString *)string count:(NSUInteger)count
|
||||
{
|
||||
NSScanner *sc = [NSScanner scannerWithString:string];
|
||||
NSMutableArray<NSString *> *valuesArray = [NSMutableArray array];
|
||||
|
||||
if ([sc scanUpToString:@"Dialogue:" intoString:nil] || [sc scanString:@"Dialogue:" intoString:nil]) {
|
||||
[sc scanString:@"Dialogue:" intoString:nil];
|
||||
|
||||
NSString *value;
|
||||
|
||||
for (NSUInteger index = 0; index < count - 1; index += 1) {
|
||||
if ([sc scanUpToString:@"," intoString:&value]) {
|
||||
[valuesArray addObject:value];
|
||||
}
|
||||
else {
|
||||
[valuesArray addObject:@""];
|
||||
}
|
||||
[sc scanString:@"," intoString:nil];
|
||||
}
|
||||
|
||||
value = [sc.string substringFromIndex:sc.scanLocation];
|
||||
if (value) {
|
||||
[valuesArray addObject:value];
|
||||
}
|
||||
}
|
||||
|
||||
return valuesArray;
|
||||
}
|
||||
|
||||
static unsigned ParseSubTime(const char *time, unsigned secondScale, BOOL hasSign)
|
||||
{
|
||||
unsigned hour, minute, second, subsecond, timeval;
|
||||
char separator[3];
|
||||
int sign = 1;
|
||||
|
||||
if (hasSign && *time == '-') {
|
||||
sign = -1;
|
||||
time++;
|
||||
}
|
||||
|
||||
if (sscanf(time, "%u:%u:%u%[,.:]%u", &hour, &minute, &second, separator, &subsecond) < 5) {
|
||||
subsecond = 0;
|
||||
if (sscanf(time, "%u:%u:%u", &hour, &minute, &second) < 3) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (second > 60) {
|
||||
second = 0;
|
||||
}
|
||||
|
||||
while (subsecond > secondScale) {
|
||||
subsecond /= 10;
|
||||
}
|
||||
|
||||
timeval = hour * 60 * 60 + minute * 60 + second;
|
||||
timeval = secondScale * timeval + subsecond;
|
||||
|
||||
return timeval * sign;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@interface MP42SSAParser ()
|
||||
|
||||
@property (nonatomic, readonly) NSString *info;
|
||||
@property (nonatomic, readonly) NSArray<MP42SSAStyle *> *styles;
|
||||
|
||||
@property (nonatomic, readonly) NSArray<NSString *> *format;
|
||||
@property (nonatomic, readonly) NSMutableArray<MP42SSALine *> *lines_internal;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MP42SSAParser
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_styles = @[];
|
||||
_lines_internal = [NSMutableArray array];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithString:(NSString *)string
|
||||
{
|
||||
NSParameterAssert(string);
|
||||
self = [self init];
|
||||
if (self) {
|
||||
[self parse:string];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHeader:(NSString *)header
|
||||
{
|
||||
NSParameterAssert(header);
|
||||
self = [self init];
|
||||
if (self) {
|
||||
[self parseHeader:header];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)parse:(NSString *)ssa
|
||||
{
|
||||
[self parseHeader:ssa];
|
||||
[self parseLines:ssa];
|
||||
}
|
||||
|
||||
#pragma mark - Header
|
||||
|
||||
- (void)parseHeader:(NSString *)header
|
||||
{
|
||||
NSString *info;
|
||||
NSString *styles;
|
||||
NSString *format;
|
||||
|
||||
NSScanner *sc = [NSScanner scannerWithString:header];
|
||||
[sc setCharactersToBeSkipped:nil];
|
||||
|
||||
if ([sc scanUpToString:@"[V4+ Styles]" intoString:&info]) {
|
||||
_info = [self parseInfo:info];
|
||||
}
|
||||
|
||||
if ([sc scanUpToString:@"[Events]" intoString:&styles]) {
|
||||
_styles = [self parseStyles:styles];
|
||||
}
|
||||
|
||||
format = [sc.string substringFromIndex:sc.scanLocation];
|
||||
if (format.length) {
|
||||
_format = [self parseFormat:format];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)parseInfo:(NSString *)info
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
- (NSArray<MP42SSAStyle *> *)parseStyles:(NSString *)styles
|
||||
{
|
||||
NSScanner *sc = [NSScanner scannerWithString:styles];
|
||||
NSMutableArray<NSString *> *formatsArray = [NSMutableArray array];
|
||||
NSMutableArray<MP42SSAStyle *> *stylesArray = [NSMutableArray array];
|
||||
|
||||
if ([sc scanUpToString:@"Format:" intoString:nil] || [sc scanString:@"Format:" intoString:nil]) {
|
||||
[sc scanString:@"Format:" intoString:nil];
|
||||
NSString *formats;
|
||||
if ([sc scanUpToString:@"\n" intoString:&formats]) {
|
||||
NSScanner *formatScanner = [NSScanner scannerWithString:formats];
|
||||
NSString *formatName;
|
||||
while ([formatScanner scanUpToString:@"," intoString:&formatName]) {
|
||||
[formatScanner scanString:@"," intoString:nil];
|
||||
[formatsArray addObject:formatName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while ([sc scanUpToString:@"Style:" intoString:nil] || [sc scanString:@"Style:" intoString:nil]) {
|
||||
[sc scanString:@"Style:" intoString:nil];
|
||||
NSString *styles;
|
||||
if ([sc scanUpToString:@"\n" intoString:&styles]) {
|
||||
NSMutableArray<NSString *> *stylesValueArray = [NSMutableArray array];
|
||||
|
||||
NSScanner *stylesScanner = [NSScanner scannerWithString:styles];
|
||||
NSString *styleValue;
|
||||
while ([stylesScanner scanUpToString:@"," intoString:&styleValue]) {
|
||||
[stylesScanner scanString:@"," intoString:nil];
|
||||
[stylesValueArray addObject:styleValue];
|
||||
}
|
||||
|
||||
MP42SSAStyle *style = [[MP42SSAStyle alloc] initWith:stylesValueArray formats:formatsArray];
|
||||
if (style) {
|
||||
[stylesArray addObject:style];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stylesArray;
|
||||
}
|
||||
|
||||
- (NSArray<NSString *> *)parseFormat:(NSString *)format
|
||||
{
|
||||
NSScanner *sc = [NSScanner scannerWithString:format];
|
||||
NSMutableArray<NSString *> *formatsArray = [NSMutableArray array];
|
||||
|
||||
if ([sc scanUpToString:@"Format:" intoString:nil] || [sc scanString:@"Format:" intoString:nil]) {
|
||||
[sc scanString:@"Format:" intoString:nil];
|
||||
NSString *formats;
|
||||
if ([sc scanUpToString:@"\n" intoString:&formats]) {
|
||||
NSScanner *formatScanner = [NSScanner scannerWithString:formats];
|
||||
NSString *formatName;
|
||||
while ([formatScanner scanUpToString:@"," intoString:&formatName]) {
|
||||
[formatScanner scanString:@"," intoString:nil];
|
||||
[formatsArray addObject:formatName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return formatsArray;
|
||||
}
|
||||
|
||||
- (void)parseLines:(NSString *)lines
|
||||
{
|
||||
NSScanner *sc = [NSScanner scannerWithString:lines];
|
||||
NSMutableArray<MP42SSALine *> *linesArray = [NSMutableArray array];
|
||||
|
||||
[sc scanUpToString:@"[Events]" intoString:nil];
|
||||
[sc scanUpToString:@"Dialogue: " intoString:nil];
|
||||
|
||||
NSString *lineString;
|
||||
|
||||
while ([sc scanUpToString:@"\n" intoString:&lineString]) {
|
||||
MP42SSALine *line = [[MP42SSALine alloc] initWithString:lineString format:_format];
|
||||
if (line) {
|
||||
[linesArray addObject:line];
|
||||
}
|
||||
}
|
||||
|
||||
_lines_internal = linesArray;
|
||||
}
|
||||
|
||||
#pragma mark - Line
|
||||
|
||||
- (NSArray<MP42SSALine *> *)lines {
|
||||
return [_lines_internal copy];
|
||||
}
|
||||
|
||||
- (void)addLine:(NSString *)lineString
|
||||
{
|
||||
MP42SSALine *line = [[MP42SSALine alloc] initWithString:lineString format:_format];
|
||||
if (line) {
|
||||
[_lines_internal addObject:line];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -227,6 +227,14 @@
|
||||
A9DFBDCC1960174500410060 /* MP42EditListsReconstructor.m in Sources */ = {isa = PBXBuildFile; fileRef = A9DFBDCA1960174500410060 /* MP42EditListsReconstructor.m */; };
|
||||
A9E8FB851D4664E80071A5F1 /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A9E8FB841D4664E80071A5F1 /* libbz2.tbd */; };
|
||||
A9E8FB871D4664F70071A5F1 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A9E8FB861D4664F70071A5F1 /* libz.tbd */; };
|
||||
A9ED5B0D1F824A9B00E0E4FA /* MP42SSAParser.h in Headers */ = {isa = PBXBuildFile; fileRef = A9ED5B091F824A9A00E0E4FA /* MP42SSAParser.h */; };
|
||||
A9ED5B0E1F824A9B00E0E4FA /* MP42SSAParser.h in Headers */ = {isa = PBXBuildFile; fileRef = A9ED5B091F824A9A00E0E4FA /* MP42SSAParser.h */; };
|
||||
A9ED5B0F1F824A9B00E0E4FA /* MP42SSAParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A9ED5B0C1F824A9B00E0E4FA /* MP42SSAParser.m */; };
|
||||
A9ED5B101F824A9B00E0E4FA /* MP42SSAParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A9ED5B0C1F824A9B00E0E4FA /* MP42SSAParser.m */; };
|
||||
A9ED5B131F824BC100E0E4FA /* MP42SSAImporter.m in Sources */ = {isa = PBXBuildFile; fileRef = A9ED5B111F824BC000E0E4FA /* MP42SSAImporter.m */; };
|
||||
A9ED5B141F824BC100E0E4FA /* MP42SSAImporter.m in Sources */ = {isa = PBXBuildFile; fileRef = A9ED5B111F824BC000E0E4FA /* MP42SSAImporter.m */; };
|
||||
A9ED5B151F824BC100E0E4FA /* MP42SSAImporter.h in Headers */ = {isa = PBXBuildFile; fileRef = A9ED5B121F824BC000E0E4FA /* MP42SSAImporter.h */; };
|
||||
A9ED5B161F824BC100E0E4FA /* MP42SSAImporter.h in Headers */ = {isa = PBXBuildFile; fileRef = A9ED5B121F824BC000E0E4FA /* MP42SSAImporter.h */; };
|
||||
FFE849961EBCAFDF000AA078 /* MP42AC3AudioEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = FFE849941EBCAFDF000AA078 /* MP42AC3AudioEncoder.h */; };
|
||||
FFE849971EBCAFDF000AA078 /* MP42AC3AudioEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = FFE849951EBCAFDF000AA078 /* MP42AC3AudioEncoder.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
@@ -440,6 +448,10 @@
|
||||
A9DFBDCA1960174500410060 /* MP42EditListsReconstructor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MP42EditListsReconstructor.m; sourceTree = "<group>"; };
|
||||
A9E8FB841D4664E80071A5F1 /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; };
|
||||
A9E8FB861D4664F70071A5F1 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
|
||||
A9ED5B091F824A9A00E0E4FA /* MP42SSAParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42SSAParser.h; sourceTree = "<group>"; };
|
||||
A9ED5B0C1F824A9B00E0E4FA /* MP42SSAParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MP42SSAParser.m; sourceTree = "<group>"; };
|
||||
A9ED5B111F824BC000E0E4FA /* MP42SSAImporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MP42SSAImporter.m; sourceTree = "<group>"; };
|
||||
A9ED5B121F824BC000E0E4FA /* MP42SSAImporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42SSAImporter.h; sourceTree = "<group>"; };
|
||||
FFE849941EBCAFDF000AA078 /* MP42AC3AudioEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42AC3AudioEncoder.h; sourceTree = "<group>"; };
|
||||
FFE849951EBCAFDF000AA078 /* MP42AC3AudioEncoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MP42AC3AudioEncoder.m; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
@@ -698,6 +710,8 @@
|
||||
A9B9C2411823923100416A4E /* MP42Mp4Importer.m */,
|
||||
A9B9C24A1823923100416A4E /* MP42SrtImporter.h */,
|
||||
A9B9C24B1823923100416A4E /* MP42SrtImporter.m */,
|
||||
A9ED5B121F824BC000E0E4FA /* MP42SSAImporter.h */,
|
||||
A9ED5B111F824BC000E0E4FA /* MP42SSAImporter.m */,
|
||||
A9B9C2231823923100416A4E /* MP42AVFImporter.h */,
|
||||
A9B9C2241823923100416A4E /* MP42AVFImporter.m */,
|
||||
A9DFBDC91960174500410060 /* MP42EditListsReconstructor.h */,
|
||||
@@ -739,6 +753,8 @@
|
||||
A9B9C2591823923200416A4E /* MP42XMLReader.m */,
|
||||
A9B9C2361823923100416A4E /* MP42HtmlParser.h */,
|
||||
A9B9C2371823923100416A4E /* MP42HtmlParser.m */,
|
||||
A9ED5B091F824A9A00E0E4FA /* MP42SSAParser.h */,
|
||||
A9ED5B0C1F824A9B00E0E4FA /* MP42SSAParser.m */,
|
||||
A96523431BAC315900E994E0 /* NSString+MP42Additions.h */,
|
||||
A96523441BAC315900E994E0 /* NSString+MP42Additions.m */,
|
||||
);
|
||||
@@ -782,8 +798,10 @@
|
||||
A91C3AD11BF20CF1008BCF87 /* MP42FormatUtilites.h in Headers */,
|
||||
A96D28941BAD390400403327 /* MP42Metadata+Private.h in Headers */,
|
||||
A90801161D4B83A3002B6950 /* MP42AudioEncoder.h in Headers */,
|
||||
A9ED5B161F824BC100E0E4FA /* MP42SSAImporter.h in Headers */,
|
||||
A9422FC81D4917AF000DB435 /* audio_resample.h in Headers */,
|
||||
A917286719FD2BCE00348DF8 /* MP42Logging.h in Headers */,
|
||||
A9ED5B0E1F824A9B00E0E4FA /* MP42SSAParser.h in Headers */,
|
||||
A99FCBC51BAD65EF0058E27A /* MP42Track+Private.h in Headers */,
|
||||
A9AEFE161B9B111B00771292 /* MP42FileImporter+Private.h in Headers */,
|
||||
A96523461BAC315900E994E0 /* NSString+MP42Additions.h in Headers */,
|
||||
@@ -807,6 +825,7 @@
|
||||
A9B9C26C1823923200416A4E /* MP42AudioTrack.h in Headers */,
|
||||
A9B9C2741823923200416A4E /* MP42ChapterTrack.h in Headers */,
|
||||
A9B9C2971823923200416A4E /* MP42SubtitleTrack.h in Headers */,
|
||||
A9ED5B151F824BC100E0E4FA /* MP42SSAImporter.h in Headers */,
|
||||
A9B9C2761823923200416A4E /* MP42ClosedCaptionTrack.h in Headers */,
|
||||
A9022A941D6F3FD9005F0920 /* MP42MetadataItem.h in Headers */,
|
||||
A9B9C2871823923200416A4E /* MP42Metadata.h in Headers */,
|
||||
@@ -840,6 +859,7 @@
|
||||
A9B9C27F1823923200416A4E /* MP42H264Importer.h in Headers */,
|
||||
A9B9C29D1823923200416A4E /* MP42PrivateUtilities.h in Headers */,
|
||||
A90801111D4B83A3002B6950 /* MP42AudioDecoder.h in Headers */,
|
||||
A9ED5B0D1F824A9B00E0E4FA /* MP42SSAParser.h in Headers */,
|
||||
A9DFBDA1195FF5BA00410060 /* MP42Heap.h in Headers */,
|
||||
A9B9C2661823923200416A4E /* MP42AACImporter.h in Headers */,
|
||||
A9B9C2681823923200416A4E /* MP42AC3Importer.h in Headers */,
|
||||
@@ -1052,6 +1072,7 @@
|
||||
A97EA7CA1D4B8A2D00257CEA /* FFmpegUtils.m in Sources */,
|
||||
A910B60318394EB20064028F /* MP42H264Importer.mm in Sources */,
|
||||
A910B60518394EB20064028F /* MP42VobSubImporter.m in Sources */,
|
||||
A9ED5B141F824BC100E0E4FA /* MP42SSAImporter.m in Sources */,
|
||||
A91C3ACF1BF20CF1008BCF87 /* MP42FormatUtilites.mm in Sources */,
|
||||
A910B60718394EB20064028F /* MP42MkvImporter.m in Sources */,
|
||||
A9D764321E278B8100ED2F78 /* MP42MetadataUtilities.m in Sources */,
|
||||
@@ -1065,6 +1086,7 @@
|
||||
A90801141D4B83A3002B6950 /* MP42AudioDecoder.m in Sources */,
|
||||
A9422FC61D4917AF000DB435 /* audio_resample.c in Sources */,
|
||||
A910B61818394EB20064028F /* MatroskaFile.c in Sources */,
|
||||
A9ED5B101F824A9B00E0E4FA /* MP42SSAParser.m in Sources */,
|
||||
A910B61A18394EB20064028F /* MatroskaParser.c in Sources */,
|
||||
A910B61C18394EB20064028F /* mbs.cpp in Sources */,
|
||||
A991714E195AAAEF005AD68E /* MP42Track+Muxer.m in Sources */,
|
||||
@@ -1094,12 +1116,14 @@
|
||||
A9B9C26B1823923200416A4E /* MP42AudioConverter.m in Sources */,
|
||||
A9B9C2711823923200416A4E /* MP42BitmapSubConverter.m in Sources */,
|
||||
A9B9C28E1823923200416A4E /* MP42Muxer.m in Sources */,
|
||||
A9ED5B0F1F824A9B00E0E4FA /* MP42SSAParser.m in Sources */,
|
||||
A991714C195AAAEF005AD68E /* MP42Track+Muxer.m in Sources */,
|
||||
A9B9C2A21823923200416A4E /* MP42VobSubImporter.m in Sources */,
|
||||
A9B9C2961823923200416A4E /* MP42SrtImporter.m in Sources */,
|
||||
A9B9C2691823923200416A4E /* MP42AC3Importer.m in Sources */,
|
||||
A9B9C26F1823923200416A4E /* MP42AVFImporter.m in Sources */,
|
||||
A9B9C2671823923200416A4E /* MP42AACImporter.mm in Sources */,
|
||||
A9ED5B131F824BC100E0E4FA /* MP42SSAImporter.m in Sources */,
|
||||
A9B9C28C1823923200416A4E /* MP42Mp4Importer.m in Sources */,
|
||||
A9B9C28A1823923200416A4E /* MP42MkvImporter.m in Sources */,
|
||||
A9B9C2731823923200416A4E /* MP42CCImporter.m in Sources */,
|
||||
|
||||
Reference in new issue
Block a user