From 96309a69f86df5a441827632425b35fd8ed7efdd Mon Sep 17 00:00:00 2001 From: "Rian (Reza Mouna Hendrian)" <52914632+Rian8337@users.noreply.github.com> Date: Sun, 5 May 2024 10:48:33 +0800 Subject: [PATCH] Use `Chrome/Android` user agent for beatmap downloader requests --- .../osu/beatmaplisting/BeatmapDownloader.kt | 10 ++++-- .../osu/beatmaplisting/BeatmapListing.kt | 32 +++++++------------ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/com/reco1l/osu/beatmaplisting/BeatmapDownloader.kt b/src/com/reco1l/osu/beatmaplisting/BeatmapDownloader.kt index 8ef717f8a..949fd915f 100644 --- a/src/com/reco1l/osu/beatmaplisting/BeatmapDownloader.kt +++ b/src/com/reco1l/osu/beatmaplisting/BeatmapDownloader.kt @@ -2,12 +2,12 @@ package com.reco1l.osu.beatmaplisting import android.os.Environment.DIRECTORY_DOWNLOADS import android.view.View -import com.reco1l.osu.mainThread import com.reco1l.framework.net.FileRequest import com.reco1l.framework.net.IDownloaderObserver +import com.reco1l.osu.mainThread import com.reco1l.osu.multiplayer.Multiplayer -import com.reco1l.osu.ui.DownloadFragment import com.reco1l.osu.multiplayer.RoomScene +import com.reco1l.osu.ui.DownloadFragment import com.reco1l.toolkt.kotlin.async import com.reco1l.toolkt.kotlin.decodeAsURL import com.reco1l.toolkt.kotlin.replaceAlphanumeric @@ -21,7 +21,6 @@ import ru.nsu.ccfit.zuev.osu.helper.FileUtils import ru.nsu.ccfit.zuev.osu.helper.StringTable import ru.nsu.ccfit.zuev.osuplus.R import java.io.IOException -import java.lang.Exception object BeatmapDownloader : IDownloaderObserver { @@ -57,6 +56,11 @@ object BeatmapDownloader : IDownloaderObserver { val file = directory?.resolve("$filename.osz")!! val downloader = FileRequest(file, url) + downloader.buildRequest { + + removeHeader("User-Agent") + addHeader("User-Agent", "Chrome/Android") + } fragment = DownloadFragment() fragment.setDownloader(downloader) { diff --git a/src/com/reco1l/osu/beatmaplisting/BeatmapListing.kt b/src/com/reco1l/osu/beatmaplisting/BeatmapListing.kt index ef3bb8958..51970a382 100644 --- a/src/com/reco1l/osu/beatmaplisting/BeatmapListing.kt +++ b/src/com/reco1l/osu/beatmaplisting/BeatmapListing.kt @@ -2,22 +2,10 @@ package com.reco1l.osu.beatmaplisting import android.graphics.BitmapFactory import android.util.Log -import android.view.ContextThemeWrapper -import android.view.KeyEvent -import android.view.LayoutInflater -import android.view.View -import android.view.View.GONE -import android.view.View.OnKeyListener -import android.view.View.VISIBLE -import android.view.ViewGroup -import android.view.ViewOutlineProvider +import android.view.* +import android.view.View.* import android.view.inputmethod.EditorInfo -import android.widget.Button -import android.widget.EditText -import android.widget.ImageButton -import android.widget.ImageView -import android.widget.LinearLayout -import android.widget.TextView +import android.widget.* import android.widget.TextView.OnEditorActionListener import androidx.core.text.buildSpannedString import androidx.core.text.color @@ -33,11 +21,7 @@ import com.reco1l.framework.net.IDownloaderObserver import com.reco1l.framework.net.JsonArrayRequest import com.reco1l.osu.OsuColors import com.reco1l.osu.mainThread -import kotlinx.coroutines.CoroutineExceptionHandler -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch +import kotlinx.coroutines.* import ru.nsu.ccfit.zuev.audio.Status import ru.nsu.ccfit.zuev.osu.Config import ru.nsu.ccfit.zuev.osu.GlobalManager @@ -46,7 +30,7 @@ import ru.nsu.ccfit.zuev.osu.ToastLogger import ru.nsu.ccfit.zuev.osuplus.R import java.net.URL import java.text.SimpleDateFormat -import java.util.TimeZone +import java.util.* object BeatmapListing : BaseFragment(), @@ -160,6 +144,12 @@ object BeatmapListing : BaseFragment(), addQueryParameter("offset", offset.toString()) } + request.buildRequest { + + removeHeader("User-Agent") + addHeader("User-Agent", "Chrome/Android") + } + val beatmapSets = mirror.search.mapResponse(request.execute().json) adapter.data.addAll(beatmapSets)