Merge pull request #4272 from ByteHamster/fix-useragent

Fix useragent
This commit is contained in:
H. Lehmann 2020-07-06 22:52:40 +02:00 committed by GitHub
commit 6c4ee6da18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -65,7 +65,7 @@ project.ext {
rxAndroidVersion = "2.1.1" rxAndroidVersion = "2.1.1"
rxJavaVersion = "2.2.2" rxJavaVersion = "2.2.2"
iconifyVersion = "2.2.2" iconifyVersion = "2.2.2"
audioPlayerVersion = "v1.0.17" audioPlayerVersion = "v2.0.0"
// Google Play build // Google Play build
wearableSupportVersion = "2.6.0" wearableSupportVersion = "2.6.0"

View File

@ -4,7 +4,10 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import android.util.Log; import android.util.Log;
import java.net.URLConnection;
import java.util.zip.CheckedOutputStream; import java.util.zip.CheckedOutputStream;
import de.danoeh.antennapod.core.ClientConfig;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
@ -80,7 +83,9 @@ public class ChapterUtils {
CountingInputStream in = null; CountingInputStream in = null;
try { try {
URL url = new URL(p.getStreamUrl()); URL url = new URL(p.getStreamUrl());
in = new CountingInputStream(url.openStream()); URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("User-Agent", ClientConfig.USER_AGENT);
in = new CountingInputStream(urlConnection.getInputStream());
List<Chapter> chapters = readChaptersFrom(in); List<Chapter> chapters = readChaptersFrom(in);
if (!chapters.isEmpty()) { if (!chapters.isEmpty()) {
p.setChapters(chapters); p.setChapters(chapters);
@ -149,7 +154,9 @@ public class ChapterUtils {
InputStream input = null; InputStream input = null;
try { try {
URL url = new URL(media.getStreamUrl()); URL url = new URL(media.getStreamUrl());
input = url.openStream(); URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("User-Agent", ClientConfig.USER_AGENT);
input = urlConnection.getInputStream();
if (input != null) { if (input != null) {
readOggChaptersFromInputStream(media, input); readOggChaptersFromInputStream(media, input);
} }

View File

@ -6,6 +6,7 @@ import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import de.danoeh.antennapod.core.ClientConfig;
import org.antennapod.audio.MediaPlayer; import org.antennapod.audio.MediaPlayer;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
@ -17,7 +18,7 @@ public class AudioPlayer extends MediaPlayer implements IPlayer {
private static final String TAG = "AudioPlayer"; private static final String TAG = "AudioPlayer";
public AudioPlayer(Context context) { public AudioPlayer(Context context) {
super(context); super(context, true, ClientConfig.USER_AGENT);
PreferenceManager.getDefaultSharedPreferences(context) PreferenceManager.getDefaultSharedPreferences(context)
.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> { .registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> {
if (key.equals(UserPreferences.PREF_MEDIA_PLAYER)) { if (key.equals(UserPreferences.PREF_MEDIA_PLAYER)) {