I have a parsing m3u playlist url but I can't parse image url too?
all source code from 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
}
Any suggestions to parsing the channel logo is provided by tvg-logo
.
example:
#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])
}
}