Added option to restart torrents that were previously seeding.

Signed-off-by: TheHacker66 <thehacker66@gmail.com>
This commit is contained in:
TheHacker66 2015-02-26 21:06:26 +01:00
parent 6fc904637b
commit e642a93f81
4 changed files with 18 additions and 3 deletions

View file

@ -172,8 +172,12 @@ msgctxt "#32805"
msgid "Stop all torrents on video playback" msgid "Stop all torrents on video playback"
msgstr "" msgstr ""
msgctxt "#32806"
msgid "When finished, also restart torrents that were previously seeding"
msgstr ""
#Errors #Errors
#empty strings from id 32806 to 32899 #empty strings from id 32807 to 32899
msgctxt "#32900" msgctxt "#32900"
msgid "An unexpected error occurred" msgid "An unexpected error occurred"

View file

@ -12,7 +12,8 @@ def get_settings():
'port': __settings__.getSetting('rpc_port'), 'port': __settings__.getSetting('rpc_port'),
'user': __settings__.getSetting('rpc_user'), 'user': __settings__.getSetting('rpc_user'),
'password': __settings__.getSetting('rpc_password'), 'password': __settings__.getSetting('rpc_password'),
'stop_all_on_playback': __settings__.getSetting('stop_all_on_playback') 'stop_all_on_playback': __settings__.getSetting('stop_all_on_playback'),
'restart_if_was_seeding': __settings__.getSetting('restart_if_was_seeding')
} }
return params return params

View file

@ -17,6 +17,7 @@ class SubstitutePlayer(xbmc.Player):
def __init__(self): def __init__(self):
xbmc.Player.__init__(self) xbmc.Player.__init__(self)
self.prev_settings = {} self.prev_settings = {}
self.wasSeeding = []
self.refreshSettings() self.refreshSettings()
def onPlayBackStarted(self): def onPlayBackStarted(self):
@ -30,15 +31,23 @@ class SubstitutePlayer(xbmc.Player):
self.startAllTorrents() self.startAllTorrents()
def startAllTorrents(self): def startAllTorrents(self):
settings = common.get_settings()
if self.transmission: if self.transmission:
torrents = self.transmission.list() torrents = self.transmission.list()
for tid, torrent in torrents.iteritems(): for tid, torrent in torrents.iteritems():
self.transmission.start(tid) if settings['restart_if_was_seeding'] == 'true':
self.transmission.start(tid)
else :
if tid not in self.wasSeeding:
self.transmission.start(tid)
def stopAllTorrents(self): def stopAllTorrents(self):
settings = common.get_settings()
if self.transmission: if self.transmission:
torrents = self.transmission.list() torrents = self.transmission.list()
for tid, torrent in torrents.iteritems(): for tid, torrent in torrents.iteritems():
if settings['restart_if_was_seeding'] == 'true' and torrent.status == "seeding":
self.wasSeeding.append(tid)
self.transmission.stop(tid) self.transmission.stop(tid)
def refreshSettings(self): def refreshSettings(self):

View file

@ -6,4 +6,5 @@
<setting id="rpc_user" type="text" label="32803" default="" /> <setting id="rpc_user" type="text" label="32803" default="" />
<setting id="rpc_password" type="text" option="hidden" label="32804" default="" /> <setting id="rpc_password" type="text" option="hidden" label="32804" default="" />
<setting id="stop_all_on_playback" type="bool" label="32805" default="false" /> <setting id="stop_all_on_playback" type="bool" label="32805" default="false" />
<setting id="restart_if_was_seeding" type="bool" label="32806" enable="eq(-1,true)" default="false" />
</settings> </settings>