2013-04-26 07:18:21 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright (c) 2013 Paul Price, Artem Glebov
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import xbmc, xbmcaddon, xbmcgui
|
|
|
|
import transmissionrpc
|
|
|
|
|
|
|
|
__settings__ = xbmcaddon.Addon(id='script.transmission')
|
|
|
|
|
|
|
|
BASE_RESOURCE_PATH = xbmc.translatePath( os.path.join( __settings__.getAddonInfo('path'), 'resources', 'lib' ) )
|
|
|
|
sys.path.append (BASE_RESOURCE_PATH)
|
|
|
|
|
|
|
|
import common
|
|
|
|
|
|
|
|
class SubstitutePlayer(xbmc.Player):
|
|
|
|
def __init__(self):
|
|
|
|
xbmc.Player.__init__(self)
|
|
|
|
self.prev_settings = {}
|
|
|
|
self.refreshSettings()
|
|
|
|
|
|
|
|
def onPlayBackStarted(self):
|
|
|
|
self.refreshSettings()
|
2014-01-23 00:17:17 +00:00
|
|
|
if self.mode != '0' and xbmc.Player().isPlayingVideo():
|
|
|
|
if self.mode == '1':
|
|
|
|
self.stopAllTorrents()
|
|
|
|
elif self.mode == '2':
|
|
|
|
self.enableSpeedLimit()
|
2013-04-26 07:18:21 +00:00
|
|
|
|
|
|
|
def onPlayBackStopped(self):
|
|
|
|
self.refreshSettings()
|
2014-01-23 00:17:17 +00:00
|
|
|
if self.mode == '1':
|
2013-04-26 07:18:21 +00:00
|
|
|
self.startAllTorrents()
|
2014-01-23 00:17:17 +00:00
|
|
|
elif self.mode == '2':
|
|
|
|
self.disableSpeedLimit()
|
2013-04-26 07:18:21 +00:00
|
|
|
|
|
|
|
def startAllTorrents(self):
|
|
|
|
if self.transmission:
|
|
|
|
torrents = self.transmission.list()
|
|
|
|
for tid, torrent in torrents.iteritems():
|
|
|
|
self.transmission.start(tid)
|
|
|
|
|
|
|
|
def stopAllTorrents(self):
|
|
|
|
if self.transmission:
|
|
|
|
torrents = self.transmission.list()
|
|
|
|
for tid, torrent in torrents.iteritems():
|
|
|
|
self.transmission.stop(tid)
|
|
|
|
|
2014-01-23 00:17:17 +00:00
|
|
|
def enableSpeedLimit(self):
|
|
|
|
if self.transmission:
|
|
|
|
self.transmission.set_session(alt_speed_enabled=True)
|
|
|
|
|
|
|
|
def disableSpeedLimit(self):
|
|
|
|
if self.transmission:
|
|
|
|
self.transmission.set_session(alt_speed_enabled=False)
|
|
|
|
|
2013-04-26 07:18:21 +00:00
|
|
|
def refreshSettings(self):
|
|
|
|
settings = common.get_settings()
|
|
|
|
if settings != self.prev_settings:
|
2014-01-23 00:17:17 +00:00
|
|
|
self.mode = settings['action_on_playback']
|
2013-04-26 07:18:21 +00:00
|
|
|
try:
|
|
|
|
self.transmission = common.get_rpc_client()
|
|
|
|
except:
|
|
|
|
self.transmission = None
|
|
|
|
self.prev_settings = settings
|
|
|
|
|
|
|
|
player = SubstitutePlayer()
|
|
|
|
|
|
|
|
while (not xbmc.abortRequested):
|
|
|
|
xbmc.sleep(5000);
|