PR#12691 fix by remarks

This commit is contained in:
fokin33 2026-01-31 00:15:05 +03:00
parent 78506f0005
commit 2d1823f2a1
14 changed files with 107 additions and 61 deletions

View File

@ -11,7 +11,7 @@ import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.downloader.Request;
import org.schabi.newpipe.extractor.downloader.Response;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.settings.ProxyManager;
import org.schabi.newpipe.util.ProxyManager;
import org.schabi.newpipe.util.InfoCache;
import java.io.IOException;

View File

@ -46,7 +46,7 @@ import com.google.common.collect.Sets;
import com.google.common.net.HttpHeaders;
import org.schabi.newpipe.DownloaderImpl;
import org.schabi.newpipe.settings.ProxyManager;
import org.schabi.newpipe.util.ProxyManager;
import java.io.IOException;
import java.io.InputStream;

View File

@ -18,12 +18,10 @@ import com.google.android.exoplayer2.source.smoothstreaming.DefaultSsChunkSource
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import org.schabi.newpipe.DownloaderImpl;
import org.schabi.newpipe.extractor.services.youtube.dashmanifestcreators.YoutubeOtfDashManifestCreator;
import org.schabi.newpipe.extractor.services.youtube.dashmanifestcreators.YoutubePostLiveStreamDvrDashManifestCreator;
import org.schabi.newpipe.extractor.services.youtube.dashmanifestcreators.YoutubeProgressiveDashManifestCreator;
@ -86,12 +84,14 @@ public class PlayerDataSource {
// make sure the static cache was created: needed by CacheFactories below
instantiateCacheIfNeeded(context);
// generic data source factories use DefaultHttpDataSource.Factory
// generic data source factories now use YoutubeHttpDataSource.Factory to support proxies
final YoutubeHttpDataSource.Factory youtubeHttpDataSourceFactory =
getYoutubeHttpDataSourceFactory(context, false, false);
cachelessDataSourceFactory = new DefaultDataSource.Factory(context,
new DefaultHttpDataSource.Factory().setUserAgent(DownloaderImpl.USER_AGENT))
youtubeHttpDataSourceFactory)
.setTransferListener(transferListener);
cacheDataSourceFactory = new CacheFactory(context, transferListener, cache,
new DefaultHttpDataSource.Factory().setUserAgent(DownloaderImpl.USER_AGENT));
youtubeHttpDataSourceFactory);
// YouTube-specific data source factories use getYoutubeHttpDataSourceFactory()
ytHlsCacheDataSourceFactory = new CacheFactory(context, transferListener, cache,

View File

@ -1,26 +1,70 @@
package org.schabi.newpipe.settings;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.preference.ListPreference;
import org.schabi.newpipe.R;
import org.schabi.newpipe.util.NavigationHelper;
/**
* A fragment that displays proxy settings.
*/
public class ProxySettingsFragment extends BasePreferenceFragment {
private boolean preferencesChanged = false;
private SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener;
@Override
public void onCreatePreferences(@Nullable final Bundle savedInstanceState,
@Nullable final String rootKey) {
addPreferencesFromResource(R.xml.proxy_settings);
//addPreferencesFromResource(R.xml.proxy_settings);
addPreferencesFromResourceRegistry();
preferenceChangeListener = (sharedPreferences, key) -> {
preferencesChanged = true;
};
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(preferenceChangeListener);
}
final ListPreference proxyTypePreference = findPreference("proxy_type");
if (proxyTypePreference != null) {
proxyTypePreference.setSummaryProvider(
ListPreference.SimpleSummaryProvider.getInstance());
@Override
public void onStop() {
super.onStop();
if (preferencesChanged && getActivity() != null && !getActivity().isFinishing()) {
showRestartDialog();
}
}
private void showRestartDialog() {
// Show Alert Dialogue
final Activity activity = getActivity();
if (activity == null) {
return;
}
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(R.string.restart_app_message);
builder.setTitle(R.string.restart_app_title);
builder.setCancelable(true);
builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
// Restarts the app
if (activity == null) {
return;
}
NavigationHelper.restartApp(activity);
});
builder.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
});
final android.app.AlertDialog alertDialog = builder.create();
alertDialog.show();
}
@Override
public void onDestroy() {
super.onDestroy();
if (preferenceChangeListener != null && getPreferenceScreen() != null) {
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener);
}
}
}

View File

@ -42,6 +42,7 @@ public final class SettingsResourceRegistry {
add(VideoAudioSettingsFragment.class, R.xml.video_audio_settings);
add(ExoPlayerSettingsFragment.class, R.xml.exoplayer_settings);
add(BackupRestoreSettingsFragment.class, R.xml.backup_restore_settings);
add(ProxySettingsFragment.class, R.xml.proxy_settings);
}
private SettingRegistryEntry add(

View File

@ -1,4 +1,4 @@
package org.schabi.newpipe.settings;
package org.schabi.newpipe.util;
import android.content.Context;
import android.content.SharedPreferences;

View File

@ -23,7 +23,7 @@ import com.squareup.picasso.Transformation;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.settings.ProxyManager;
import org.schabi.newpipe.util.ProxyManager;
import java.io.File;
import java.io.IOException;

View File

@ -1,5 +1,6 @@
package us.shandian.giga.get;
import android.content.Context;
import android.os.Handler;
import android.system.ErrnoException;
import android.system.OsConstants;
@ -17,6 +18,7 @@ import java.io.InterruptedIOException;
import java.io.Serializable;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.UnknownHostException;
@ -25,6 +27,7 @@ import java.util.Objects;
import javax.net.ssl.SSLException;
import org.schabi.newpipe.util.ProxyManager;
import org.schabi.newpipe.streams.io.StoredFileHelper;
import us.shandian.giga.postprocessing.Postprocessing;
import us.shandian.giga.service.DownloadManagerService;
@ -34,7 +37,7 @@ import static org.schabi.newpipe.BuildConfig.DEBUG;
public class DownloadMission extends Mission {
private static final long serialVersionUID = 6L;// last bump: 07 october 2019
private final Context context;
static final int BUFFER_SIZE = 64 * 1024;
static final int BLOCK_SIZE = 512 * 1024;
@ -153,9 +156,10 @@ public class DownloadMission extends Mission {
public transient Thread[] threads = new Thread[0];
public transient Thread init = null;
public DownloadMission(String[] urls, StoredFileHelper storage, char kind, Postprocessing psInstance) {
public DownloadMission(final Context context, String[] urls, StoredFileHelper storage, char kind, Postprocessing psInstance) {
if (Objects.requireNonNull(urls).length < 1)
throw new IllegalArgumentException("urls array is empty");
this.context = context;
this.urls = urls;
this.kind = kind;
this.offsets = new long[urls.length];
@ -164,6 +168,7 @@ public class DownloadMission extends Mission {
this.storage = storage;
this.psAlgorithm = psInstance;
if (DEBUG && psInstance == null && urls.length > 1) {
Log.w(TAG, "mission created with multiple urls ¿missing post-processing algorithm?");
}
@ -219,7 +224,14 @@ public class DownloadMission extends Mission {
}
HttpURLConnection openConnection(String url, boolean headRequest, long rangeStart, long rangeEnd) throws IOException {
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
final ProxyManager proxyManager = new ProxyManager(context);
final Proxy proxy = proxyManager.getProxy();
final HttpURLConnection conn;
if (proxy != null) {
conn = (HttpURLConnection) new URL(url).openConnection(proxy);
} else {
conn = (HttpURLConnection) new URL(url).openConnection();
}
conn.setInstanceFollowRedirects(true);
conn.setRequestProperty("User-Agent", DownloaderImpl.USER_AGENT);
conn.setRequestProperty("Accept", "*/*");

View File

@ -408,7 +408,7 @@ public class DownloadManagerService extends Service {
else
ps = Postprocessing.getAlgorithm(psName, psArgs, streamInfo);
final DownloadMission mission = new DownloadMission(urls, storage, kind, ps);
final DownloadMission mission = new DownloadMission(this, urls, storage, kind, ps);
mission.threadCount = threads;
mission.source = streamInfo.getUrl();
mission.nearLength = nearLength;

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_search"
android:title="@string/search"
app:showAsAction="ifRoom" />
</menu>

View File

@ -34,6 +34,14 @@
<string name="use_external_video_player_title">Внешний видеоплеер</string>
<string name="use_external_audio_player_title">Внешний аудиоплеер</string>
<string name="background_player_playing_toast">Воспроизведение в фоновом режиме</string>
<string name="proxy_settings_title">Настройки прокси</string>
<string name="use_proxy">Использовать прокси</string>
<string name="use_proxy_summary">Перенаправлять трафик через прокси</string>
<string name="proxy_host">Хост прокси</string>
<string name="proxy_host_summary">Имя хоста или IP-адрес прокси</string>
<string name="proxy_port">Порт прокси</string>
<string name="proxy_port_summary">Номер порта прокси</string>
<string name="proxy_port_dialog_message">Введите номер порта прокси</string>
<string name="theme_title">Тема</string>
<string name="dark_theme_title">Тёмная</string>
<string name="light_theme_title">Светлая</string>
@ -868,4 +876,6 @@
<string name="youtube_player_http_403">Во время воспроизведения получена ошибка HTTP 403 от сервера, вероятно, вызванная блокировкой IP-адреса или проблемами деобфускации URL-адреса потоковой передачи</string>
<string name="sign_in_confirm_not_bot_error">%1$s отказался предоставить данные, запросив логин для подтверждения, что запросчик не бот.\n\nВозможно, ваш IP-адрес временно заблокирован %1$s. Вы можете подождать некоторое время или переключиться на другой IP-адрес (например, включив/выключив VPN или переключившись с Wi-Fi на мобильный интернет).</string>
<string name="unsupported_content_in_country">Этот контент недоступен для выбранной страны контента.\n\nИзмените свой выбор в разделе «Настройки &gt; Контент &gt; Страна контента по умолчанию».</string>
<string name="restart_app_title">Перезапуск приложения</string>
<string name="restart_app_message">Настройки прокси изменены. Для применения изменений требуется перезапуск приложения.</string>
</resources>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="proxy_settings_title">Настройки прокси</string>
<string name="use_proxy">Использовать прокси</string>
<string name="use_proxy_summary">Перенаправлять трафик через прокси</string>
<string name="proxy_host">Хост прокси</string>
<string name="proxy_host_summary">Имя хоста или IP-адрес прокси</string>
<string name="proxy_port">Порт прокси</string>
<string name="proxy_port_summary">Номер порта прокси</string>
<string name="proxy_port_dialog_message">Введите номер порта прокси</string>
</resources>

View File

@ -159,6 +159,23 @@
<string name="settings_category_player_notification_title">Player notification</string>
<string name="settings_category_player_notification_summary">Configure current playing stream notification</string>
<string name="settings_category_backup_restore_title">Backup and restore</string>
<string name="proxy_settings_title">Proxy Settings</string>
<string name="use_proxy">Use proxy</string>
<string name="use_proxy_summary">Redirect traffic through a proxy</string>
<string name="proxy_host">Proxy host</string>
<string name="proxy_host_summary">Hostname or IP address of the proxy</string>
<string name="proxy_port">Proxy port</string>
<string name="proxy_port_summary">Port number of the proxy</string>
<string name="proxy_port_dialog_message">Enter the proxy port number</string>
<string name="proxy_type">Proxy type</string>
<string-array name="proxy_type_entries">
<item>HTTP</item>
<item>SOCKS</item>
</string-array>
<string-array name="proxy_type_values">
<item>HTTP</item>
<item>SOCKS</item>
</string-array>
<string name="background_player_playing_toast">Playing in background</string>
<string name="popup_playing_toast">Playing in popup mode</string>
<string name="content">Content</string>
@ -882,4 +899,6 @@
<string name="youtube_player_http_403">HTTP error 403 received from server while playing, likely caused by an IP ban or streaming URL deobfuscation issues</string>
<string name="sign_in_confirm_not_bot_error">%1$s refused to provide data, asking for a login to confirm the requester is not a bot.\n\nYour IP might have been temporarily banned by %1$s, you can wait some time or switch to a different IP (for example by turning on/off a VPN, or by switching from WiFi to mobile data).</string>
<string name="unsupported_content_in_country">This content is not available for the currently selected content country.\n\nChange your selection from \"Settings > Content > Default content country\".</string>
<string name="restart_app_title">Restart application</string>
<string name="restart_app_message">The proxy settings have been changed. A restart of the application is required for the changes to take effect.</string>
</resources>

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="proxy_settings_title">Proxy Settings</string>
<string name="use_proxy">Use proxy</string>
<string name="use_proxy_summary">Redirect traffic through a proxy</string>
<string name="proxy_host">Proxy host</string>
<string name="proxy_host_summary">Hostname or IP address of the proxy</string>
<string name="proxy_port">Proxy port</string>
<string name="proxy_port_summary">Port number of the proxy</string>
<string name="proxy_port_dialog_message">Enter the proxy port number</string>
<string name="proxy_type">Proxy type</string>
<string-array name="proxy_type_entries">
<item>HTTP</item>
<item>SOCKS</item>
</string-array>
<string-array name="proxy_type_values">
<item>HTTP</item>
<item>SOCKS</item>
</string-array>
</resources>