swift - 如何解析m3u播放列表中的徽标图像
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift - 如何解析m3u播放列表中的徽标图像相关的知识,希望对你有一定的参考价值。
我有一个解析m3u播放列表网址,但我也无法解析图片网址?
来自GitHub的所有源代码:https://github.com/ArtemStepuk/zombobox
extension IPTVM3U8PareserService: M3U8ParserService {
func extractChannelsFromRawString(_ string: String) -> [Channel] {
var channels = [Channel]()
string.enumerateLines { line, shouldStop in
if line.hasPrefix("#EXTINF:") {
let infoLine = line.replacingOccurrences(of: "#EXTINF:", with: "")
let infoItems = infoLine.components(separatedBy: ",")
if let title = infoItems.last {
let channel = Channel(title: title, url: nil, logo: nil)
channels.append(channel)
}
} else {
if var channel = channels.popLast() {
channel.url = URL(string: line)
channels.append(channel)
}
}
}
return channels
}
tvg-logo
提供了解析频道徽标的任何建议。
例:
#EXTINF:-1 tvg-logo="http://i.cdn.turner.com/adultswim/big/video/mainstream/liveStream.jpg" group-title="USA",[AS] Live Stream
http://adultswimhls-i.akamaihd.net/hls/live/238460/adultswim/main/1/master_Layer5.m3u8
答案
//You can do this, and linkIm3 gives you the url for the image
let val2 = line.components(separatedBy: " ")
for sep in val2{
if sep.hasPrefix("tvg-logo="){
let sep2 = sep.components(separatedBy: ",")
let sep1 = sep2[0]
let indexStartOfText = sep1.index(sep1.startIndex, offsetBy: 10)
linkIm2 = String(sep1[indexStartOfText...])
let indexEndOfText = linkIm2.index(linkIm2.endIndex, offsetBy: -1)
linkIm3 = String(linkIm2[..<indexEndOfText])
}
}
以上是关于swift - 如何解析m3u播放列表中的徽标图像的主要内容,如果未能解决你的问题,请参考以下文章