Advertisement
Guest User

mashles

a guest
Jan 14th, 2010
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1. # Author: Nic Wolfe <nic@wolfeden.ca>
  2. # URL: http://code.google.com/p/sickbeard/
  3. #
  4. # This file is part of Sick Beard.
  5. #
  6. # Sick Beard is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Sick Beard is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Sick Beard.  If not, see <http://www.gnu.org/licenses/>.
  18.  
  19.  
  20. import struct, socket, sys, time, os
  21.  
  22. import autoProcessTV
  23.  
  24. #Simply change the host, port and mac values to those of your xbmc box
  25. host = '192.168.0.27'
  26. port = '8080'
  27. mac = '90:e6:ba:7a:4e:d8'
  28.  
  29. #Wake function
  30. def WakeOnLan(ethernet_address):
  31.  
  32.     addr_byte = ethernet_address.split(':')
  33.     hw_addr = struct.pack('BBBBBB', int(addr_byte[0], 16),
  34.     int(addr_byte[1], 16),
  35.     int(addr_byte[2], 16),
  36.     int(addr_byte[3], 16),
  37.     int(addr_byte[4], 16),
  38.     int(addr_byte[5], 16))
  39.  
  40.     # Build the Wake-On-LAN "Magic Packet"...
  41.  
  42.     msg = '\xff' * 6 + hw_addr * 16
  43.  
  44.     # ...and send it to the broadcast address using UDP
  45.  
  46.     ss = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  47.     ss.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
  48.     ss.sendto(msg, ('<broadcast>', 9))
  49.     ss.close()
  50.  
  51. #Test Connection function
  52. def TestCon(host,port):
  53.     (family, socktype, proto, garbage, address) = \
  54.     socket.getaddrinfo(host, port)[0]
  55.     s = socket.socket(family, socktype, proto)
  56.     try:
  57.      s.connect(address)
  58.      return "Up"
  59.     except:
  60.      return "Down"
  61.  
  62.  
  63. if len(sys.argv) < 2:
  64.     print "No folder supplied - is this being called from SABnzbd?"
  65.     sys.exit()
  66. elif len(sys.argv) >= 3:
  67.     i=1
  68.     while TestCon(host,port)=="Down" and i<4:
  69.      WakeOnLan(mac)
  70.      time.sleep(20)
  71.      i=i+1
  72.     autoProcessTV.processEpisode(sys.argv[1], sys.argv[2])
  73. else:
  74.     i=1
  75.     while TestCon(host,port)=="Down" and i<4:
  76.      WakeOnLan(mac)
  77.      time.sleep(20)
  78.      i=i+1
  79.     autoProcessTV.processEpisode(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement