phoenix EPG

This commit is contained in:
Li ZongYing 2024-03-13 12:09:13 +08:00
parent 0c2beb936a
commit 7bed18ee6d
12 changed files with 1107 additions and 1090 deletions

View File

@ -39,11 +39,11 @@ class CardPresenter(
cardView.setBackgroundColor(Color.WHITE)
cardView.setMainImageScaleType(ImageView.ScaleType.CENTER_INSIDE)
tvViewModel.program.observe(owner) { _ ->
val program = tvViewModel.getProgramOne()
if (program != null) {
cardView.contentText = program.name
}
val epg = tvViewModel.epg.value?.filter { it.beginTime < Utils.getDateTimestamp() }
if (!epg.isNullOrEmpty()) {
cardView.contentText = epg.last().title
} else {
cardView.contentText = ""
}
}

View File

@ -2,6 +2,7 @@ package com.lizongying.mytv
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -34,9 +35,12 @@ class InfoFragment : Fragment() {
.load(tvViewModel.logo.value)
.into(binding.infoLogo)
val program = tvViewModel.getProgramOne()
if (program != null) {
binding.infoDesc.text = program.name
Log.i(TAG, "${tvViewModel.title.value} ${tvViewModel.epg.value}")
val epg = tvViewModel.epg.value?.filter { it.beginTime < Utils.getDateTimestamp() }
if (!epg.isNullOrEmpty()) {
binding.infoDesc.text = epg.last().title
} else {
binding.infoDesc.text = ""
}
handler.removeCallbacks(removeRunnable)

View File

@ -36,16 +36,6 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
private val delayHideMain: Long = 10000
private val delayHideSetting: Long = 10000
// init {
// lifecycleScope.launch(Dispatchers.IO) {
// val utilsJob = async(start = CoroutineStart.LAZY) { Utils.init() }
//
// utilsJob.start()
//
// utilsJob.await()
// }
// }
override fun onCreate(savedInstanceState: Bundle?) {
Log.i(TAG, "onCreate")
super.onCreate(savedInstanceState)
@ -459,5 +449,4 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
private companion object {
const val TAG = "MainActivity"
}
}

View File

@ -34,9 +34,6 @@ class MainFragment : BrowseSupportFragment() {
private var lastVideoUrl = ""
private val handler = Handler(Looper.getMainLooper())
private lateinit var mUpdateProgramRunnable: UpdateProgramRunnable
override fun onCreate(savedInstanceState: Bundle?) {
Log.i(TAG, "onCreate")
super.onCreate(savedInstanceState)
@ -57,9 +54,6 @@ class MainFragment : BrowseSupportFragment() {
setupEventListeners()
mUpdateProgramRunnable = UpdateProgramRunnable()
handler.post(mUpdateProgramRunnable)
tvListViewModel.tvListViewModel.value?.forEach { tvViewModel ->
tvViewModel.errInfo.observe(viewLifecycleOwner) { _ ->
if (tvViewModel.errInfo.value != null
@ -141,6 +135,8 @@ class MainFragment : BrowseSupportFragment() {
tvViewModel.setItemPosition(idx2)
tvListViewModel.addTVViewModel(tvViewModel)
listRowAdapter.add(tvViewModel)
updateEPG(tvViewModel)
}
tvListViewModel.maxNum.add(v.size)
val header = HeaderItem(idx, k)
@ -277,30 +273,11 @@ class MainFragment : BrowseSupportFragment() {
}
}
fun updateProgram(tvViewModel: TVViewModel) {
val timestamp = getDateTimestamp()
if (timestamp - tvViewModel.programUpdateTime > 60) {
if (tvViewModel.program.value!!.isEmpty()) {
tvViewModel.programUpdateTime = timestamp
Request.fetchProgram(tvViewModel)
} else {
if (tvViewModel.program.value!!.last().et - timestamp < 600) {
tvViewModel.programUpdateTime = timestamp
Request.fetchProgram(tvViewModel)
}
}
}
}
inner class UpdateProgramRunnable : Runnable {
override fun run() {
tvListViewModel.tvListViewModel.value?.filter { it.programId.value != null && it.programId.value != "" }
?.forEach { tvViewModel ->
updateProgram(
tvViewModel
)
}
handler.postDelayed(this, 60000)
private fun updateEPG(tvViewModel: TVViewModel) {
if (tvViewModel.getTV().channel == "港澳台") {
Request.fetchFEPG(tvViewModel)
} else {
Request.fetchYEPG(tvViewModel)
}
}
@ -313,18 +290,16 @@ class MainFragment : BrowseSupportFragment() {
Log.i(TAG, "onStop")
super.onStop()
SP.itemPosition = itemPosition
Log.i(TAG, "position saved")
Log.i(TAG, "$POSITION $itemPosition saved")
}
override fun onDestroy() {
Log.i(TAG, "onDestroy")
super.onDestroy()
if (::mUpdateProgramRunnable.isInitialized) {
handler.removeCallbacks(mUpdateProgramRunnable)
}
}
companion object {
private const val TAG = "MainFragment"
private const val POSITION = "position"
}
}

View File

@ -10,6 +10,7 @@ import com.lizongying.mytv.api.Auth
import com.lizongying.mytv.api.AuthRequest
import com.lizongying.mytv.api.FAuth
import com.lizongying.mytv.api.FAuthService
import com.lizongying.mytv.api.FEPG
import com.lizongying.mytv.api.Info
import com.lizongying.mytv.api.InfoV2
import com.lizongying.mytv.api.LiveInfo
@ -400,7 +401,7 @@ object Request {
tvModel.allReady()
tvModel.tokenRetryTimes = 0
} else {
Log.e(TAG, "auth status error")
Log.e(TAG, "auth status error ${response.code()}")
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
tvModel.tokenRetryTimes++
fetchFAuth(tvModel)
@ -419,7 +420,6 @@ object Request {
}
fun fetchData(tvModel: TVViewModel) {
Log.d(TAG, "fetchData")
if (tvModel.getTV().channel == "港澳台") {
fetchFAuth(tvModel)
return
@ -463,20 +463,20 @@ object Request {
if (e != null) {
handler.postDelayed(
tokenRunnable,
max(600000, (e - 1500) * 1000).toLong()
max(30 * 60 * 1000, (e - 1500) * 1000).toLong()
)
} else {
Log.e(TAG, "e empty")
handler.postDelayed(
tokenRunnable,
600000
30 * 60 * 1000
)
}
} else {
Log.e(TAG, "token empty")
handler.postDelayed(
tokenRunnable,
600000
30 * 60 * 1000
)
}
if (!f.isNullOrEmpty()) {
@ -491,7 +491,7 @@ object Request {
Log.e(TAG, "token status error")
handler.postDelayed(
tokenRunnable,
600000
30 * 60 * 1000
)
}
listener?.onRequestFinished()
@ -501,7 +501,7 @@ object Request {
Log.e(TAG, "token request error $t")
handler.postDelayed(
tokenRunnable,
600000
30 * 60 * 1000
)
listener?.onRequestFinished()
}
@ -521,27 +521,27 @@ object Request {
if (e != null) {
handler.postDelayed(
tokenRunnable,
max(600000, (e - 1500) * 1000).toLong()
max(30 * 60 * 1000, (e - 1500) * 1000).toLong()
)
} else {
Log.e(TAG, "e empty")
handler.postDelayed(
tokenRunnable,
600000
30 * 60 * 1000
)
}
} else {
Log.e(TAG, "token empty")
handler.postDelayed(
tokenRunnable,
600000
30 * 60 * 1000
)
}
} else {
Log.e(TAG, "token status error")
handler.postDelayed(
tokenRunnable,
600000
30 * 60 * 1000
)
}
}
@ -550,7 +550,7 @@ object Request {
Log.e(TAG, "token request error $t")
handler.postDelayed(
tokenRunnable,
600000
30 * 60 * 1000
)
}
})
@ -632,7 +632,7 @@ object Request {
})
}
fun fetchProgram(tvViewModel: TVViewModel) {
fun fetchYEPG(tvViewModel: TVViewModel) {
val title = tvViewModel.title.value
yspProtoService.getProgram(tvViewModel.programId.value!!, getDateFormat("yyyyMMdd"))
.enqueue(object : Callback<epgProgramModel.Response> {
@ -643,7 +643,7 @@ object Request {
if (response.isSuccessful) {
val program = response.body()
if (program != null) {
tvViewModel.addProgram(program.dataListList)
tvViewModel.addYEPG(program.dataListList)
Log.d(TAG, "$title program ${program.dataListList.size}")
}
} else {
@ -657,6 +657,31 @@ object Request {
})
}
fun fetchFEPG(tvViewModel: TVViewModel) {
val title = tvViewModel.title.value
fAuthService.getEPG(tvViewModel.pid.value!!, getDateFormat("yyyyMMdd"))
.enqueue(object : Callback<List<FEPG>> {
override fun onResponse(
call: Call<List<FEPG>>,
response: Response<List<FEPG>>
) {
if (response.isSuccessful) {
val program = response.body()
if (program != null) {
tvViewModel.addFEPG(program)
Log.d(TAG, "$title program ${program.size}")
}
} else {
Log.w(TAG, "$title program error")
}
}
override fun onFailure(call: Call<List<FEPG>>, t: Throwable) {
Log.e(TAG, "$title program request failed $t")
}
})
}
private fun encryptTripleDES(key: ByteArray, iv: ByteArray): String {
return try {
val keySpec = SecretKeySpec(key, "DESede")

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@ package com.lizongying.mytv.api
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Path
import retrofit2.http.Query
interface FAuthService {
@ -12,4 +13,11 @@ interface FAuthService {
@Query("live_id") live_id: String = "",
@Query("live_qa") live_qa: String = "",
): Call<FAuth>
@GET("api/v3/live/{liveId}/resources")
fun getEPG(
@Path("liveId") liveId: String,
@Query("date") date: String,
@Query("dir") dir: String = "asc"
): Call<List<FEPG>>
}

View File

@ -0,0 +1,7 @@
package com.lizongying.mytv.api
data class FEPG(
val title: String,
val event_time: String,
)

View File

@ -0,0 +1,7 @@
package com.lizongying.mytv.models
data class EPG(
val title: String,
val beginTime: Int,
)

View File

@ -11,8 +11,10 @@ import androidx.media3.common.util.UnstableApi
import androidx.media3.datasource.DefaultHttpDataSource
import androidx.media3.exoplayer.hls.HlsMediaSource
import com.lizongying.mytv.TV
import com.lizongying.mytv.Utils.getDateTimestamp
import com.lizongying.mytv.api.FEPG
import com.lizongying.mytv.proto.Ysp.cn.yangshipin.omstv.common.proto.programModel.Program
import java.text.SimpleDateFormat
import java.util.TimeZone
class TVViewModel(private var tv: TV) : ViewModel() {
@ -33,9 +35,9 @@ class TVViewModel(private var tv: TV) : ViewModel() {
val programId: LiveData<String>
get() = _programId
private var _program = MutableLiveData<MutableList<Program>>()
val program: LiveData<MutableList<Program>>
get() = _program
private var _epg = MutableLiveData<MutableList<EPG>>()
val epg: LiveData<MutableList<EPG>>
get() = _epg
private val _id = MutableLiveData<Int>()
val id: LiveData<Int>
@ -120,10 +122,8 @@ class TVViewModel(private var tv: TV) : ViewModel() {
_programId.value = tv.programId
_pid.value = tv.pid
_sid.value = tv.sid
_program.value = mutableListOf()
}
fun getRowPosition(): Int {
return rowPosition
}
@ -152,37 +152,23 @@ class TVViewModel(private var tv: TV) : ViewModel() {
return tv
}
fun getProgramOne(): Program? {
val programNew =
(_program.value?.filter { it.et > getDateTimestamp() })?.toMutableList()
if (programNew != null && _program.value != programNew) {
_program.value = programNew
}
if (_program.value!!.isEmpty()) {
return null
}
return _program.value?.first()
fun addYEPG(p: MutableList<Program>) {
_epg.value = p.map { EPG(it.name, it.st.toInt()) }.toMutableList()
}
fun addProgram(p: MutableList<Program>) {
val timestamp = getDateTimestamp()
// after now & not empty & different
val p1 = (p.filter { it.et > timestamp }).toMutableList()
if (p1.isEmpty() || _program.value == p1) {
return
}
if (_program.value!!.isEmpty()) {
_program.value = p1
} else {
_program.value =
((_program.value?.filter { it.et > timestamp && it.st < p1.first().st })?.plus(
p1
))?.toMutableList()
private fun formatFTime(s: String): Int {
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
dateFormat.timeZone = TimeZone.getTimeZone("UTC")
val date = dateFormat.parse(s.substring(0, 19))
if (date != null) {
return (date.time / 1000).toInt()
}
return 0
}
fun addFEPG(p: List<FEPG>) {
_epg.value = p.map { EPG(it.title, formatFTime(it.event_time)) }.toMutableList()
}
private var mHeaders: Map<String, String>? = mapOf()

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -130,7 +130,7 @@
"programId": "600004078",
"needToken": true,
"mustToken": false,
"title": "CCTV9 录",
"title": "CCTV9 录",
"videoUrl": [
"http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226197/index.m3u8"
]