M3UKit - A µ framework for parsing m3u files

Overview

M3UKit

A µ framework for parsing m3u files.

CI codecov


Usage

1. Create a parser

let parser = PlaylistParser()

2. Parse a playlist

The playlist parser can parse a playlist from any source that conforms to the protocol PlaylistSource, by default: String, and URL.

let url = URL(string: "https://domain.com/link/to/m3u/file")
let playlist = try parser.parse(url)

or

let url = Bundle.main.url(forResource: "playlist", withExtension: "m3u")!
let playlist = try parser.parse(url)

or

let raw = """
#EXTM3U
#EXTINF:-1 tvg-id="DenHaagTV.nl",Den Haag TV (1080p)
http://wowza5.video-streams.nl:1935/denhaag/denhaag/playlist.m3u8
"""
let playlist = try parser.parse(raw)

M3UKit also supports asynchronous parsing with a completion handler or with the new async/await API

parser.parse(url) { result in
    switch result {
    case .success(let playlist):
        // consume playlist
    case .failure(let error):
        // handle error
    }
}

or

let playlist = try await parser.parse(url)

Schema

M3U exposes one model; Playlist, with the following schema:

Playlist
└── channels
Channel
├── duration
├── attributes
├── name
└── url
Attributes
├── id (tvg-id)
├── name (tvg-name)
├── country (tvg-country)
├── language (tvg-language)
├── logo (tvg-logo)
├── channelNumber (tvg-chno)
├── shift (tvg-shift)
└── groupTitle (group-title)

Installation

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code.

  1. Add the following to your Package.swift file:
dependencies: [
    .package(url: "https://github.com/omaralbeik/M3UKit.git", from: "0.4.0")
]
  1. Build your project:
$ swift build

CocoaPods

To integrate M3UKit into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'M3UKit', :git => 'https://github.com/omaralbeik/M3UKit.git', :tag => '0.4.0'

Carthage

To integrate M3UKit into your Xcode project using Carthage, specify it in your Cartfile:

0.4.0">
github "omaralbeik/M3UKit" ~> 0.4.0

Manually

Add the Sources folder to your Xcode project.


Thanks

Special thanks to Bashar Ghadanfar for helping with the regex patterns used for parsing m3u files 👏


License

M3UKit is released under the MIT license. See LICENSE for more information.

You might also like...
CoreML-Face-Parsing - how to use face-parsing CoreML model in iOS
CoreML-Face-Parsing - how to use face-parsing CoreML model in iOS

CoreML-Face-Parsing The simple sample how to use face-parsing CoreML model in iO

A Swift package for parsing Clang module map files

Clangler is a Swift package used to parse Clang module map files into an abstract syntax tree (AST) representation. Once parsed, you can inspect or manipulate the nodes in the file, then generate and save a new file reflecting your changes.

Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files.
Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files.

Installation • Configuration • Usage • Build Script • Donation • Migration Guides • Issues • Contributing • License BartyCrouch BartyCrouch incrementa

A Swift sample code to reads ISO 10303-21 exchange structures (STEP P21 files for AP242) split into multiple files using external references approach.

multipleP21ReadsSample A Swift sample code to reads ISO 10303-21 exchange structures (STEP P21 files for AP242) split into multiple files using extern

BeatboxiOS - A sample implementation for merging multiple video files and/or image files using AVFoundation

MergeVideos This is a sample implementation for merging multiple video files and

NotionDrive - A swift package that can upload files to Notion.so or download files from Notion.so

NotionDrive NotionDrive is a swift package that can upload files to Notion.so or

Freddy - A reusable framework for parsing JSON in Swift.
Freddy - A reusable framework for parsing JSON in Swift.

Why Freddy? Parsing JSON elegantly and safely can be hard, but Freddy is here to help. Freddy is a reusable framework for parsing JSON in Swift. It ha

A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.
A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.

PhoneNumberKit Swift 5.3 framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber. Features F

A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.
A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.

PhoneNumberKit Swift 5.3 framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber. Features F

OysterKit is a framework that provides a native Swift scanning, lexical analysis, and parsing capabilities. In addition it provides a language that can be used to rapidly define the rules used by OysterKit called STLR

OysterKit A Swift Framework for Tokenizing, Parsing, and Interpreting Languages OysterKit enables native Swift scanning, lexical analysis, and parsing

Lightweight Networking and Parsing framework made for iOS, Mac, WatchOS and tvOS.
Lightweight Networking and Parsing framework made for iOS, Mac, WatchOS and tvOS.

NetworkKit A lightweight iOS, Mac and Watch OS framework that makes networking and parsing super simple. Uses the open-sourced JSONHelper with functio

Framework for easily parsing your JSON data directly to Swift object.
Framework for easily parsing your JSON data directly to Swift object.

Server sends the all JSON data in black and white format i.e. its all strings & we make hard efforts to typecast them into their respective datatypes

StorageManager - FileManager framework that handels Store, fetch, delete and update files in local storage
StorageManager - FileManager framework that handels Store, fetch, delete and update files in local storage

StorageManager - FileManager framework that handels Store, fetch, delete and update files in local storage. Requirements iOS 8.0+ / macOS 10.10+ / tvOS

 Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.
Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Localize iOS apps in a smarter way using JSON files. Swift framework.
Localize iOS apps in a smarter way using JSON files. Swift framework.

Swifternalization Swift library that helps in localizing apps in a different, better, simpler, more powerful way than system localization does. It use

Merges a given number of PDF files into one file using the PDFKit framework

Titanium iOS PDF Merge Merges a given number of PDF files into one file using the PDFKit framework Requirements iOS 11+ Titanium SDK 9+ API's Methods

Swift framework for zipping and unzipping files.
Swift framework for zipping and unzipping files.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

MultiPeer-Progress-iOS - Swift project to demo the use of the MultiPeer framework to send files between iOS devices and show the progress
Straightforward, type-safe argument parsing for Swift

Swift Argument Parser Usage Begin by declaring a type that defines the information that you need to collect from the command line. Decorate each store

Comments
  • Special characters in M3U file can fail parsing

    Special characters in M3U file can fail parsing

    http://bit.ly/022qseed breaks the parser, It contains a special character at the beginning which makes the code in file "PlaylistParser" to fail with error "ParsingError.invalidSource".

    Would be possible to treat this case in the parser? Something like

    guard rawString.<remove-illegal-chars>.starts(with: filePrefix) else {
           throw ParsingError.invalidSource
     }
    
    bug good first issue 
    opened by cpvbruno 2
Releases(0.8.0)
  • 0.8.0(Nov 19, 2022)

    What's Changed

    • Add parser options by @omaralbeik in https://github.com/omaralbeik/M3UKit/pull/12

    Full Changelog: https://github.com/omaralbeik/M3UKit/compare/0.7.0...0.8.0

    Source code(tar.gz)
    Source code(zip)
  • 0.7.0(Nov 13, 2022)

    What's Changed

    • Parse kind from URL path by @omaralbeik in https://github.com/omaralbeik/M3UKit/pull/11

    Full Changelog: https://github.com/omaralbeik/M3UKit/compare/0.6.0...0.7.0

    Source code(tar.gz)
    Source code(zip)
  • 0.6.0(May 5, 2022)

    What's Changed

    • Renamed Channel to Media.
    • Added season/episode parsing.

    Full Changelog: https://github.com/omaralbeik/M3UKit/compare/0.5.3...0.6.0

    Source code(tar.gz)
    Source code(zip)
  • 0.5.3(Apr 28, 2022)

    What's Changed

    • Update concurrency in parser by @omaralbeik in https://github.com/omaralbeik/M3UKit/pull/8

    Full Changelog: https://github.com/omaralbeik/M3UKit/compare/0.5.2...0.5.3

    Source code(tar.gz)
    Source code(zip)
  • 0.5.2(Apr 24, 2022)

    What's Changed

    • Call completion on main queue in parser by @omaralbeik in https://github.com/omaralbeik/M3UKit/pull/7

    Full Changelog: https://github.com/omaralbeik/M3UKit/compare/0.5.1...0.5.2

    Source code(tar.gz)
    Source code(zip)
  • 0.5.1(Apr 22, 2022)

    What's Changed

    • Fix a bug where channel url was not correctly set by @omaralbeik in https://github.com/omaralbeik/M3UKit/pull/6

    Full Changelog: https://github.com/omaralbeik/M3UKit/compare/0.5.0...0.5.1

    Source code(tar.gz)
    Source code(zip)
  • 0.5.0(Apr 19, 2022)

    What's Changed

    • Add walking over a playlist by @omaralbeik in https://github.com/omaralbeik/M3UKit/pull/5

    Full Changelog: https://github.com/omaralbeik/M3UKit/compare/0.4.0...0.5.0

    Source code(tar.gz)
    Source code(zip)
  • 0.4.0(Apr 8, 2022)

    What's Changed

    • Fix a bug where files with #EXTVLCOPT lines fail to parse by @omaralbeik in https://github.com/omaralbeik/M3UKit/pull/4

    Full Changelog: https://github.com/omaralbeik/M3UKit/compare/0.3.0...0.4.0

    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Apr 4, 2022)

    What's Changed

    • Add asynchronous parsing by @omaralbeik in https://github.com/omaralbeik/M3UKit/pull/3

    Full Changelog: https://github.com/omaralbeik/M3UKit/compare/0.2.0...0.3.0

    Source code(tar.gz)
    Source code(zip)
  • 0.1(Mar 27, 2022)

Owner
Omar Albeik
It’s not a bug – it’s an undocumented feature!
Omar Albeik
App for adding and listening audio files

SomeSa SomeSa (самса) – приложение, позволяющее загружать и воспроизводить произвольные аудиофайлы. Протестировано на форматах файлов .wav и .mp3, раз

Yegor Dobrodeyev 0 Nov 7, 2021
MusicKit is a framework and DSL for creating, analyzing, and transforming music in Swift.

MusicKit MusicKit is a framework and DSL for creating, analyzing, and transforming music in Swift. Examples Functional harmony let C5 = Pitch(midi: 72

Ben Guo 591 Oct 18, 2022
A speech recognition framework designed for SwiftUI.

SwiftSpeech Speech Recognition Made Simple Recognize your user's voice elegantly without having to figure out authorization and audio engines. SwiftSp

cayZ 297 Dec 17, 2022
SoundManager - A simple framework to load and play sounds in your app.

SoundManager - A simple framework to load and play sounds in your app.

Jonathan Chacón 3 Jan 5, 2022
An iOS and macOS audio visualization framework built upon Core Audio useful for anyone doing real-time, low-latency audio processing and visualizations.

A simple, intuitive audio framework for iOS and OSX. Deprecated EZAudio has recently been deprecated in favor of AudioKit. However, since some people

Syed Haris Ali 4.9k Jan 2, 2023
The Amazing Audio Engine is a sophisticated framework for iOS audio applications, built so you don't have to.

Important Notice: The Amazing Audio Engine has been retired. See the announcement here The Amazing Audio Engine The Amazing Audio Engine is a sophisti

null 523 Nov 12, 2022
iOS framework for the Quiet Modem (data over sound)

QuietModemKit This is the iOS framework for https://github.com/quiet/quiet With this library, you can send data through sound. Live demo: https://quie

Quiet Modem Project 442 Nov 17, 2022
Functional DSP / Audio Framework for Swift

Lullaby Lullaby is an audio synthesis framework for Swift that supports both macOS and Linux! It was inspired by other audio environments like FAUST,

Jae 16 Nov 5, 2022
iOS framework that enables detecting and handling voice commands using microphone.

iOS framework that enables detecting and handling voice commands using microphone. Built using Swift with minumum target iOS 14.3.

Ahmed Abdelkarim 20 Aug 4, 2022
Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable

Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable. Elevate should no longer be used for

Nike Inc. 611 Oct 23, 2022