mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-06-12 13:17:38 +02:00
chore: Separate extensions by app (#3905)
This commit is contained in:
5
extensions/syncforreddit/build.gradle.kts
Normal file
5
extensions/syncforreddit/build.gradle.kts
Normal file
@ -0,0 +1,5 @@
|
||||
dependencies {
|
||||
compileOnly(project(":extensions:shared:library"))
|
||||
compileOnly(project(":extensions:syncforreddit:stub"))
|
||||
compileOnly(libs.annotation)
|
||||
}
|
1
extensions/syncforreddit/src/main/AndroidManifest.xml
Normal file
1
extensions/syncforreddit/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1 @@
|
||||
<manifest/>
|
@ -0,0 +1,77 @@
|
||||
package app.revanced.extension.syncforreddit;
|
||||
|
||||
import android.util.Pair;
|
||||
import androidx.annotation.Nullable;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @noinspection unused
|
||||
*/
|
||||
public class FixRedditVideoDownloadPatch {
|
||||
private static @Nullable Pair<Integer, String> getBestMpEntry(Element element) {
|
||||
var representations = element.getElementsByTagName("Representation");
|
||||
var entries = new ArrayList<Pair<Integer, String>>();
|
||||
|
||||
for (int i = 0; i < representations.getLength(); i++) {
|
||||
Element representation = (Element) representations.item(i);
|
||||
var bandwidthStr = representation.getAttribute("bandwidth");
|
||||
try {
|
||||
var bandwidth = Integer.parseInt(bandwidthStr);
|
||||
var baseUrl = representation.getElementsByTagName("BaseURL").item(0);
|
||||
if (baseUrl != null) {
|
||||
entries.add(new Pair<>(bandwidth, baseUrl.getTextContent()));
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (entries.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Collections.sort(entries, (e1, e2) -> e2.first - e1.first);
|
||||
return entries.get(0);
|
||||
}
|
||||
|
||||
private static String[] parse(byte[] data) throws ParserConfigurationException, IOException, SAXException {
|
||||
var adaptionSets = DocumentBuilderFactory
|
||||
.newInstance()
|
||||
.newDocumentBuilder()
|
||||
.parse(new ByteArrayInputStream(data))
|
||||
.getElementsByTagName("AdaptationSet");
|
||||
|
||||
String videoUrl = null;
|
||||
String audioUrl = null;
|
||||
|
||||
for (int i = 0; i < adaptionSets.getLength(); i++) {
|
||||
Element element = (Element) adaptionSets.item(i);
|
||||
var contentType = element.getAttribute("contentType");
|
||||
var bestEntry = getBestMpEntry(element);
|
||||
if (bestEntry == null) continue;
|
||||
|
||||
if (contentType.equalsIgnoreCase("video")) {
|
||||
videoUrl = bestEntry.second;
|
||||
} else if (contentType.equalsIgnoreCase("audio")) {
|
||||
audioUrl = bestEntry.second;
|
||||
}
|
||||
}
|
||||
|
||||
return new String[]{videoUrl, audioUrl};
|
||||
}
|
||||
|
||||
public static String[] getLinks(byte[] data) {
|
||||
try {
|
||||
return parse(data);
|
||||
} catch (ParserConfigurationException | IOException | SAXException e) {
|
||||
return new String[]{null, null};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package app.revanced.extension.syncforreddit;
|
||||
|
||||
import com.laurencedawson.reddit_sync.ui.activities.WebViewActivity;
|
||||
|
||||
import app.revanced.extension.shared.fixes.slink.BaseFixSLinksPatch;
|
||||
|
||||
/** @noinspection unused*/
|
||||
public class FixSLinksPatch extends BaseFixSLinksPatch {
|
||||
static {
|
||||
INSTANCE = new FixSLinksPatch();
|
||||
}
|
||||
|
||||
private FixSLinksPatch() {
|
||||
webViewActivityClass = WebViewActivity.class;
|
||||
}
|
||||
|
||||
public static boolean patchResolveSLink(String link) {
|
||||
return INSTANCE.resolveSLink(link);
|
||||
}
|
||||
|
||||
public static void patchSetAccessToken(String accessToken) {
|
||||
INSTANCE.setAccessToken(accessToken);
|
||||
}
|
||||
}
|
17
extensions/syncforreddit/stub/build.gradle.kts
Normal file
17
extensions/syncforreddit/stub/build.gradle.kts
Normal file
@ -0,0 +1,17 @@
|
||||
plugins {
|
||||
id(libs.plugins.android.library.get().pluginId)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "app.revanced.extension"
|
||||
compileSdk = 33
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 24
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
<manifest/>
|
@ -0,0 +1,6 @@
|
||||
package com.laurencedawson.reddit_sync.ui.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
public class WebViewActivity extends Activity {
|
||||
}
|
Reference in New Issue
Block a user