import xbmc
import xbmcgui
import requests
from xbmctorrent import plugin, torrent2http

class TorrentPlayer(xbmc.Player):
    # def __init__(self, *args, **kwargs):
    #     super(TorrentPlayer).__init__(self, *args, **kwargs)

    def init(self, magnet_uri):
        self.magnet_uri = magnet_uri
        self.torrent2http = torrent2http.start(magnet=magnet_uri)
        xbmc.sleep(1000)
        self.dialog = xbmcgui.DialogProgress()
        self.dialog_hidden = True
        self.status = {}
        self.is_playing = False
        self.is_paused = False
        self.is_stopped = False
        return self

    def show_dialog(self):
        if self.dialog_hidden:
            self.dialog_hidden = False
            self.dialog.create(plugin.name)

    def hide_dialog(self):
        if not self.dialog_hidden:
            self.dialog_hidden = True
            self.dialog.close()

    def onPlayBackStarted(self):
        self.is_playing = True
        self.is_paused = False
        self.is_stopped = False
        self.hide_dialog()

    def onPlayBackResumed(self):
        self.onPlayBackStarted()

    def onPlayBackPaused(self):
        self.is_playing = False
        self.is_paused = True
        self.is_stopped = False

    def onPlayBackStopped(self):
        self.is_playing = False
        self.is_paused = False
        self.is_stopped = True

    def loop(self):
        state_str = ['Queued', 'Checking', 'Downloading metadata', \
                     'Downloading', 'Finished', 'Seeding', 'Allocating', "Checking resume data"]

        has_resolved = False
        self.show_dialog()
        while not xbmc.abortRequested:
            if self.is_stopped:
                self.torrent2http.terminate()
                return

            if self.dialog.iscanceled():
                self.hide_dialog()
                self.torrent2http.terminate()
                return

            status = requests.get("http://localhost:5000/status").json()
            if not self.dialog_hidden:
                xbmc.log(repr(status))
                if status["state"] >= 0:
                    self.dialog.update(
                        int(status["progress"] * 100),
                        state_str[status["state"]],
                        "%.2f%% D:%.2fkb/s U:%.2fkb/s" % (status["progress"] * 100, status["download_rate"], status["upload_rate"]),
                        "S:%d P:%d" % (status["num_seeds"], status["num_peers"])
                    )

            if self.is_paused:
                plugin.notify(
                    "%.2f%% D:%.2fkb/s U:%.2fkb/s" % (status["progress"] * 100, status["download_rate"], status["upload_rate"]),
                    "XBMCtorrent - %s" % state_str[status["state"]],
                    delay=1000)

            if status["total_pieces"] > 0 and not has_resolved:
                percentage = float(status["max_piece"]) / float(status["total_pieces"]) * 100.0
                if percentage >= 0.5: # we can start playback at 0.5%
                    has_resolved = True
                    plugin.set_resolved_url({
                        "path": "http://localhost:5000/file",
                        "is_playable": True,
                    })
            xbmc.sleep(1000)

@@ -1614,19 +1614,36 @@
   while 
-not
+True:%0A            if
  xbmc.ab
@@ -1654,32 +1654,19 @@
 equested
-:%0A            if
+ or
  self.is

Make sure we kill torrent2http when we quit XBMC in Play