P2P Export - Nodes - Patch
This commit is contained in:
71
leenkx/blender/lnx/logicnode/custom/LN_torrent_control.py
Normal file
71
leenkx/blender/lnx/logicnode/custom/LN_torrent_control.py
Normal file
@ -0,0 +1,71 @@
|
||||
from lnx.logicnode.lnx_nodes import *
|
||||
|
||||
|
||||
class TorrentControlNode(LnxLogicTreeNode):
|
||||
"""Torrent Control"""
|
||||
bl_idname = 'LNTorrentControlNode'
|
||||
bl_label = 'Torrent Control'
|
||||
bl_description = ('Start, stop, remove or prioritize a torrent.')
|
||||
lnx_category = 'Leenkx'
|
||||
lnx_version = 1
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(TorrentControlNode, self).__init__(*args, **kwargs)
|
||||
array_nodes[str(id(self))] = self
|
||||
|
||||
property0: HaxeEnumProperty('property0',
|
||||
items=[('start', 'Start', 'Start or resume the torrent session'),
|
||||
('stop', 'Stop', 'Pause the torrent (announces stopped to trackers); it stays registered and can be started again'),
|
||||
('remove', 'Remove', 'Destroy the torrent and remove it from the client'),
|
||||
('remove-data', 'Remove + Data', 'Destroy the torrent and delete the stored content bytes'),
|
||||
('select', 'Select', 'Prioritize a piece range: File handle or Start/End bytes, Priority optional (webtorrent torrent.select)'),
|
||||
('deselect', 'Deselect', 'Drop a priority selection, back to normal order'),
|
||||
('critical', 'Critical', 'Top-priority selection for streaming seeks'),
|
||||
('add-peer', 'Add Peer', 'Connect to a peer directly; Address is host:port (sys/Krom targets only)'),
|
||||
('add-web-seed', 'Add Web Seed', 'Register a BEP 19 webseed; Address is an http(s) URL, fills pieces when peers can\'t serve them')],
|
||||
name='Action', default='start',
|
||||
update=lambda self, context: self._rebuild_inputs())
|
||||
|
||||
def _rebuild_inputs(self):
|
||||
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[3:]:
|
||||
self.inputs.remove(socket)
|
||||
self._add_action_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_action_inputs(self):
|
||||
if self.property0 in ('select', 'deselect', 'critical'):
|
||||
self.add_input('LnxDynamicSocket', 'File')
|
||||
self.add_input('LnxIntSocket', 'Start')
|
||||
self.add_input('LnxIntSocket', 'End')
|
||||
self.add_input('LnxIntSocket', 'Priority')
|
||||
elif self.property0 == 'add-peer':
|
||||
self.add_input('LnxStringSocket', 'Address')
|
||||
elif self.property0 == 'add-web-seed':
|
||||
self.add_input('LnxStringSocket', 'Address')
|
||||
|
||||
def lnx_init(self, context):
|
||||
self.add_input('LnxNodeSocketAction', 'In')
|
||||
self.add_input('LnxDynamicSocket', 'Connection')
|
||||
self.add_input('LnxDynamicSocket', 'Torrent')
|
||||
self._add_action_inputs()
|
||||
|
||||
self.add_output('LnxNodeSocketAction', 'Out')
|
||||
|
||||
def draw_buttons(self, context, layout):
|
||||
layout.prop(self, 'property0')
|
||||
|
||||
|
||||
def register():
|
||||
add_category('Leenkx', icon='ORIENTATION_CURSOR')
|
||||
TorrentControlNode.on_register()
|
||||
Reference in New Issue
Block a user