-
Notifications
You must be signed in to change notification settings - Fork 3
/
player.py
54 lines (43 loc) · 1.5 KB
/
player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
# Copyright (c) 2013 Paul Price, Artem Glebov
from kodi_six import xbmc
from resources.lib import common
from resources.lib import transmissionrpc
from six import iteritems
import sys
class SubstitutePlayer(xbmc.Player):
def __init__(self):
xbmc.Player.__init__(self)
self.prev_settings = {}
self.refreshSettings()
def onAVStarted(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 iteritems(torrents):
self.transmission.start(tid)
def stopAllTorrents(self):
if self.transmission:
torrents = self.transmission.list()
for tid, torrent in iteritems(torrents):
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.Monitor().waitForAbort(1):
del player
sys.exit(0)