Latest 0.1.0-a
Homepage https://github.com/soranoba/MpegUrlKit
License MIT
Platforms ios 8.0
Authors

MpegUrlKit is a serializer/deserializer of m3u (m3u8) format used in HLS.

CI Status
Version
License
Platform

Overview

It can serialize and deserialize of m3u8 file formats.

  • It supported up to version 7 (#EXT-X-VERSION:7).
  • It provide a way to parse your original tags.

What is MpegUrl ?

The Internet Media Type of M3U is application/mpegurl.

I am taking it from here.

I avoided the name of M3U in order to avoid conflict with other libraries.

Reference link

Installation

MpegUrlKit is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'MpegUrlKit'

How to use functions of MpegUrlKit

Parse a M3U8 file

// #import <MpegUrlKit/MUKSerializer.h>
// #import <MpegUrlKit/MUKMediaPlaylist.h>

MUKSerializer* serializer = [MUKSerializer new];
serializer.serializableClasses = @[ MUKMediaPlaylist.class ];

NSError* error;
MUKMediaPlaylist* playlist = [serializer serializeFromString:@"#EXTM3Un"
                                                             @"#EXT-X-TARGETDURATION:5n"
                                                             @"...."
                                                       error:&error];

Generate a M3U8 file

TODO

Create a parser corresponding to your own tag

TODO

How to use AttributeModel (AttributeSerializer)

One of tag formats of HLS has Attribute Lists.

This library contains the model converter of the Attribute List.

When creating AttributeModel, inherit from MUKAttributeModel and define MUKAttributeSerializing protocol.

#import <MpegUrlKit/MUKAttributeModel.h>

@interface MUKXKey : MUKAttributeModel <MUKAttributeSerializing>
@end
@implementation MUKXKey

#pragma mark - MUKAttributeSerializing

+ (NSDictionary<NSString*, NSString*>* _Nonnull)propertyByAttributeKey
{
    //
    // {AttributeKey : PropertyName}
    //
    return @{ @"METHOD" : @"method",
              @"URI" : @"uri",
              @"IV" : @"aesInitializeVector",
              @"KEYFORMAT" : @"keyFormat",
              @"KEYFORMATVERSIONS" : @"keyFormatVersions" };
}

If it is a supported type, MUKAttributeSerializer automatically converts it according to the type of property.

Supported types are as below

  • NSUInteger, double, CGSize, BOOL
    • When converting to string from model, if the value is 0, it is ignored.
  • NSString, NSDate, NSData, NSURL
    • When converting to string from model, if the value is nil, it is ignored.

Please refer to MUKAttributeSerializer # valueForObject:forKey and MUKAttributeSerializer # setValue:forObject:forKey:error: for implementation.

In the case of a type that does not support or if you want to perform special conversion, you need to define transformer.

#pragma mark MUKAttributeSerializing (Optional)

///
/// + (MUKTransformer* _Nonnull) ${propertyName}Transformer
///
+ (MUKTransformer* _Nonnull)keyFormatVersionsTransformer
{
    return [MUKTransformer transformerWithBlock:^id _Nullable(MUKAttributeValue* _Nonnull value) {
        // If format of the value is "quoted-string", it is YES.
        if (value.isQuotedString) {
            return [value.value componentsSeparatedByString:@"/"];
        } else {
            // It returns nil that means unsupported format. So, conversion fails.
            return nil;
        }
    }
        reverseBlock:^MUKAttributeValue* _Nullable(id _Nonnull value) {
            NSString* str = [value appendString:@"/"];
            return [[MUKAttributeValue alloc] initWithValue:str isQuotedString:YES];
        }];
}

For more details, please see below

Contribute

Pull request is welcome =D

License

MIT License

Latest podspec

{
    "name": "MpegUrlKit",
    "version": "0.1.0-a",
    "summary": "MpegUrlKit is a serializer/deserializer of m3u (m3u8) format used in HLS.",
    "homepage": "https://github.com/soranoba/MpegUrlKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "soranoba": "[email protected]"
    },
    "source": {
        "git": "https://github.com/soranoba/MpegUrlKit.git",
        "tag": "0.1.0-a"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "MpegUrlKit/Classes/**/*.{m,h}",
    "private_header_files": "MpegUrlKit/Classes/Private/*.h"
}

Pin It on Pinterest

Share This