[Android] Allow changing the HTTP user agent
Nicolas Pomepuy
git at videolan.org
Wed Mar 27 15:35:23 UTC 2024
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Mar 27 10:28:38 2024 +0100| [682d618638b7671049397161fdd3bf2a993cafb1] | committer: Nicolas Pomepuy
Allow changing the HTTP user agent
Fixes #2759
> https://code.videolan.org/videolan/vlc-android/commit/682d618638b7671049397161fdd3bf2a993cafb1
---
application/resources/src/main/res/values/strings.xml | 1 +
application/tools/src/main/java/org/videolan/tools/Settings.kt | 1 +
application/vlc-android/res/xml/preferences_adv.xml | 8 ++++++++
.../vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt | 4 ++++
4 files changed, 14 insertions(+)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 368c51abc3..e4a738b7cb 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -556,6 +556,7 @@
<string name="dump_logcat">Dump logcat log</string>
<string name="dump_logcat_success">Logcat successfully dumped to %1$s!</string>
<string name="dump_logcat_failure">Failed to dump logcat.</string>
+ <string name="http_user_agent">HTTP user agent</string>
<string name="custom_libvlc_options">Custom libVLC options</string>
<string name="custom_libvlc_options_invalid">Invalid libVLC options!</string>
diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index 994a4f07a8..2981b5f6db 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -220,6 +220,7 @@ const val SLEEP_TIMER_WAIT = "sleep_timer_wait"
const val NOTIFICATION_PERMISSION_ASKED = "notification_permission_asked"
const val PLAYLIST_REPLACE = "playlist_replace"
+const val HTTP_USER_AGENT = "http_user_agent"
//files
const val BROWSER_SHOW_HIDDEN_FILES = "browser_show_hidden_files"
diff --git a/application/vlc-android/res/xml/preferences_adv.xml b/application/vlc-android/res/xml/preferences_adv.xml
index dd833ed0e1..e241087cd8 100644
--- a/application/vlc-android/res/xml/preferences_adv.xml
+++ b/application/vlc-android/res/xml/preferences_adv.xml
@@ -25,6 +25,14 @@
android:summary="@string/prefersmbv1_summary"
android:title="@string/prefersmbv1"/>
+ <EditTextPreference
+ android:defaultValue=""
+ android:inputType="textMultiLine"
+ android:key="http_user_agent"
+ app:useSimpleSummaryProvider="true"
+ android:singleLine="false"
+ android:title="@string/http_user_agent"/>
+
<Preference
android:enabled="true"
android:key="dump_media_db"
diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 685cdbbbf0..9c9a35172b 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -53,6 +53,7 @@ import org.videolan.tools.AUDIO_RESUME_PLAYBACK
import org.videolan.tools.AUDIO_SHUFFLING
import org.videolan.tools.AUDIO_STOP_AFTER
import org.videolan.tools.AppScope
+import org.videolan.tools.HTTP_USER_AGENT
import org.videolan.tools.KEY_AUDIO_FORCE_SHUFFLE
import org.videolan.tools.KEY_INCOGNITO
import org.videolan.tools.KEY_PLAYBACK_RATE
@@ -512,6 +513,9 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
shouldDisableCookieForwarding = false
media.addOption(":no-http-forward-cookies")
}
+ settings.getString(HTTP_USER_AGENT, null)?.let {
+ media.addOption(":http-user-agent=$it")
+ }
//todo in VLC 4.0, this should be done by using libvlc_media_player_set_time instead of start-time
media.addOption(":start-time=${start/1000L}")
VLCOptions.setMediaOptions(media, ctx, flags or mw.flags, PlaybackService.hasRenderer())
More information about the Android
mailing list