mirror of
https://github.com/correl/Transmission-XBMC.git
synced 2024-11-22 03:00:15 +00:00
Ability to stop all torrents on video playback
This commit is contained in:
parent
7d1d517102
commit
bb4b001fb6
7 changed files with 98 additions and 15 deletions
|
@ -10,6 +10,9 @@
|
|||
</requires>
|
||||
<extension point="xbmc.python.script"
|
||||
library="default.py" />
|
||||
<extension point="xbmc.service"
|
||||
library="resources/lib/player.py"
|
||||
start="startup"/>
|
||||
<extension point="xbmc.addon.metadata">
|
||||
<summary lang="en">A client for the popular Transmission BitTorrent application</summary>
|
||||
<summary lang="hu">A népszerű Transmission Bittorrent alkalmazás vezérlése</summary>
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
<string id="1002">Port</string>
|
||||
<string id="1003">User</string>
|
||||
<string id="1004">Password</string>
|
||||
<string id="1005">Stop all torrents on video playback</string>
|
||||
|
||||
<!-- Errors -->
|
||||
<string id="9000">An unexpected error occurred</string>
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
<string id="1002">Порт</string>
|
||||
<string id="1003">Пользователь</string>
|
||||
<string id="1004">Пароль</string>
|
||||
<string id="1005">Останавливать все закачки на время просмотра видео</string>
|
||||
|
||||
<!-- Errors -->
|
||||
<string id="9000">Неизвестная ошибка</string>
|
||||
|
|
30
resources/lib/common.py
Normal file
30
resources/lib/common.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2013 Artem Glebov
|
||||
|
||||
import sys
|
||||
import transmissionrpc
|
||||
|
||||
__settings__ = sys.modules[ "__main__" ].__settings__
|
||||
|
||||
def get_settings():
|
||||
params = {
|
||||
'address': __settings__.getSetting('rpc_host'),
|
||||
'port': __settings__.getSetting('rpc_port'),
|
||||
'user': __settings__.getSetting('rpc_user'),
|
||||
'password': __settings__.getSetting('rpc_password'),
|
||||
'stop_all_on_playback': __settings__.getSetting('stop_all_on_playback')
|
||||
}
|
||||
return params
|
||||
|
||||
def get_params():
|
||||
params = {
|
||||
'address': __settings__.getSetting('rpc_host'),
|
||||
'port': __settings__.getSetting('rpc_port'),
|
||||
'user': __settings__.getSetting('rpc_user'),
|
||||
'password': __settings__.getSetting('rpc_password'),
|
||||
}
|
||||
return params
|
||||
|
||||
def get_rpc_client():
|
||||
params = get_params()
|
||||
return transmissionrpc.Client(**params)
|
|
@ -9,6 +9,7 @@ import xbmcgui
|
|||
from basictypes.bytes import Bytes
|
||||
import transmissionrpc
|
||||
import search
|
||||
import common
|
||||
|
||||
_ = sys.modules[ "__main__" ].__language__
|
||||
__settings__ = sys.modules[ "__main__" ].__settings__
|
||||
|
@ -31,27 +32,16 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
|
|||
self.list = {}
|
||||
self.torrents = {}
|
||||
self.timer = None
|
||||
def get_settings(self):
|
||||
params = {
|
||||
'address': __settings__.getSetting('rpc_host'),
|
||||
'port': __settings__.getSetting('rpc_port'),
|
||||
'user': __settings__.getSetting('rpc_user'),
|
||||
'password': __settings__.getSetting('rpc_password')
|
||||
}
|
||||
return params
|
||||
def set_settings(self, params):
|
||||
__settings__.setSetting('rpc_host', params['address'])
|
||||
__settings__.setSetting('rpc_port', params['port'])
|
||||
__settings__.setSetting('rpc_user', params['user'])
|
||||
__settings__.setSetting('rpc_password', params['password'])
|
||||
def get_rpc_client(self):
|
||||
params = self.get_settings()
|
||||
return transmissionrpc.Client(**params)
|
||||
def onInit(self):
|
||||
p = xbmcgui.DialogProgress()
|
||||
p.create(_(0), _(1)) # 'Transmission', 'Connecting to Transmission'
|
||||
try:
|
||||
self.transmission = self.get_rpc_client()
|
||||
self.transmission = common.get_rpc_client()
|
||||
except:
|
||||
p.close()
|
||||
self.close()
|
||||
|
@ -192,12 +182,12 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
|
|||
self.close()
|
||||
if (controlID == 118):
|
||||
# Settings button
|
||||
prev_settings = self.get_settings()
|
||||
prev_settings = common.get_settings()
|
||||
__settings__.openSettings()
|
||||
p = xbmcgui.DialogProgress()
|
||||
p.create(_(0), _(1)) # 'Transmission', 'Connecting to Transmission'
|
||||
try:
|
||||
self.transmission = self.get_rpc_client()
|
||||
self.transmission = common.get_rpc_client()
|
||||
self.updateTorrents()
|
||||
p.close()
|
||||
except:
|
||||
|
@ -206,7 +196,7 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
|
|||
# restore settings
|
||||
self.set_settings(prev_settings)
|
||||
try:
|
||||
self.transmission = self.get_rpc_client()
|
||||
self.transmission = common.get_rpc_client()
|
||||
except err:
|
||||
xbmcgui.Dialog().ok(_(2), _(9001))
|
||||
self.close()
|
||||
|
|
57
resources/lib/player.py
Normal file
57
resources/lib/player.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
# -*- 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()
|
||||
if self.active and xbmc.Player().isPlayingVideo():
|
||||
self.stopAllTorrents()
|
||||
|
||||
def onPlayBackStopped(self):
|
||||
self.refreshSettings()
|
||||
if self.active:
|
||||
self.startAllTorrents()
|
||||
|
||||
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)
|
||||
|
||||
def refreshSettings(self):
|
||||
settings = common.get_settings()
|
||||
if settings != self.prev_settings:
|
||||
self.active = (settings['stop_all_on_playback'] == 'true')
|
||||
try:
|
||||
self.transmission = common.get_rpc_client()
|
||||
except:
|
||||
self.transmission = None
|
||||
self.prev_settings = settings
|
||||
|
||||
player = SubstitutePlayer()
|
||||
|
||||
while (not xbmc.abortRequested):
|
||||
xbmc.sleep(5000);
|
|
@ -5,4 +5,5 @@
|
|||
<setting id="rpc_port" type="number" label="1002" default="9091" />
|
||||
<setting id="rpc_user" type="text" label="1003" default="" />
|
||||
<setting id="rpc_password" type="text" option="hidden" label="1004" default="" />
|
||||
<setting id="stop_all_on_playback" type="bool" label="1005" default="false" />
|
||||
</settings>
|
||||
|
|
Loading…
Reference in a new issue