diff --git a/app/src/main/java/com/imcys/bilibilias/base/network/NetworkService.kt b/app/src/main/java/com/imcys/bilibilias/base/network/NetworkService.kt index 4661ef83b..96d5c27dd 100644 --- a/app/src/main/java/com/imcys/bilibilias/base/network/NetworkService.kt +++ b/app/src/main/java/com/imcys/bilibilias/base/network/NetworkService.kt @@ -1,160 +1,101 @@ package com.imcys.bilibilias.base.network -import com.imcys.bilibilias.base.model.login.LoginQrcodeBean -import com.imcys.bilibilias.base.model.login.LoginStateBean -import com.imcys.bilibilias.base.model.user.LikeVideoBean -import com.imcys.bilibilias.base.model.user.UserInfoBean -import com.imcys.bilibilias.common.base.api.BiliBiliAsApi -import com.imcys.bilibilias.common.base.api.BilibiliApi -import com.imcys.bilibilias.common.base.app.BaseApplication -import com.imcys.bilibilias.common.base.constant.BILIBILI_URL -import com.imcys.bilibilias.common.base.constant.COOKIE -import com.imcys.bilibilias.common.base.constant.COOKIES -import com.imcys.bilibilias.common.base.constant.ROAM_API -import com.imcys.bilibilias.common.base.model.common.BangumiFollowList -import com.imcys.bilibilias.common.base.model.user.AsUserLoginModel -import com.imcys.bilibilias.common.base.model.user.BiLiCookieResponseModel -import com.imcys.bilibilias.common.base.model.user.MyUserData -import com.imcys.bilibilias.common.base.model.user.ResponseResult -import com.imcys.bilibilias.common.base.model.user.UserBiliBiliCookieModel -import com.imcys.bilibilias.common.base.utils.http.KtHttpUtils -import com.imcys.bilibilias.common.di.AsCookiesStorage -import com.imcys.bilibilias.home.ui.model.BangumiPlayBean -import com.imcys.bilibilias.home.ui.model.BangumiSeasonBean -import com.imcys.bilibilias.home.ui.model.CollectionDataBean -import com.imcys.bilibilias.home.ui.model.CollectionResultBean -import com.imcys.bilibilias.home.ui.model.DashBangumiPlayBean -import com.imcys.bilibilias.home.ui.model.DashVideoPlayBean -import com.imcys.bilibilias.home.ui.model.DonateViewBean -import com.imcys.bilibilias.home.ui.model.OldDonateBean -import com.imcys.bilibilias.home.ui.model.OldHomeAdBean -import com.imcys.bilibilias.home.ui.model.OldHomeBannerDataBean -import com.imcys.bilibilias.home.ui.model.OldToolItemBean -import com.imcys.bilibilias.home.ui.model.OldUpdateDataBean -import com.imcys.bilibilias.home.ui.model.PlayHistoryBean -import com.imcys.bilibilias.home.ui.model.UpStatBeam -import com.imcys.bilibilias.home.ui.model.UserBaseBean -import com.imcys.bilibilias.home.ui.model.UserCardBean -import com.imcys.bilibilias.home.ui.model.UserCreateCollectionBean -import com.imcys.bilibilias.home.ui.model.UserNavDataModel -import com.imcys.bilibilias.home.ui.model.UserWorksBean -import com.imcys.bilibilias.home.ui.model.VideoBaseBean -import com.imcys.bilibilias.home.ui.model.VideoCoinAddBean -import com.imcys.bilibilias.home.ui.model.VideoPageListData -import com.imcys.bilibilias.home.ui.model.VideoPlayBean -import com.imcys.bilibilias.home.ui.viewmodel.AsLoginBsViewModel -import io.ktor.client.HttpClient -import io.ktor.client.call.body -import io.ktor.client.request.HttpRequestBuilder -import io.ktor.client.request.forms.submitForm -import io.ktor.client.request.get -import io.ktor.client.request.header -import io.ktor.client.request.parameter -import io.ktor.client.request.post -import io.ktor.client.statement.readBytes -import io.ktor.http.HttpHeaders -import io.ktor.http.parameters -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -import javax.inject.Inject -import javax.inject.Singleton -import kotlin.coroutines.CoroutineContext -import kotlin.coroutines.coroutineContext -import kotlin.reflect.full.createType +import com.imcys.bilibilias.base.model.login.* +import com.imcys.bilibilias.base.model.user.* +import com.imcys.bilibilias.common.base.api.* +import com.imcys.bilibilias.common.base.app.* +import com.imcys.bilibilias.common.base.constant.* +import com.imcys.bilibilias.common.base.model.common.* +import com.imcys.bilibilias.common.base.model.user.* +import com.imcys.bilibilias.common.base.utils.http.* +import com.imcys.bilibilias.common.di.* +import com.imcys.bilibilias.home.ui.model.* +import com.imcys.bilibilias.home.ui.viewmodel.* +import io.ktor.client.* +import io.ktor.client.call.* +import io.ktor.client.request.* +import io.ktor.client.request.forms.* +import io.ktor.client.statement.* +import io.ktor.http.* +import kotlinx.coroutines.* +import javax.inject.* @Singleton class NetworkService @Inject constructor( - private val ktHttpUtils: KtHttpUtils, - private val httpClient: HttpClient, - private val asCookiesStorage: AsCookiesStorage + private val ktHttpUtils: KtHttpUtils, + private val httpClient: HttpClient, + private val asCookiesStorage: AsCookiesStorage ) { - private val ioDispatcher = Dispatchers.IO - suspend fun n1(cid: Long, qn: Int): DashBangumiPlayBean = runCatchingOnWithContextIo { - httpClient.get("${ROAM_API}pgc/player/web/playurl?cid=$cid&qn=$qn&fnval=4048&fourk=1") { - refererBILIHarder() - }.body() - } - - // --------------------------------------------------------------------------------------------- - suspend fun n2(bvid: String, cid: Long, qn: Int): DashVideoPlayBean = - runCatchingOnWithContextIo { videoPlayPath(bvid, cid.toString(), qn) } - - suspend fun n10(bvid: String, cid: Long): DashVideoPlayBean = runCatchingOnWithContextIo { - videoPlayPath(bvid, cid.toString(), 64) - } - suspend fun n29(bvid: String, cid: Long): DashVideoPlayBean = runCatchingOnWithContextIo { - videoPlayPath(bvid, cid.toString(), 64) + suspend fun pgcPlayUrl(cId: Long, qn: Int): DashBangumiPlayBean = runCatchingOnWithContextIo { + httpClient.get(BilibiliApi.bangumiPlayPath) { + parameterCID(cId.toString()) + parameter("qn", qn) + parameter("fnval", "4048") + parameter("fourk", "1") + }.body() } - suspend fun getDashBangumiPlay(cid: Long, qn: Int): DashBangumiPlayBean = - runCatchingOnWithContextIo { - httpClient.get("${ROAM_API}pgc/player/web/playurl?cid=$cid&qn=$qn&fnval=4048&fourk=1") { - refererBILIHarder() - }.body() - } + suspend fun viewDash(bvid: String, cid: Long, qn: Int): DashVideoPlayBean = + runCatchingOnWithContextIo { + viewPlayUrl(bvid, cid.toString(), qn) + } - suspend fun getPlayHistory(max: Long, viewAt: Long, type: String): PlayHistoryBean = - runCatchingOnWithContextIo { - httpClient.get("${BilibiliApi.userPlayHistoryPath}?max=$max&view_at=$viewAt&type=archive") - .body() + suspend fun getPlayHistory(max: Long, viewAt: Long): PlayHistoryBean = + runCatchingOnWithContextIo { + httpClient.get(BilibiliApi.userPlayHistoryPath) { + parameter("max", max) + parameter("view_at", viewAt) + parameter("type", "archive") } + .body() + } - - private suspend inline fun videoPlayPath( - bvid: String, - cid: String, - qn: Int, - fnval: Int = 4048, + private suspend inline fun viewPlayUrl( + bvid: String, + cid: String, + qn: Int, ): T = runCatchingOnWithContextIo { httpClient.get(BilibiliApi.videoPlayPath) { - refererBILIHarder() parameterBVID(bvid) parameterCID(cid) parameter("qn", qn) - parameter("fnval", fnval) + parameter("fnval", 4048) parameter("fourk", 1) }.body() } private fun HttpRequestBuilder.parameterBVID(bvid: String): Unit = - url.parameters.append("bvid", bvid) + url.parameters.append("bvid", bvid) private fun HttpRequestBuilder.parameterCID(cid: String): Unit = - url.parameters.append("cid", cid) + url.parameters.append("cid", cid) private fun HttpRequestBuilder.parameterUpMID(upMid: String): Unit = - url.parameters.append("up_mid", upMid) + url.parameters.append("up_mid", upMid) private fun HttpRequestBuilder.refererBILIHarder(): Unit = - header(HttpHeaders.Referrer, BILIBILI_URL) + header(HttpHeaders.Referrer, BILIBILI_URL) private fun HttpRequestBuilder.parameterMID(mid: String): Unit = - url.parameters.append("mid", mid) + url.parameters.append("mid", mid) private fun HttpRequestBuilder.parameterEpID(epid: String): Unit = - url.parameters.append("ep_id", epid) + url.parameters.append("ep_id", epid) // --------------------------------------------------------------------------------------------- - suspend fun n3(bvid: String, cid: Long, qn: Int): VideoPlayBean = runCatchingOnWithContextIo { - videoPlayPath(bvid, cid.toString(), qn, fnval = 0) - } - - suspend fun n9(bvid: String, cid: Long): VideoPlayBean = runCatchingOnWithContextIo { - videoPlayPath(bvid, cid.toString(), 64, fnval = 0) - } + suspend fun viewFlv(bvid: String, cid: Long, qn: Int): VideoPlayBean = + runCatchingOnWithContextIo { + viewPlayUrl(bvid, cid.toString(), qn) + } // --------------------------------------------------------------------------------------------- - suspend fun n4(cid: Long, qn: Int): BangumiPlayBean = runCatchingOnWithContextIo { - httpClient.get("${ROAM_API}pgc/player/web/playurl?cid=$cid&qn=$qn&fnval=0&fourk=1") { - refererBILIHarder() - }.body() - } - - suspend fun n16(epid: Long): BangumiPlayBean = runCatchingOnWithContextIo { - httpClient.get("${ROAM_API}pgc/player/web/playurl?ep_id=$epid&qn=64&fnval=0&fourk=1") { - refererBILIHarder() + suspend fun flvPgcPlayUrl(cId: Long, qn: Int): BangumiPlayBean = runCatchingOnWithContextIo { + httpClient.get(BilibiliApi.bangumiPlayPath) { + parameterCID(cId.toString()) + parameter("qn", qn) + parameter("fnval", "0") + parameter("fourk", "1") }.body() } @@ -207,10 +148,10 @@ class NetworkService @Inject constructor( } suspend fun getUserCollection(id: Long, pn: Int): CollectionDataBean = - runCatchingOnWithContextIo { - httpClient.get("${BilibiliApi.userCollectionDataPath}?media_id=${id}&pn=${pn}&ps=20") - .body() - } + runCatchingOnWithContextIo { + httpClient.get("${BilibiliApi.userCollectionDataPath}?media_id=$id&pn=$pn&ps=20") + .body() + } suspend fun getDonateData(): OldDonateBean = runCatchingOnWithContextIo { httpClient.get("${BiliBiliAsApi.appFunction}?type=Donate").body() @@ -221,18 +162,16 @@ class NetworkService @Inject constructor( } suspend fun getBangumiFollow(vmid: Long, type: Int, pn: Int, ps: Int): BangumiFollowList = - runCatchingOnWithContextIo { - httpClient.get("${BilibiliApi.bangumiFollowPath}?vmid=$vmid&type=$type&pn=$pn&ps=$ps") - .body() - - } + runCatchingOnWithContextIo { + httpClient.get("${BilibiliApi.bangumiFollowPath}?vmid=$vmid&type=$type&pn=$pn&ps=$ps") + .body() + } suspend fun getUpdateData(): OldUpdateDataBean = runCatchingOnWithContextIo { httpClient.get("${BiliBiliAsApi.updateDataPath}?type=json&version=${BiliBiliAsApi.version}") - .body() + .body() } - suspend fun getOldHomeAd(): OldHomeAdBean = runCatchingOnWithContextIo { httpClient.get("${BiliBiliAsApi.appFunction}?type=oldHomeAd").body() } @@ -249,7 +188,7 @@ class NetworkService @Inject constructor( } suspend fun n13(epid: Long): BangumiSeasonBean = runCatchingOnWithContextIo { - httpClient.get(ROAM_API + "pgc/view/web/season?ep_id=" + epid).body() + n25(epid) } suspend fun n18(firstEp: Int): BangumiSeasonBean = runCatchingOnWithContextIo { @@ -257,7 +196,9 @@ class NetworkService @Inject constructor( } suspend fun n25(epId: Long): BangumiSeasonBean = runCatchingOnWithContextIo { - httpClient.get("${BilibiliApi.bangumiVideoDataPath}?ep_id=$epId").body() + httpClient.get(BilibiliApi.bangumiVideoDataPath) { + parameterEpID(epId.toString()) + }.body() } // --------------------------------------------------------------------------------------------- @@ -334,8 +275,10 @@ class NetworkService @Inject constructor( } // ---------------------------------------------------------------------------------------------- - suspend fun n23(): UpStatBeam = runCatchingOnWithContextIo { - httpClient.get("${BilibiliApi.userUpStat}?mid=${BaseApplication.asUser.mid}").body() + suspend fun getUpStat(mid: String): UpStatBeam = runCatchingOnWithContextIo { + httpClient.get(BilibiliApi.userUpStat) { + parameterMID(mid) + }.body() } suspend fun n28(paramsStr: String): UserInfoBean = runCatchingOnWithContextIo { @@ -345,87 +288,86 @@ class NetworkService @Inject constructor( // --------------------------------------------------------------------------------------------- suspend fun videoLike(bvid: String): LikeVideoBean = runCatchingOnWithContextIo { httpClient.submitForm( - url = BilibiliApi.videLikePath, - formParameters = parameters { - append("csrf", asCookiesStorage.getCookieValue("bili_jct") ?: "") - append("like", "1") - append("bvid", bvid) - } + url = BilibiliApi.videLikePath, + formParameters = parameters { + append("csrf", asCookiesStorage.getCookieValue("bili_jct") ?: "") + append("like", "1") + append("bvid", bvid) + } ).body() } suspend fun n32(bvid: String): LikeVideoBean = runCatchingOnWithContextIo { ktHttpUtils.addHeader( - COOKIE, - BaseApplication.dataKv.decodeString(COOKIES, "")!!, + COOKIE, + BaseApplication.dataKv.decodeString(COOKIES, "")!!, ) - .addParam("csrf", asCookiesStorage.getCookieValue("bili_jct") ?: "") - .addParam("like", "2") - .addParam("bvid", bvid) - .asyncPost(BilibiliApi.videLikePath) + .addParam("csrf", asCookiesStorage.getCookieValue("bili_jct") ?: "") + .addParam("like", "2") + .addParam("bvid", bvid) + .asyncPost(BilibiliApi.videLikePath) } suspend fun n33(bvid: String): VideoCoinAddBean = runCatchingOnWithContextIo { ktHttpUtils - .addHeader(COOKIE, asCookiesStorage.getCookieValue("bili_jct") ?: "") - .addParam("bvid", bvid) - .addParam("multiply", "2") - .addParam("csrf", BaseApplication.dataKv.decodeString("bili_jct", "")!!) - .asyncPost(BilibiliApi.videoCoinAddPath) + .addHeader(COOKIE, asCookiesStorage.getCookieValue("bili_jct") ?: "") + .addParam("bvid", bvid) + .addParam("multiply", "2") + .addParam("csrf", BaseApplication.dataKv.decodeString("bili_jct", "")!!) + .asyncPost(BilibiliApi.videoCoinAddPath) } suspend fun n35(toString: String, addMediaIds: String): CollectionResultBean = - runCatchingOnWithContextIo { - httpClient.get(BilibiliApi.videoCollectionSetPath) { - parameter("rid", toString) - parameter("add_media_ids", addMediaIds) - parameter("csrf", asCookiesStorage.getCookieValue("bili_jct") ?: "") - parameter("type", "2") - }.body() - } + runCatchingOnWithContextIo { + httpClient.get(BilibiliApi.videoCollectionSetPath) { + parameter("rid", toString) + parameter("add_media_ids", addMediaIds) + parameter("csrf", asCookiesStorage.getCookieValue("bili_jct") ?: "") + parameter("type", "2") + }.body() + } suspend fun n36( - asCookie: String?, - asLoginInfo: AsLoginBsViewModel.AsLoginInfo + asCookie: String?, + asLoginInfo: AsLoginBsViewModel.AsLoginInfo ): AsUserLoginModel = - runCatchingOnWithContextIo { - ktHttpUtils.addHeader(COOKIE, asCookie!!).asyncPostJson( - "${BiliBiliAsApi.serviceTestApi}users/login", - asLoginInfo, - ) - } + runCatchingOnWithContextIo { + ktHttpUtils.addHeader(COOKIE, asCookie!!).asyncPostJson( + "${BiliBiliAsApi.serviceTestApi}users/login", + asLoginInfo, + ) + } suspend fun n37(asCookie: String?): UserBiliBiliCookieModel = runCatchingOnWithContextIo { ktHttpUtils.addHeader(COOKIE, asCookie!!) - .asyncGet("${BiliBiliAsApi.serviceTestApi}BiliBiliCookie") + .asyncGet("${BiliBiliAsApi.serviceTestApi}BiliBiliCookie") } suspend fun n39(asCookie: String?, data: UserBiliBiliCookieModel.Data): ResponseResult = - runCatchingOnWithContextIo { - ktHttpUtils.addHeader(COOKIE, asCookie!!).asyncDeleteJson( - "${BiliBiliAsApi.serviceTestApi}BiliBiliCookie", - data, - ) - } + runCatchingOnWithContextIo { + ktHttpUtils.addHeader(COOKIE, asCookie!!).asyncDeleteJson( + "${BiliBiliAsApi.serviceTestApi}BiliBiliCookie", + data, + ) + } suspend fun n41(): LoginQrcodeBean = - runCatchingOnWithContextIo { ktHttpUtils.asyncGet(BilibiliApi.getLoginQRPath) } + runCatchingOnWithContextIo { ktHttpUtils.asyncGet(BilibiliApi.getLoginQRPath) } suspend fun n43(biliBiliCookieInfo: AsLoginBsViewModel.BiliBiliCookieInfo): BiLiCookieResponseModel = - runCatchingOnWithContextIo { - - ktHttpUtils.addHeader(COOKIE, BaseApplication.asUser.asCookie) - .asyncPostJson( - "${BiliBiliAsApi.serviceTestApi}BiliBiliCookie", - biliBiliCookieInfo, - ) - } + runCatchingOnWithContextIo { + ktHttpUtils.addHeader(COOKIE, BaseApplication.asUser.asCookie) + .asyncPostJson( + "${BiliBiliAsApi.serviceTestApi}BiliBiliCookie", + biliBiliCookieInfo, + ) + } private suspend inline fun runCatchingOnWithContextIo( - noinline block: suspend CoroutineScope.() -> T + noinline block: suspend CoroutineScope.() -> T ): T { return runCatching { - withContext(ioDispatcher, block) + withContext(Dispatchers.IO, block) }.getOrElse { val clazz = T::class val constructors = clazz.constructors @@ -434,7 +376,6 @@ class NetworkService @Inject constructor( } } - suspend fun n44() = runCatchingOnWithContextIo {} suspend fun n45() = runCatchingOnWithContextIo {} suspend fun n46() = runCatchingOnWithContextIo {} diff --git a/app/src/main/java/com/imcys/bilibilias/base/utils/DialogUtils.kt b/app/src/main/java/com/imcys/bilibilias/base/utils/DialogUtils.kt index 0b6d2e7e9..d7362af2e 100644 --- a/app/src/main/java/com/imcys/bilibilias/base/utils/DialogUtils.kt +++ b/app/src/main/java/com/imcys/bilibilias/base/utils/DialogUtils.kt @@ -1186,7 +1186,7 @@ object DialogUtils { launchIO { flow { bangumiPageMutableList.forEach { - val dashBangumiPlayBean = networkService.n1(it.cid, qn) + val dashBangumiPlayBean = networkService.pgcPlayUrl(it.cid, qn) emit(VideoData(dashBangumiPlayBean, it)) } }.collect { @@ -1271,7 +1271,7 @@ object DialogUtils { launchIO { flow { videoPageMutableList.forEach { - val dashVideoPlayBean = networkService.n2(videoBaseBean.data.bvid, it.cid, qn) + val dashVideoPlayBean = networkService.viewDash(videoBaseBean.data.bvid, it.cid, qn) emit(VideoData(dashVideoPlayBean, it)) // 生产者发送数据 } @@ -1363,7 +1363,7 @@ object DialogUtils { launchIO { flow { videoPageMutableList.forEach { - val videoPlayBean = networkService.n3(videoBaseBean.data.bvid, it.cid, qn) + val videoPlayBean = networkService.viewFlv(videoBaseBean.data.bvid, it.cid, qn) emit(VideoData(videoPlayBean, it)) } }.collect { @@ -1410,7 +1410,7 @@ object DialogUtils { launchIO { flow { bangumiPageMutableList.forEach { - val bangumiPlayBean = networkService.n4(it.cid, qn) + val bangumiPlayBean = networkService.flvPgcPlayUrl(it.cid, qn) emit(VideoData(bangumiPlayBean, it)) } }.collect { diff --git a/app/src/main/java/com/imcys/bilibilias/home/ui/activity/AsVideoActivity.kt b/app/src/main/java/com/imcys/bilibilias/home/ui/activity/AsVideoActivity.kt index 2e08b2f0b..cd4f4cb4a 100644 --- a/app/src/main/java/com/imcys/bilibilias/home/ui/activity/AsVideoActivity.kt +++ b/app/src/main/java/com/imcys/bilibilias/home/ui/activity/AsVideoActivity.kt @@ -1,73 +1,53 @@ package com.imcys.bilibilias.home.ui.activity -import android.annotation.SuppressLint -import android.content.Context -import android.content.Intent -import android.content.pm.ActivityInfo -import android.graphics.Color +import android.annotation.* +import android.content.* +import android.content.pm.* +import android.graphics.* +import android.os.* import android.os.Build -import android.os.Bundle -import android.view.View -import android.view.ViewGroup -import androidx.activity.viewModels -import androidx.core.view.isVisible -import androidx.core.view.updateLayoutParams -import androidx.databinding.DataBindingUtil -import androidx.recyclerview.widget.LinearLayoutManager -import cn.jzvd.JZDataSource -import cn.jzvd.Jzvd -import cn.jzvd.JzvdStd -import com.baidu.mobstat.StatService -import com.imcys.asbottomdialog.bottomdialog.AsDialog +import android.view.* +import androidx.activity.* +import androidx.core.view.* +import androidx.databinding.* +import androidx.recyclerview.widget.* +import cn.jzvd.* +import com.baidu.mobstat.* +import com.imcys.asbottomdialog.bottomdialog.* import com.imcys.bilibilias.R -import com.imcys.bilibilias.base.BaseActivity -import com.imcys.bilibilias.base.network.NetworkService -import com.imcys.bilibilias.base.utils.DialogUtils -import com.imcys.bilibilias.base.utils.TokenUtils -import com.imcys.bilibilias.base.view.AppAsJzvdStd -import com.imcys.bilibilias.common.base.api.BilibiliApi +import com.imcys.bilibilias.base.* +import com.imcys.bilibilias.base.network.* +import com.imcys.bilibilias.base.utils.* +import com.imcys.bilibilias.base.view.* +import com.imcys.bilibilias.common.base.api.* import com.imcys.bilibilias.common.base.app.BaseApplication.Companion.asUser -import com.imcys.bilibilias.common.base.constant.BILIBILI_URL -import com.imcys.bilibilias.common.base.constant.BROWSER_USER_AGENT -import com.imcys.bilibilias.common.base.constant.COOKIE -import com.imcys.bilibilias.common.base.constant.REFERER -import com.imcys.bilibilias.common.base.constant.USER_AGENT -import com.imcys.bilibilias.common.base.extend.launchUI -import com.imcys.bilibilias.common.base.utils.VideoNumConversion -import com.imcys.bilibilias.common.base.view.JzbdStdInfo -import com.imcys.bilibilias.common.network.base.ResBean -import com.imcys.bilibilias.danmaku.BiliDanmukuParser -import com.imcys.bilibilias.databinding.ActivityAsVideoBinding -import com.imcys.bilibilias.home.ui.adapter.BangumiSubsectionAdapter -import com.imcys.bilibilias.home.ui.adapter.SubsectionAdapter +import com.imcys.bilibilias.common.base.constant.* +import com.imcys.bilibilias.common.base.extend.* +import com.imcys.bilibilias.common.base.utils.* +import com.imcys.bilibilias.common.base.view.* +import com.imcys.bilibilias.common.network.base.* +import com.imcys.bilibilias.danmaku.* +import com.imcys.bilibilias.databinding.* +import com.imcys.bilibilias.home.ui.adapter.* import com.imcys.bilibilias.home.ui.model.* -import com.imcys.bilibilias.home.ui.viewmodel.AsVideoViewModel -import dagger.hilt.android.AndroidEntryPoint -import io.ktor.client.HttpClient -import io.ktor.client.call.body -import io.ktor.client.request.get -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -import master.flame.danmaku.controller.IDanmakuView -import master.flame.danmaku.danmaku.loader.IllegalDataException -import master.flame.danmaku.danmaku.loader.android.DanmakuLoaderFactory -import master.flame.danmaku.danmaku.model.BaseDanmaku -import master.flame.danmaku.danmaku.model.DanmakuTimer -import master.flame.danmaku.danmaku.model.GlobalFlagValues -import master.flame.danmaku.danmaku.model.IDisplayer -import master.flame.danmaku.danmaku.model.android.DanmakuContext -import master.flame.danmaku.danmaku.model.android.Danmakus -import master.flame.danmaku.danmaku.parser.BaseDanmakuParser -import okio.BufferedSink -import okio.buffer -import okio.sink -import java.io.ByteArrayOutputStream -import java.io.File -import java.io.FileInputStream +import com.imcys.bilibilias.home.ui.viewmodel.* +import dagger.hilt.android.* +import io.ktor.client.* +import io.ktor.client.call.* +import io.ktor.client.request.* +import kotlinx.coroutines.* +import master.flame.danmaku.controller.* +import master.flame.danmaku.danmaku.loader.* +import master.flame.danmaku.danmaku.loader.android.* +import master.flame.danmaku.danmaku.model.* +import master.flame.danmaku.danmaku.model.android.* +import master.flame.danmaku.danmaku.parser.* +import okio.* +import java.io.* import java.io.IOException -import java.io.InputStream -import java.util.zip.Inflater -import javax.inject.Inject +import java.util.zip.* +import javax.inject.* +import kotlin.collections.set @AndroidEntryPoint @@ -116,10 +96,6 @@ class AsVideoActivity : BaseActivity() { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT } -// override fun attachBaseContext(newBase: Context?) { -// super.attachBaseContext(newBase) -// -// } /** * 加载用户信息,为了确保会员视频及时通知用户 */ @@ -168,7 +144,7 @@ class AsVideoActivity : BaseActivity() { "video" -> { launchUI { // 获取播放信息 - val videoPlayBean = networkService.n9(bvid, cid) + val videoPlayBean = networkService.viewFlv(bvid, cid, 64) // 设置布局视频播放数据 binding.videoPlayBean = videoPlayBean // 有部分视频不存在flv接口下的mp4,无法提供播放服务,需要及时通知。 @@ -185,7 +161,7 @@ class AsVideoActivity : BaseActivity() { } }.show() } else { - val dashVideoPlayBean = networkService.n10(bvid, cid) + val dashVideoPlayBean = networkService.viewDash(bvid, cid, 64) if (dashVideoPlayBean.code != 0) { setAsJzvdConfig(videoPlayBean.data.durl[0].url, "") } @@ -223,7 +199,7 @@ class AsVideoActivity : BaseActivity() { "bangumi" -> { launchIO { - val bangumiPlayBean = networkService.n16(epid) + val bangumiPlayBean = networkService.flvPgcPlayUrl(epid, 64) launchUI { // 设置布局视频播放数据 diff --git a/app/src/main/java/com/imcys/bilibilias/home/ui/activity/user/PlayHistoryActivity.kt b/app/src/main/java/com/imcys/bilibilias/home/ui/activity/user/PlayHistoryActivity.kt index 822a4931c..5043f0893 100644 --- a/app/src/main/java/com/imcys/bilibilias/home/ui/activity/user/PlayHistoryActivity.kt +++ b/app/src/main/java/com/imcys/bilibilias/home/ui/activity/user/PlayHistoryActivity.kt @@ -10,11 +10,7 @@ import com.baidu.mobstat.StatService import com.imcys.bilibilias.R import com.imcys.bilibilias.base.BaseActivity import com.imcys.bilibilias.base.network.NetworkService -import com.imcys.bilibilias.common.base.api.BilibiliApi -import com.imcys.bilibilias.common.base.app.BaseApplication.Companion.asUser -import com.imcys.bilibilias.common.base.constant.COOKIE import com.imcys.bilibilias.common.base.utils.RecyclerViewUtils -import com.imcys.bilibilias.common.base.utils.http.HttpUtils import com.imcys.bilibilias.databinding.ActivityPlayHistoryBinding import com.imcys.bilibilias.home.ui.adapter.PlayHistoryAdapter import com.imcys.bilibilias.home.ui.model.PlayHistoryBean @@ -61,7 +57,7 @@ class PlayHistoryActivity : BaseActivity() { StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL) launchUI { - networkService.getPlayHistory(0, 0, "archive").let { + networkService.getPlayHistory(0, 0).let { max = it.data.cursor.max viewAt = it.data.cursor.view_at playHistoryDataMutableList.addAll(it.data.list) @@ -81,7 +77,7 @@ class PlayHistoryActivity : BaseActivity() { private fun loadPlayHistory() { launchUI { - networkService.getPlayHistory(max, viewAt, "archive").let { + networkService.getPlayHistory(max, viewAt).let { max = it.data.cursor.max viewAt = it.data.cursor.view_at playHistoryDataMutableList.addAll(it.data.list) diff --git a/app/src/main/java/com/imcys/bilibilias/home/ui/fragment/UserFragment.kt b/app/src/main/java/com/imcys/bilibilias/home/ui/fragment/UserFragment.kt index 2bf605a95..89d6b6ca6 100644 --- a/app/src/main/java/com/imcys/bilibilias/home/ui/fragment/UserFragment.kt +++ b/app/src/main/java/com/imcys/bilibilias/home/ui/fragment/UserFragment.kt @@ -1,36 +1,26 @@ package com.imcys.bilibilias.home.ui.fragment -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.Toast -import androidx.databinding.DataBindingUtil -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import androidx.recyclerview.widget.StaggeredGridLayoutManager -import com.baidu.mobstat.StatService +import android.os.* +import android.view.* +import android.widget.* +import androidx.databinding.* +import androidx.recyclerview.widget.* +import com.baidu.mobstat.* import com.imcys.bilibilias.R -import com.imcys.bilibilias.base.network.NetworkService -import com.imcys.bilibilias.base.utils.TokenUtils -import com.imcys.bilibilias.base.utils.asToast -import com.imcys.bilibilias.common.base.BaseFragment +import com.imcys.bilibilias.base.network.* +import com.imcys.bilibilias.base.utils.* +import com.imcys.bilibilias.common.base.* import com.imcys.bilibilias.common.base.app.BaseApplication.Companion.asUser -import com.imcys.bilibilias.common.base.extend.launchUI -import com.imcys.bilibilias.databinding.FragmentUserBinding -import com.imcys.bilibilias.home.ui.adapter.UserDataAdapter -import com.imcys.bilibilias.home.ui.adapter.UserWorksAdapter -import com.imcys.bilibilias.home.ui.model.UpStatBeam -import com.imcys.bilibilias.home.ui.model.UserBaseBean -import com.imcys.bilibilias.home.ui.model.UserCardBean -import com.imcys.bilibilias.home.ui.model.UserViewItemBean -import com.imcys.bilibilias.home.ui.model.UserWorksBean -import com.zackratos.ultimatebarx.ultimatebarx.addStatusBarTopPadding -import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.async -import me.dkzwm.widget.srl.RefreshingListenerAdapter -import javax.inject.Inject -import kotlin.math.ceil +import com.imcys.bilibilias.common.base.extend.* +import com.imcys.bilibilias.databinding.* +import com.imcys.bilibilias.home.ui.adapter.* +import com.imcys.bilibilias.home.ui.model.* +import com.zackratos.ultimatebarx.ultimatebarx.* +import dagger.hilt.android.* +import kotlinx.coroutines.* +import me.dkzwm.widget.srl.* +import javax.inject.* +import kotlin.math.* @AndroidEntryPoint class UserFragment : BaseFragment() { @@ -120,7 +110,6 @@ class UserFragment : BaseFragment() { private fun loadUserWorks() { val oldMutableList = userWorksBean.data.list.vlist launchIO { - val userWorksBean = networkService.n20(userWorksBean.data.page.pn + 1) this@UserFragment.userWorksBean = userWorksBean @@ -179,10 +168,10 @@ class UserFragment : BaseFragment() { val userBaseBean = async { getUserData() } // 用户卡片信息 - val userCardBean = async { getUserCardBean() } + val userCardBean = getUserCardBean() // 获取up状态 - val userUpStat = async { getUpStat() } + val userUpStat = async { networkService.getUpStat(userCardBean.data.card.mid) } if (userBaseBean.await().code == 0) { userDataMutableList.add( @@ -197,12 +186,12 @@ class UserFragment : BaseFragment() { userDataRvAd.submitList(userDataMutableList + mutableListOf()) } - if (userCardBean.await().code == 0 && userUpStat.await().code == 0) { + if (userUpStat.await().code == 0) { userDataMutableList.add( UserViewItemBean( 2, upStatBeam = userUpStat.await(), - userCardBean = userCardBean.await(), + userCardBean = userCardBean, ), ) } @@ -226,15 +215,6 @@ class UserFragment : BaseFragment() { return networkService.n22(paramsStr) } - /** - * 获取用户状态信息 - * @return UpStatBeam - */ - private suspend fun getUpStat(): UpStatBeam { - - return networkService.n23() - } - /** * 获取用户基础信息 * @return UserBaseBean diff --git a/app/src/main/java/com/imcys/bilibilias/home/ui/viewmodel/AsVideoViewModel.kt b/app/src/main/java/com/imcys/bilibilias/home/ui/viewmodel/AsVideoViewModel.kt index b86e56b2b..d4fbc5de0 100644 --- a/app/src/main/java/com/imcys/bilibilias/home/ui/viewmodel/AsVideoViewModel.kt +++ b/app/src/main/java/com/imcys/bilibilias/home/ui/viewmodel/AsVideoViewModel.kt @@ -1,50 +1,36 @@ package com.imcys.bilibilias.home.ui.viewmodel -import android.annotation.SuppressLint -import android.content.ClipData -import android.content.ClipboardManager -import android.content.Context +import android.annotation.* +import android.content.* import android.content.Context.CLIPBOARD_SERVICE -import android.os.Build -import android.view.View -import android.widget.Toast -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import androidx.preference.PreferenceManager -import com.imcys.asbottomdialog.bottomdialog.AsDialog +import android.os.* +import android.view.* +import android.widget.* +import androidx.lifecycle.* +import androidx.preference.* +import com.imcys.asbottomdialog.bottomdialog.* import com.imcys.bilibilias.R -import com.imcys.bilibilias.base.network.NetworkService -import com.imcys.bilibilias.base.utils.DialogUtils -import com.imcys.bilibilias.base.utils.asToast -import com.imcys.bilibilias.common.base.api.BilibiliApi -import com.imcys.bilibilias.common.base.extend.Result -import com.imcys.bilibilias.common.base.extend.launchIO -import com.imcys.bilibilias.common.base.extend.launchUI -import com.imcys.bilibilias.common.base.utils.VideoNumConversion +import com.imcys.bilibilias.base.network.* +import com.imcys.bilibilias.base.utils.* +import com.imcys.bilibilias.common.base.api.* +import com.imcys.bilibilias.common.base.extend.* +import com.imcys.bilibilias.common.base.utils.* import com.imcys.bilibilias.common.base.utils.file.FileUtils -import com.imcys.bilibilias.common.base.utils.http.HttpUtils -import com.imcys.bilibilias.common.network.danmaku.DanmakuRepository -import com.imcys.bilibilias.danmaku.change.CCJsonToAss -import com.imcys.bilibilias.danmaku.change.DmXmlToAss -import com.imcys.bilibilias.home.ui.activity.AsVideoActivity +import com.imcys.bilibilias.common.base.utils.http.* +import com.imcys.bilibilias.common.network.danmaku.* +import com.imcys.bilibilias.danmaku.change.* +import com.imcys.bilibilias.home.ui.activity.* import com.imcys.bilibilias.home.ui.model.* -import com.microsoft.appcenter.analytics.Analytics -import dagger.hilt.android.lifecycle.HiltViewModel -import io.ktor.client.HttpClient -import io.ktor.client.call.body -import io.ktor.client.request.get -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.async -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.update -import kotlinx.coroutines.launch -import okio.BufferedSink -import okio.buffer -import okio.sink -import java.io.File -import java.io.FileOutputStream -import javax.inject.Inject +import com.microsoft.appcenter.analytics.* +import dagger.hilt.android.lifecycle.* +import io.ktor.client.* +import io.ktor.client.call.* +import io.ktor.client.request.* +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* +import okio.* +import java.io.* +import javax.inject.* /** * 解析视频的ViewModel @@ -76,9 +62,9 @@ class AsVideoViewModel @Inject constructor(private val danmakuRepository: Danmak viewModelScope.launchUI { if ((context as AsVideoActivity).userBaseBean.data.level >= 2) { //并发 - val dashVideoPlayDeferred = async { networkService.n29(context.bvid, context.cid) } + val dashVideoPlayDeferred = async { networkService.viewDash(context.bvid, context.cid) } val dashBangumiPlayDeferred = - async { networkService.getDashBangumiPlay(context.cid, 64) } + async { networkService.pgcPlayUrl(context.cid, 64) } // 等待两个请求的结果 val dashVideoPlayBean = dashVideoPlayDeferred.await() @@ -139,9 +125,9 @@ class AsVideoViewModel @Inject constructor(private val danmakuRepository: Danmak viewModelScope.launchUI { if ((context as AsVideoActivity).userBaseBean.data.level >= 2) { //并发 - val dashVideoPlayDeferred = async { networkService.n29(context.bvid, context.cid) } + val dashVideoPlayDeferred = async { networkService.viewDash(context.bvid, context.cid) } val dashBangumiPlayDeferred = - async { networkService.getDashBangumiPlay(context.cid, 64) } + async { networkService.pgcPlayUrl(context.cid, 64) } // 等待两个请求的结果 val dashVideoPlayBean = dashVideoPlayDeferred.await() diff --git a/common/src/main/java/com/imcys/bilibilias/common/base/api/BilibiliApi.kt b/common/src/main/java/com/imcys/bilibilias/common/base/api/BilibiliApi.kt index f19b6ab07..5ee6e6fac 100644 --- a/common/src/main/java/com/imcys/bilibilias/common/base/api/BilibiliApi.kt +++ b/common/src/main/java/com/imcys/bilibilias/common/base/api/BilibiliApi.kt @@ -1,7 +1,5 @@ package com.imcys.bilibilias.common.base.api -import com.imcys.bilibilias.common.base.constant.ROAM_API - object BilibiliApi { /** @@ -10,110 +8,80 @@ object BilibiliApi { */ const val loginApi = "https://passport.bilibili.com/" - private const val liveRoomApi = "https://api.live.bilibili.com/" - const val getLoginQRPath = loginApi + "x/passport-login/web/qrcode/generate" // 需要登陆密钥 const val getLoginStatePath = loginApi + "x/passport-login/web/qrcode/poll" - // 需要传入PS为展示项 - const val homeRCMDVideoPath = ROAM_API + "x/web-interface/index/top/feed/rcmd" - - // 热门视频 - // get,ps和pn - const val homePopularVideoPath = ROAM_API + "x/web-interface/popular" - // 需要传入mid - const val getUserInfoPath = ROAM_API + "x/space/wbi/acc/info" + const val getUserInfoPath = "x/space/wbi/acc/info" // 获取个人基本信息 - const val getMyUserData = ROAM_API + "x/member/web/account" + const val getMyUserData = "x/member/web/account" // 获取用户卡片信息 - const val getUserCardPath = ROAM_API + "x/web-interface/card" - - // post aid bvid like:1,2 csrf:j_xx - const val likeVideoPath = ROAM_API + "x/web-interface/archive/like" + const val getUserCardPath = "x/web-interface/card" // 获取视频详细信息 get bvid avid - const val getVideoDataPath = ROAM_API + "x/web-interface/view" + const val getVideoDataPath = "x/web-interface/view" // 对视频进行点赞 - const val videLikePath = ROAM_API + "x/web-interface/archive/like" + const val videLikePath = "x/web-interface/archive/like" //视频V2接口信息->名称暂定 要求AID CID同时存在 - const val videoInfoV2 = ROAM_API + "x/player/wbi/v2" - - // 对视频进行投币 - const val videAddCoinPath = ROAM_API + "x/web-interface/coin/add" + const val videoInfoV2 = "x/player/wbi/v2" // 获取收藏列表 - const val userCreatedScFolderPath = ROAM_API + "x/v3/fav/folder/created/list-all" + const val userCreatedScFolderPath = "x/v3/fav/folder/created/list-all" // 收藏夹详细内容 - const val userCollectionDataPath = ROAM_API + "x/v3/fav/resource/list" + const val userCollectionDataPath = "x/v3/fav/resource/list" - const val videoPlayPath = ROAM_API + "x/player/playurl" - var bangumiPlayPath = ROAM_API + "pgc/player/web/playurl" + const val videoPlayPath = "x/player/playurl" + const val bangumiPlayPath = "pgc/player/web/playurl" // 弹幕下载 - const val videoDanMuPath = ROAM_API + "x/v1/dm/list.so" - - // 当前弹幕缓存 - const val thisVideoDanmakuPath = ROAM_API + "x/v2/dm/web/seg.so" - + const val videoDanMuPath = "x/v1/dm/list.so" // 视频列表 - const val videoPageListPath = ROAM_API + "x/player/pagelist" + const val videoPageListPath = "x/player/pagelist" // 修改视频收藏 - const val videoCollectionSetPath = ROAM_API + "x/v3/fav/resource/deal" + const val videoCollectionSetPath = "x/v3/fav/resource/deal" // 投币地址 - const val videoCoinAddPath = ROAM_API + "x/web-interface/coin/add" + const val videoCoinAddPath = "x/web-interface/coin/add" // 获取剧集明细 get season_id / ep_id - var bangumiVideoDataPath = ROAM_API + "pgc/view/web/season" + const val bangumiVideoDataPath = "pgc/view/web/season" // 获取用户基本信息 - const val userBaseDataPath = ROAM_API + "x/space/wbi/acc/info" + const val userBaseDataPath = "x/space/wbi/acc/info" // 用户导航栏信息 - const val userNavDataPath = ROAM_API + "x/web-interface/nav" + const val userNavDataPath = "x/web-interface/nav" // 用户状态 - const val userUpStat = ROAM_API + "x/space/upstat" + const val userUpStat = "x/space/upstat" // 用户投稿 - const val userWorksPath = ROAM_API + "x/space/wbi/arc/search" + const val userWorksPath = "x/space/wbi/arc/search" // 播放历史 - const val userPlayHistoryPath = ROAM_API + "x/web-interface/history/cursor" + const val userPlayHistoryPath = "x/web-interface/history/cursor" // 注销登录 const val exitLogin = loginApi + "login/exit/v2" // 点赞判断 - const val archiveHasLikePath = ROAM_API + "x/web-interface/archive/has/like" + const val archiveHasLikePath = "x/web-interface/archive/has/like" // 投币判断 - const val archiveCoinsPath = ROAM_API + "x/web-interface/archive/coins" + const val archiveCoinsPath = "x/web-interface/archive/coins" // 收藏判断 - const val archiveFavoured = ROAM_API + "x/v2/fav/video/favoured" + const val archiveFavoured = "x/v2/fav/video/favoured" // 追番剧列表 - const val bangumiFollowPath = ROAM_API + "x/space/bangumi/follow/list" - - // 直播间信息 - const val liveRoomDataPath = liveRoomApi + "room/v1/Room/get_info" - - // 直播用户信息 - const val liveUserMasterInfo = liveRoomApi + "live_user/v1/Master/info" - - // 直播间播放数据信息 - const val roomPlayInfo = liveRoomApi + "xlive/web-room/v2/index/getRoomPlayInfo" - - const val liveRoomPlayUrl = liveRoomApi + "room/v1/Room/playUrl" + const val bangumiFollowPath = "x/space/bangumi/follow/list" }