76 lines
2.9 KiB
Python
76 lines
2.9 KiB
Python
from lnx.logicnode.lnx_nodes import *
|
|
|
|
|
|
class SetTrackersNode(LnxLogicTreeNode):
|
|
"""Set Trackers"""
|
|
bl_idname = 'LNSetTrackersNode'
|
|
bl_label = 'Set Trackers'
|
|
bl_description = ('Add/Override edit the tracker announce list of a live torrent')
|
|
lnx_category = 'Leenkx'
|
|
lnx_version = 1
|
|
|
|
tracker_props = {
|
|
'interval': ('LnxIntSocket', 'Interval'),
|
|
'port': ('LnxIntSocket', 'Port'),
|
|
'key': ('LnxIntSocket', 'Key'),
|
|
'numwant': ('LnxIntSocket', 'Num Want'),
|
|
'trackerId': ('LnxStringSocket', 'Tracker ID'),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super(SetTrackersNode, 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_target_inputs()
|
|
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_target_inputs(self):
|
|
if self.property0 in ('add', 'override'):
|
|
self.add_input('LnxDynamicSocket', 'Connection')
|
|
self.add_input('LnxDynamicSocket', 'Torrent')
|
|
self.add_input('LnxNodeSocketArray', 'Trackers')
|
|
else:
|
|
self.add_input('LnxDynamicSocket', 'Tracker')
|
|
socket_type, label = self.tracker_props.get(
|
|
self.property0, self.tracker_props['interval'])
|
|
self.add_input(socket_type, label)
|
|
|
|
property0: HaxeEnumProperty('property0',
|
|
items=[('add', 'Add', 'Merge the Trackers input on top of the existing announce list'),
|
|
('override', 'Override', 'Replace the announce list entirely; running tracker connections are restarted'),
|
|
('interval', 'Interval', 'Announce interval in seconds'),
|
|
('port', 'Port', 'Listening port reported to the tracker'),
|
|
('key', 'Key', 'Session key sent with announces'),
|
|
('numwant', 'Num Want', 'Number of peers requested per announce'),
|
|
('trackerId', 'Tracker ID', 'Tracker id echoed back by the tracker')],
|
|
name='Property', default='add', update=update_sockets)
|
|
|
|
def lnx_init(self, context):
|
|
self.add_input('LnxNodeSocketAction', 'In')
|
|
self._add_target_inputs()
|
|
|
|
self.add_output('LnxNodeSocketAction', 'Out')
|
|
self.add_output('LnxDynamicSocket', 'Target')
|
|
|
|
def draw_buttons(self, context, layout):
|
|
layout.prop(self, 'property0')
|
|
|
|
|
|
def register():
|
|
add_category('Leenkx', icon='ORIENTATION_CURSOR')
|
|
SetTrackersNode.on_register()
|