Internal VK Proxy Support (#1579)

thanks @awers24 for tests
This commit is contained in:
Artur Skubei
2024-03-02 21:47:34 +03:00
committed by GitHub
parent 5466dd72dd
commit 6b1e6f07c5
193 changed files with 18200 additions and 6218 deletions
@@ -0,0 +1,38 @@
package ru.vtosters.hooks;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
public class FirebaseGzipSupport {
public static JSONObject getJsonObjectFromConnection(URLConnection connection) throws IOException, JSONException {
InputStream inputStream = getDecompressedInputStream(connection);
String jsonString = readInputStream(inputStream);
return new JSONObject(jsonString);
}
private static InputStream getDecompressedInputStream(URLConnection connection) throws IOException {
String contentEncoding = connection.getHeaderField("Content-Encoding");
if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) {
return new GZIPInputStream(connection.getInputStream());
}
return connection.getInputStream();
}
private static String readInputStream(InputStream inputStream) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
int read;
while ((read = bufferedReader.read()) != -1) {
sb.append((char) read);
}
return sb.toString();
}
}
@@ -1,13 +1,22 @@
package ru.vtosters.hooks;
import android.util.Log;
import com.vk.core.network.Network;
import com.vtosters.lite.R;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.ProxyUtils;
import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException;
import static com.vk.core.network.Network.ClientType.CLIENT_API;
import static ru.vtosters.hooks.other.Preferences.*;
import static ru.vtosters.lite.net.Request.makeRequest;
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
@@ -85,22 +94,34 @@ public class OnlineFormatterHook {
if (appname != null) return appname;
makeRequest("https://" + getApi() + "/method/apps.get?app_id=" + appid + "&v=5.99&access_token=" + getUserToken(),
response -> {
try {
JSONObject mainJson = new JSONObject(response);
JSONObject responseJson = mainJson.getJSONObject("response");
JSONArray itemsJson = responseJson.getJSONArray("items");
okhttp3.Request req = new okhttp3.Request.a()
.b("https://" + getApi() + "/method/apps.get?app_id=" + appid + "&v=5.99&access_token=" + getUserToken())
.a();
AppName = itemsJson.getJSONObject(0).optString("title", "");
Network.b(CLIENT_API).a(req).a(new Callback() {
@Override
public void a(Call call, IOException e) {
e.fillInStackTrace();
}
prefs.edit().putString(String.valueOf(appid), AppName).apply();
@Override
public void a(Call call, Response response) throws IOException {
try {
JSONObject mainJson = new JSONObject(response.a().g());
JSONObject responseJson = mainJson.getJSONObject("response");
JSONArray itemsJson = responseJson.getJSONArray("items");
AppName = itemsJson.getJSONObject(0).optString("title", "");
prefs.edit().putString(String.valueOf(appid), AppName).apply();
if (dev()) sendToast("AppName: " + AppName + " for appid: " + appid);
} catch (JSONException e) {
e.fillInStackTrace();
}
}
});
if (dev()) sendToast("AppName: " + AppName + " for appid: " + appid);
} catch (JSONException e) {
e.printStackTrace();
}
});
return AppName;
}
@@ -15,6 +15,7 @@ import android.widget.Toast;
import androidx.core.content.FileProvider;
import com.vk.core.dialogs.actionspopup.ActionsPopup;
import com.vk.core.dialogs.alert.VkAlertDialog;
import com.vk.core.network.Network;
import com.vk.core.util.ToastUtils;
import com.vk.dto.common.AttachmentWithMedia;
import com.vk.dto.common.ImageSize;
@@ -90,7 +91,7 @@ public class PhotoViewer {
var req = new Request.a()
.b(getImageUrlFromAttachment(attachment))
.a();
client.a(req).a(new Callback() {
Network.b(Network.ClientType.CLIENT_API).a(req).a(new Callback() {
@Override
public void a(Call call, IOException e) {
e.printStackTrace();
@@ -100,7 +101,7 @@ public class PhotoViewer {
public void a(Call call, Response response)
throws IOException {
var tmpImage = new File(AndroidUtils.getGlobalContext().getExternalCacheDir(), attachment.getId() + ".jpg");
try (var resp = client.a(req).execute();
try (var resp = Network.b(Network.ClientType.CLIENT_IMAGE_LOADER).a(req).execute();
var sink = Okio.a(Okio.b(tmpImage))) {
sink.a(resp.a().f());
var manager = (ClipboardManager) AndroidUtils.getGlobalContext().getSystemService(Context.CLIPBOARD_SERVICE);
@@ -175,4 +176,4 @@ public class PhotoViewer {
}
return max.url;
}
}
}
@@ -26,26 +26,15 @@ import static ru.vtosters.lite.utils.LifecycleUtils.restartApplication;
public class ProxyHook {
public static String linkReplacer(String link) {
var vkapi = "api.vk.com";
var oauth = "oauth.vk.com";
var vkstatic = "static.vk.com";
String vkapi = "api.vk.com";
String oauth = "oauth.vk.com";
String vkstatic = "static.vk.com";
var proxyapi = getString("proxyapi");
var proxyoauth = getString("proxyoauth");
var proxystatic = getString("proxystatic");
String proxyapi = getProxyHost("proxyapi");
String proxyoauth = getProxyHost("proxyoauth");
String proxystatic = getProxyHost("proxystatic");
if (isVikaProxyEnabled()) {
proxyapi = VikaMobile.getApiHost();
proxyoauth = VikaMobile.getOauthHost();
proxystatic = VikaMobile.getStaticHost();
}
if (!isAnyProxyEnabled() || link.isEmpty()) {
return link;
}
if (proxyapi.isEmpty() || proxyoauth.isEmpty() || proxystatic.isEmpty()) {
Log.d("VTLite", "Proxy is not set" + " " + proxyapi + " " + proxyoauth + " " + proxystatic);
if (!isAnyProxyEnabled() || link.isEmpty() || areProxyHostsEmpty(proxyapi, proxyoauth, proxystatic)) {
return link;
}
@@ -64,6 +53,29 @@ public class ProxyHook {
return link;
}
private static String getProxyHost(String hostType) {
if (isVikaProxyEnabled()) {
return switch (hostType) {
case "proxyapi" -> VikaMobile.getApiHost();
case "proxyoauth" -> VikaMobile.getOauthHost();
case "proxystatic" -> VikaMobile.getStaticHost();
default -> "";
};
} else {
return "";
}
}
private static boolean areProxyHostsEmpty(String... hosts) {
for (String host : hosts) {
if (host.isEmpty()) {
Log.d("VTLite", "Proxy is not set: " + host);
return true;
}
}
return false;
}
public static String staticFix(String str) {
var string = getString("proxystatic");
@@ -108,22 +120,18 @@ public class ProxyHook {
RadioButton rgDefault = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
RadioButton rgZaborona = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
// RadioButton rgRandomProxy = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
RadioButton rgVika = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
SwitchHook.setCompoundButton(rgDefault);
SwitchHook.setCompoundButton(rgZaborona);
// SwitchHook.setCompoundButton(rgRandomProxy);
SwitchHook.setCompoundButton(rgVika);
rg.addView(rgDefault);
rg.addView(rgVika);
rg.addView(rgZaborona);
// rg.addView(rgRandomProxy);
rgDefault.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
rgZaborona.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
// rgRandomProxy.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
rgVika.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
rg.setPadding(dp2px(18f), dp2px(12f), dp2px(18f), 0);
@@ -134,28 +142,21 @@ public class ProxyHook {
rgZaborona.setText(ctx.getString(R.string.proxy_enable) + " (Zaborona)");
rgZaborona.setTextColor(getTextAttr());
// rgRandomProxy.setText(ctx.getString(R.string.proxy_enable) + " (Random Socks Proxy)");
// rgRandomProxy.setTextColor(getTextAttr());
rgVika.setText(ctx.getString(R.string.proxy_enable) + " (Vika Mobile)");
rgVika.setTextColor(getTextAttr());
rgZaborona.setChecked(isZaboronaEnabled());
rgDefault.setChecked(!isZaboronaEnabled() && !isRandomProxyEnabled() && !isVikaProxyEnabled());
// rgRandomProxy.setChecked(isRandomProxyEnabled());
rgDefault.setChecked(!isZaboronaEnabled() && !isVikaProxyEnabled());
rgVika.setChecked(isVikaProxyEnabled());
new VkAlertDialog.Builder(ctx)
.setTitle(ctx.getString(R.string.vtlproxy))
.setMessage(ctx.getString(R.string.proxy_warning))
.setMessage(ctx.getString(R.string.proxy_warning) + "\n\nТак же можно включить встроенный прокси от ВКонтакте перейдя в настройки прокси")
.setView(rg)
.setPositiveButton(ctx.getString(R.string.vtl_confirm), ((dialog, which) -> { // Применить
if (rgZaborona.isChecked()) {
Preferences.getPreferences().edit().putString("proxy", "zaborona").commit();
restartApplication();
// } else if (rgRandomProxy.isChecked()) {
// Preferences.getPreferences().edit().putString("proxy", "randomproxy").commit();
// restartApplication();
} else if (rgVika.isChecked()) {
Preferences.getPreferences().edit().putString("proxy", "vika").commit();
restartApplication();
@@ -169,4 +170,4 @@ public class ProxyHook {
})
.show();
}
}
}
@@ -5,19 +5,18 @@ import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
import com.vk.core.network.Network;
import com.vk.core.util.DeviceIdProvider;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
import ru.vtosters.lite.music.cache.MusicCacheImpl;
import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException;
import static com.vk.core.network.Network.ClientType.CLIENT_API;
import static ru.vtosters.hooks.DateHook.getLocale;
import static ru.vtosters.hooks.GroupsCatalogInjector.injectIntoCatalog;
import static ru.vtosters.hooks.other.Preferences.getBoolValue;
@@ -26,8 +25,6 @@ import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserId;
public class CatalogJsonInjector {
private static final OkHttpClient mClient = VtOkHttpClient.getInstance();
public static JSONObject music(JSONObject json) throws JSONException {
var catalog = json.optJSONObject("catalog");
var oldItems = catalog != null ? catalog.optJSONArray("sections") : null;
@@ -265,7 +262,7 @@ public class CatalogJsonInjector {
+ AccountManagerUtils.getUserToken())
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8")).a();
try {
var json = new JSONObject(mClient.a(request).execute().a().g()).getJSONObject("response");
var json = new JSONObject(Network.b(CLIENT_API).a(request).execute().a().g()).getJSONObject("response");
var catalogarr = json.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0);
var title = catalogarr.optString("title");
@@ -10,4 +10,4 @@ public class VtOkHttpClient extends OkHttpClient {
private static class LazyHolder {
private static final VtOkHttpClient instance = new VtOkHttpClient();
}
}
}
@@ -6,7 +6,6 @@ import com.vk.im.engine.models.dialogs.Dialog;
import com.vk.im.engine.models.messages.Msg;
import com.vk.im.engine.utils.ImDialogsUtils;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import ru.vtosters.hooks.other.ThemesUtils;
import ru.vtosters.lite.concurrent.VTExecutors;
import ru.vtosters.lite.net.Request;
@@ -15,21 +14,49 @@ import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.LifecycleUtils;
import java.io.IOException;
import static com.vk.core.network.Network.ClientType.CLIENT_API;
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
public class Requests {
public static void hookRead(Dialog dialog) {
Request.makeRequest("https://" + ProxyUtils.getApi() + "/method/messages.markAsRead?start_message_id=" + dialog.F1() + "&peer_id=" + dialog.getId() + "&v=5.119&access_token=" + AccountManagerUtils.getUserToken(), response -> {
});
okhttp3.Request req = new okhttp3.Request.a()
.b("https://" + ProxyUtils.getApi() + "/method/messages.markAsRead?start_message_id=" + dialog.F1() + "&peer_id=" + dialog.getId() + "&v=5.119&access_token=" + AccountManagerUtils.getUserToken())
.a();
try {
Network.b(CLIENT_API).a(req).execute().close();;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void hookReadStartMsgTo(Msg dialog) {
Request.makeRequest("https://" + ProxyUtils.getApi() + "/method/messages.markAsRead?start_message_id=" + dialog.C1() + "&peer_id=" + dialog.v1() + "&v=5.119&access_token=" + AccountManagerUtils.getUserToken(), response -> {
});
okhttp3.Request req = new okhttp3.Request.a()
.b("https://" + ProxyUtils.getApi() + "/method/messages.markAsRead?start_message_id=" + dialog.C1() + "&peer_id=" + dialog.v1() + "&v=5.119&access_token=" + AccountManagerUtils.getUserToken())
.a();
try {
Network.b(CLIENT_API).a(req).execute().close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void hookKick(Msg dialog) {
if (dialog.getFrom().t1() == AccountManagerUtils.getUserId()) return;
Request.makeRequest("https://" + ProxyUtils.getApi() + "/method/messages.removeChatUser?member_id=" + dialog.getFrom().t1() + "&chat_id=" + ImDialogsUtils.c(dialog.v1()) + "&v=5.119&access_token=" + AccountManagerUtils.getUserToken(), response -> {
});
okhttp3.Request req = new okhttp3.Request.a()
.b("https://" + ProxyUtils.getApi() + "/method/messages.removeChatUser?member_id=" + dialog.getFrom().t1() + "&chat_id=" + ImDialogsUtils.c(dialog.v1()) + "&v=5.119&access_token=" + AccountManagerUtils.getUserToken())
.a();
try {
Network.b(CLIENT_API).a(req).execute().close();;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void hookDialogInfo(Dialog dialog) {
@@ -51,7 +78,7 @@ public class Requests {
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8"))
.a();
new OkHttpClient().a(request).execute().a().g();
Network.b(CLIENT_API).a(request).execute().a().g();
} catch (Exception e) {
e.printStackTrace();
}
@@ -1,29 +1,29 @@
package ru.vtosters.lite.downloaders;
import android.app.DownloadManager;
import android.content.Context;
import android.net.Uri;
import android.media.MediaScannerConnection;
import android.os.Environment;
import com.vk.core.network.Network;
import com.vk.dto.common.ImageSize;
import com.vk.dto.stories.model.StoryEntry;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import static ru.vtosters.lite.downloaders.VideoDownloader.downloadVideo;
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
public class StoryDownloader {
public static void downloadStory(StoryEntry story) {
if (story.T1()) {
List<ImageSize> imageSizes = story.E.Q.t1();
String url = imageSizes.get(imageSizes.size() - 1).url;
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setTitle("photo" + story.E.a + ".jpg");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, "photo" + story.E.a + ".jpg");
request.allowScanningByMediaScanner();
((DownloadManager) getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
downloadImage(story);
return;
}
// if story is a video
@@ -31,4 +31,55 @@ public class StoryDownloader {
downloadVideo(story.F, null);
}
}
}
public static void downloadImage(StoryEntry story) {
List<ImageSize> imageSizes = story.E.Q.t1();
String url = imageSizes.get(imageSizes.size() - 1).url;
OkHttpClient client = Network.b(Network.ClientType.CLIENT_IMAGE_LOADER);
Request request = new Request.a()
.b(url)
.a();
try (Response response = client.a(request).execute()) {
if (!response.h()) {
throw new IOException("Unexpected code " + response);
}
ResponseBody responseBody = response.a();
if (responseBody == null) {
throw new IOException("No response body");
}
String fileName = "photo" + story.E.a + ".jpg";
File outputDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "/Stories/");
if (!outputDir.exists()) {
outputDir.mkdirs();
}
File outputFile = new File(outputDir, fileName);
try (InputStream inputStream = responseBody.a();
FileOutputStream outputStream = new FileOutputStream(outputFile)) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.flush();
MediaScannerConnection.scanFile(AndroidUtils.getGlobalContext(), new String[]{outputFile.toString()}, null, null);
AndroidUtils.sendToast("Файл скачан в Pictures/Stories");
} catch (IOException e) {
e.fillInStackTrace();
}
} catch (IOException e) {
e.fillInStackTrace();
}
}
}
@@ -1,9 +1,8 @@
package ru.vtosters.lite.downloaders;
import android.app.DownloadManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.net.Uri;
import android.media.MediaScannerConnection;
import android.os.Environment;
import android.text.TextUtils;
import android.view.View;
@@ -13,35 +12,112 @@ import android.widget.TextView;
import android.widget.Toast;
import com.vk.core.dialogs.alert.VkAlertDialog;
import com.vk.core.dialogs.bottomsheet.MenuBottomSheetAction;
import com.vk.core.network.Network;
import com.vk.core.util.ToastUtils;
import com.vk.dto.common.VideoFile;
import com.vk.dto.stories.model.StoryEntry;
import com.vtosters.lite.R;
import okhttp3.*;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.LifecycleUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import static com.vk.core.network.Network.ClientType.CLIENT_API;
import static ru.vtosters.hooks.other.ThemesUtils.getTextAttr;
import static ru.vtosters.lite.net.Request.makeRequest;
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
public class VideoDownloader {
public static final int DOWNLOAD_ID = 0;
public static final int OPEN_EXTERNAL_LINK_ID = 1;
public static int DOWNLOAD_ID = 0;
public static int OPEN_EXTERNAL_LINK_ID = 1;
public static void addAction(List<MenuBottomSheetAction> actions, int... ints) {
actions.add(new MenuBottomSheetAction(ints[0], ints[1], ints[2], ints[3]));
}
public static void downloadVideo(VideoFile videoFile, Context context) {
final List<String> qualities = new ArrayList<>();
final List<String> urls = new ArrayList<>();
List<String> qualities = new ArrayList<>();
List<String> urls = new ArrayList<>();
addVideos(videoFile, qualities, urls);
Context finalContext = context != null ? context : LifecycleUtils.getCurrentActivity();
if (qualities.isEmpty()) {
ToastUtils.a(finalContext.getString(R.string.videodownloaderr));
return;
}
var adapter = new ArrayAdapter(
finalContext,
android.R.layout.simple_list_item_1,
qualities.toArray(new String[0])) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getView(position, convertView, parent);
textView.setTextColor(getTextAttr());
return textView;
}
};
new VkAlertDialog.Builder(finalContext)
.setAdapter(adapter, (dialog, which) -> {
String url = urls.get(which);
OkHttpClient client = Network.b(Network.ClientType.CLIENT_IMAGE_LOADER);;
Request request = new Request.a()
.b(url)
.a();
try (Response response = client.a(request).execute()) {
if (!response.h()) {
throw new IOException("Unexpected code " + response);
}
ResponseBody responseBody = response.a();
File outputDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), "/VKVideo/");
if (!outputDir.exists()) {
outputDir.mkdirs();
}
File outputFile = new File(outputDir, videoFile + ".mp4");
try (InputStream inputStream = responseBody.a();
FileOutputStream outputStream = new FileOutputStream(outputFile)) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.flush();
MediaScannerConnection.scanFile(finalContext, new String[]{outputFile.toString()}, null, null);
AndroidUtils.sendToast("Файл скачан в Movies/VKVideo");
} catch (IOException e) {
e.fillInStackTrace();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
})
.show();
}
public static void addVideos(VideoFile videoFile, List<String> qualities, List<String> urls) {
if (!TextUtils.isEmpty(videoFile.D)) {
qualities.add("2160p");
urls.add(videoFile.D);
@@ -75,40 +151,6 @@ public class VideoDownloader {
qualities.add("240p");
urls.add(videoFile.e);
}
Context finalContext = context != null ? context : LifecycleUtils.getCurrentActivity();
if (qualities.isEmpty()) {
ToastUtils.a(finalContext.getString(R.string.videodownloaderr));
return;
}
var adapter = new ArrayAdapter(
finalContext,
android.R.layout.simple_list_item_1,
qualities.toArray(new String[0])) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getView(position, convertView, parent);
textView.setTextColor(getTextAttr());
return textView;
}
};
new VkAlertDialog.Builder(finalContext)
.setAdapter(adapter, (dialog, which) -> {
try {
var url = urls.get(which);
var request = new DownloadManager.Request(Uri.parse(url))
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setTitle(videoFile.toString())
.setDestinationInExternalPublicDir(Environment.DIRECTORY_MOVIES, videoFile + ".mp4");
request.allowScanningByMediaScanner();
((DownloadManager) finalContext.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
} catch (Throwable ignored) {
}
})
.show();
}
public static void parseVideoLink(String url, Context ctx) {
@@ -124,20 +166,34 @@ public class VideoDownloader {
progressDialog.setMessage(ctx.getString(R.string.video_dl_progress));
progressDialog.show();
makeRequest("https://" + getApi() + "/method/stories.getById?stories=" + storyId + "&v=5.99&access_token=" + getUserToken(),
response -> {
progressDialog.cancel();
var req = new Request.a()
.b("https://" + getApi() + "/method/stories.getById?stories=" + storyId + "&v=5.99&access_token=" + getUserToken())
.a();
Network.b(CLIENT_API).a(req).a(new Callback() {
try {
JSONObject mainJson = new JSONObject(response);
JSONObject responseJson = mainJson.getJSONObject("response").optJSONArray("items").optJSONObject(0);
StoryEntry story = new StoryEntry(responseJson);
StoryDownloader.downloadStory(story);
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(ctx, ctx.getString(R.string.video_dl_error), Toast.LENGTH_SHORT).show();
}
});
@Override
public void a(Call call, IOException e) {
e.fillInStackTrace();
Toast.makeText(ctx, ctx.getString(R.string.video_dl_error), Toast.LENGTH_SHORT).show();
}
@Override
public void a(Call call, Response response) throws IOException {
progressDialog.cancel();
try {
JSONObject mainJson = new JSONObject(response.a().g());
JSONObject responseJson = mainJson.getJSONObject("response").optJSONArray("items").optJSONObject(0);
StoryEntry story = new StoryEntry(responseJson);
StoryDownloader.downloadStory(story);
} catch (JSONException e) {
e.fillInStackTrace();
Toast.makeText(ctx, ctx.getString(R.string.video_dl_error), Toast.LENGTH_SHORT).show();
}
}
});
return;
}
@@ -149,25 +205,37 @@ public class VideoDownloader {
String videoId = url.split("video")[1];
String ownerId = videoId.split("_")[0];
final ProgressDialog progressDialog = new ProgressDialog(ctx);
ProgressDialog progressDialog = new ProgressDialog(ctx);
progressDialog.setMessage(ctx.getString(R.string.video_dl_progress));
progressDialog.show();
makeRequest("https://" + getApi() + "/method/video.get?owner_id=" + ownerId + "&videos=" + videoId + "&v=5.99&access_token=" + getUserToken(),
response -> {
progressDialog.cancel();
var req = new Request.a()
.b("https://" + getApi() + "/method/video.get?owner_id=" + ownerId + "&videos=" + videoId + "&v=5.99&access_token=" + getUserToken())
.a();
try {
JSONObject mainJson = new JSONObject(response);
JSONObject responseJson = mainJson.getJSONObject("response");
JSONArray itemsJson = responseJson.getJSONArray("items");
Network.b(CLIENT_API).a(req).a(new Callback() {
@Override
public void a(Call call, IOException e) {
e.fillInStackTrace();
Toast.makeText(ctx, ctx.getString(R.string.video_dl_error), Toast.LENGTH_SHORT).show();
}
VideoFile videoFile = new VideoFile(itemsJson.getJSONObject(0));
downloadVideo(videoFile, ctx);
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(ctx, ctx.getString(R.string.video_dl_error), Toast.LENGTH_SHORT).show();
}
});
@Override
public void a(Call call, Response response) throws IOException {
progressDialog.cancel();
try {
JSONObject mainJson = new JSONObject(response.a().g());
JSONObject responseJson = mainJson.getJSONObject("response");
JSONArray itemsJson = responseJson.getJSONArray("items");
VideoFile videoFile = new VideoFile(itemsJson.getJSONObject(0));
downloadVideo(videoFile, ctx);
} catch (JSONException e) {
e.fillInStackTrace();
Toast.makeText(ctx, ctx.getString(R.string.video_dl_error), Toast.LENGTH_SHORT).show();
}
}
});
}
}
@@ -3,6 +3,7 @@ package ru.vtosters.lite.downloaders.messages;
import android.util.Log;
import android.util.SparseArray;
import androidx.annotation.Nullable;
import com.vk.core.network.Network;
import com.vk.core.util.ToastUtils;
import com.vtosters.lite.R;
import okhttp3.Call;
@@ -12,7 +13,6 @@ import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
import ru.vtosters.lite.downloaders.messages.items.MiniMsg;
import ru.vtosters.lite.downloaders.messages.items.MiniUser;
import ru.vtosters.lite.proxy.ProxyUtils;
@@ -28,6 +28,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static com.vk.core.network.Network.ClientType.CLIENT_API;
public class MessagesDownloader {
private static final int[] VIDEO_QUALITIES = {144, 240, 360, 480, 720, 1080, 1440, 2160};
@@ -105,7 +107,7 @@ public class MessagesDownloader {
var req = new Request.a()
.b(url)
.a();
VtOkHttpClient.getInstance().a(req).a(new Callback() {
Network.b(CLIENT_API).a(req).a(new Callback() {
@Override
public void a(Call call, IOException e) {
Log.d("MessagesDownloader", e.getMessage());
@@ -11,6 +11,8 @@ import okhttp3.Response;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
import ru.vtosters.lite.proxy.ProxyUtils;
import ru.vtosters.lite.proxy.api.VikaMobile;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.LifecycleUtils;
@@ -24,9 +26,6 @@ import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
import static ru.vtosters.lite.proxy.ProxyUtils.isAnyProxyEnabled;
public class FoafBase {
private static final Pattern FOAF_REGEX = Pattern.compile("<ya:created dc:date=\"(.+?)\"");
private static final String DELETED = "<ya:profileState>deleted</ya:profileState>";
@@ -67,7 +66,7 @@ public class FoafBase {
}
private static String getLink(int i) {
String prefix = isAnyProxyEnabled() ? "https://" + getApi() + "/_/vk.com/foaf.php?id=" : "https://vk.com/foaf.php?id=";
String prefix = (ProxyUtils.isAnyProxyEnabled() || ProxyUtils.isVKProxyEnabled()) ? "https://" + (ProxyUtils.isVKProxyEnabled() ? VikaMobile.getApiHost() : ProxyUtils.getApi()) + "/_/vk.com/foaf.php?id=" : "https://vk.com/foaf.php?id=";
return prefix + i;
}
@@ -14,7 +14,6 @@ import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
import ru.vtosters.lite.downloaders.AudioDownloader;
import ru.vtosters.lite.music.cache.MusicCacheImpl;
import ru.vtosters.lite.ui.fragments.MusicFragment;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException;
@@ -6,7 +6,6 @@ import com.vk.dto.music.MusicTrack;
import com.vk.dto.music.Playlist;
import java8.util.concurrent.CompletableFuture;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.json.JSONException;
import org.json.JSONObject;
@@ -19,6 +18,7 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import static com.vk.core.network.Network.ClientType.CLIENT_API;
import static ru.vtosters.hooks.DateHook.getLocale;
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
@@ -55,7 +55,7 @@ public class PlaylistConverter {
try {
var response = CompletableFuture.supplyAsync(() -> {
try {
return new OkHttpClient().a(request).execute().a().g();
return Network.b(CLIENT_API).a(request).execute().a().g();
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -6,7 +6,6 @@ import com.vk.core.util.DeviceIdProvider;
import com.vk.dto.music.MusicTrack;
import java8.util.concurrent.CompletableFuture;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.json.JSONException;
import org.json.JSONObject;
@@ -18,6 +17,7 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import static com.vk.core.network.Network.ClientType.CLIENT_API;
import static ru.vtosters.hooks.DateHook.getLocale;
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserId;
@@ -49,7 +49,7 @@ public class AudioGet {
try {
var response = CompletableFuture.supplyAsync(() -> {
try {
return new OkHttpClient().a(request).execute().a().g();
return Network.b(CLIENT_API).a(request).execute().a().g();
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -1,38 +0,0 @@
package ru.vtosters.lite.proxy;
import android.util.Log;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
public class GithubList {
private static final OkHttpClient mClient = VtOkHttpClient.getInstance();
public static ArrayList<String> getProxy(String url, String proxyname) throws IOException {
Request link = new Request.a()
.b(url)
.a();
try {
var response = mClient.a(link).execute().a().g();
if (!response.contains(":")) {
Log.d(proxyname, "No proxy found");
return null;
}
Log.d(proxyname, response);
return new ArrayList<>(Arrays.asList(response.split("\n")));
} catch (Exception e) {
Log.d(proxyname, "Failed to fetch data, link: " + link);
return null;
}
}
}
@@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.util.ArrayMap;
import android.util.Log;
import com.vk.core.network.Network;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.http.CustomHttp;
import ru.vtosters.lite.proxy.https.CustomHttps;
@@ -62,16 +63,15 @@ public class ProxyUtils {
}
public static Boolean isAnyProxyEnabled() {
return isApiProxyEnabled() || isVikaProxyEnabled();
return (isApiProxyEnabled() || isVikaProxyEnabled()) && !isVKProxyEnabled();
}
public static Boolean isZaboronaEnabled() {
return Preferences.getString("proxy").equals("zaborona");
}
public static Boolean isRandomProxyEnabled() {
// return Preferences.getString("proxy").equals("randomproxy");
return false;
public static Boolean isVKProxyEnabled() {
return Network.l.b().d();
}
public static Boolean isApiProxyEnabled() {
@@ -125,15 +125,10 @@ public class ProxyUtils {
}
}
public static boolean hasProxy(String list) {
return list.contains(":"); // proxy format: ip:port
}
public static void setProxy() {
if (!isAnyProxyEnabled()) return;
if (!isAnyProxyEnabled() || Preferences.getString("proxy").equals("vika") || Preferences.getString("proxy").equals("apiproxy")) return;
switch (Preferences.getString("proxy")) {
case "zaborona" -> Zaborona.loadProxy();
// case "randomproxy" -> RandomProxy.loadProxy();
case "socks" -> CustomSocks.loadProxy();
case "http" -> CustomHttp.loadProxy();
case "https" -> CustomHttps.loadProxy();
@@ -154,4 +149,4 @@ public class ProxyUtils {
clearProperty("socksPortHost");
forceProxyApplying();
} // Reset all proxies
}
}
@@ -1,66 +0,0 @@
package ru.vtosters.lite.proxy;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.socks.Hookzof;
import ru.vtosters.lite.proxy.socks.Jetkai;
import ru.vtosters.lite.proxy.socks.Roosterkid;
import ru.vtosters.lite.proxy.socks.TheSpeedX;
import java.io.IOException;
import static ru.vtosters.lite.proxy.ProxyUtils.resetProxy;
public class RandomProxy {
public static String type = Preferences.getPreferences().getString("random_type", "none");
public static String host = Preferences.getPreferences().getString("random_host", "");
public static boolean showProxyResult = false;
public static void loadProxy() throws IOException {
if (host.isEmpty()) {
if (getProxy()) loadProxy();
return;
}
switch (type) {
case "socks" -> {
System.setProperty("socksProxyHost", host.split(":")[0]);
System.setProperty("socksProxyPort", host.split(":")[1]);
}
case "http" -> {
System.setProperty("http.proxyHost", host.split(":")[0]);
System.setProperty("http.proxyPort", host.split(":")[1]);
}
case "https" -> {
System.setProperty("https.proxyHost", host.split(":")[0]);
System.setProperty("https.proxyPort", host.split(":")[1]);
}
}
}
public static void setupNewProxy() throws IOException {
Preferences.getPreferences().edit().putString("random_type", "none").putString("random_host", "").commit();
resetProxy();
showProxyResult = true;
getProxy();
Preferences.getPreferences().edit().putString("proxy", "randomproxy").commit();
}
public static boolean getProxy() throws IOException {
var random = new java.util.Random();
var randomInt = random.nextInt(8);
switch (randomInt) {
case 0 -> Hookzof.loadProxy();
case 1 -> TheSpeedX.loadProxy();
case 2 -> Jetkai.loadProxy();
case 3 -> Roosterkid.loadProxy();
case 4 -> ru.vtosters.lite.proxy.http.Jetkai.loadProxy();
case 5 -> ru.vtosters.lite.proxy.http.TheSpeedX.loadProxy();
case 6 -> ru.vtosters.lite.proxy.https.Jetkai.loadProxy();
case 7 -> ru.vtosters.lite.proxy.https.Roosterkid.loadProxy();
}
return true;
}
}
@@ -1,48 +0,0 @@
package ru.vtosters.lite.proxy.http;
import android.util.Log;
import com.vtosters.lite.R;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.RandomProxy;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException;
import java.util.ArrayList;
import static ru.vtosters.lite.proxy.GithubList.getProxy;
import static ru.vtosters.lite.proxy.ProxyUtils.forceProxyApplying;
import static ru.vtosters.lite.proxy.ProxyUtils.hasProxy;
public class Jetkai {
private static final String TAG = "Jetkai_Http";
public static void loadProxy() throws IOException {
ArrayList<String> proxyList = getProxy("https://raw.githubusercontent.com/jetkai/proxy-list/main/online-proxies/txt/proxies-http.txt", TAG);
if (proxyList == null) {
Log.d(TAG, "No proxy found");
return;
}
String proxy = proxyList.get(new java.util.Random().nextInt(proxyList.size()));
if (!hasProxy(proxy)) {
Log.d(TAG, "No proxy port found");
return;
}
Log.d(TAG, "Setting proxy: " + proxy.split(":")[0] + ":" + proxy.split(":")[1]);
if (RandomProxy.showProxyResult) {
AndroidUtils.sendToast(AndroidUtils.getString(R.string.proxy_setup_success) + " " + proxy);
RandomProxy.showProxyResult = false;
RandomProxy.showProxyResult = false;
}
Preferences.getPreferences().edit().putString("random_type", "http").putString("random_host", proxy).commit();
System.setProperty("http.proxyHost", proxy.split(":")[0]);
System.setProperty("http.proxyPort", proxy.split(":")[1]);
forceProxyApplying();
}
}
@@ -1,47 +0,0 @@
package ru.vtosters.lite.proxy.http;
import android.util.Log;
import com.vtosters.lite.R;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.RandomProxy;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException;
import java.util.ArrayList;
import static ru.vtosters.lite.proxy.GithubList.getProxy;
import static ru.vtosters.lite.proxy.ProxyUtils.forceProxyApplying;
import static ru.vtosters.lite.proxy.ProxyUtils.hasProxy;
public class TheSpeedX {
private static final String TAG = "TheSpeedX_Http";
public static void loadProxy() throws IOException {
ArrayList<String> proxyList = getProxy("https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/http.txt", TAG);
if (proxyList == null) {
Log.d(TAG, "No proxy found");
return;
}
String proxy = proxyList.get(new java.util.Random().nextInt(proxyList.size()));
if (!hasProxy(proxy)) {
Log.d(TAG, "No proxy port found");
return;
}
Log.d(TAG, "Setting proxy: " + proxy.split(":")[0] + ":" + proxy.split(":")[1]);
if (RandomProxy.showProxyResult) {
AndroidUtils.sendToast(AndroidUtils.getString(R.string.proxy_setup_success) + " " + proxy);
RandomProxy.showProxyResult = false;
}
Preferences.getPreferences().edit().putString("random_type", "http").putString("random_host", proxy).commit();
System.setProperty("http.proxyHost", proxy.split(":")[0]);
System.setProperty("http.proxyPort", proxy.split(":")[1]);
forceProxyApplying();
}
}
@@ -1,47 +0,0 @@
package ru.vtosters.lite.proxy.https;
import android.util.Log;
import com.vtosters.lite.R;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.RandomProxy;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException;
import java.util.ArrayList;
import static ru.vtosters.lite.proxy.GithubList.getProxy;
import static ru.vtosters.lite.proxy.ProxyUtils.forceProxyApplying;
import static ru.vtosters.lite.proxy.ProxyUtils.hasProxy;
public class Jetkai {
private static final String TAG = "Jetkai_Https";
public static void loadProxy() throws IOException {
ArrayList<String> proxyList = getProxy("https://raw.githubusercontent.com/jetkai/proxy-list/main/online-proxies/txt/proxies-https.txt", TAG);
if (proxyList == null) {
Log.d(TAG, "No proxy found");
return;
}
String proxy = proxyList.get(new java.util.Random().nextInt(proxyList.size()));
if (!hasProxy(proxy)) {
Log.d(TAG, "No proxy port found");
return;
}
Log.d(TAG, "Setting proxy: " + proxy.split(":")[0] + ":" + proxy.split(":")[1]);
if (RandomProxy.showProxyResult) {
AndroidUtils.sendToast(AndroidUtils.getString(R.string.proxy_setup_success) + " " + proxy);
RandomProxy.showProxyResult = false;
}
Preferences.getPreferences().edit().putString("random_type", "https").putString("random_host", proxy).commit();
System.setProperty("https.proxyHost", proxy.split(":")[0]);
System.setProperty("https.proxyPort", proxy.split(":")[1]);
forceProxyApplying();
}
}
@@ -1,48 +0,0 @@
package ru.vtosters.lite.proxy.https;
import android.util.Log;
import com.vtosters.lite.R;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.RandomProxy;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException;
import java.util.ArrayList;
import static ru.vtosters.lite.proxy.GithubList.getProxy;
import static ru.vtosters.lite.proxy.ProxyUtils.forceProxyApplying;
import static ru.vtosters.lite.proxy.ProxyUtils.hasProxy;
public class Roosterkid {
private static final String TAG = "Roosterkid_Https";
public static void loadProxy() throws IOException {
ArrayList<String> proxyList = getProxy("https://raw.githubusercontent.com/roosterkid/openproxylist/main/HTTPS_RAW.txt", TAG);
if (proxyList == null) {
Log.d(TAG, "No proxy found");
return;
}
String proxy = proxyList.get(new java.util.Random().nextInt(proxyList.size()));
if (!hasProxy(proxy)) {
Log.d(TAG, "No proxy port found");
return;
}
Log.d(TAG, "Setting proxy: " + proxy.split(":")[0] + ":" + proxy.split(":")[1]);
if (RandomProxy.showProxyResult) {
AndroidUtils.sendToast(AndroidUtils.getString(R.string.proxy_setup_success) + " " + proxy);
RandomProxy.showProxyResult = false;
}
Preferences.getPreferences().edit().putString("random_type", "https").putString("random_host", proxy).commit();
System.setProperty("https.proxyHost", proxy.split(":")[0]);
System.setProperty("https.proxyPort", proxy.split(":")[1]);
forceProxyApplying();
}
}
@@ -1,47 +0,0 @@
package ru.vtosters.lite.proxy.socks;
import android.util.Log;
import com.vtosters.lite.R;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.RandomProxy;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException;
import java.util.ArrayList;
import static ru.vtosters.lite.proxy.GithubList.getProxy;
import static ru.vtosters.lite.proxy.ProxyUtils.forceProxyApplying;
import static ru.vtosters.lite.proxy.ProxyUtils.hasProxy;
public class Hookzof {
private static final String TAG = "Hookzof_Socks";
public static void loadProxy() throws IOException {
ArrayList<String> proxyList = getProxy("https://raw.githubusercontent.com/hookzof/socks5_list/master/proxy.txt", TAG);
if (proxyList == null) {
Log.d(TAG, "No proxy found");
return;
}
String proxy = proxyList.get(new java.util.Random().nextInt(proxyList.size()));
if (!hasProxy(proxy)) {
Log.d(TAG, "No proxy port found");
return;
}
Log.d(TAG, "Setting proxy: " + proxy.split(":")[0] + ":" + proxy.split(":")[1]);
if (RandomProxy.showProxyResult) {
AndroidUtils.sendToast(AndroidUtils.getString(R.string.proxy_setup_success) + " " + proxy);
RandomProxy.showProxyResult = false;
}
Preferences.getPreferences().edit().putString("random_type", "socks").putString("random_host", proxy).commit();
System.setProperty("socksProxyHost", proxy.split(":")[0]);
System.setProperty("socksProxyPort", proxy.split(":")[1]);
forceProxyApplying();
}
}
@@ -1,47 +0,0 @@
package ru.vtosters.lite.proxy.socks;
import android.util.Log;
import com.vtosters.lite.R;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.RandomProxy;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException;
import java.util.ArrayList;
import static ru.vtosters.lite.proxy.GithubList.getProxy;
import static ru.vtosters.lite.proxy.ProxyUtils.forceProxyApplying;
import static ru.vtosters.lite.proxy.ProxyUtils.hasProxy;
public class Jetkai {
private static final String TAG = "Jetkai_Socks";
public static void loadProxy() throws IOException {
ArrayList<String> proxyList = getProxy("https://raw.githubusercontent.com/jetkai/proxy-list/main/online-proxies/txt/proxies-socks5.txt", TAG);
if (proxyList == null) {
Log.d(TAG, "No proxy found");
return;
}
String proxy = proxyList.get(new java.util.Random().nextInt(proxyList.size()));
if (!hasProxy(proxy)) {
Log.d(TAG, "No proxy port found");
return;
}
Log.d(TAG, "Setting proxy: " + proxy.split(":")[0] + ":" + proxy.split(":")[1]);
if (RandomProxy.showProxyResult) {
AndroidUtils.sendToast(AndroidUtils.getString(R.string.proxy_setup_success) + " " + proxy);
RandomProxy.showProxyResult = false;
}
Preferences.getPreferences().edit().putString("random_type", "socks").putString("random_host", proxy).commit();
System.setProperty("socksProxyHost", proxy.split(":")[0]);
System.setProperty("socksProxyPort", proxy.split(":")[1]);
forceProxyApplying();
}
}
@@ -1,47 +0,0 @@
package ru.vtosters.lite.proxy.socks;
import android.util.Log;
import com.vtosters.lite.R;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.RandomProxy;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException;
import java.util.ArrayList;
import static ru.vtosters.lite.proxy.GithubList.getProxy;
import static ru.vtosters.lite.proxy.ProxyUtils.forceProxyApplying;
import static ru.vtosters.lite.proxy.ProxyUtils.hasProxy;
public class Roosterkid {
private static final String TAG = "Roosterkid_Socks";
public static void loadProxy() throws IOException {
ArrayList<String> proxyList = getProxy("https://raw.githubusercontent.com/roosterkid/openproxylist/main/SOCKS5_RAW.txt", TAG);
if (proxyList == null) {
Log.d(TAG, "No proxy found");
return;
}
String proxy = proxyList.get(new java.util.Random().nextInt(proxyList.size()));
if (!hasProxy(proxy)) {
Log.d(TAG, "No proxy port found");
return;
}
Log.d(TAG, "Setting proxy: " + proxy.split(":")[0] + ":" + proxy.split(":")[1]);
if (RandomProxy.showProxyResult) {
AndroidUtils.sendToast(AndroidUtils.getString(R.string.proxy_setup_success) + " " + proxy);
RandomProxy.showProxyResult = false;
}
Preferences.getPreferences().edit().putString("random_type", "socks").putString("random_host", proxy).commit();
System.setProperty("socksProxyHost", proxy.split(":")[0]);
System.setProperty("socksProxyPort", proxy.split(":")[1]);
forceProxyApplying();
}
}
@@ -1,47 +0,0 @@
package ru.vtosters.lite.proxy.socks;
import android.util.Log;
import com.vtosters.lite.R;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.RandomProxy;
import ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException;
import java.util.ArrayList;
import static ru.vtosters.lite.proxy.GithubList.getProxy;
import static ru.vtosters.lite.proxy.ProxyUtils.forceProxyApplying;
import static ru.vtosters.lite.proxy.ProxyUtils.hasProxy;
public class TheSpeedX {
private static final String TAG = "TheSpeedX_Socks";
public static void loadProxy() throws IOException {
ArrayList<String> proxyList = getProxy("https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/socks5.txt", TAG);
if (proxyList == null) {
Log.d(TAG, "No proxy found");
return;
}
String proxy = proxyList.get(new java.util.Random().nextInt(proxyList.size()));
if (!hasProxy(proxy)) {
Log.d(TAG, "No proxy port found");
return;
}
Log.d(TAG, "Setting proxy: " + proxy.split(":")[0] + ":" + proxy.split(":")[1]);
if (RandomProxy.showProxyResult) {
AndroidUtils.sendToast(AndroidUtils.getString(R.string.proxy_setup_success) + " " + proxy);
RandomProxy.showProxyResult = false;
}
Preferences.getPreferences().edit().putString("random_type", "socks").putString("random_host", proxy).commit();
System.setProperty("socksProxyHost", proxy.split(":")[0]);
System.setProperty("socksProxyPort", proxy.split(":")[1]);
forceProxyApplying();
}
}
@@ -8,4 +8,4 @@ public class Zaborona {
System.setProperty("socksProxyPort", "1488");
forceProxyApplying();
}
}
}
@@ -15,7 +15,7 @@ public class Utils {
"&vt_dark=" + (ThemesUtils.isDarkTheme() ? "1" : "0") +
"&vt_amoled=" + (ThemesUtils.isAmoledTheme() && ThemesUtils.isDarkTheme() ? "1" : "0") +
"&secret=" + AccountManagerUtils.getUserSecret() +
"&proxy=" + (ProxyUtils.isAnyProxyEnabled() ? "1" : "0") +
"&proxy=" + ((ProxyUtils.isAnyProxyEnabled() || ProxyUtils.isVKProxyEnabled()) ? "1" : "0") +
"&lang=" + DateHook.getLocale() +
"&vt=1" +
"&useragent=" + Base64Utils.encodeValue(Base64Utils.encode(Network.l.c().a())) +
@@ -5,6 +5,7 @@ import com.vk.core.dialogs.alert.VkAlertDialog;
import com.vtosters.lite.R;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.proxy.ProxyUtils;
import ru.vtosters.lite.proxy.api.VikaMobile;
import ru.vtosters.lite.ui.fragments.VKUIwrapper;
import ru.vtosters.lite.utils.NavigatorUtils;
@@ -11,7 +11,6 @@ import com.vk.core.dialogs.alert.VkAlertDialog;
import com.vk.core.network.Network;
import com.vtosters.lite.R;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.json.JSONObject;
import ru.vtosters.hooks.other.Preferences;
@@ -26,6 +25,8 @@ import ru.vtosters.lite.utils.SearchEngine;
import java.util.Arrays;
import static com.vk.core.network.Network.ClientType.CLIENT_API;
public class MediaFragment extends TrackedMaterialPreferenceToolbarFragment {
public static void download(Context ctx) {
EditText input = new EditText(ctx);
@@ -106,7 +107,7 @@ public class MediaFragment extends TrackedMaterialPreferenceToolbarFragment {
.a();
try {
var response = new JSONObject(new OkHttpClient().a(request).execute().a().g());
var response = new JSONObject(Network.b(CLIENT_API).a(request).execute().a().g());
if (response.optInt("response") == 1) {
requireActivity().runOnUiThread(() -> AndroidUtils.sendToast(requireContext().getString(R.string.video_history_cleaned)));
@@ -1,21 +1,32 @@
package ru.vtosters.lite.ui.fragments;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import b.h.g.k.VKProgressDialog;
import com.vk.core.network.Network;
import com.vk.core.network.proxy.NetworkProxy;
import com.vk.core.util.ToastUtils;
import com.vtosters.lite.NetworkProxyPreferences;
import com.vtosters.lite.R;
import com.vtosters.lite.ViewUtils;
public class ProxySettingsFragment extends TrackedMaterialPreferenceToolbarFragment {
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.preferences_proxy);
// findPreference("random_proxy").setOnPreferenceClickListener(preference -> {
// try {
// setupNewProxy();
// } catch (IOException e) {
// sendToast(requireContext().getString(R.string.get_proxy_error));
// }
// return true;
// });
initComponents();
}
private void initComponents() {
NetworkProxy networkProxy = Network.l.b();
boolean isEnabled = networkProxy.d();
SwitchPreference switchPreference = (SwitchPreference) findPreference("vkproxy");
switchPreference.setChecked(isEnabled);
switchPreference.setOnPreferenceChangeListener(new ProxyChangeListener(networkProxy, switchPreference));
}
@Override
@@ -23,3 +34,89 @@ public class ProxySettingsFragment extends TrackedMaterialPreferenceToolbarFragm
return R.string.vtlproxy;
}
}
class ProxyChangeListener implements Preference.OnPreferenceChangeListener {
private final NetworkProxy networkProxy;
private final SwitchPreference switchPreference;
ProxyChangeListener(NetworkProxy networkProxy, SwitchPreference switchPreference) {
this.networkProxy = networkProxy;
this.switchPreference = switchPreference;
}
@Override
public boolean onPreferenceChange(Preference preference, Object obj) {
handleProxyChange(preference, (Boolean) obj);
return false;
}
private void handleProxyChange(Preference preference, Boolean isEnabled) {
if (!networkProxy.d() && isEnabled) {
enableProxy(preference);
} else {
disableProxy();
}
}
private void enableProxy(Preference preference) {
networkProxy.a(true);
VKProgressDialog vKProgressDialog = createProgressDialog(preference.getContext());
networkProxy.a((NetworkProxy.c) new ProxyPreferences(vKProgressDialog));
}
private void disableProxy() {
Network.l.b().a(false);
switchPreference.setChecked(networkProxy.d());
}
private VKProgressDialog createProgressDialog(Context context) {
VKProgressDialog vKProgressDialog = new VKProgressDialog(context);
vKProgressDialog.setMessage(context.getString(R.string.loading));
vKProgressDialog.setOnDismissListener(new OnDismissListener());
ViewUtils.b(vKProgressDialog);
return vKProgressDialog;
}
private class OnDismissListener implements DialogInterface.OnDismissListener {
@Override
public void onDismiss(DialogInterface dialogInterface) {
switchPreference.setChecked(networkProxy.d());
}
}
private class ProxyPreferences extends NetworkProxyPreferences {
private final VKProgressDialog progressDialog;
ProxyPreferences(VKProgressDialog vKProgressDialog) {
this.progressDialog = vKProgressDialog;
}
@Override
public void b(NetworkProxy.Reason reason) {
super.b(reason);
dismissProgressDialog();
switchPreference.setChecked(networkProxy.d());
showToast(reason);
}
@Override
public void e() {
super.e();
dismissProgressDialog();
switchPreference.setChecked(networkProxy.d());
}
private void dismissProgressDialog() {
ViewUtils.a(progressDialog);
}
private void showToast(NetworkProxy.Reason reason) {
if (reason == NetworkProxy.Reason.PROXY_NOT_AVAILABLE) {
ToastUtils.a(R.string.sett_proxy_not_available);
} else {
ToastUtils.a(R.string.sett_no_proxy);
}
}
}
}
@@ -42,6 +42,7 @@ import ru.vtosters.hooks.ui.SystemThemeChangerHook;
import ru.vtosters.lite.BuildConfig;
import ru.vtosters.lite.concurrent.VTExecutors;
import ru.vtosters.lite.deviceinfo.OEMDetector;
import ru.vtosters.lite.proxy.ProxyUtils;
import ru.vtosters.lite.ssfs.Utils;
import ru.vtosters.lite.themes.utils.RecolorUtils;
import ru.vtosters.lite.ui.PreferenceFragmentUtils;
@@ -77,9 +78,13 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
public static String getProxysumm() {
String type = Preferences.getString("proxy");
boolean isVKProxy = ProxyUtils.isVKProxyEnabled();
if (type.equals("noproxy") || type.isEmpty())
if (isVKProxy) {
type = "Встроенный";
} else if (type.equals("noproxy") || type.isEmpty()) {
type = AndroidUtils.getString(R.string.vtlsettdisabled);
}
return AndroidUtils.getString(R.string.vtlproxysumm) + ": " + type;
}
@@ -8,6 +8,7 @@ import android.os.Build;
import android.text.TextUtils;
import com.vk.core.dialogs.alert.VkAlertDialog;
import com.vk.dto.common.VideoFile;
import ru.vtosters.lite.downloaders.VideoDownloader;
import java.util.ArrayList;
import java.util.Arrays;
@@ -77,40 +78,7 @@ public class ExternalLinkParser {
* this.D = var66.optString("mp4_2160");
*/
public static boolean parseVKVideo(VideoFile videoFile, List<String> qualities, List<String> urls) {
if (!TextUtils.isEmpty(videoFile.D)) {
qualities.add("2160p");
urls.add(videoFile.D);
}
if (!TextUtils.isEmpty(videoFile.C)) {
qualities.add("1440p");
urls.add(videoFile.C);
}
if (!TextUtils.isEmpty(videoFile.B)) {
qualities.add("1080p");
urls.add(videoFile.B);
}
if (!TextUtils.isEmpty(videoFile.h)) {
qualities.add("720p");
urls.add(videoFile.h);
}
if (!TextUtils.isEmpty(videoFile.g)) {
qualities.add("480p");
urls.add(videoFile.g);
}
if (!TextUtils.isEmpty(videoFile.f)) {
qualities.add("360p");
urls.add(videoFile.f);
}
if (!TextUtils.isEmpty(videoFile.e)) {
qualities.add("240p");
urls.add(videoFile.e);
}
VideoDownloader.addVideos(videoFile, qualities, urls);
return qualities.size() > 0;
}
@@ -6,33 +6,48 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import com.vk.core.network.Network;
import okhttp3.Request;
import okhttp3.Response;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.hooks.other.ThemesUtils;
import java.net.URL;
import java.io.IOException;
public class ImageUtils {
// must be called asynchronously
public static Drawable getDrawableFromUrl(String url, int placeholderRes, boolean rounded, boolean scaled) {
if (NetworkUtils.isNetworkConnected() && !NetworkUtils.isInternetSlow()) {
try {
var bmp = BitmapFactory.decodeStream(new URL(url).openStream());
Bitmap bmp = downloadBitmap(url);
if (bmp != null) {
if (rounded) bmp = getBitmapClippedCircle(bmp);
if (scaled)
bmp = Bitmap.createScaledBitmap(bmp, AndroidUtils.dp2px(256), AndroidUtils.dp2px(256), true);
return new BitmapDrawable(AndroidUtils.getResources(), bmp);
if (bmp != null) {
if (rounded) {
bmp = getBitmapClippedCircle(bmp);
}
} catch (Exception e) {
e.printStackTrace();
if (scaled) {
bmp = Bitmap.createScaledBitmap(bmp, AndroidUtils.dp2px(256), AndroidUtils.dp2px(256), true);
}
return new BitmapDrawable(AndroidUtils.getResources(), bmp);
}
}
return placeholderRes > 0 ? ContextCompat.getDrawable(AndroidUtils.getGlobalContext(), placeholderRes) : null;
}
public static Bitmap downloadBitmap(String url) {
Request request = new Request.a()
.b(url)
.a();
try (Response resp = Network.b(Network.ClientType.CLIENT_IMAGE_LOADER).a(request).execute()) {
return BitmapFactory.decodeStream(resp.a().a());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();