Use the public TimeFromString function in SBChapterDB

This commit is contained in:
Damiano Galassi committed 2015-11-25 16:52:19 +01:00
1 parent 6c4f46c42f
commit 658a424e84
1 file changed
+14 -4
+14 -4
View File
@@ -9,7 +9,8 @@
#import "SBChapterDB.h" #import "SBChapterDB.h"
#import "SBChapterResult.h" #import "SBChapterResult.h"
#import <MP42Foundation/MP42ChapterTrack.h> #import <MP42Foundation/MP42TextSample.h>
#import <MP42Foundation/MP42Utilities.h>
#define API_KEY @"ETET7TXFJH45YNYW0I4A" #define API_KEY @"ETET7TXFJH45YNYW0I4A"
@@ -24,7 +25,7 @@
NSXMLDocument *xml = [[NSXMLDocument alloc] initWithData:xmlData NSXMLDocument *xml = [[NSXMLDocument alloc] initWithData:xmlData
options:0 options:0
error:nil]; error:NULL];
NSMutableArray<SBChapterResult *> *resultsArray = [[[NSMutableArray alloc] init] autorelease]; NSMutableArray<SBChapterResult *> *resultsArray = [[[NSMutableArray alloc] init] autorelease];
@@ -92,7 +93,7 @@
NSArray<NSXMLNode *> *tag = [node nodesForXPath:@"./*:source/*:duration" error:NULL]; NSArray<NSXMLNode *> *tag = [node nodesForXPath:@"./*:source/*:duration" error:NULL];
NSString *durationString = tag.firstObject.stringValue; NSString *durationString = tag.firstObject.stringValue;
if (durationString) { if (durationString) {
return ParseSubTime(durationString.UTF8String, 1000, NO); return (NSUInteger)TimeFromString(durationString, 1000);
} }
return 0; return 0;
} }
@@ -108,6 +109,8 @@
NSArray<NSXMLNode *> *times = [child nodesForXPath:@"./*:chapters/*:chapter/@time" error:NULL]; NSArray<NSXMLNode *> *times = [child nodesForXPath:@"./*:chapters/*:chapter/@time" error:NULL];
NSArray<NSXMLNode *> *names = [child nodesForXPath:@"./*:chapters/*:chapter/@name" error:NULL]; NSArray<NSXMLNode *> *names = [child nodesForXPath:@"./*:chapters/*:chapter/@name" error:NULL];
MP42Duration currentTime = 0;
if (times && names) { if (times && names) {
for (NSInteger i = 0; i < times.count && i < names.count; i++) { for (NSInteger i = 0; i < times.count && i < names.count; i++) {
@@ -116,7 +119,14 @@
NSString *timestamp = times[i].stringValue; NSString *timestamp = times[i].stringValue;
if (name && timestamp) { if (name && timestamp) {
unsigned time = ParseSubTime(timestamp.UTF8String, 1000, NO); MP42Duration time = TimeFromString(timestamp, 1000);
if (time < currentTime) {
break;
}
else {
currentTime = time;
}
MP42TextSample *chapter = [[MP42TextSample alloc] init]; MP42TextSample *chapter = [[MP42TextSample alloc] init];
chapter.title = name; chapter.title = name;