forked from Onek8/LNXSDK
74 lines
1.7 KiB
Haxe
74 lines
1.7 KiB
Haxe
package leenkx.logicnode;
|
|
#if lnx_torrent
|
|
import haxe.io.Bytes;
|
|
import leenkx.network.torrent.Magnet;
|
|
import leenkx.network.torrent.MetaInfo;
|
|
#end
|
|
|
|
class ParseTorrentNode extends LogicNode {
|
|
var meta:Dynamic;
|
|
var magnet:Dynamic;
|
|
var idHex:String;
|
|
public var property0:String;
|
|
|
|
public function new(tree:LogicTree) {
|
|
super(tree);
|
|
}
|
|
|
|
override function run(from:Int) {
|
|
#if lnx_torrent
|
|
meta = null;
|
|
magnet = null;
|
|
idHex = null;
|
|
var src = inputs[1].get();
|
|
if (src == null) return;
|
|
|
|
switch (property0 != null ? property0 : "magnet") {
|
|
case "file":
|
|
if (Std.isOfType(src, MetaInfo)) {
|
|
meta = src;
|
|
} else {
|
|
var b = Std.isOfType(src, Bytes) ? src : Bytes.ofString(Std.string(src));
|
|
try {
|
|
meta = MetaInfo.fromTorrentBytes(b);
|
|
} catch(e:Dynamic) {
|
|
trace(e);
|
|
return;
|
|
}
|
|
}
|
|
case "id":
|
|
var s = Std.string(src);
|
|
idHex = s.length == 64 ? "v2:" + s : s;
|
|
default:
|
|
var m = Magnet.parse(Std.string(src));
|
|
if (m == null) {
|
|
return;
|
|
}
|
|
magnet = m;
|
|
idHex = m.infoHashHex != null ? m.infoHashHex : m.infoHashV2Hex;
|
|
}
|
|
#end
|
|
runOutput(0);
|
|
}
|
|
|
|
override function get(from:Int):Dynamic {
|
|
#if lnx_torrent
|
|
var m:MetaInfo = meta;
|
|
var mg:Magnet = magnet;
|
|
return switch (from) {
|
|
case 1: m;
|
|
case 2: m != null ? (m.infoHashHex != null ? m.infoHashHex : m.infoHashV2Hex) : idHex;
|
|
case 3: m != null ? m.name : (mg != null ? mg.name : null);
|
|
case 4: m != null ? m.announce : (mg != null ? mg.trackers : null);
|
|
case 5: m != null ? m.urlList : (mg != null ? mg.webSeeds : null);
|
|
case 6: m != null ? m.files : null;
|
|
case 7: m != null ? m.totalLength : 0;
|
|
case 8: m != null ? m.toTorrentBytes() : null;
|
|
default: throw "Unreachable";
|
|
}
|
|
#else
|
|
return null;
|
|
#end
|
|
}
|
|
}
|