This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
38 changed files
with
2,186 additions
and
2,034 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/src/main/java/app/revanced/integrations/syncforreddit/FixRedditVideoDownloadPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package app.revanced.integrations.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}; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...in/java/app/revanced/integrations/twitter/patches/links/ChangeLinkSharingDomainPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package app.revanced.integrations.twitter.patches.links; | ||
|
||
public final class ChangeLinkSharingDomainPatch { | ||
private static final String DOMAIN_NAME = "https://fxtwitter.com"; | ||
private static final String LINK_FORMAT = "%s/%s/status/%s"; | ||
|
||
public static String formatResourceLink(Object... formatArgs) { | ||
String username = (String) formatArgs[0]; | ||
String tweetId = (String) formatArgs[1]; | ||
return String.format(LINK_FORMAT, DOMAIN_NAME, username, tweetId); | ||
} | ||
|
||
public static String formatLink(long tweetId, String username) { | ||
return String.format(LINK_FORMAT, DOMAIN_NAME, username, tweetId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.