Guest User

default.py

a guest
Mar 2nd, 2013
41
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("192.168.0.3", 9091, "transmission", "transmission")
  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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×