Skip to content

Commit

Permalink
video info
Browse files Browse the repository at this point in the history
  • Loading branch information
GangJust committed Jun 19, 2024
1 parent 2499805 commit 79ce01d
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 77 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "io.github.fplus"
minSdk 24
targetSdk 33
versionCode 128
versionName "1.3.1"
versionCode 129
versionName "1.3.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/assets/update.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v1.3.2
增加清爽模式菜单视频信息查询
移除清爽模式菜单过滤统计选项
修复文件下载不通知媒体库刷新的问题

v1.3.1
增加横屏播放单独的状态栏沉浸逻辑
增加根据内容自动匹配下载文件的格式 (表情包无法发送微信问题)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.1-128
1.3.2-129
2 changes: 0 additions & 2 deletions core/src/main/java/io/github/fplus/core/base/BaseHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import android.view.View
import android.widget.FrameLayout
import android.widget.ProgressBar
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.DrawableRes
import androidx.compose.runtime.Composable
import androidx.core.view.isVisible
Expand Down Expand Up @@ -53,7 +52,6 @@ abstract class BaseHook : HookEntity() {
private var singleMainJob: MutableMap<String, Job?> = mutableMapOf()
private var singleIOJob: MutableMap<String, Job?> = mutableMapOf()

private var toast: Toast? = null
private var kDialog: KDialog? = null

private fun launch(context: CoroutineContext, block: suspend CoroutineScope.() -> Unit): Job {
Expand Down
22 changes: 19 additions & 3 deletions core/src/main/java/io/github/fplus/core/hook/HLongPressLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import io.github.fplus.core.base.BaseHook
import io.github.fplus.core.config.ConfigV1
import io.github.fplus.core.helper.DexkitBuilder
import io.github.fplus.core.hook.logic.DownloadLogic
import io.github.fplus.core.hook.logic.cityInfo
import io.github.fplus.core.hook.logic.createDate
import io.github.fplus.core.ui.activity.FreedomSettingActivity
import io.github.xpler.core.entity.OnAfter
import io.github.xpler.core.hookBlockRunning
Expand Down Expand Up @@ -171,9 +173,11 @@ class HLongPressLayout : BaseHook() {
items.add(0, if (!config.neatModeState) "清爽模式" else "普通模式")
}

if (config.isVideoFilter) {
items.add("过滤统计")
}
// if (config.isVideoFilter) {
// items.add("过滤统计")
// }

items.add("视频信息")

if (!config.isDisablePlugin) {
items.add("模块设置")
Expand Down Expand Up @@ -209,6 +213,18 @@ class HLongPressLayout : BaseHook() {
)
}

"视频信息" -> {
singleLaunchMain("$item") {
val msg = "视频属地: ${aweme?.cityInfo()}\n发布时间: ${aweme?.createDate()}".trim()
showMessageDialog(
context = view.context,
title = "视频信息",
content = msg,
singleButton = true,
)
}
}

"过滤统计" -> {
val builder = StringBuilder()
if (HVerticalViewPager.filterLiveCount > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class HVerticalViewPager : BaseHook() {
val mData = mModel?.fieldGet(name = "mData")
if (mData?.javaClass?.name?.contains("FeedItemList") == true) {
val items = mData.fieldGet(name = "items")?.asOrNull<List<Aweme>>() ?: emptyList()
if (items.size < 3) return@onBefore
if (items.size < 10) return@onBefore

mData.fieldSet(name = "items", filterAwemeList(items))
// val array = items.map { it.sortString() }.toTypedArray()
Expand All @@ -251,7 +251,7 @@ class HVerticalViewPager : BaseHook() {
val mData = mModel?.fieldGet(name = "mData")
if (mData?.javaClass?.name?.contains("FollowFeedList") == true) {
val mItems = mData.fieldGet(name = "mItems")?.asOrNull<List<FollowFeed>>() ?: emptyList()
if (mItems.size < 3) return@onBefore
if (mItems.size < 10) return@onBefore

mData.fieldSet("mItems", filterFollowFeedList(mItems))
// val array = mItems.map { it.aweme.sortString() }.toTypedArray()
Expand Down
29 changes: 29 additions & 0 deletions core/src/main/java/io/github/fplus/core/hook/logic/AwemeExt.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
package io.github.fplus.core.hook.logic

import com.freegang.extension.format
import com.freegang.extension.getStringOrDefault
import com.freegang.extension.parseJSON
import com.freegang.ktutils.net.KHttpUtils
import com.ss.android.ugc.aweme.feed.model.Aweme
import com.ss.ugc.aweme.ImageUrlStruct
import io.github.xpler.core.log.XplerLog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.util.Date

fun Aweme.createDate(): String {
return Date(this.createTime * 1000).format()
}

suspend fun Aweme.cityInfo(): String {
return withContext(Dispatchers.IO) {
runCatching {
val result = KHttpUtils.get("http://api.ip33.com/Area_Code/GetArea/?code=$city")
val areaJson = result.parseJSON()
val province = areaJson.getStringOrDefault("province")
val city = areaJson.getStringOrDefault("city")
val county = areaJson.getStringOrDefault("county")

"$province $city $county".trim()
}.getOrElse {
XplerLog.e(it)
"获取失败"
}
}
}

fun Aweme.getH265VideoUrlList(): List<String> {
val video = video ?: return emptyList()
Expand Down
79 changes: 41 additions & 38 deletions core/src/main/java/io/github/fplus/core/hook/logic/DownloadLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.freegang.extension.secureFilename
import com.freegang.ktutils.app.IProgressNotification
import com.freegang.ktutils.app.KNotifiUtils
import com.freegang.ktutils.app.KToastUtils
import com.freegang.ktutils.log.KLogCat
import com.freegang.ktutils.media.KMediaUtils
import com.freegang.ktutils.net.KHttpUtils
import com.freegang.ktutils.text.KTextUtils
Expand All @@ -25,7 +24,6 @@ import io.github.xpler.core.log.XplerLog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
import java.io.FileOutputStream

/// 下载(视频/图文/音乐)逻辑
class DownloadLogic(
Expand Down Expand Up @@ -216,19 +214,16 @@ class DownloadLogic(
val imageFiles = mutableListOf<File>()
var downloadCount = 0 // 下载计数器
structList.forEachIndexed { index, urlStruct ->
val downloadFile =
File(mImageParent.need(), mPureFileName.secureFilename("_${index + 1}.jpg"))
val finished =
download(
urlStruct.urlList.first(),
downloadFile,
it,
"$index/${aweme.images.size} %s%%"
)
if (finished) {
val resultFile = downloadFile(
url = urlStruct.urlList.first(),
downloadFile = File(mImageParent.need(), mPureFileName.secureFilename("_${index + 1}.jpg")),
notify = it,
progressText = "$index/${aweme.images.size} %s%%",
)
if (resultFile != null) {
downloadCount += 1
imageFiles.add(downloadFile)
KMediaUtils.notifyMediaUpdate(context, downloadFile.absolutePath)
imageFiles.add(resultFile)
KMediaUtils.notifyMediaUpdate(context, resultFile.absolutePath)
}
}

Expand Down Expand Up @@ -288,18 +283,15 @@ class DownloadLogic(
hook.singleLaunchIO(mPureFileName) {
var downloadCount = 0 // 下载计数器
structList.forEachIndexed { index, urlStruct ->
val downloadFile =
File(mImageParent.need(), mPureFileName.secureFilename("_${index + 1}.jpg"))
val finished =
download(
urlStruct.urlList.first(),
downloadFile,
notify,
"$index/${aweme.images.size} %s%%"
)
if (finished) {
val resultFile = downloadFile(
url = urlStruct.urlList.first(),
downloadFile = File(mImageParent.need(), mPureFileName.secureFilename("_${index + 1}.jpg")),
notify = notify,
progressText = "$index/${aweme.images.size} %s%%",
)
if (resultFile != null) {
downloadCount += 1
KMediaUtils.notifyMediaUpdate(context, downloadFile.absolutePath)
KMediaUtils.notifyMediaUpdate(context, resultFile.absolutePath)
}
}

Expand Down Expand Up @@ -360,19 +352,23 @@ class DownloadLogic(
listener = {
// 下载逻辑
hook.singleLaunchIO(pureFileName) {
val downloadFile = File(parentPath.need(), pureFileName)
val finished = download(urlList.first(), downloadFile, it, "下载中 %s%%")
if (finished) {
val resultFile = downloadFile(
url = urlList.first(),
downloadFile = File(parentPath.need(), pureFileName),
notify = it,
progressText = "下载中 %s%%",
)
if (resultFile != null) {
hook.refresh {
val message = if (isWebDav) "下载成功, 正在上传WebDav!" else "下载成功!"
it.setFinishedText(message)
hook.showToast(context, message)
KMediaUtils.notifyMediaUpdate(context, downloadFile.absolutePath)
KMediaUtils.notifyMediaUpdate(context, resultFile.absolutePath)
}

// 上传WebDav
if (isWebDav) {
val uploadStatus = uploadToWebDav(downloadFile)
val uploadStatus = uploadToWebDav(resultFile)
hook.refresh {
it.setFinishedText("上传WebDav${if (uploadStatus) "成功!" else "失败!"}")
hook.showToast(context, "上传WebDav${if (uploadStatus) "成功!" else "失败!"}")
Expand Down Expand Up @@ -403,20 +399,24 @@ class DownloadLogic(
listener = { dialog, notify ->
// 下载逻辑
hook.singleLaunchIO(pureFileName) {
val downloadFile = File(parentPath.need(), pureFileName)
val finished = download(urlList.first(), downloadFile, notify, "%s%%")
if (finished) {
val resultFile = downloadFile(
url = urlList.first(),
downloadFile = File(parentPath.need(), pureFileName),
notify = notify,
progressText = "%s%%",
)
if (resultFile != null) {
hook.refresh {
dialog.dismiss()
val message = if (isWebDav) "下载成功, 正在上传WebDav!" else "下载成功!"
notify.setFinishedText(message)
hook.showToast(context, message)
KMediaUtils.notifyMediaUpdate(context, downloadFile.absolutePath)
KMediaUtils.notifyMediaUpdate(context, resultFile.absolutePath)
}

// 上传WebDav
if (isWebDav) {
val uploadStatus = uploadToWebDav(downloadFile)
val uploadStatus = uploadToWebDav(resultFile)
hook.showToast(context, "上传WebDav${if (uploadStatus) "成功!" else "失败!"}")
}
} else {
Expand All @@ -434,14 +434,17 @@ class DownloadLogic(
/**
* 下载至本地
*/
private suspend fun download(
private suspend fun downloadFile(
url: String,
downloadFile: File,
notify: IProgressNotification,
progressText: String,
): Boolean {
): File? {
return withContext(Dispatchers.IO) {
KHttpUtils.download(url, downloadFile) { real, total, e ->
KHttpUtils.download(
sourceUrl = url,
file = downloadFile,
) { real, total, e ->
if (e != null)
XplerLog.e(e)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ class SaveAudioLogic(

// 构建保存文件名
hook.showToast(context, "保存语音, 请稍后..")
val file = File(parentPath, "${filename}.mp3")

val result = KHttpUtils.download(url, file)
if (result) {
val resultFile = KHttpUtils.download(
sourceUrl = url,
file = File(parentPath, "${filename}.mp3"),
)
if (resultFile != null) {
hook.showToast(context, "保存成功!")
KMediaUtils.notifyMediaUpdate(context, file.absolutePath)
KMediaUtils.notifyMediaUpdate(context, resultFile.absolutePath)
if (config.vibrate) hook.vibrate(context, 5L)
} else {
hook.showToast(context, "保存失败!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class SaveCommentLogic(
}
}.onFailure {
XplerLog.e(it)
hook.showToast(context, "基本信息获取失败")
}
}

Expand All @@ -56,17 +55,20 @@ class SaveCommentLogic(

// 保存评论区图片
private fun onSaveCommentImage(urlList: List<String>) {
hook.singleLaunchIO("SaveCommentImage") {
val url = urlList.first()
hook.singleLaunchIO(url) {
// 默认保存路径: `/外置存储器/Download/Freedom/picture/comment`
val parentPath = ConfigV1.getFreedomDir(context).child("picture").child("comment").need()

// 构建保存文件名
hook.showToast(context, "保存图片, 请稍后..")
val file = File(parentPath, "${System.currentTimeMillis() / 1000}.png")
val result = KHttpUtils.download(urlList.first(), file)
if (result) {
val resultFile = KHttpUtils.download(
sourceUrl = url,
file = File(parentPath, "${System.currentTimeMillis() / 1000}.png"),
)
if (resultFile != null) {
hook.showToast(context, "保存成功!")
KMediaUtils.notifyMediaUpdate(context, file.absolutePath)
KMediaUtils.notifyMediaUpdate(context, resultFile.absolutePath)
if (config.vibrate) hook.vibrate(context, 5L)
} else {
hook.showToast(context, "保存失败!")
Expand All @@ -76,17 +78,20 @@ class SaveCommentLogic(

// 保存评论区视频
private fun onSaveCommentVideo(urlList: List<String>) {
hook.singleLaunchIO("SaveCommentVideo") {
val url = urlList.first()
hook.singleLaunchIO(url) {
// 默认保存路径: `/外置存储器/Download/Freedom/video/comment`
val parentPath = ConfigV1.getFreedomDir(context).child("video").child("comment").need()

// 构建保存文件名
hook.showToast(context, "保存视频, 请稍后..")
val file = File(parentPath, "${System.currentTimeMillis() / 1000}.mp4")
val result = KHttpUtils.download(urlList.first(), file)
if (result) {
val resultFile = KHttpUtils.download(
sourceUrl = urlList.first(),
file = File(parentPath, "${System.currentTimeMillis() / 1000}.mp4"),
)
if (resultFile != null) {
hook.showToast(context, "保存成功!")
KMediaUtils.notifyMediaUpdate(context, file.absolutePath)
KMediaUtils.notifyMediaUpdate(context, resultFile.absolutePath)
if (config.vibrate) hook.vibrate(context, 5L)
} else {
hook.showToast(context, "保存失败!")
Expand Down
Loading

0 comments on commit 79ce01d

Please sign in to comment.