diff --git a/app/src/main/java/net/harimurti/tv/extension/Playlist.kt b/app/src/main/java/net/harimurti/tv/extension/Playlist.kt index ca73bde..565dd11 100644 --- a/app/src/main/java/net/harimurti/tv/extension/Playlist.kt +++ b/app/src/main/java/net/harimurti/tv/extension/Playlist.kt @@ -2,6 +2,7 @@ package net.harimurti.tv.extension import com.google.gson.Gson import com.google.gson.JsonParseException +import net.harimurti.tv.extra.AppLog import net.harimurti.tv.extra.M3uTool import net.harimurti.tv.model.* @@ -21,32 +22,38 @@ fun List?.toPlaylist(): Playlist? { var drm: DrmLicense? for (item in this) { - //hashset drm (disable same value) - if(!item.licenseKey.isNullOrEmpty()) { - drm = DrmLicense() - drm.name = item.licenseName - drm.url = item.licenseKey - if (hashSet.none { d -> d.name == item.licenseName }) - hashSet.add(drm) - } - //hashmap (map same groupname as key) - map = hashMap[item.groupName] - //set map value as channel - ch = Channel() - if (map != null) { - ch.name = item.channelName - ch.streamUrl = item.streamUrl - ch.drmName = item.licenseName - map.add(ch) - }else { - map = ArrayList() - ch.name = item.channelName - ch.streamUrl = item.streamUrl - ch.drmName = item.licenseName - map.add(ch) + for (i in item.streamUrl!!.indices) { + //hashset drm (disable same value) + if (!item.licenseKey.isNullOrEmpty()) { + drm = DrmLicense() + drm.name = item.licenseName + drm.url = item.licenseKey + if (hashSet.none { d -> d.name == item.licenseName }) + hashSet.add(drm) + } + + //hashmap (map same groupname as key) + map = hashMap[item.groupName] + //set map value as channel + ch = Channel() + if (map != null) { + ch.name = + if (i > 0) item.channelName + " #$i" else item.channelName + ch.streamUrl = item.streamUrl!![i] + ch.drmName = item.licenseName + map.add(ch) + }else { + map = ArrayList() + ch.name = + if (i > 0) item.channelName + " #$i" else item.channelName + ch.streamUrl = item.streamUrl!![i] + ch.drmName = item.licenseName + map.add(ch) + } + hashMap[item.groupName.toString()] = map + AppLog.d("Load channel "+map.size.toString()) } - hashMap[item.groupName.toString()] = map } //set map as categories diff --git a/app/src/main/java/net/harimurti/tv/extra/M3uTool.kt b/app/src/main/java/net/harimurti/tv/extra/M3uTool.kt index 32072a8..16a8924 100644 --- a/app/src/main/java/net/harimurti/tv/extra/M3uTool.kt +++ b/app/src/main/java/net/harimurti/tv/extra/M3uTool.kt @@ -39,6 +39,7 @@ class M3uTool { var m3u = M3U() var userAgent: String? = null + var extGrp: String? = null while (buffer.readLine().also { line = it } != null) { lineNumber++ when { @@ -47,16 +48,13 @@ class M3uTool { userAgent = regexUserAgent(line) } isExtGrp(line) -> { - // reset if GroupName is set - if(!m3u.groupName.isNullOrEmpty()) - m3u= M3U() - - // set group name - m3u.groupName = regexGrp(line)?.normalize() + // get extgroup name + extGrp = regexGrp(line)?.normalize() } isExtInf(line) -> { // reset if ChannelName is set if(!m3u.channelName.isNullOrEmpty()) + result.add(m3u) m3u= M3U() // set channel name @@ -64,6 +62,11 @@ class M3uTool { // set group name m3u.groupName = regexTitle(line)?.normalize() + + if(m3u.channelName.isNullOrEmpty() || m3u.channelName!!.startsWith(M3U.EXTINF)) + m3u.channelName = "NO NAME" + if(m3u.groupName.isNullOrBlank()) + m3u.groupName = extGrp ?: "UNCATAGORIZED" } isKodi(line) -> { // set drm license @@ -71,21 +74,13 @@ class M3uTool { m3u.licenseName = md5(regexKodi(line).toString()) } isStream(line) -> { - if(m3u.channelName.isNullOrEmpty() || m3u.channelName!!.startsWith(M3U.EXTINF)) - m3u.channelName = "NO NAME" - if(m3u.groupName.isNullOrBlank()) - m3u.groupName = "UNCATAGORIZED" - // add channel val streamUrl = line?.trim() - m3u.streamUrl = if (userAgent == null) streamUrl else "$streamUrl|User-Agent=$userAgent" - result.add(m3u) - - // reset channel - m3u= M3U() + m3u.streamUrl!!.add((if (userAgent == null) streamUrl else "$streamUrl|User-Agent=$userAgent")!!) } } } + buffer.close() } catch (e: IOException) { throw M3U.ParsingException(lineNumber, "Cannot read file", e) } diff --git a/app/src/main/java/net/harimurti/tv/model/M3U.kt b/app/src/main/java/net/harimurti/tv/model/M3U.kt index 6966543..0eeb975 100644 --- a/app/src/main/java/net/harimurti/tv/model/M3U.kt +++ b/app/src/main/java/net/harimurti/tv/model/M3U.kt @@ -9,7 +9,7 @@ class M3U { @SerializedName("name") var channelName: String? = null @SerializedName("stream_url") - var streamUrl: String? = null + var streamUrl: ArrayList? = ArrayList() @SerializedName("drm_url") var licenseKey: String? = null @SerializedName("drm_name")