Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

阅后即焚 #1839

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

阅后即焚 #1839

wants to merge 8 commits into from

Conversation

publieople
Copy link

添加功能配置:

  1. 下载后的资源阅后即焚
  2. 每隔24h检查并清理 bangumi 账户中被标记为'看过'的本地资源

该功能默认关闭,可在设置中打开

更新开发文档

@Him188 Him188 added s: player 子系统: 视频播放器 s: cache 子系统: 缓存系统 labels Mar 25, 2025
@StageGuard
Copy link
Member

需要为新的 extension 添加对应单元测试

@@ -10,42 +18,271 @@ import me.him188.ani.utils.logging.logger
import org.koin.core.Koin
import org.openani.mediamp.MediampPlayer
import org.openani.mediamp.PlaybackState
import kotlin.time.Duration.Companion.seconds
import java.util.concurrent.CopyOnWriteArrayList
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No java package in common source, use kotlinx.collections.immutable.PersistentList (persistentListOf) with MutableStateFlow instead.

PlaybackState.FINISHED -> {
val mediaData = context.player.mediaData.value as? TorrentMediaData ?: return@collect

stateMutex.withLock {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

过于复杂的逻辑,需要考虑重新实现。

上面 doc 中有四个条件,可以抽象出一个接口:

private interface BurnCondition {
    val result: Flow<Boolean>
}

为每个条件实现 BurnCondition

inner class PlaybackProgressGe90Percent : BurnCondition {
    // 启动协程或其他操作来执行监听播放进度超过 90% 的逻辑
    override val result = MutableStateFlow(false) // 满足条件时设置为 true
}

监听所有 result flow 来执行真正的删除逻辑:

combine(list) { results -> results.all { it } }
    .filter { it }
    .collect {
        // 执行删除逻辑
    }

注意这只是其中一种可行的修改方案,如果你有更好的方案就用你的。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我倒是觉得 @StageGuard proposed 的比较过度封装了, 这里只需要抽几个函数就行了, 才不到 100 行代码

Comment on lines 44 to 45
// 使用线程安全的列表管理后台任务
private val backgroundJobs = CopyOnWriteArrayList<Job>()
Copy link
Member

@Him188 Him188 Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job 生命周期由上层框架管理, 会自动停止 jobs. Extension 无需考虑关闭 job.

* 1. 播放进度超过 90%
* 2. 播放时长超过 60 秒
* 3. 不是由于用户手动跳转到结尾导致的播放完成
* 4. 播放完成后等待 30 秒,期间如果开始新的播放或暂停则取消删除
*/
class BurnAfterReadExtension(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个需要增加 test

* 1. 播放进度超过 90%
* 2. 播放时长超过 60 秒
* 3. 不是由于用户手动跳转到结尾导致的播放完成
* 4. 播放完成后等待 30 秒,期间如果开始新的播放或暂停则取消删除
*/
class BurnAfterReadExtension(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

相对于 "BurnAfterRead" (需要思考才能知道是在干什么), 我更倾向于直白的 DeleteCacheAfterWatchedExtension.

MarkAsWatchedExtension,
BurnAfterReadExtension,
).map { it.create(context, koin) },
intrinsicExtensions.map { it.create(context, koin) } + extensions.map { it.create(context, koin) },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改变了顺序. 顺序最好不变变动

Comment on lines 74 to 79
val intrinsicExtensions = listOf(
EpisodePlayerExtensionFactory { _, _ -> LoadMediaOnSelectExtension() },
RememberPlayProgressExtension,
MarkAsWatchedExtension,
BurnAfterReadExtension,
)
Copy link
Member

@Him188 Him188 Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加 intrinsic Extension 是不好的, 这可能会破坏现有的单元测试.

BurnAfterReadExtension 应当是一个可选的功能.

Comment on lines +42 to +43
// 每24小时检查一次
kotlinx.coroutines.delay(24 * 60 * 60 * 1000)
Copy link
Member

@Him188 Him188 Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 每24小时检查一次
kotlinx.coroutines.delay(24 * 60 * 60 * 1000)
// 每24小时检查一次
kotlinx.coroutines.delay(24.hours)

nit

PlaybackState.FINISHED -> {
val mediaData = context.player.mediaData.value as? TorrentMediaData ?: return@collect

stateMutex.withLock {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我倒是觉得 @StageGuard proposed 的比较过度封装了, 这里只需要抽几个函数就行了, 才不到 100 行代码

) {
Group(
title = {
Text("缓存设置")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其他地方已经有一个缓存设置了.

expect 函数不能有 body

@@ -16,6 +16,7 @@ ani.dandanplay.app.secret=aaaaaaaaaaaaaaa
## 打包 Android APP

在 IDE 中双击 Ctrl,可用的命令:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@Him188
Copy link
Member

Him188 commented Mar 26, 2025

请检查代码能通过编译并且在本地测试一下

由于播放器是核心功能, 我们比较期望有覆盖单元测试以确保它未来不会被破坏, 所以也请增加相关的单元测试.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s: cache 子系统: 缓存系统 s: player 子系统: 视频播放器
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants