Better searching

main
Toldi Balázs Ádám 2 years ago
parent 78345fd7d7
commit 339b59eef8

@ -181,6 +181,7 @@ func main() {
urlList := [...]string{
"https://iptvcat.com/united_kingdom_-_-_-_-_-_-_-/s/bbc",
"https://iptvcat.com/s/bbc_world_news",
}
for _, element := range urlList {

@ -0,0 +1,14 @@
[
{
"channelName":"BBC News HD",
"searchString": "bbc news hd",
"tvg_id": "bbcnewshd.uk",
"tvg_logo": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/62/BBC_News_2019.svg/180px-BBC_News_2019.svg.png"
},
{
"channelName":"BBC World News HD",
"searchString": "bbc world news",
"tvg_id": "BBCWorldNews.uk",
"tvg_logo": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/32/BBC_World_News_2019.svg/170px-BBC_World_News_2019.svg.png"
}
]

@ -4,8 +4,10 @@ import com.beust.klaxon.Klaxon
import eu.toldi.iptv.model.IPTVChannels
import eu.toldi.iptv.model.Status
import eu.toldi.iptv.model.HLSChannel
import eu.toldi.iptv.model.SearchChannel
import java.io.File
import java.net.URL
import kotlin.math.pow
fun main(args: Array<String>) {
val klaxon = Klaxon()
@ -15,16 +17,21 @@ fun main(args: Array<String>) {
m3u8Chanels.addAll(staticChannels)
val json = File("scraper/data/all-streams.json").readText()
val channels = IPTVChannels.fromJson(json)
val top = channels.filter { it.status == Status.Online && it.channel.lowercase().contains("news hd") }.sortedByDescending { it.mbps.toDouble() * (it.liveliness.toDouble()/100) }.first()
println(top)
val processBuilder = ProcessBuilder("yt-dlp","-g",top.link)
processBuilder.redirectErrorStream(true)
val process = processBuilder.start()
//val results: List<String> = readProcessOutput(process.inputStream)
val output = process.inputStream.bufferedReader().use { it.readText() }.split('\n').last { it.startsWith("http") }
val bbcNews = HLSChannel("BBC News HD",output,"bbcnewshd.uk","https://upload.wikimedia.org/wikipedia/commons/thumb/6/62/BBC_News_2019.svg/180px-BBC_News_2019.svg.png")
m3u8Chanels.add(bbcNews)
val searchList = klaxon.parseArray<SearchChannel>(File("searchList.json"))!!
searchList.forEach { searchChannel ->
val top = channels.filter { it.status == Status.Online && it.channel.lowercase().contains(searchChannel.searchString) }.sortedByDescending { it.mbps.toDouble() * (it.liveliness.toDouble().pow(2)/100) }.first()
println(top)
val processBuilder = ProcessBuilder("yt-dlp","-g",top.link)
processBuilder.redirectErrorStream(true)
val process = processBuilder.start()
//val results: List<String> = readProcessOutput(process.inputStream)
val output = process.inputStream.bufferedReader().use { it.readText() }.split('\n').last { it.startsWith("http") }
val channel = HLSChannel(searchChannel.channelName,output,searchChannel.tvg_id,searchChannel.tvg_logo)
m3u8Chanels.add(channel)
}
File("data/all.m3u8").writeText(
buildString {

@ -11,10 +11,10 @@ private fun <T> Klaxon.convert(k: kotlin.reflect.KClass<*>, fromJson: (JsonValue
})
private val klaxon = Klaxon()
.convert(Country::class, { Country.fromValue(it.string!!) }, { "\"${it.value}\"" })
// .convert(Country::class, { Country.fromValue(it.string!!) }, { "\"${it.value}\"" })
.convert(Format::class, { Format.fromValue(it.string!!) }, { "\"${it.value}\"" })
.convert(Status::class, { Status.fromValue(it.string!!) }, { "\"${it.value}\"" })
.convert(URI::class, { URI.fromValue(it.string!!) }, { "\"${it.value}\"" })
// .convert(URI::class, { URI.fromValue(it.string!!) }, { "\"${it.value}\"" })
class IPTVChannels(elements: Collection<Channel>) : ArrayList<Channel>(elements) {
public fun toJson() = klaxon.toJsonString(this)
@ -28,7 +28,7 @@ data class Channel (
val id: String,
val channel: String,
val link: String,
val country: Country,
val country: String,
val liveliness: String,
val status: Status,
val lastChecked: String,
@ -36,20 +36,9 @@ data class Channel (
val mbps: String,
@Json(name = "URI")
val uri: List<URI>
val uri: List<String>
)
enum class Country(val value: String) {
UnitedKingdom("united kingdom");
companion object {
public fun fromValue(value: String): Country = when (value) {
"united kingdom" -> UnitedKingdom
else -> throw IllegalArgumentException()
}
}
}
enum class Format(val value: String) {
Fhd2K("fhd 2k"),
HD("hd"),
@ -78,17 +67,4 @@ enum class Status(val value: String) {
else -> throw IllegalArgumentException()
}
}
}
enum class URI(val value: String) {
URIUnitedKingdom("united_kingdom"),
UnitedKingdom("united_kingdom_-_-_-_-_-_-_-");
companion object {
public fun fromValue(value: String): URI = when (value) {
"united_kingdom" -> URIUnitedKingdom
"united_kingdom_-_-_-_-_-_-_-" -> UnitedKingdom
else -> throw IllegalArgumentException()
}
}
}
}

@ -0,0 +1,3 @@
package eu.toldi.iptv.model
data class SearchChannel(val channelName: String,val searchString: String,val tvg_id: String? = null,val tvg_logo: String? = null)
Loading…
Cancel
Save