Hi there,
Sorry if I am posting this in the wrong place on the forum.
I’m not really experienced at Python or Plex channel development but I’m trying to get something put together, and could use some help please.
The idea: To create a plex channel that can be used to make the PMS send a Wake on LAN (WOL) request to another device on the local network.
For example, I have a PMS which I run 24x7. I also have some HTPC, which I don’t leave on the time. I might want to access recordings or DVR functionality on those HTPC. The idea is to use a Plex plugin to wake those devices so that I can access the content.
I’ve drafted some code below, by borrowing bits from various places. Ideally I’d want the plug configurable so that I can have 3 different HTPC devices that could be woken up.
What each device will need:
-A name, or alias
-Its MAC Address
-Port Number for sending the request (usually 7 or 9)
-An optional broadcast or forwarding address (255.255.255.255 for a local subnet broadcast).
Code below. This is just proof of concept code but it doesn’t give a channel icon. Any help appreciated.
Many thanks,
Andrew
ART = ‘artlogo.jpg’
ICON = ‘icon-default.jpg’
NAME = ‘WOL Utility’
TARGET_ONE_MAC = ‘60a44cd03a99’
TARGET_ONE_ALIAS = ‘LR-PC’
TARGET_ONE_PORT = ‘9’
TARGET_ONE_BROADCAST = ‘255.255.255.255’
####################################################################################################
def Start():
ObjectContainer.art = R(ART)
ObjectContainer.title1 = NAME
TrackObject.thumb = R(ICON)
####################################################################################################
@handler(’/Utility/WOL’, NAME, thumb=ICON, art=ART)
def MainMenu():
sendmagic(macaddress=TARGET_ONE_MAC, alias=TARGET_ONE_ALIAS, DEFAULT_PORT=TARGET_ONE_PORT, BROADCAST_IP=TARGET_ONE_BROADCAST)
return
####################################################################################################
def sendmagic(macaddress, alias, DEFAULT_PORT, BROADCAST_IP):
import socket
import struct
if len(macaddress) == 12:
pass
elif len(macaddress) == 17:
sep = macaddress[2]
macaddress = macaddress.replace(sep, '')
else:
raise ValueError('Incorrect MAC address format')
# Pad the synchronization stream
data = b'FFFFFFFFFFFF' + (macaddress * 20).encode()
send_data = b''
# Split up the hex values in pack
for i in range(0, len(data), 2):
send_data += struct.pack(b'B', int(data[i: i + 2], 16))
packets = []
ip = kwargs.pop('ip_address', BROADCAST_IP)
port = kwargs.pop('port', DEFAULT_PORT)
for k in kwargs:
raise TypeError('send_magic_packet() got an unexpected keyword '
'argument {!r}'.format(k))
for mac in macs:
packet = create_magic_packet(mac)
packets.append(packet)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.connect((ip, port))
for packet in packets:
sock.send(packet)
sock.close()
return
It doesn’t wake the PC, and I can see in the 