added Wake (WOL) option

This commit is contained in:
clinton-hall 2013-04-15 16:05:14 +09:30
commit 5433d9ad20
10 changed files with 103 additions and 1 deletions

View file

@ -210,6 +210,9 @@ if __name__ == "__main__":
Logger.info("====================") # Seperate old from new log
Logger.info("TorrentToMedia %s", VERSION)
WakeUp()
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")

View file

@ -114,6 +114,16 @@ def migrate():
option, value = item
confignew.set(section, option, value)
section = "WakeOnLan"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
confignew.set(section, option, value)
section = "loggers"
original = []
try:

View file

@ -4,6 +4,9 @@ import os
import re
import sys
import shutil
import struct
import socket
import time
import linktastic.linktastic as linktastic
@ -209,6 +212,71 @@ def iterate_media_files(dirname):
yield dirpath, os.path.join(dirpath, filename)
#Wake function
def WakeOnLan(ethernet_address):
addr_byte = ethernet_address.split(':')
hw_addr = struct.pack('BBBBBB', int(addr_byte[0], 16),
int(addr_byte[1], 16),
int(addr_byte[2], 16),
int(addr_byte[3], 16),
int(addr_byte[4], 16),
int(addr_byte[5], 16))
# Build the Wake-On-LAN "Magic Packet"...
msg = '\xff' * 6 + hw_addr * 16
# ...and send it to the broadcast address using UDP
ss = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ss.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
ss.sendto(msg, ('<broadcast>', 9))
ss.close()
#Test Connection function
def TestCon(host,port):
(family, socktype, proto, garbage, address) = socket.getaddrinfo(host, port)[0]
s = socket.socket(family, socktype, proto)
try:
s.connect(address)
return "Up"
except:
return "Down"
def WakeUp():
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
if not os.path.isfile(configFilename):
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
return 1 # failure
config.read(configFilename)
wake = config.get("WakeOnLan", "wake")
if wake == 0: # just return if we don't need to wake anything.
return
Logger.info("Loading WakeOnLan config from %s", configFilename)
config.get("WakeOnLan", "host")
host = config.get("WakeOnLan", "host")
port = config.get("WakeOnLan", "port")
mac = config.get("WakeOnLan", "mac")
i=1
while TestCon(host,port) == "Down" and i < 4:
Logger.info("Sending WakeOnLan Magic Packet for mac: %s", mac)
WakeOnLan(mac)
time.sleep(20)
i=i+1
if TestCon(host,port) == "Down": # final check.
Logger.warning("System with mac: %s has not woken after 3 attempts. Continuing with the rest of the script.", mac)
else:
Logger.info("System with mac: %s has been woken. Continuing with the rest of the script.", mac)
def parse_other(args):
return os.path.normpath(sys.argv[1]), '', '', '', ''

View file

@ -113,6 +113,14 @@ outputAudioCodec = libmp3lame
outputAudioBitrate = 128k
outputSubtitleCodec =
[WakeOnLan]
###### set wake = 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) the host and port specified.
wake = 0
host = 192.168.1.37
port = 80
mac = 00:01:2e:2D:64:e1
# Logging configuration
[loggers]
keys = root

View file

@ -19,6 +19,8 @@ Logger = logging.getLogger(__name__)
Logger.info("====================") # Seperate old from new log
Logger.info("nzbToCouchPotato %s", VERSION)
WakeUp()
# SABnzbd
if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS:
# SABnzbd argv:

View file

@ -19,6 +19,8 @@ Logger = logging.getLogger(__name__)
Logger.info("====================") # Seperate old from new log
Logger.info("nzbToGamez %s", VERSION)
WakeUp()
# SABnzbd
if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS:
# SABnzbd argv:

View file

@ -19,6 +19,8 @@ Logger = logging.getLogger(__name__)
Logger.info("====================") # Seperate old from new log
Logger.info("nzbToHeadPhones %s", VERSION)
WakeUp()
# SABnzbd
if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS:
# SABnzbd argv:

View file

@ -23,6 +23,9 @@ Logger = logging.getLogger(__name__)
Logger.info("====================") # Seperate old from new log
Logger.info("nzbToMedia %s", VERSION)
WakeUp()
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
if not os.path.isfile(configFilename):
@ -36,7 +39,7 @@ cpsCategory = config.get("CouchPotato", "cpsCategory")
sbCategory = config.get("SickBeard", "sbCategory") # tv
hpCategory = config.get("HeadPhones", "hpCategory") # music
mlCategory = config.get("Mylar", "mlCategory") # comics
gzCategory = config.get("Gamez", "gzCategory")
gzCategory = config.get("Gamez", "gzCategory") # games
# SABnzbd
if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS:

View file

@ -19,6 +19,8 @@ Logger = logging.getLogger(__name__)
Logger.info("====================") # Seperate old from new log
Logger.info("nzbToMylar %s", VERSION)
WakeUp()
# SABnzbd
if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS:
# SABnzbd argv:

View file

@ -41,6 +41,8 @@ Logger = logging.getLogger(__name__)
Logger.info("====================") # Seperate old from new log
Logger.info("nzbToSickBeard %s", VERSION)
WakeUp
# SABnzbd
if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS:
# SABnzbd argv: