Skip to content

Commit

Permalink
Fix a little mistake and add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfcon committed Jul 13, 2022
1 parent e5efb7a commit 91d18bc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 36 deletions.
6 changes: 1 addition & 5 deletions M3U8Kit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
01B38E4420EA30FD00AC6443 /* M3U8LineReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 01B38E4020EA30AB00AC6443 /* M3U8LineReader.m */; };
01C15384287D0EFB009D0C01 /* NSArray+m3u8.h in Headers */ = {isa = PBXBuildFile; fileRef = 01C15382287D0EFB009D0C01 /* NSArray+m3u8.h */; settings = {ATTRIBUTES = (Public, ); }; };
01C15385287D0EFB009D0C01 /* NSArray+m3u8.m in Sources */ = {isa = PBXBuildFile; fileRef = 01C15383287D0EFB009D0C01 /* NSArray+m3u8.m */; };
9D79F1291EF77CE500D16AFD /* M3U8Kit.h in Headers */ = {isa = PBXBuildFile; fileRef = 9D79F1271EF77CE500D16AFD /* M3U8Kit.h */; settings = {ATTRIBUTES = (Public, ); }; };
9D79F14A1EF784E500D16AFD /* NSString+m3u8.h in Headers */ = {isa = PBXBuildFile; fileRef = 9D79F12F1EF784E500D16AFD /* NSString+m3u8.h */; settings = {ATTRIBUTES = (Public, ); }; };
9D79F14C1EF784E500D16AFD /* NSString+m3u8.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D79F1301EF784E500D16AFD /* NSString+m3u8.m */; };
9D79F14E1EF784E500D16AFD /* NSURL+m3u8.h in Headers */ = {isa = PBXBuildFile; fileRef = 9D79F1311EF784E500D16AFD /* NSURL+m3u8.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -84,7 +83,6 @@
01C15383287D0EFB009D0C01 /* NSArray+m3u8.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSArray+m3u8.m"; sourceTree = "<group>"; };
9D05821D18E52DF500A12776 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
9D79F1251EF77CE400D16AFD /* M3U8Parser.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = M3U8Parser.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9D79F1271EF77CE500D16AFD /* M3U8Kit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = M3U8Kit.h; sourceTree = "<group>"; };
9D79F1281EF77CE500D16AFD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9D79F12F1EF784E500D16AFD /* NSString+m3u8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+m3u8.h"; sourceTree = "<group>"; };
9D79F1301EF784E500D16AFD /* NSString+m3u8.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+m3u8.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -176,7 +174,6 @@
9D79F1261EF77CE500D16AFD /* M3U8Kit */ = {
isa = PBXGroup;
children = (
9D79F1271EF77CE500D16AFD /* M3U8Kit.h */,
9D79F1281EF77CE500D16AFD /* Info.plist */,
);
path = M3U8Kit;
Expand All @@ -186,8 +183,8 @@
isa = PBXGroup;
children = (
011650B024483537001E4A35 /* M3U8Parser.modulemap */,
9D79F12E1EF784E500D16AFD /* Categories */,
9D79F1331EF784E500D16AFD /* M3U8Parser.h */,
9D79F12E1EF784E500D16AFD /* Categories */,
9D79F1341EF784E500D16AFD /* M3U8PlaylistModel.h */,
9D79F1351EF784E500D16AFD /* M3U8PlaylistModel.m */,
9D79F1361EF784E500D16AFD /* M3U8TagsAndAttributes.h */,
Expand Down Expand Up @@ -261,7 +258,6 @@
9D79F1521EF784E500D16AFD /* M3U8Parser.h in Headers */,
9D79F15E1EF784E500D16AFD /* M3U8ExtXMediaList.h in Headers */,
9D79F1761EF784E500D16AFD /* M3U8SegmentInfoList.h in Headers */,
9D79F1291EF77CE500D16AFD /* M3U8Kit.h in Headers */,
9D79F14A1EF784E500D16AFD /* NSString+m3u8.h in Headers */,
9D79F1621EF784E500D16AFD /* M3U8ExtXStreamInf.h in Headers */,
9D79F14E1EF784E500D16AFD /* NSURL+m3u8.h in Headers */,
Expand Down
20 changes: 0 additions & 20 deletions M3U8Kit/M3U8Kit.h

This file was deleted.

9 changes: 7 additions & 2 deletions M3U8KitTests/M3U8KitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ - (void)testPlaylistM3U {
M3U8SegmentInfoList *segments = playList.mainMediaPl.segmentList;
XCTAssertEqual(segments.count, 23);

NSDictionary *additionalParamaters = [segments segmentInfoAtIndex:0].additionalParameters;
XCTAssertEqual(additionalParamaters.count, 5);
M3U8SegmentInfo *segment0 = [segments segmentInfoAtIndex:0];
XCTAssertEqual(segment0.additionalParameters.count, 5);
XCTAssertEqual(segment0.duration, 2.0);

M3U8SegmentInfo *segment1 = [segments segmentInfoAtIndex:1];
XCTAssertNil(segment1.additionalParameters);
XCTAssertEqual(segment1.duration, 2.0);

XCTAssertNil(error);
}
Expand Down
16 changes: 8 additions & 8 deletions Source/M3U8MediaPlaylist.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "M3U8LineReader.h"
#import "M3U8ExtXKey.h"
#import "M3U8ExtXByteRange.h"
#import "NSArray+m3u8.h"

@interface M3U8MediaPlaylist()

Expand Down Expand Up @@ -106,16 +107,15 @@ - (void)parseMediaPlaylist
NSArray<NSString *> *components = [line componentsSeparatedByString:@","];
NSString *info = components.firstObject;
if (info) {
NSArray<NSString *> *additions = [info componentsSeparatedByString:@" "];
NSString *blankMark = @" ";
NSMutableArray<NSString *> *additions = [[info componentsSeparatedByString:blankMark] mutableCopy];
// get duration
if (additions.count == 1) {
NSString *duration = additions.firstObject;
params[M3U8_EXTINF_DURATION] = duration;
NSString *duration = additions.firstObject;
params[M3U8_EXTINF_DURATION] = duration;

// get additional parameters from Extended M3U https://en.wikipedia.org/wiki/M3U#Extended_M3U
} else {
NSString *extraInfo = [info stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@ ", additions.firstObject] withString:@""];

params[M3U8_EXTINF_ADDITIONAL_PARAMETERS] = extraInfo.m3u_attributesFromAssignmentByBlank;
if (additions.count > 1) {
params[M3U8_EXTINF_ADDITIONAL_PARAMETERS] = [additions m3u_attributesFromAssignmentByMark:blankMark];
}
}
if (components.count > 1) {
Expand Down
10 changes: 9 additions & 1 deletion Source/NSArray+m3u8.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ NS_ASSUME_NONNULL_BEGIN
@interface NSArray (m3u8)

/** @return "key=value" transform to dictionary */
- (NSMutableDictionary *)m3u_attributesFromAssignmentByMark:(NSString *)mark;
- (NSMutableDictionary *)m3u_attributesFromAssignment;

/**
If check by invalid value, value will append to last element with specific mark.
@param mark attribute will be ignored if it is invalid.
@return "key=value" transform to dictionary
*/
- (NSMutableDictionary *)m3u_attributesFromAssignmentByMark:(nullable NSString *)mark;

@end

Expand Down
5 changes: 5 additions & 0 deletions Source/NSArray+m3u8.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

@implementation NSArray (m3u8)

- (NSMutableDictionary *)m3u_attributesFromAssignment {
return [self m3u_attributesFromAssignmentByMark:nil];
}

- (NSMutableDictionary *)m3u_attributesFromAssignmentByMark:(NSString *)mark {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];

Expand All @@ -19,6 +23,7 @@ - (NSMutableDictionary *)m3u_attributesFromAssignmentByMark:(NSString *)mark {
NSRange equalMarkRange = [keyValue rangeOfString:@"="];
// if equal mark is not found, it means this value is previous value left. eg: CODECS=\"avc1.42c01e,mp4a.40.2\"
if (equalMarkRange.location == NSNotFound) {
if (!mark) continue;
if (!lastkey) continue;
NSString *lastValue = dict[lastkey];
NSString *supplement = [lastValue stringByAppendingFormat:@"%@%@", mark, keyValue.m3u_stringByTrimmingQuoteMark];
Expand Down

0 comments on commit 91d18bc

Please sign in to comment.