Skip to content

Commit

Permalink
支持添加种子文件
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 27, 2024
1 parent 255904c commit da57675
Show file tree
Hide file tree
Showing 14 changed files with 461 additions and 98 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/local.properties
/.idea
.idea
.idea/
.DS_Store
/build
/captures
Expand Down
5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
2. 网盘文件相关(剪切、删除、重命名、新建文件夹、多选、回收站、获取下载链接、搜索、~~小文本创建、在线解压~~
3. 离线文件相关(离线列表、点击跳转到网盘文件夹、查看视频文件、删除、清空)
4. 查看(~~小文本、音频~~、照片、视频)
5. 离线(磁力链接离线下载、115sha1导出、~~种子离线下载~~
5. 离线(磁力链接离线下载、115sha1导出、种子离线下载)
6. 自定义(单次文件请求数量、默认离线位置)
7. 其他(磁力跳转、~~支持大屏~~

不支持**文件的上传与下载****两步验证****安全密钥**

# 下载
尝鲜版
## 尝鲜版

需登录github账户:https://github.com/zerorooot/nap511/actions/workflows/generate-apk-release.yml

无需登录https://nightly.link/zerorooot/nap511/workflows/generate-apk-release/main?preview
无需登录github账户https://nightly.link/zerorooot/nap511/workflows/generate-apk-release/main?preview

稳定版
## 稳定版
https://github.com/zerorooot/nap511/releases
101 changes: 29 additions & 72 deletions app/src/main/java/github/zerorooot/nap511/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package github.zerorooot.nap511

import android.annotation.SuppressLint
import android.app.AppOpsManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
Expand All @@ -18,12 +15,15 @@ import androidx.compose.ui.unit.dp
import androidx.work.Data
import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequest
import androidx.work.WorkInfo
import androidx.work.WorkManager
import androidx.work.WorkQuery
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import github.zerorooot.nap511.activity.OfflineTaskWorker
import github.zerorooot.nap511.bean.LoginBean
import github.zerorooot.nap511.bean.TorrentFileBean
import github.zerorooot.nap511.bean.TorrentFileListWeb
import github.zerorooot.nap511.factory.CookieViewModelFactory
import github.zerorooot.nap511.screen.*
import github.zerorooot.nap511.ui.theme.Nap511Theme
Expand All @@ -34,11 +34,6 @@ import github.zerorooot.nap511.viewmodel.FileViewModel
import github.zerorooot.nap511.viewmodel.OfflineFileViewModel
import github.zerorooot.nap511.viewmodel.RecycleViewModel
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.Request
import java.lang.reflect.Field
import java.lang.reflect.InvocationTargetException
import java.lang.reflect.Method
import kotlin.concurrent.thread


Expand All @@ -57,11 +52,12 @@ class MainActivity : ComponentActivity() {
Login()
return@Surface
}
//初始化
Init(cookie)
//允许通知, 方便离线下载交互 OfflineTaskActivity
if (!isNotificationEnabled(this)) {
if (!App.instance.isNotificationEnabled(this)) {
App.instance.toast("检测到未开启通知权限,为保证交互效果,建议开启")
goToNotificationSetting(this)
App.instance.goToNotificationSetting(this)
}
//直接添加磁力,但提示请验证账号;跳转到验证账号界面
if (intent.action == "jump") {
Expand All @@ -72,60 +68,6 @@ class MainActivity : ComponentActivity() {
}
}

/**
* 判断允许通知,是否已经授权
* 返回值为true时,通知栏打开,false未打开。
* @param context 上下文
*/
private fun isNotificationEnabled(context: Context): Boolean {
val CHECK_OP_NO_THROW = "checkOpNoThrow"
val OP_POST_NOTIFICATION = "OP_POST_NOTIFICATION"
val mAppOps = context.getSystemService(APP_OPS_SERVICE) as AppOpsManager
val appInfo = context.applicationInfo
val pkg = context.applicationContext.packageName
val uid = appInfo.uid
val appOpsClass: Class<*>?
/* Context.APP_OPS_MANAGER */try {
appOpsClass = Class.forName(AppOpsManager::class.java.name)
val checkOpNoThrowMethod: Method = appOpsClass.getMethod(
CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE,
String::class.java
)
val opPostNotificationValue: Field = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION)
val value = opPostNotificationValue.get(Int::class.java) as Int
return checkOpNoThrowMethod.invoke(
mAppOps,
value,
uid,
pkg
) as Int == AppOpsManager.MODE_ALLOWED
} catch (e: ClassNotFoundException) {
e.printStackTrace()
} catch (e: NoSuchMethodException) {
e.printStackTrace()
} catch (e: NoSuchFieldException) {
e.printStackTrace()
} catch (e: InvocationTargetException) {
e.printStackTrace()
} catch (e: IllegalAccessException) {
e.printStackTrace()
}
return false
}

/**
* 跳转到app的设置界面--开启通知
* @param context
*/
private fun goToNotificationSetting(context: Context) {
val intent = Intent()
// android 8.0引导
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS")
intent.putExtra("android.provider.extra.APP_PACKAGE", context.packageName)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}

@Composable
private fun Init(cookie: String) {
val fileViewModel by viewModels<FileViewModel> {
Expand Down Expand Up @@ -164,13 +106,23 @@ class MainActivity : ComponentActivity() {
/**
* 检测添加的离线链接。防止因为种种原因,app添加离线链接,但链接没有上传到115
* 后台添加离线链接的代码在OfflineTaskActivity
*
*/
private fun checkOfflineTask(cookie: String) {
val size =
WorkManager.getInstance(applicationContext).getWorkInfosByTag("addOfflineTaskByTime")
.get().size + WorkManager.getInstance(applicationContext)
.getWorkInfosByTag("addOfflineTaskByCount").get().size
println("checkOfflineTask workManager size $size")
val workQuery = WorkQuery.Builder.fromStates(
listOf(
WorkInfo.State.ENQUEUED,
WorkInfo.State.RUNNING,
WorkInfo.State.SUCCEEDED,
WorkInfo.State.FAILED,
WorkInfo.State.BLOCKED,
WorkInfo.State.CANCELLED
)
).build()
val workInfos: List<WorkInfo> =
WorkManager.getInstance(applicationContext).getWorkInfos(workQuery).get()
val size = workInfos.size
println("checkOfflineTask workManager size $size workInfos $workInfos")
if (size != 0) {
return
}
Expand Down Expand Up @@ -249,7 +201,7 @@ class MainActivity : ComponentActivity() {
content = {
when (App.selectedItem) {
"登录" -> Login()
"我的文件" -> MyFileScreen(fileViewModel)
"我的文件" -> MyFileScreen(offlineFileViewModel, fileViewModel)
"离线下载" -> OfflineDownloadScreen(offlineFileViewModel, fileViewModel)
"离线列表" -> OfflineFileScreen(offlineFileViewModel, fileViewModel)
"网页版" -> WebViewScreen()
Expand All @@ -260,6 +212,7 @@ class MainActivity : ComponentActivity() {
"https://captchaapi.115.com/?ac=security_code&type=web&cb=Close911_" + System.currentTimeMillis()
CaptchaWebViewScreen()
}

"验证video账号" -> {
CaptchaVideoWebViewScreen()
}
Expand Down Expand Up @@ -311,11 +264,15 @@ class MainActivity : ComponentActivity() {
}

@Composable
private fun MyFileScreen(fileViewModel: FileViewModel) {
private fun MyFileScreen(
offlineFileViewModel: OfflineFileViewModel,
fileViewModel: FileViewModel
) {
fileViewModel.init()

FileScreen(
fileViewModel,
offlineFileViewModel,
appBarClick(fileViewModel),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ class OfflineTaskActivity : Activity() {
.split("\n")
.filter { i -> i != "" && i != " " }
.toSet()
.toMutableList()
.toMutableSet()
//添加所有
currentOfflineTaskList.addAll(urlList)
//离线任务缓存方式,true为x分钟后统一下载,false为集满后统一下载
if (DataStoreUtil.getData(ConfigUtil.offlineMethod, true)) {
addOfflineTaskByTime(currentOfflineTaskList)
addOfflineTaskByTime(currentOfflineTaskList.toList())
} else {
addOfflineTaskByCount(currentOfflineTaskList)
addOfflineTaskByCount(currentOfflineTaskList.toList())
}
} else {
App.instance.toast("仅支持以http、ftp、magnet、ed2k开头的链接")
Expand Down Expand Up @@ -177,7 +177,7 @@ class OfflineTaskWorker(
""
)
}
println(message)
// println(message)
toast(message, a)
return Result.success(addTaskData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TorrentTaskActivity : Activity() {
super.onCreate(savedInstanceState)
if (intent.action == Intent.ACTION_VIEW && intent.data != null) {
val torrentFile = fileFromContentUri(this, intent.data!!)
val uid = DataStoreUtil.getData(ConfigUtil.uid, "0")
val uid = App.uid
val defaultOfflineCid = DataStoreUtil.getData(ConfigUtil.defaultOfflineCid, "0")
initUpload(torrentFile, App.cookie, uid, defaultOfflineCid)
}
Expand Down
44 changes: 44 additions & 0 deletions app/src/main/java/github/zerorooot/nap511/bean/Bean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,47 @@ data class InitUploadBean(
val signature: String,
val callback: String
)

/**
* {
* "state": true,
* "errno": 0,
* "errtype": "suc",
* "errcode": 0,
* "file_size": 70966705837,
* "torrent_name": "name",
* "file_count": 28,
* "info_hash": "hash",
* "torrent_filelist_web": [
* {
* "size": 3902418,
* "path": "预览图/2021_04_24_07_37_IMG_1379.JPG",
* "wanted": 1
* }
* ]
* }
*/
data class TorrentFileBean(
var state: Boolean = false,
var errno: Long = 0,
var errtype: String = "suc",
var errcode: Long = 0,
@SerializedName("file_size")
var fileSize: Long = 0,
var fileSizeString: String = "",
@SerializedName("torrent_name")
var torrentName: String = "",
@SerializedName("file_count")
var fileCount: Int = 0,
@SerializedName("info_hash")
var infoHash: String = "",
@SerializedName("torrent_filelist_web")
var torrentFileListWeb: ArrayList<TorrentFileListWeb> = arrayListOf(),
)

data class TorrentFileListWeb(
var size: Long = 0,
var sizeString: String = "",
var path: String = "",
val wanted: Int = -1,
)
Loading

0 comments on commit da57675

Please sign in to comment.