wangrong
2024-11-30 bd54352f44f33caef57a8dbb541e5e84a372dcbb
app 升级功能
3个文件已修改
103 ■■■■■ 已修改文件
app/src/main/java/com/shsening/autouploadvideos/AppConfig.kt 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/shsening/autouploadvideos/action/ActionDouyin.kt 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/shsening/autouploadvideos/utils/Utils.kt 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/shsening/autouploadvideos/AppConfig.kt
@@ -8,7 +8,7 @@
)
class AppConfig {
    companion object {
        const val APP_VERSION_NAME = "1.1.0"
        const val APP_VERSION_NAME = "1.1.2"
        const val MSG_MY_TAB_COPY_TO_CLIPBOARD = "文本已复制到剪切板"
        const val MSG_MY_TAB_ADD_WECHAT = "详细内容请添加微信咨询"
@@ -57,7 +57,7 @@
            PlatformItem(5,"YouTube", false,"https://creator.douyin.com/creator-micro/content/publish?enter_from=publish_page"),
            PlatformItem(6,"TikTok", false,"https://creator.douyin.com/creator-micro/content/publish?enter_from=publish_page")
        )
        val SESSION_PROFILE_TYPE: Map<Int, String> = mapOf(0 to "美女跳舞", 1 to "美女穿搭",2 to "AI美景", 3 to "搞笑动物")
        val SESSION_PROFILE_TYPE: Map<Int, String> = mapOf(0 to "美女跳舞", 1 to "美女穿搭",2 to "AI美景", 3 to "搞笑动物", 4 to "AI黑丝", 5 to "宠物", 6 to "旗袍", 7 to "二次元", 8 to "亚洲性感美女")
    }
}
app/src/main/java/com/shsening/autouploadvideos/action/ActionDouyin.kt
@@ -4,6 +4,7 @@
import android.app.Instrumentation
import android.os.SystemClock
import android.os.Handler
import android.util.Log
import com.shsening.autouploadvideos.UploadSessionActivity
import com.shsening.autouploadvideos.utils.Utils
import com.shsening.autouploadvideos.WebviewUtils
@@ -12,6 +13,7 @@
    private var webView = activity.sessionProfileWebView
    private var TAG = "ActionDouyin"
    var jsCode_CheckContentLoaded = """
@@ -27,39 +29,16 @@
    private fun updatePostDescription(){
        WebviewUtils.addValueToInput(
            webView,
            "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div.editor-container-zRPSAi > div > div > div > div:nth-child(1) > div > div > input",
            videoInfo.title
        )
        WebviewUtils.addValueToInput(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div.editor-container-zRPSAi > div > div > div > div:nth-child(1) > div > div > input",videoInfo.title)
        WebviewUtils.addValueToDiv(
            webView,
            "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div.editor-container-zRPSAi > div > div > div > div.outerdocbody.editor-kit-outer-container > div",
            videoInfo.description
        )
        WebviewUtils.addValueToDiv(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div.editor-container-zRPSAi > div > div > div > div.outerdocbody.editor-kit-outer-container > div",videoInfo.description)
        WebviewUtils.simpleElementClick(
            webView,
            "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div:nth-child(3) > div > div.activity-list-container-AZzfdV > div:nth-child(1)"
        )
        WebviewUtils.simpleElementClick(
            webView,
            "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div:nth-child(3) > div > div.activity-list-container-AZzfdV > div:nth-child(2)"
        )
        WebviewUtils.simpleElementClick(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div:nth-child(3) > div > div.activity-list-container-AZzfdV > div:nth-child(1)")
        WebviewUtils.simpleElementClick(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div:nth-child(3) > div > div.activity-list-container-AZzfdV > div:nth-child(2)")
        WebviewUtils.simpleElementClick(
            webView,
            "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.content-upload-new > div > div.recommendContainer-HXvL9W > div.recommendDisplay-ifUYki > div > div:nth-child(1) > div"
        )
        WebviewUtils.simpleElementClick(
            webView,
            "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.download-content-Lci5tL > div > label:nth-child(2)"
        )
        WebviewUtils.simpleElementClick(
            webView,
            "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-settings-WtW_ZW > div.schedule-part-V615Zn > div.row-suTOx_ > label:nth-child(2)"
        )
        WebviewUtils.simpleElementClick(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.content-upload-new > div > div.recommendContainer-HXvL9W > div.recommendDisplay-ifUYki > div > div:nth-child(1) > div")
        WebviewUtils.simpleElementClick(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.download-content-Lci5tL > div > label:nth-child(2)")
        WebviewUtils.simpleElementClick(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-settings-WtW_ZW > div.schedule-part-V615Zn > div.row-suTOx_ > label:nth-child(2)")
        addValueToDatePickerInput(true,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-settings-WtW_ZW > div.schedule-part-V615Zn > div.row-suTOx_ > div.date-picker-ioPchj > div > div",videoInfo.datetime)
@@ -85,7 +64,7 @@
    }
    private fun startToPublishVideo(){
        WebviewUtils.simpleElementClick(webView, jsPath_PublishVideo)
        WebviewUtils.simpleElementClick(webView,jsPath_PublishVideo)
        checkVideoPublishFinished()
    }
@@ -111,11 +90,8 @@
        webView.postDelayed({
            webView.evaluateJavascript(jsCode_PublishVideo_Finished) { result ->
                if (result == "true") {
                    // video published successfully!!!
                    activity.checkAndStartNextTask()
                } else {
                    // 元素不存在,1秒后再次检查
                    webView.postDelayed({
@@ -133,7 +109,7 @@
        var dpPanelText = datetimes[0].toString()+"年 "+datetimes[1].toString()+"月";
        var dateRowColum = Utils.getDatePosition(datetimes[0], datetimes[1], datetimes[2]) ?:return;
        var dateRowColum = Utils.getDatePosition(datetimes[0],datetimes[1],datetimes[2])?:return;
        val jsCode = """
       try {
@@ -144,17 +120,17 @@
           // need time to popup date-picker
           setTimeout(() => {
               var dpPanel = document.querySelector('.semi-popover-content');
               var dpPanelSpan = dpPanel.querySelector('div > div > div > div:nth-child(1) > div.semi-datepicker-navigation > div > button > span > span');
               var dpPanelSpan = document.querySelectorAll(".semi-datepicker")[1].querySelector(".semi-datepicker-navigation-month");
               if (dpPanelSpan && dpPanelSpan.textContent != '${dpPanelText}'){
                  dpPanel.querySelector('div > div > div > div > div:nth-child(1) > div.semi-datepicker-navigation > button:nth-child(3)').click();
                  document.querySelectorAll(".semi-datepicker")[1].querySelectorAll(".semi-button-content")[2].click();
               }
               dpPanel.querySelector('div > div > div > div > div:nth-child(1) > div.semi-datepicker-month > div.semi-datepicker-weeks > div:nth-child(${dateRowColum[0]}) > div:nth-child(${dateRowColum[1]})').click()
               document.querySelectorAll(".semi-datepicker-month")[0].querySelectorAll(".semi-datepicker-weeks")[0].querySelector("div:nth-child(${dateRowColum[0]}) > div:nth-child(${dateRowColum[1]})").click();
               
               //switch to time selection
               dpPanel.querySelector('div > div > div > div > div.semi-datepicker-switch > div.semi-datepicker-switch-time').click();
               document.querySelectorAll(".semi-datepicker-switch-time")[0].click()
               setTimeout(() => {
                  dpPanel.querySelector('div > div > div > div.semi-datepicker-tpk > div > div > div.semi-scrolllist-body > div.semi-scrolllist-item-wheel.undefined-list-hour > div.semi-scrolllist-list-outer > ul > li:nth-child(${(datetimes[3]+1)})').click();
                  dpPanel.querySelector('div > div > div > div.semi-datepicker-tpk > div > div > div.semi-scrolllist-body > div.semi-scrolllist-item-wheel.undefined-list-minute > div.semi-scrolllist-list-outer > ul > li:nth-child(${(datetimes[4]+1)})').click();
                  document.querySelectorAll('.semi-scrolllist-body')[0].querySelectorAll('.semi-scrolllist-item-wheel')[0].querySelector('div.semi-scrolllist-list-outer > ul > li:nth-child(${(datetimes[3]+1)})').click();
                  document.querySelectorAll('.semi-scrolllist-body')[0].querySelectorAll('.semi-scrolllist-item-wheel')[1].querySelector('div.semi-scrolllist-list-outer > ul > li:nth-child(${(datetimes[4]+1)})').click();
               }, 500);
           }, 500);
       } catch (error) {
@@ -178,12 +154,17 @@
        val y = height / 3f // Y 坐标在屏幕中间
        Thread {
            Utils.instrumentationSwipe(instrumentation, startX, y, endX, y)
            SystemClock.sleep(500)
            Utils.instrumentationSwipe(instrumentation, startX, y, endX, y)
            SystemClock.sleep(500)
            Utils.instrumentationClick(instrumentation, width / 2f, height * 2 / 4f)
            // back to main thread
            try {
                Utils.instrumentationSwipe(instrumentation, startX, y, endX, y)
                SystemClock.sleep(500)
                Utils.instrumentationSwipe(instrumentation, startX, y, endX, y)
                SystemClock.sleep(500)
                Utils.instrumentationClick(instrumentation, width / 2f, height * 2 / 3f)
                // back to main thread
            } catch (e: Exception) {
                Log.e(TAG, "滑动操作失败:应用可能在后台", e)
            }
            threadHandler.post {
                checkVideoUploadFinished()
            }
app/src/main/java/com/shsening/autouploadvideos/utils/Utils.kt
@@ -278,7 +278,7 @@
    suspend fun downloadCommonFileToExternalFilesDir(context: Context, url: String, filename: String, install: Boolean) {
        val tmpFile = File(context.getExternalFilesDir(null), filename)
        try{
        try {
            if (tmpFile.exists()) {
                return
            }
@@ -292,17 +292,20 @@
                    override fun onFailure(call: Call, e: IOException) {
                        deferred.completeExceptionally(e) // 下载失败时标记为异常
                    }
                    override fun onResponse(call: Call, response: Response) {
                        response.use {
                            if (!response.isSuccessful) {
                                deferred.completeExceptionally(IOException("Unexpected code $response")) // 如果响应不成功,标记为异常
                                return
                            }
                            tmpFile.outputStream().use { outputStream ->
                                outputStream.write(response.body?.bytes())
                            }
                            if (install) {
                                installApk(context,tmpFile)
                                installApk(context, tmpFile)
                            }
                            deferred.complete(Unit) // 下载成功时返回文件
@@ -311,19 +314,22 @@
                })
            }
            // 等待下载完成
            Toast.makeText(context, filename + " " + AppConfig.MSG_DOWNLOAD_FINISHED, Toast.LENGTH_SHORT).show()
            // Switch to main thread for Toast
            withContext(Dispatchers.Main) {
                Toast.makeText(context, "$filename ${AppConfig.MSG_DOWNLOAD_FINISHED}", Toast.LENGTH_SHORT).show()
            }
            deferred.await()
        }catch(e:Exception){
        } catch (e: Exception) {
            e.printStackTrace()
            Toast.makeText(context, filename+" download fails, Please try again later!", Toast.LENGTH_SHORT)
                    .show()
            // Switch to main thread for Toast
            withContext(Dispatchers.Main) {
                Toast.makeText(context, "$filename download fails, Please try again later!", Toast.LENGTH_SHORT).show()
            }
        }
    }
    fun installApk(context: Context,apkFile: File) {
        val intent = Intent(Intent.ACTION_VIEW)
        val apkUri = FileProvider.getUriForFile(context, AppConfig.FILE_PROVIDER, apkFile)