diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index b589d56e9..b86273d94 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index d26dee585..47e6a3606 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -220,7 +220,7 @@ dependencies {
} // JSON Parser
// Torrent Support
- implementation(libs.torrentserver)
+ // implementation(libs.torrentserver)
// Downloading & Networking
implementation(libs.work.runtime)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index aacce0393..1a0b514a2 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,8 +2,6 @@
-
-
diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/Torrent.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/Torrent.kt
index 391d4f586..0f9460e78 100644
--- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/Torrent.kt
+++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/Torrent.kt
@@ -8,6 +8,7 @@ import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.ExtractorLinkType
+import go.Seq
import torrServer.TorrServer
import java.io.File
import java.net.ConnectException
@@ -201,6 +202,8 @@ object Torrent {
* FYI this will throw a os.Exit(1) if port is taken and is not currently checked,
* so if someone complains then add an extra check. */
private suspend fun setup(dir: String): Boolean {
+ Seq.load()
+
if (echo()) {
return true
}
diff --git a/app/src/main/java/go/Seq.java b/app/src/main/java/go/Seq.java
new file mode 100644
index 000000000..2a510bdca
--- /dev/null
+++ b/app/src/main/java/go/Seq.java
@@ -0,0 +1,413 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package go;
+
+import android.content.Context;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.HashSet;
+import java.util.logging.Logger;
+
+import torrServer.TorrServer;
+
+// Seq is a sequence of machine-dependent encoded values.
+// Used by automatically generated language bindings to talk to Go.
+public class Seq {
+ private static Logger log = Logger.getLogger("GoSeq");
+
+ // also known to bind/seq/ref.go and bind/objc/seq_darwin.m
+ private static final int NULL_REFNUM = 41;
+
+ // use single Ref for null Object
+ public static final Ref nullRef = new Ref(NULL_REFNUM, null);
+
+ // The singleton GoRefQueue
+ private static GoRefQueue goRefQueue = null;
+
+ static Boolean hasLoaded = false;
+
+ // We want to lazy loadLibrary in case of crashes
+ public static synchronized void load() {
+ if (hasLoaded) return;
+ hasLoaded = true;
+ log.info("Starting loading gojni");
+ System.loadLibrary("gojni");
+ log.info("Starting loading gojni init");
+ init();
+ log.info("Starting loading gojni goRefQueue");
+ goRefQueue = new GoRefQueue();
+ log.info("Starting loading gojni Universe");
+ Universe.touch();
+ Universe._init();
+ log.info("Starting loading gojni TorrServer");
+ TorrServer.touch();
+ TorrServer._init();
+ log.info("Loaded torrent server");
+ }
+
+ // setContext sets the context in the go-library to be used in RunOnJvm.
+ public static void setContext(Context context) {
+ setContext((java.lang.Object)context);
+ }
+
+ private static native void init();
+
+ // Empty method to run class initializer
+ public static void touch() {}
+
+ private Seq() {
+ }
+
+ // ctx is an android.context.Context.
+ static native void setContext(java.lang.Object ctx);
+
+ public static void incRefnum(int refnum) {
+ tracker.incRefnum(refnum);
+ }
+
+ // incRef increments the reference count of Java objects.
+ // For proxies for Go objects, it calls into the Proxy method
+ // incRefnum() to make sure the Go reference count is positive
+ // even if the Proxy is garbage collected and its Ref is finalized.
+ public static int incRef(Object o) {
+ return tracker.inc(o);
+ }
+
+ public static int incGoObjectRef(GoObject o) {
+ return o.incRefnum();
+ }
+
+ // trackGoRef tracks a Go reference and decrements its refcount
+ // when the given GoObject wrapper is garbage collected.
+ //
+ // TODO(crawshaw): We could cut down allocations for frequently
+ // sent Go objects by maintaining a map to weak references. This
+ // however, would require allocating two objects per reference
+ // instead of one. It also introduces weak references, the bane
+ // of any Java debugging session.
+ //
+ // When we have real code, examine the tradeoffs.
+ public static void trackGoRef(int refnum, GoObject obj) {
+ if (refnum > 0) {
+ throw new RuntimeException("trackGoRef called with Java refnum " + refnum);
+ }
+ goRefQueue.track(refnum, obj);
+ }
+
+ public static Ref getRef(int refnum) {
+ return tracker.get(refnum);
+ }
+
+ // Increment the Go reference count before sending over a refnum.
+ // The ref parameter is only used to make sure the referenced
+ // object is not garbage collected before Go increments the
+ // count. It's the equivalent of Go's runtime.KeepAlive.
+ public static native void incGoRef(int refnum, GoObject ref);
+
+ // Informs the Go ref tracker that Java is done with this refnum.
+ static native void destroyRef(int refnum);
+
+ // decRef is called from seq.FinalizeRef
+ static void decRef(int refnum) {
+ tracker.dec(refnum);
+ }
+
+ // A GoObject is a Java class implemented in Go. When a GoObject
+ // is passed to Go, it is wrapped in a Go proxy, to make it behave
+ // the same as passing a regular Java class.
+ public interface GoObject {
+ // Increment refcount and return the refnum of the proxy.
+ //
+ // The Go reference count need to be bumped while the
+ // refnum is passed to Go, to avoid finalizing and
+ // invalidating it before being translated on the Go side.
+ int incRefnum();
+ }
+ // A Proxy is a Java object that proxies a Go object. Proxies, unlike
+ // GoObjects, are unwrapped to their Go counterpart when deserialized
+ // in Go.
+ public interface Proxy extends GoObject {}
+
+ // A Ref represents an instance of a Java object passed back and forth
+ // across the language boundary.
+ public static final class Ref {
+ public final int refnum;
+
+ private int refcnt; // Track how many times sent to Go.
+
+ public final Object obj; // The referenced Java obj.
+
+ Ref(int refnum, Object o) {
+ if (refnum < 0) {
+ throw new RuntimeException("Ref instantiated with a Go refnum " + refnum);
+ }
+ this.refnum = refnum;
+ this.refcnt = 0;
+ this.obj = o;
+ }
+
+ void inc() {
+ // Count how many times this ref's Java object is passed to Go.
+ if (refcnt == Integer.MAX_VALUE) {
+ throw new RuntimeException("refnum " + refnum + " overflow");
+ }
+ refcnt++;
+ }
+ }
+
+ static final RefTracker tracker = new RefTracker();
+
+ static final class RefTracker {
+ private static final int REF_OFFSET = 42;
+
+ // Next Java object reference number.
+ //
+ // Reference numbers are positive for Java objects,
+ // and start, arbitrarily at a different offset to Go
+ // to make debugging by reading Seq hex a little easier.
+ private int next = REF_OFFSET; // next Java object ref
+
+ // Java objects that have been passed to Go. refnum -> Ref
+ // The Ref obj field is non-null.
+ // This map pins Java objects so they don't get GCed while the
+ // only reference to them is held by Go code.
+ private final RefMap javaObjs = new RefMap();
+
+ // Java objects to refnum
+ private final IdentityHashMap