Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Author: Nic Wolfe <nic@wolfeden.ca>
- # URL: http://code.google.com/p/sickbeard/
- #
- # This file is part of Sick Beard.
- #
- # Sick Beard is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # Sick Beard is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
- import struct, socket, sys, time, os
- import autoProcessTV
- #Simply change the host, port and mac values to those of your xbmc box
- host = '192.168.0.27'
- port = '8080'
- mac = '90:e6:ba:7a:4e:d8'
- #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"
- if len(sys.argv) < 2:
- print "No folder supplied - is this being called from SABnzbd?"
- sys.exit()
- elif len(sys.argv) >= 3:
- i=1
- while TestCon(host,port)=="Down" and i<4:
- WakeOnLan(mac)
- time.sleep(20)
- i=i+1
- autoProcessTV.processEpisode(sys.argv[1], sys.argv[2])
- else:
- i=1
- while TestCon(host,port)=="Down" and i<4:
- WakeOnLan(mac)
- time.sleep(20)
- i=i+1
- autoProcessTV.processEpisode(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement