Skip to content

Commit

Permalink
combin channel
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Aug 4, 2024
1 parent bc8aaa6 commit c46f6e5
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 46 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## 更新日志

### v1.2.9

* 同頻道多視頻地址合併
* 更新了默認的視頻源,已安裝過的用戶需要在配置裡恢復默認
* “收藏模式”下,上下按鍵頻道只會在收藏列表裡進行切換

### v1.2.8

* 修復部分視頻源無法播放的問題
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/lizongying/mytv0/GroupAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.lizongying.mytv0

import android.content.Context
import android.util.Log
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -101,14 +100,14 @@ class GroupAdapter(
view.setOnKeyListener { _, keyCode, event: KeyEvent? ->
if (event?.action == KeyEvent.ACTION_UP) {
recyclerView.postDelayed({
var oldlikemode = tvGroupModel.isInLikeMode;
val oldLikeMode = tvGroupModel.isInLikeMode;
tvGroupModel.isInLikeMode = position == 0
if (tvGroupModel.isInLikeMode) {
Toast.makeText(context, "收藏模式", Toast.LENGTH_SHORT).show()
} else if ( oldlikemode){
} else if (oldLikeMode) {
Toast.makeText(context, "标准模式", Toast.LENGTH_SHORT).show()
}
},500)
}, 500)
}
if (event?.action == KeyEvent.ACTION_DOWN) {
if (keyCode == KeyEvent.KEYCODE_DPAD_UP && position == 0) {
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/com/lizongying/mytv0/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,14 @@ class MainActivity : FragmentActivity() {
val prevGroup = TVList.getTVModel().groupIndex
var position = TVList.position.value?.dec() ?: 0

var currentId = TVList.getTVModel().tv.id
if (TVList.groupModel.isInLikeMode) {
var likeList = TVList.groupModel.getTVListModel(0)
val currentId = TVList.getTVModel().tv.id
if (SP.defaultLike && TVList.groupModel.isInLikeMode) {
val likeList = TVList.groupModel.getTVListModel(0)
if (likeList != null) {
var oldPositionInList = -1;
for (i in 0 until likeList.size()) {
var tvmodel = likeList.getTVModel(i)
if (tvmodel != null && tvmodel.tv.id == currentId) {
val tvModel = likeList.getTVModel(i)
if (tvModel != null && tvModel.tv.id == currentId) {
oldPositionInList = i;
break
}
Expand Down Expand Up @@ -391,14 +391,14 @@ class MainActivity : FragmentActivity() {
fun next() {
val prevGroup = TVList.getTVModel().groupIndex
var position = TVList.position.value?.inc() ?: 0
var currentId = TVList.getTVModel().tv.id
if (TVList.groupModel.isInLikeMode) {
var likeList = TVList.groupModel.getTVListModel(0)
val currentId = TVList.getTVModel().tv.id
if (SP.defaultLike && TVList.groupModel.isInLikeMode) {
val likeList = TVList.groupModel.getTVListModel(0)
if (likeList != null) {
var oldPositionInList = -1;
for (i in 0 until likeList.size()) {
var tvmodel = likeList.getTVModel(i)
if (tvmodel != null && tvmodel.tv.id == currentId) {
val tvModel = likeList.getTVModel(i)
if (tvModel != null && tvModel.tv.id == currentId) {
oldPositionInList = i;
break
}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/lizongying/mytv0/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ object SP {
}

sp.edit().putStringSet(KEY_LIKE, stringSet).apply()
sp.edit().commit()
}

fun deleteLike() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.lifecycle.ViewModel
import com.lizongying.mytv0.SP

class TVGroupModel : ViewModel() {
public var isInLikeMode = false;
var isInLikeMode = false
private val _tvGroupModel = MutableLiveData<List<TVListModel>>()
val tvGroupModel: LiveData<List<TVListModel>>
get() = _tvGroupModel
Expand Down Expand Up @@ -61,6 +61,7 @@ class TVGroupModel : ViewModel() {

init {
_position.value = SP.positionGroup
isInLikeMode = SP.defaultLike
}

fun size(): Int {
Expand Down
69 changes: 51 additions & 18 deletions app/src/main/java/com/lizongying/mytv0/models/TVList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ object TVList {
"EPG状态错误".showToast()
}
} catch (e: Exception) {
e.printStackTrace()
Log.e("", "request error $e")
"EPG请求错误".showToast()
}
Expand Down Expand Up @@ -138,6 +139,7 @@ object TVList {
Log.e("Null Pointer Error", e.toString())
"无法读取频道".showToast()
} catch (e: Exception) {
e.printStackTrace()
Log.e("", "request error $e")
"频道请求错误".showToast()
}
Expand Down Expand Up @@ -209,6 +211,7 @@ object TVList {
val groupRegex = Regex("""group-title="([^"]+)"""")

val l = mutableListOf<TV>()
val tvMap = mutableMapOf<String, List<TV>>()
for ((index, line) in lines.withIndex()) {
val trimmedLine = line.trim()
if (trimmedLine.startsWith("#EXTM3U")) {
Expand All @@ -217,14 +220,15 @@ object TVList {
} else if (trimmedLine.startsWith("#EXTINF")) {
val info = trimmedLine.split(",")
val title = info.last().trim()
val name = nameRegex.find(info.first())?.groupValues?.get(1)?.trim()
var name = nameRegex.find(info.first())?.groupValues?.get(1)?.trim()
name = name ?: title
val group = groupRegex.find(info.first())?.groupValues?.get(1)?.trim()
val logo = logRegex.find(info.first())?.groupValues?.get(1)?.trim()
val uris =
if (index + 1 < lines.size) listOf(lines[index + 1].trim()) else emptyList()
val tv = TV(
0,
name ?: "",
name,
title,
"",
logo ?: "",
Expand All @@ -236,9 +240,30 @@ object TVList {
listOf(),
)

l.add(tv)
if (!tvMap.containsKey(name)) {
tvMap[name] = listOf()
}
tvMap[name] = tvMap[name]!! + tv
}
}
for ((_, tv) in tvMap) {
val uris = tv.map { t -> t.uris }.flatten()
val t0 = tv[0]
val t1 = TV(
0,
t0.name,
t0.name,
"",
t0.logo,
"",
uris,
mapOf(),
t0.group,
SourceType.UNKNOWN,
listOf(),
)
l.add(t1)
}
list = l
Log.i(TAG, "导入频道 ${list.size}")
}
Expand All @@ -247,6 +272,7 @@ object TVList {
val lines = string.lines()
var group = ""
val l = mutableListOf<TV>()
val tvMap = mutableMapOf<String, List<String>>()
for (line in lines) {
val trimmedLine = line.trim()
if (trimmedLine.isNotEmpty()) {
Expand All @@ -256,24 +282,31 @@ object TVList {
val arr = trimmedLine.split(',').map { it.trim() }
val title = arr.first().trim()
val uris = arr.drop(1)
val tv = TV(
0,
"",
title,
"",
"",
"",
uris,
mapOf(),
group,
SourceType.UNKNOWN,
listOf(),
)

l.add(tv)

if (!tvMap.containsKey(title)) {
tvMap[title] = listOf()
}
tvMap[title] = tvMap[title]!! + uris
}
}
}
for ((title, uris) in tvMap) {
val tv = TV(
0,
"",
title,
"",
"",
"",
uris,
mapOf(),
group,
SourceType.UNKNOWN,
listOf(),
)

l.add(tv)
}
list = l
Log.i(TAG, "导入频道 ${list.size}")
}
Expand Down
21 changes: 10 additions & 11 deletions app/src/main/java/com/lizongying/mytv0/models/TVModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.media3.exoplayer.source.ProgressiveMediaSource
import com.lizongying.mytv0.SP
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random

class TVModel(var tv: TV) : ViewModel() {
private val _position = MutableLiveData<Int>()
Expand Down Expand Up @@ -55,14 +56,6 @@ class TVModel(var tv: TV) : ViewModel() {
val program: LiveData<MutableList<Program>>
get() = _program

private val _videoUrl = MutableLiveData<String>()
val videoUrl: LiveData<String>
get() = _videoUrl

fun setVideoUrl(url: String) {
_videoUrl.value = url
}

private fun getVideoUrl(): String? {
if (_videoIndex.value == null || tv.uris.isEmpty()) {
return null
Expand All @@ -72,7 +65,8 @@ class TVModel(var tv: TV) : ViewModel() {
return null
}

return tv.uris[_videoIndex.value!!]
val index = min(max(_videoIndex.value!!, 0), tv.uris.size - 1)
return tv.uris[index]
}

private val _like = MutableLiveData<Boolean>()
Expand All @@ -88,6 +82,12 @@ class TVModel(var tv: TV) : ViewModel() {
get() = _ready

fun setReady() {
// _videoIndex.value = (_videoIndex.value!! + 1) % tv.uris.size
// if (tv.uris.size < 2) {
// _videoIndex.value = 0
// } else {
// _videoIndex.value = Random.nextInt(0, tv.uris.size - 1)
// }
_ready.value = true
}

Expand All @@ -101,9 +101,8 @@ class TVModel(var tv: TV) : ViewModel() {

init {
_position.value = 0
_videoIndex.value = 0
_videoIndex.value = max(0, tv.uris.size - 1)
_like.value = SP.getLike(tv.id)
_videoUrl.value = getVideoUrl()
_program.value = mutableListOf()

buildSource()
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version_code": 16910336, "version_name": "v1.2.8"}
{"version_code": 16910592, "version_name": "v1.2.9"}

0 comments on commit c46f6e5

Please sign in to comment.