From 44ab3a6669bc45416bf6929af3e57c8c4efec444 Mon Sep 17 00:00:00 2001 From: Li ZongYing Date: Sat, 3 Feb 2024 23:30:37 +0800 Subject: [PATCH] fix channel number did not disappear --- README.md | 4 ++ .../com/lizongying/mytv/ChannelFragment.kt | 7 ++ .../java/com/lizongying/mytv/MainActivity.kt | 3 + .../java/com/lizongying/mytv/MainFragment.kt | 2 +- .../main/java/com/lizongying/mytv/Request.kt | 68 ++++++++++++++----- .../main/java/com/lizongying/mytv/TVList.kt | 8 +-- .../com/lizongying/mytv/models/TVViewModel.kt | 30 +++++++- 7 files changed, 98 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index dac5184..6185d42 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,10 @@ ## 更新日志 +### v1.5.2(通用版) + +* 修复APP恢复后频道号、频道列表不自动消失的问题 + ### v1.5.1(高版本专用) * 性能优化 diff --git a/app/src/main/java/com/lizongying/mytv/ChannelFragment.kt b/app/src/main/java/com/lizongying/mytv/ChannelFragment.kt index 07adb88..1d42d8c 100644 --- a/app/src/main/java/com/lizongying/mytv/ChannelFragment.kt +++ b/app/src/main/java/com/lizongying/mytv/ChannelFragment.kt @@ -48,6 +48,13 @@ class ChannelFragment : Fragment() { } } + override fun onResume() { + super.onResume() + if (view?.visibility == View.VISIBLE) { + handler.postDelayed(hideRunnable, delay) + } + } + override fun onPause() { super.onPause() handler.removeCallbacks(hideRunnable) diff --git a/app/src/main/java/com/lizongying/mytv/MainActivity.kt b/app/src/main/java/com/lizongying/mytv/MainActivity.kt index 792a709..06e0a4d 100644 --- a/app/src/main/java/com/lizongying/mytv/MainActivity.kt +++ b/app/src/main/java/com/lizongying/mytv/MainActivity.kt @@ -496,6 +496,9 @@ class MainActivity : FragmentActivity() { override fun onResume() { Log.i(TAG, "onResume") super.onResume() + if (!mainFragment.isHidden){ + handler.postDelayed(hideMain, delayHideMain) + } } override fun onPause() { diff --git a/app/src/main/java/com/lizongying/mytv/MainFragment.kt b/app/src/main/java/com/lizongying/mytv/MainFragment.kt index 9dfb048..49424e8 100644 --- a/app/src/main/java/com/lizongying/mytv/MainFragment.kt +++ b/app/src/main/java/com/lizongying/mytv/MainFragment.kt @@ -271,7 +271,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener { inner class UpdateProgramRunnable : Runnable { override fun run() { - tvListViewModel.tvListViewModel.value?.filter { it.programId.value != null } + tvListViewModel.tvListViewModel.value?.filter { it.programId.value != null && it.programId.value != "" } ?.forEach { tvViewModel -> updateProgram( tvViewModel diff --git a/app/src/main/java/com/lizongying/mytv/Request.kt b/app/src/main/java/com/lizongying/mytv/Request.kt index f1fd929..c80b42d 100644 --- a/app/src/main/java/com/lizongying/mytv/Request.kt +++ b/app/src/main/java/com/lizongying/mytv/Request.kt @@ -39,6 +39,10 @@ class Request { private lateinit var btraceRunnable: BtraceRunnable private var tokenRunnable: TokenRunnable = TokenRunnable() + private val regex = Regex("""des_key = "([^"]+).+var des_iv = "([^"]+)""") + private val input = + """{"mver":"1","subver":"1.2","host":"www.yangshipin.cn/#/tv/home?pid=","referer":"","canvas":"YSPANGLE(Apple,AppleM1Pro,OpenGL4.1)"}""".toByteArray() + private var mapping = mapOf( "CCTV4K" to "CCTV4K 超高清", "CCTV1" to "CCTV1 综合", @@ -121,7 +125,6 @@ class Request { Base64.DEFAULT ) val decodedString = String(decodedBytes) - val regex = Regex("""des_key = "([^"]+).+var des_iv = "([^"]+)""") val matchResult = regex.find(decodedString) if (matchResult != null) { val (key, iv) = matchResult.destructured @@ -142,8 +145,14 @@ class Request { if (tvModel.retryTimes < tvModel.retryMaxTimes) { tvModel.retryTimes++ if (tvModel.needToken) { - token = "" - fetchVideo(tvModel) + if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) { + if (!tvModel.mustToken) { + fetchVideo(tvModel, cookie) + } + } else { + token = "" + fetchVideo(tvModel) + } } else { fetchVideo(tvModel, cookie) } @@ -158,8 +167,14 @@ class Request { if (tvModel.retryTimes < tvModel.retryMaxTimes) { tvModel.retryTimes++ if (tvModel.needToken) { - token = "" - fetchVideo(tvModel) + if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) { + if (!tvModel.mustToken) { + fetchVideo(tvModel, cookie) + } + } else { + token = "" + fetchVideo(tvModel) + } } else { fetchVideo(tvModel, cookie) } @@ -171,8 +186,14 @@ class Request { if (tvModel.retryTimes < tvModel.retryMaxTimes) { tvModel.retryTimes++ if (tvModel.needToken) { - token = "" - fetchVideo(tvModel) + if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) { + if (!tvModel.mustToken) { + fetchVideo(tvModel, cookie) + } + } else { + token = "" + fetchVideo(tvModel) + } } else { fetchVideo(tvModel, cookie) } @@ -185,8 +206,14 @@ class Request { if (tvModel.retryTimes < tvModel.retryMaxTimes) { tvModel.retryTimes++ if (tvModel.needToken) { - token = "" - fetchVideo(tvModel) + if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) { + if (!tvModel.mustToken) { + fetchVideo(tvModel, cookie) + } + } else { + token = "" + fetchVideo(tvModel) + } } else { fetchVideo(tvModel, cookie) } @@ -208,18 +235,28 @@ class Request { fetchVideo(tvModel, cookie) } else { Log.e(TAG, "info status error") - if (tvModel.retryTimes < tvModel.retryMaxTimes) { - tvModel.retryTimes++ + if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) { + tvModel.tokenRetryTimes++ fetchVideo(tvModel) + } else { + if (!tvModel.mustToken) { + val cookie = "vplatform=109" + fetchVideo(tvModel, cookie) + } } } } override fun onFailure(call: Call, t: Throwable) { Log.e(TAG, "info request error $t") - if (tvModel.retryTimes < tvModel.retryMaxTimes) { - tvModel.retryTimes++ + if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) { + tvModel.tokenRetryTimes++ fetchVideo(tvModel) + } else { + if (!tvModel.mustToken) { + val cookie = "vplatform=109" + fetchVideo(tvModel, cookie) + } } } }) @@ -375,15 +412,12 @@ class Request { } private fun encryptTripleDES(key: ByteArray, iv: ByteArray): String { - val plaintext = - """{"mver":"1","subver":"1.2","host":"www.yangshipin.cn/#/tv/home?pid=","referer":"","canvas":"YSPANGLE(Apple,AppleM1Pro,OpenGL4.1)"}""" return try { val keySpec = SecretKeySpec(key, "DESede") val ivSpec = IvParameterSpec(iv) val cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding") cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec) - val encryptedBytes = cipher.doFinal(plaintext.toByteArray()) - return encryptedBytes.let { it -> it.joinToString("") { "%02x".format(it) } } + return cipher.doFinal(input).let { it -> it.joinToString("") { "%02x".format(it) } } } catch (e: Exception) { e.printStackTrace() "" diff --git a/app/src/main/java/com/lizongying/mytv/TVList.kt b/app/src/main/java/com/lizongying/mytv/TVList.kt index ca03d67..66bb78f 100644 --- a/app/src/main/java/com/lizongying/mytv/TVList.kt +++ b/app/src/main/java/com/lizongying/mytv/TVList.kt @@ -71,7 +71,7 @@ object TVList { ) private var mappingEPG = mapOf( "CCTV4K 超高清" to "600002264", - "CCTV8K 超高清" to "600156816", +// "CCTV8K 超高清" to "600156816", "CCTV1 综合" to "600001859", "CCTV2 财经" to "600001800", "CCTV3 综艺" to "600001801", @@ -95,7 +95,7 @@ object TVList { "CGTN 俄语频道" to "600084758", "CGTN 阿拉伯语频道" to "600084782", "CGTN 西班牙语频道" to "600084744", - "CGTN 记录频道" to "600084781", +// "CGTN 记录频道" to "600084781", "风云剧场" to "600099658", "第一剧场" to "600099655", "怀旧剧场" to "600099620", @@ -130,8 +130,8 @@ object TVList { "四川卫视" to "600002516", "东南卫视" to "600002484", "海南卫视" to "600002506", - "天津卫视" to "600152137", - "新疆卫视" to "600152138", +// "天津卫视" to "600152137", +// "新疆卫视" to "600152138", ) private var mappingVideo = mapOf( "CCTV4K 超高清" to arrayOf("600002264", "2000266303"), diff --git a/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt b/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt index 16d7a83..a2a4451 100644 --- a/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt +++ b/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt @@ -19,8 +19,10 @@ class TVViewModel(private var tv: TV) : ViewModel() { private var rowPosition: Int = 0 private var itemPosition: Int = 0 - var retryTimes: Int = 0 - var retryMaxTimes: Int = 8 + var retryTimes = 0 + var tokenRetryTimes = 0 + var retryMaxTimes = 8 + var tokenRetryMaxTimes = 2 var programUpdateTime: Long = 0 private val _errInfo = MutableLiveData() @@ -77,6 +79,8 @@ class TVViewModel(private var tv: TV) : ViewModel() { var needToken = false + var mustToken = false + private val channelsNeedToken = arrayOf( "CCTV4K 超高清", "CCTV2 财经", @@ -134,6 +138,25 @@ class TVViewModel(private var tv: TV) : ViewModel() { "新疆卫视", ) + private val channelsMustToken = arrayOf( + "CCTV3 综艺", + "CCTV6 电影", + "CCTV8 电视剧", + "风云剧场", + "第一剧场", + "怀旧剧场", + "世界地理", + "风云音乐", + "兵器科技", + "风云足球", + "高尔夫网球", + "女性时尚", + "央视文化精品", + "央视台球", + "电视指南", + "卫生健康", + ) + fun addVideoUrl(url: String) { if (_videoUrl.value?.isNotEmpty() == true) { if (_videoUrl.value!!.last().contains("cctv.cn")) { @@ -188,6 +211,9 @@ class TVViewModel(private var tv: TV) : ViewModel() { if (tv.title in channelsNeedToken) { needToken = true } + if (tv.title in channelsMustToken) { + mustToken = true + } } fun getRowPosition(): Int {