Don't like ads? PRO users don't see any ads ;-)
Guest

30_softhddevice

By: a guest on Jul 29th, 2012  |  syntax: Python  |  size: 2.78 KB  |  hits: 96  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?cs if:(vdr.frontend == "softhddevice") ?>
  2.  
  3. end script
  4.  
  5. script
  6.  
  7. python - <<END
  8.  
  9. import sys, os, subprocess, gobject, dbus, socket, string
  10.  
  11. bus = dbus.SystemBus()
  12. shutdownproxy = bus.get_object("de.tvdr.vdr","/Shutdown")
  13. ask_vdrshutdown = dbus.Interface(shutdownproxy,"de.tvdr.vdr.shutdown")
  14. softhddeviceproxy = bus.get_object("de.tvdr.vdr","/Plugins/softhddevice")
  15. softhddevice = dbus.Interface(softhddeviceproxy,"de.tvdr.vdr.plugin")
  16. remoteproxy = bus.get_object("de.tvdr.vdr","/Remote")
  17. remote = dbus.Interface(softhddeviceproxy,"de.tvdr.vdr.remote")
  18.  
  19. frontend_active = 0
  20.  
  21. def get_status():
  22.     reply,status =  softhddevice.SVDRPCommand("STAT","")
  23.     status = status.split()[-1]
  24.     return status
  25.    
  26. def detach():
  27.     reply,answer = softhddevice.SVDRPCommand(dbus.String("DETA"),"")
  28.     remote.Disable()
  29.     return True
  30.  
  31. def resume(status):
  32.     if status == "SUSPENDED":
  33.         softhddevice.SVDRCommand(dbus.String("RESU"),"")
  34.     elif status == "SUSPEND_DETACHED":
  35.         softhddevice.SVDRPCommand(dbus.String("ATTA"),dbus.String("-d :1"))
  36.     remote.Enable()
  37.  
  38. def handler(sock, *args):
  39.     global frontend_active
  40.     buf = sock.recv(1024)
  41.     lines = string.split(buf, "\n")
  42.     for line in lines[:-1]:
  43.         code,count,cmd,device = string.split(line, " ")
  44.         if cmd == "KEY_PROG1":
  45.             if get_status() == "NOT_SUSPENDED":
  46.                 detach()
  47.                 frontend_active = 0
  48.             else:
  49.                 resume(status)
  50.         elif cmd == "KEY_POWER2":
  51.             if get_status() == "NOT_SUSPENDED":
  52.                 detach()
  53.                 frontend_active = 0
  54.             else:
  55.                 remote.HitKey("POWER")                
  56.         else:
  57.           if frontend_active == 0:
  58.             remote.Enable()
  59.             resume(get_status())
  60.             frontend_active = 1
  61.           else: pass
  62.     return True
  63.  
  64. if ask_vdrshutdown.ManualStart() == True:
  65.     status =  get_status()
  66.     resume(status)
  67. else:
  68.     # deactivate Remote
  69.     remote.Disable()
  70.  
  71. def connect_eventlircd():
  72.     socket_path = "/var/run/lirc/lircd"
  73.     sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  74.     sock.connect(socket_path)
  75.     gobject.io_add_watch(sock, gobject.IO_IN, handler)
  76.  
  77. def try_connection():
  78.   try:
  79.     connect_eventlircd()
  80.   except:
  81.     print "Error: could not connect to eventlircd"
  82.     try_connection()
  83.  
  84. try_connection()
  85. gobject.MainLoop().run()
  86. END
  87.  
  88. end script
  89.  
  90. post-stop script
  91. if [ "$(vdr-dbus-send /Plugins/softhddevice plugin.SVDRPCommand string:"STAT" | grep -q "SUSPEND_NORMAL")" ]; then
  92.     vdr-dbus-send /Plugins/softhddevice plugin.SVDRPCommand string:'RESU' ||: &> /dev/null
  93. fi
  94. vdr-dbus-send /Plugins/softhddevice plugin.SVDRPCommand string:'DETA' ||: &> /dev/null
  95. end script
  96. <?cs /if ?>
  97.  
  98. <?cs /if ?>