Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ object Authors {
val Derlan = Author("Derlan", 821545900807028757L)
val Link = Author("Link", 725923756555501658L)
val ArjixWasTaken = Author("ArjixWasTaken", 674710789138939916L)
val PikachuGabe = Author("pikachugabe", 701095070870274139L)
}

/**
Expand Down
34 changes: 34 additions & 0 deletions plugins/TwitterDownloadFix/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import com.aliucord.gradle.repo.Authors
import com.aliucord.gradle.repo.author

plugins {
id("com.aliucord.plugins-repo")
}

version = "1.3.1"
description = "Make Twitter embed images download as `jpg` instead of `jpg:large`."

aliucord {
author(Authors.PikachuGabe)

changelog.set("""
# 1.3.1
Bluesky actually stores the files as @jpeg instead of .jpeg so changing the URL doesn't work, so I can't fix that right now.
Will have to figure out how to change the file type after downloading instead of just changing the download URL.

# 1.3.0
Added bluesky support because I noticed it uses `@` instead of `.` when denoting file type. Not updating plugin name as that would break the updater.

# 1.2.0
Fixed the plugin. Again.
Now downloads directly from twitter instead of through discord's external image stuff.

# 1.1.0
Fixed the plugin.
Switched to regex for file renaming.
Renamed plugin at Rushii's request.

# 1.0.0
Plugin release
""")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.aluicord.plugins;

import android.content.Context;
import android.net.Uri;

import com.aliucord.annotations.AliucordPlugin;
import com.aliucord.entities.Plugin;
import com.aliucord.patcher.PreHook;
import com.discord.utilities.io.NetworkUtils;

import java.util.List;

import kotlin.jvm.functions.Function1;

@AliucordPlugin
public class TwitterDownloadFix extends Plugin {

@Override
public void start(Context context) throws Throwable {

patcher.patch(
NetworkUtils.class.getDeclaredMethod("downloadFile", Context.class, Uri.class, String.class, String.class, Function1.class, Function1.class),
new PreHook(param -> {
Uri uri = (Uri) param.args[1];

String Url = "tmp"; // I have to set up this variable before the if statements so the compiler can see them when it compiles the try/catch statement.

String uriStr = uri.toString();
// logger.verbose(uriStr);

if (uri.getPath().contains(".twimg.com")) {
Url = "twt";
// } else if (uri.getPath().contains("cdn.bsky.app")) {
// Url = "bsky";
} else {
return;
}

try {
if (Url == "twt") {
uriStr = uriStr.replaceAll("(?i)((\\.jpg:large)|(\\.jpg%3Alarge)|(\\.jpg_large)|(\\.jpg%5Flarge))$", ".jpg");
uriStr = uriStr.replaceAll(".*https\\/", "https://");
uri = Uri.parse(uriStr);
// } else if (Url == "bsky") {
// uriStr = uriStr.replaceAll("(?i)((@)|(%40))", ".");
// logger.verbose(uriStr);
// uriStr = uriStr.replaceAll(".*https\\/", "https://");
// logger.verbose(uriStr);
// uri = Uri.parse(uriStr);
// Bluesky actually stores the files as @jpeg instead of .jpeg so changing the URL doesn't work, will have to figure out how to change the file type after downloading.
}
} catch (Exception e) {
logger.error(e);
}

param.args[1] = uri;
})
);

}

@Override
public void stop(Context context) {
patcher.unpatchAll();
}


}