用于解析 m3u 文件的μ框架

M3UKit

用于解析 m3u 文件的μ框架。

词 科德科夫


用法

1. 创建解析器

let parser = PlaylistParser()

2. 解析播放列表

播放列表解析器可以从符合协议的任何源解析播放列表,默认情况下:、 和 。PlaylistSourceStringURL

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

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

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 还支持使用完成处理程序或新的 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; , with the following schema:Playlist

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 file:Package.swift

dependencies: [
    .package(url: "https://github.com/omaralbeik/M3UKit.git", from: "0.3.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.3.0'

Carthage

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

github "omaralbeik/M3UKit" ~> 0.3.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.

GitHub

点击跳转