Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xbmc, transmissionrpc
- class MyPlayer(xbmc.Player):
- def __init__(self):
- xbmc.Player.__init__(self)
- self.active = True
- self.tc = TransmissionController()
- def onPlayBackStarted(self):
- if self.active and xbmc.Player().isPlayingVideo():
- xbmc.executebuiltin("Notification(Torrent Suspender, Stopped {0} torrents)".format(self.tc.torrentstatus("downloading")))
- self.tc.stopalltorrents()
- def onPlayBackStopped(self):
- if self.active:
- xbmc.executebuiltin("Notification(Torrent Suspender, Resumed {0} torrents)".format(self.tc.torrentstatus("stopped")))
- self.tc.startalltorrents()
- class TransmissionController():
- def __init__(self):
- self.client = transmissionrpc.Client("192.168.0.3", 9091, "transmission", "transmission")
- def torrentstatus(self, status):
- torrents = self.client.list()
- if len(torrents) > 0:
- i = 0
- for tid, torrent in torrents.iteritems():
- if torrent.status == status:
- i += 1
- return i
- def startalltorrents(self):
- if self.torrentstatus("stopped") > 0:
- torrents = self.client.list()
- for tid, torrent in torrents.iteritems():
- self.client.start(tid)
- def stopalltorrents(self):
- if self.torrentstatus("downloading") > 0:
- torrents = self.client.list()
- for tid, torrent in torrents.iteritems():
- self.client.stop(tid)
- player = MyPlayer()
- while player.active:
- xbmc.sleep(5000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement