SHARE
TWEET

Untitled

a guest Mar 4th, 2013 13 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import xbmc, transmissionrpc
  2.  
  3. class MyPlayer(xbmc.Player):
  4.         def __init__(self):
  5.                 xbmc.Player.__init__(self)
  6.                 self.active = True
  7.                 self.tc = TransmissionController()
  8.  
  9.         def onPlayBackStarted(self):
  10.                 if self.active and xbmc.Player().isPlayingVideo():
  11.                         xbmc.executebuiltin("Notification(Torrent Suspender, Stopped {0} torrents)".format(self.tc.torrentstatus("downloading")))
  12.                         self.tc.stopalltorrents()
  13.  
  14.         def onPlayBackStopped(self):
  15.                 if self.active:
  16.                         xbmc.executebuiltin("Notification(Torrent Suspender, Resumed {0} torrents)".format(self.tc.torrentstatus("stopped")))
  17.                         self.tc.startalltorrents()
  18.  
  19. class TransmissionController():
  20.         def __init__(self):
  21.                 self.client = transmissionrpc.Client("localhost", 9091, "xbian", "raspberry")
  22.  
  23.         def torrentstatus(self, status):
  24.                 torrents = self.client.list()
  25.                 if len(torrents) > 0:
  26.                         i = 0
  27.                         for tid, torrent in torrents.iteritems():
  28.                                 if torrent.status == status:
  29.                                         i += 1
  30.  
  31.                         return i
  32.  
  33.         def startalltorrents(self):
  34.                 if self.torrentstatus("stopped") > 0:
  35.                         torrents = self.client.list()
  36.                         for tid, torrent in torrents.iteritems():
  37.                                 self.client.start(tid)
  38.  
  39.         def stopalltorrents(self):
  40.                 if self.torrentstatus("downloading") > 0:
  41.                         torrents = self.client.list()
  42.                         for tid, torrent in torrents.iteritems():
  43.                                 self.client.stop(tid)
  44.  
  45. player = MyPlayer()
  46.  
  47. while player.active:
  48.         xbmc.sleep(5000);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top