@@ -84,7 +84,7 @@ class MainViewModel : ViewModel() {
8484 SP .configUrl?.let {
8585 if (it.startsWith(" http" )) {
8686 viewModelScope.launch {
87- Log .i(TAG , " updateConfig $it " )
87+ Log .i(TAG , " update config url: $it " )
8888 importFromUrl(it)
8989 updateEPG()
9090 }
@@ -117,12 +117,13 @@ class MainViewModel : ViewModel() {
117117 cacheChannels = getCache()
118118
119119 if (cacheChannels.isEmpty()) {
120+ Log .i(TAG , " cacheChannels isEmpty" )
120121 cacheChannels =
121122 context.resources.openRawResource(DEFAULT_CHANNELS_FILE ).bufferedReader()
122123 .use { it.readText() }
123124 }
124125
125- Log .i(TAG , " cacheChannels $cacheChannels " )
126+ Log .i(TAG , " cacheChannels $cacheFile $ cacheChannels" )
126127
127128 try {
128129 str2Channels(cacheChannels)
@@ -344,7 +345,9 @@ class MainViewModel : ViewModel() {
344345 fun tryStr2Channels (str : String , file : File ? , url : String , id : String = "") {
345346 try {
346347 if (str2Channels(str)) {
348+ Log .i(TAG , " write to cacheFile $cacheFile $str " )
347349 cacheFile!! .writeText(str)
350+ Log .i(TAG , " cacheFile ${getCache()} " )
348351 cacheChannels = str
349352 if (url.isNotEmpty()) {
350353 SP .configUrl = url
@@ -358,11 +361,13 @@ class MainViewModel : ViewModel() {
358361 }
359362 _channelsOk .value = true
360363 R .string.channel_import_success.showToast()
364+ Log .i(TAG , " channel import success" )
361365 } else {
362366 R .string.channel_import_error.showToast()
367+ Log .w(TAG , " channel import error" )
363368 }
364369 } catch (e: Exception ) {
365- e.printStackTrace( )
370+ Log .e( TAG , " tryStr2Channels " , e )
366371 file?.deleteOnExit()
367372 R .string.channel_read_error.showToast()
368373 }
@@ -407,6 +412,7 @@ class MainViewModel : ViewModel() {
407412 val lines = string.lines()
408413 val nameRegex = Regex (""" tvg-name="([^"]+)"""" )
409414 val logRegex = Regex (""" tvg-logo="([^"]+)"""" )
415+ val numRegex = Regex (""" tvg-chno="([^"]+)"""" )
410416 val epgRegex = Regex (""" x-tvg-url="([^"]+)"""" )
411417 val groupRegex = Regex (""" group-title="([^"]+)"""" )
412418
@@ -422,7 +428,6 @@ class MainViewModel : ViewModel() {
422428 if (trimmedLine.startsWith(" #EXTM3U" )) {
423429 epgUrl = epgRegex.find(trimmedLine)?.groupValues?.get(1 )?.trim()
424430 } else if (trimmedLine.startsWith(" #EXTINF" )) {
425- Log .i(TAG , " TV $tv " )
426431 val key = tv.group + tv.name
427432 if (key.isNotEmpty()) {
428433 tvMap[key] =
@@ -434,6 +439,8 @@ class MainViewModel : ViewModel() {
434439 var name = nameRegex.find(info.first())?.groupValues?.get(1 )?.trim()
435440 tv.name = if (name.isNullOrEmpty()) tv.title else name
436441 tv.logo = logRegex.find(info.first())?.groupValues?.get(1 )?.trim() ? : " "
442+ tv.number =
443+ numRegex.find(info.first())?.groupValues?.get(1 )?.trim()?.toInt() ? : - 1
437444 tv.group = groupRegex.find(info.first())?.groupValues?.get(1 )?.trim() ? : " "
438445 } else if (trimmedLine.startsWith(" #EXTVLCOPT:http-" )) {
439446 val keyValue =
@@ -476,6 +483,7 @@ class MainViewModel : ViewModel() {
476483 t0.headers,
477484 t0.group,
478485 SourceType .UNKNOWN ,
486+ t0.number,
479487 emptyList(),
480488 )
481489 l.add(t1)
@@ -525,12 +533,14 @@ class MainViewModel : ViewModel() {
525533 emptyMap(),
526534 channelGroup,
527535 SourceType .UNKNOWN ,
536+ - 1 ,
528537 emptyList(),
529538 )
530539
531540 l.add(tv)
532541 }
533542 list = l
543+ Log .d(TAG , " 导入频道 $list " )
534544 Log .i(TAG , " 导入频道 ${list.size} " )
535545 }
536546 }
@@ -565,6 +575,10 @@ class MainViewModel : ViewModel() {
565575
566576 listModel = listModelNew
567577
578+ for (ii in listModel) {
579+ Log .d(TAG , " ${ii.tv.title} ${ii.tv.number} " )
580+ }
581+
568582 // 全部频道
569583 groupModel.tvGroupValue[1 ].setTVListModel(listModel)
570584
0 commit comments