forked from LeenkxTeam/LNXSDK
P2P Export - Nodes - Patch
This commit is contained in:
68
leenkx/blender/lnx/logicnode/custom/LN_parse_torrent.py
Normal file
68
leenkx/blender/lnx/logicnode/custom/LN_parse_torrent.py
Normal file
@ -0,0 +1,68 @@
|
||||
from lnx.logicnode.lnx_nodes import *
|
||||
|
||||
|
||||
class ParseTorrentNode(LnxLogicTreeNode):
|
||||
"""Parse Torrent"""
|
||||
bl_idname = 'LNParseTorrentNode'
|
||||
bl_label = 'Parse Torrent'
|
||||
bl_description = ('Parse a torrent id without joining a swarm')
|
||||
lnx_category = 'Leenkx'
|
||||
lnx_version = 1
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ParseTorrentNode, self).__init__(*args, **kwargs)
|
||||
array_nodes[str(id(self))] = self
|
||||
|
||||
def update_sockets(self, context):
|
||||
if not self.inputs:
|
||||
return
|
||||
links = {}
|
||||
for socket in self.inputs:
|
||||
for link in socket.links:
|
||||
links.setdefault(socket.name, []).append(
|
||||
(link.from_node, link.from_socket))
|
||||
for socket in self.inputs[1:]:
|
||||
self.inputs.remove(socket)
|
||||
self._add_id_input()
|
||||
tree = self.id_data
|
||||
for socket in self.inputs:
|
||||
if socket.name in links:
|
||||
for from_node, from_socket in links[socket.name]:
|
||||
tree.links.new(from_socket, socket)
|
||||
|
||||
def _add_id_input(self):
|
||||
mode_sockets = {
|
||||
'magnet': ('LnxStringSocket', 'Magnet URI', 'Magnet URI (magnet:?xt=...)'),
|
||||
'id': ('LnxStringSocket', 'Infohash', '40-char v1 or 64-char v2 infohash hex'),
|
||||
'file': ('LnxDynamicSocket', 'Torrent File (Bytes)', '.torrent file bytes'),
|
||||
}
|
||||
socket_type, label, desc = mode_sockets.get(self.property0, mode_sockets['magnet'])
|
||||
self.add_input(socket_type, label)
|
||||
|
||||
property0: HaxeEnumProperty('property0',
|
||||
items=[('magnet', 'Magnet', 'Magnet URI (magnet:?xt=...)'),
|
||||
('id', 'Infohash', '40-char v1 or 64-char v2 infohash hex'),
|
||||
('file', 'Torrent File', '.torrent file bytes')],
|
||||
name='Input', default='magnet', update=update_sockets)
|
||||
|
||||
def lnx_init(self, context):
|
||||
self.add_input('LnxNodeSocketAction', 'In')
|
||||
self._add_id_input()
|
||||
|
||||
self.add_output('LnxNodeSocketAction', 'Out')
|
||||
self.add_output('LnxDynamicSocket', 'Meta')
|
||||
self.add_output('LnxStringSocket', 'InfoHash')
|
||||
self.add_output('LnxStringSocket', 'Name')
|
||||
self.add_output('LnxNodeSocketArray', 'Trackers')
|
||||
self.add_output('LnxNodeSocketArray', 'Web Seeds')
|
||||
self.add_output('LnxNodeSocketArray', 'Files')
|
||||
self.add_output('LnxFloatSocket', 'Total Size')
|
||||
self.add_output('LnxDynamicSocket', 'Torrent Bytes')
|
||||
|
||||
def draw_buttons(self, context, layout):
|
||||
layout.prop(self, 'property0')
|
||||
|
||||
|
||||
def register():
|
||||
add_category('Leenkx', icon='ORIENTATION_CURSOR')
|
||||
ParseTorrentNode.on_register()
|
||||
Reference in New Issue
Block a user