swift - 如何从 m3u 播放列表解析徽标图像

swift - how to parse logo image from m3u playlist

我有一个解析 m3u 播放列表 url 但我也无法解析图像 url?

来自 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])
     }
 }