Skip to content

Commit

Permalink
cetv1
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Mar 7, 2024
1 parent 0ebc166 commit 00e6c8d
Show file tree
Hide file tree
Showing 23 changed files with 402 additions and 216 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ body:
label: my-ty 版本
description: 请选择正在使用的版本
options:
- 最新稳定版
- 最新 CI 版
- 通用版
- 专用版
validations:
required: true
- type: textarea
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ body:
options:
- label: 之前没有人提交过类似或相同的功能请求。
required: true
- label: 这个建议不会背离 LibChecker 的初衷。
- label: 这个建议不会背离 my-tv 的初衷。
required: true
- type: textarea
id: propose
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@

## 更新日志

### v1.6.4(通用)

* 增加CETV1
* 增加凤凰卫视
* 默认关闭开机启动

### v1.6.2(通用)

* 修复按键无效的问题
* 新的频道列表样式

### v1.6.1(安卓5及以上专用)

* 增加凤凰卫视

### v1.6.0(通用)

* 通用(春晚緊急修復)
Expand Down Expand Up @@ -195,7 +205,7 @@ adb install my-tv.apk
## TODO

* 音量不同
* 大湾区卫视、广东4k超高清、广东珠江
* 大湾区卫视、广东4k超高清、广东珠江、三沙卫视
* CETV教育频道
* CHC高清三个电影频道
* 地方频道
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<provider
android:name=".InitializerProvider"
android:authorities="${applicationId}.InitializerProvider"
android:exported="false"/>
</application>
</manifest>
3 changes: 1 addition & 2 deletions app/src/main/java/com/lizongying/mytv/BootReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import android.content.Intent
class BootReceiver : BroadcastReceiver() {

override fun onReceive(context: Context, intent: Intent) {
val sp = context.getSharedPreferences("MainActivity", Context.MODE_PRIVATE)
if (sp.getBoolean(MainActivity.BOOT_STARTUP, true)) {
if (SP.bootStartup) {
context.startActivity(
Intent(context, MainActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/lizongying/mytv/CardAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class CardAdapter(
.centerInside()
.into(cardView.mainImageView)

"CETV1" -> Glide.with(viewHolder.view.context)
.load(R.drawable.cetv1)
.centerInside()
.into(cardView.mainImageView)

else -> Glide.with(viewHolder.view.context)
.load(tvViewModel.logo.value)
.centerInside()
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/lizongying/mytv/InfoFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class InfoFragment : Fragment() {
.load(R.drawable.bingtuan)
.into(binding.infoLogo)

"CETV1" -> Glide.with(this)
.load(R.drawable.cetv1)
.into(binding.infoLogo)

else -> Glide.with(this)
.load(tvViewModel.logo.value)
.into(binding.infoLogo)
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/com/lizongying/mytv/InitializerProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.lizongying.mytv

import android.content.ContentProvider
import android.content.ContentValues
import android.net.Uri

internal class InitializerProvider : ContentProvider() {

// Happens before Application#onCreate.It's fine to init something here
override fun onCreate(): Boolean {
SP.init(context!!)
return true
}

override fun query(
uri: Uri,
projection: Array<out String>?,
selection: String?,
selectionArgs: Array<out String>?,
sortOrder: String?,
) = unsupported()

override fun getType(uri: Uri) = unsupported()

override fun insert(uri: Uri, values: ContentValues?) = unsupported()

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?) =
unsupported()

override fun update(
uri: Uri,
values: ContentValues?,
selection: String?,
selectionArgs: Array<out String>?,
) = unsupported()

private fun unsupported(errorMessage: String? = null): Nothing =
throw UnsupportedOperationException(errorMessage)
}
55 changes: 7 additions & 48 deletions app/src/main/java/com/lizongying/mytv/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.lizongying.mytv

import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.pm.Signature
Expand Down Expand Up @@ -44,11 +42,6 @@ class MainActivity : FragmentActivity() {
private val delayHideMain: Long = 5000
private val delayHideSetting: Long = 10000

lateinit var sharedPref: SharedPreferences
private var channelReversal = false
private var channelNum = true
private var bootStartup = false

init {
lifecycleScope.launch(Dispatchers.IO) {
val utilsJob = async(start = CoroutineStart.LAZY) { Utils.init() }
Expand Down Expand Up @@ -78,26 +71,19 @@ class MainActivity : FragmentActivity() {
.commit()
}
gestureDetector = GestureDetector(this, GestureListener())

sharedPref = getPreferences(Context.MODE_PRIVATE)
channelReversal = sharedPref.getBoolean(CHANNEL_REVERSAL, channelReversal)
channelNum = sharedPref.getBoolean(CHANNEL_NUM, channelNum)
bootStartup = sharedPref.getBoolean(BOOT_STARTUP, bootStartup)

val packageInfo = getPackageInfo()
val versionName = packageInfo.versionName
val versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo.longVersionCode
} else {
packageInfo.versionCode.toLong()
}
settingFragment =
SettingFragment(versionName, versionCode, channelReversal, channelNum, bootStartup)
settingFragment = SettingFragment(versionName, versionCode, SP.channelReversal, SP.channelNum, SP.bootStartup)
}

fun showInfoFragment(tvViewModel: TVViewModel) {
infoFragment.show(tvViewModel)
if (channelNum) {
if (SP.channelNum) {
channelFragment.show(tvViewModel)
}
}
Expand All @@ -111,7 +97,7 @@ class MainActivity : FragmentActivity() {
return
}

if (channelNum) {
if (SP.channelNum) {
channelFragment.show(channel)
}
}
Expand Down Expand Up @@ -239,30 +225,6 @@ class MainActivity : FragmentActivity() {
}
}

fun saveChannelReversal(channelReversal: Boolean) {
with(sharedPref.edit()) {
putBoolean(CHANNEL_REVERSAL, channelReversal)
apply()
}
this.channelReversal = channelReversal
}

fun saveChannelNum(channelNum: Boolean) {
with(sharedPref.edit()) {
putBoolean(CHANNEL_NUM, channelNum)
apply()
}
this.channelNum = channelNum
}

fun saveBootStartup(bootStartup: Boolean) {
with(sharedPref.edit()) {
putBoolean(BOOT_STARTUP, bootStartup)
apply()
}
this.bootStartup = bootStartup
}

private fun showSetting() {
if (!mainFragment.isHidden) {
return
Expand All @@ -286,7 +248,7 @@ class MainActivity : FragmentActivity() {

private fun channelUp() {
if (mainFragment.isHidden) {
if (channelReversal) {
if (SP.channelReversal) {
next()
return
}
Expand All @@ -303,7 +265,7 @@ class MainActivity : FragmentActivity() {

private fun channelDown() {
if (mainFragment.isHidden) {
if (channelReversal) {
if (SP.channelReversal) {
prev()
return
}
Expand Down Expand Up @@ -557,10 +519,7 @@ class MainActivity : FragmentActivity() {
handler.removeCallbacks(hideMain)
}

companion object {
private const val TAG = "MainActivity"
private const val CHANNEL_REVERSAL = "channel_reversal"
private const val CHANNEL_NUM = "channel_num"
const val BOOT_STARTUP = "boot_startup"
private companion object {
const val TAG = "MainActivity"
}
}
11 changes: 2 additions & 9 deletions app/src/main/java/com/lizongying/mytv/MainFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lizongying.mytv

import android.content.SharedPreferences
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand Down Expand Up @@ -37,8 +36,6 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {

var tvListViewModel = TVListViewModel()

private lateinit var sharedPref: SharedPreferences

private var lastVideoUrl = ""

private val handler = Handler(Looper.getMainLooper())
Expand All @@ -56,9 +53,8 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
super.onActivityCreated(savedInstanceState)

activity?.let { request.initYSP(it) }
sharedPref = (activity as? MainActivity)?.sharedPref!!

itemPosition = sharedPref.getInt(POSITION, 0)
itemPosition = SP.itemPosition

view?.post {
val content = binding.content
Expand Down Expand Up @@ -343,10 +339,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
override fun onStop() {
Log.i(TAG, "onStop")
super.onStop()
with(sharedPref.edit()) {
putInt(POSITION, itemPosition)
apply()
}
SP.itemPosition = itemPosition
Log.i(TAG, "$POSITION $itemPosition saved")
}

Expand Down
48 changes: 46 additions & 2 deletions app/src/main/java/com/lizongying/mytv/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.lizongying.mytv.Utils.getDateFormat
import com.lizongying.mytv.api.ApiClient
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.Info
import com.lizongying.mytv.api.LiveInfo
import com.lizongying.mytv.api.LiveInfoRequest
Expand All @@ -33,6 +35,7 @@ class Request {
private var yspApiService: YSPApiService = ApiClient().yspApiService
private var yspBtraceService: YSPBtraceService = ApiClient().yspBtraceService
private var yspProtoService: YSPProtoService = ApiClient().yspProtoService
private var fAuthService: FAuthService = ApiClient().fAuthService
private var ysp: YSP? = null
private var token = ""

Expand Down Expand Up @@ -328,7 +331,7 @@ class Request {
token = response.body()?.data?.token!!
Log.i(TAG, "info success $token")
val cookie =
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109;yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
fetchVideo(tvModel, cookie)
} else {
Log.e(TAG, "info status error")
Expand Down Expand Up @@ -361,12 +364,53 @@ class Request {
})
} else {
val cookie =
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109;yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
fetchVideo(tvModel, cookie)
}
}

private var fAuth: Call<FAuth>? = null
fun fetchFAuth(tvModel: TVViewModel) {
call?.cancel()
callAuth?.cancel()
fAuth?.cancel()

val title = tvModel.title.value

fAuth = fAuthService.getAuth(tvModel.getTV().pid, "HD")
fAuth?.enqueue(object : Callback<FAuth> {
override fun onResponse(call: Call<FAuth>, response: Response<FAuth>) {
if (response.isSuccessful && response.body()?.data?.live_url != null) {
val url = response.body()?.data?.live_url!!
// Log.d(TAG, "$title url $url")
tvModel.addVideoUrl(url)
tvModel.allReady()
tvModel.retryTimes = 0
} else {
Log.e(TAG, "auth status error")
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
tvModel.tokenRetryTimes++
fetchFAuth(tvModel)
}
}
}

override fun onFailure(call: Call<FAuth>, t: Throwable) {
Log.e(TAG, "auth request error $t")
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
tvModel.tokenRetryTimes++
fetchFAuth(tvModel)
}
}
})
}

fun fetchData(tvModel: TVViewModel) {
if (tvModel.getTV().channel == "港澳台") {
fetchFAuth(tvModel)
return
}

if (tvModel.getTV().needToken) {
if (needAuth) {
fetchAuth(tvModel)
Expand Down
Loading

0 comments on commit 00e6c8d

Please sign in to comment.