Exemple #1
0
    def loop(self):
        from xbmctorrent.utils import SafeDialogProgress

        has_resolved = False

        plugin.log.info("Starting torrent2http...")
        with closing(torrent2http.start(**self.torrent2http_options)) as t2h_instance:
            t2h = lambda cmd: url_get_json("http://%s/%s" % (t2h_instance.bind_address, cmd), with_immunicity=False)

            if not self._wait_t2h_startup(t2h):
                return

            plugin.log.info("Opening download dialog...")
            with closing(SafeDialogProgress(delay_create=0)) as dialog:
                dialog.create(plugin.name)

                plugin.log.info("Waiting for file resolution...")
                while not has_resolved:
                    if xbmc.abortRequested or dialog.iscanceled():
                        return

                    status = t2h("status")
                    self.display_name = status["name"]

                    if status["state"] < 3:
                        dialog.update(0, *self._get_status_lines(status))
                    if status["state"] >= 3 and not has_resolved: # Downloading?
                        files = t2h("ls")["files"]
                        biggest_file = sorted(files, key=lambda x: x["size"])[-1]
                        biggest_file["name"] = biggest_file["name"].encode("utf-8")
                        dialog.update(int(biggest_file["buffer"] * 100.0), *self._get_status_lines(status))

                        if biggest_file["buffer"] >= 1.0:
                            plugin.log.info("Resolving to http://%s/files/%s" % (t2h_instance.bind_address, biggest_file["name"]))
                            has_resolved = True
                            item = {
                                "path": "http://%s/files/%s" % (t2h_instance.bind_address, urllib.quote(biggest_file["name"])),
                            }
                            if not xbmc.getInfoLabel("ListItem.Title"):
                                item["label"] = self.display_name
                            plugin.set_resolved_url(item)
                            break

                    xbmc.sleep(TORRENT2HTTP_POLL)

            # We are now playing
            plugin.log.info("Now playing torrent...")
            last_playing_event = 0
            with closing(OverlayText(w=OVERLAY_WIDTH, h=OVERLAY_HEIGHT, alignment=XBFONT_CENTER_X | XBFONT_CENTER_Y)) as overlay:
                with nested(self.attach(overlay.show, self.on_playback_paused),
                            self.attach(overlay.hide, self.on_playback_resumed, self.on_playback_stopped)):
                    while not xbmc.abortRequested and self.isPlaying():
                        overlay.text = "\n".join(self._get_status_lines(t2h("status")))
                        now = time.time()
                        if (now - last_playing_event) > PLAYING_EVENT_INTERVAL:
                            track_event("video", "playing", self.display_name)
                            last_playing_event = now
                        xbmc.sleep(TORRENT2HTTP_POLL)

        plugin.log.info("Closing Torrent player.")
Exemple #2
0
    def loop(self):
        from xbmctorrent.utils import SafeDialogProgress

        has_resolved = False

        plugin.log.info("Starting torrent2http...")
        with closing(torrent2http.start(**self.torrent2http_options)) as t2h_instance:
            t2h = lambda cmd: url_get_json("http://%s/%s" % (t2h_instance.bind_address, cmd), with_immunicity=False)

            if not self._wait_t2h_startup(t2h):
                return

            plugin.log.info("Opening download dialog...")
            with closing(SafeDialogProgress(delay_create=0)) as dialog:
                dialog.create(plugin.name)

                plugin.log.info("Waiting for file resolution...")
                while not has_resolved:
                    if xbmc.abortRequested or dialog.iscanceled():
                        return

                    status = t2h("status")
                    self.display_name = status["name"]

                    if status["state"] < 3:
                        dialog.update(0, *self._get_status_lines(status))
                    if status["state"] >= 3 and not has_resolved: # Downloading?
                        files = t2h("ls")["files"]
                        biggest_file = sorted(files, key=lambda x: x["size"])[-1]
                        biggest_file["name"] = biggest_file["name"].encode("utf-8")
                        dialog.update(int(biggest_file["buffer"] * 100.0), *self._get_status_lines(status))

                        if biggest_file["buffer"] >= 1.0:
                            plugin.log.info("Resolving to http://%s/files/%s" % (t2h_instance.bind_address, biggest_file["name"]))
                            has_resolved = True
                            item = {
                                "path": "http://%s/files/%s" % (t2h_instance.bind_address, urllib.quote(biggest_file["name"])),
                            }
                            if not xbmc.getInfoLabel("ListItem.Title"):
                                item["label"] = self.display_name
                            plugin.set_resolved_url(item)
                            break

                    xbmc.sleep(TORRENT2HTTP_POLL)

            # We are now playing
            plugin.log.info("Now playing torrent...")
            last_playing_event = 0
            with closing(OverlayText(w=OVERLAY_WIDTH, h=OVERLAY_HEIGHT, alignment=XBFONT_CENTER_X | XBFONT_CENTER_Y)) as overlay:
                with nested(self.attach(overlay.show, self.on_playback_paused),
                            self.attach(overlay.hide, self.on_playback_resumed, self.on_playback_stopped)):
                    while not xbmc.abortRequested and self.isPlaying():
                        overlay.text = "\n".join(self._get_status_lines(t2h("status")))
                        now = time.time()
                        if (now - last_playing_event) > PLAYING_EVENT_INTERVAL:
                            track_event("video", "playing", self.display_name)
                            last_playing_event = now
                        xbmc.sleep(TORRENT2HTTP_POLL)

        plugin.log.info("Closing Torrent player.")
Exemple #3
0
 def onPlayBackStarted(self):
     for f in self.on_playback_started:
         f()
     try: tagname = xbmc.Player().getPlayingFile()[xbmc.Player().getPlayingFile().index('%5C')+3:-4]
     except: tagname = xbmc.Player().getPlayingFile()[xbmc.Player().getPlayingFile().index('/files/')+7:-4]
     if getSetting("subtitles") == 'true': self.subtitle = subtitles.getsubtitles(self.display_name,tagname, '', '',getSetting("sublang1"),getSetting("sublang2"))			
     self.setSubtitles(self.subtitle)
     track_event("video", "play", self.display_name)
Exemple #4
0
 def init(self, magnet_uri):
     track_event("torrent_player", "start")
     self.magnet_uri = magnet_uri
     self.magnet_args = urlparse.parse_qs(self.magnet_uri.replace("magnet:?", "")) # I know about urlparse.urlsplit but this is faster
     self.magnet_display_name = ""
     if self.magnet_args["dn"]:
         self.magnet_display_name = self.magnet_args["dn"][0]
     self.torrent2http_options = {
         "magnet": magnet_uri,
         "dlpath": plugin.get_setting("dlpath") or ".",
         "dlrate": plugin.get_setting("max_download_rate") or "0",
         "ulrate": plugin.get_setting("max_upload_rate") or "0",
         "ulrate": plugin.get_setting("max_upload_rate") or "0",
         "encryption": plugin.get_setting("encryption"),
     }
     if plugin.get_setting("keep"):
         self.torrent2http_options["keep"] = None
     track_event("download", "start", magnet_uri)
     self.on_playback_started = []
     self.on_playback_resumed = []
     self.on_playback_paused = []
     self.on_playback_stopped = []
     return self
Exemple #5
0
 def onPlayBackStopped(self):
     for f in self.on_playback_stopped:
         f()
     track_event("video", "stop", self.display_name)
Exemple #6
0
 def onPlayBackPaused(self):
     for f in self.on_playback_paused:
         f()
     track_event("video", "pause", self.display_name)
Exemple #7
0
 def onPlayBackStarted(self):
     for f in self.on_playback_started:
         f()
     track_event("video", "play", self.display_name)
Exemple #8
0
 def onPlayBackStopped(self):
     for f in self.on_playback_stopped:
         f()
     track_event("video", "stop", self.display_name)
Exemple #9
0
 def onPlayBackPaused(self):
     for f in self.on_playback_paused:
         f()
     track_event("video", "pause", self.display_name)
Exemple #10
0
 def onPlayBackStarted(self):
     for f in self.on_playback_started:
         f()
     track_event("video", "play", self.display_name)
Exemple #11
0
    def loop(self):
        from xbmctorrent.utils import SafeDialogProgress

        has_resolved = False

        plugin.log.info("Starting torrent2http...")
        with closing(torrent2http.start(**self.torrent2http_options)) as t2h_instance:
            t2h = lambda cmd: url_get_json("http://%s/%s" % (t2h_instance.bind_address, cmd), with_immunicity=False)

            track_event("video", "download", self.magnet_display_name)

            if not self._wait_t2h_startup(t2h):
                return

            plugin.log.info("Opening download dialog...")
            with closing(SafeDialogProgress(delay_create=0)) as dialog:
                dialog.create(plugin.name)

                plugin.log.info("Waiting for file resolution...")
                while not has_resolved:
                    if xbmc.abortRequested or dialog.iscanceled():
                        return

                    status = t2h("status")

                    if status["state"] >= 0:
                        dialog.update(int(status["progress"] * 100), *self._get_status_lines(status))

                    if status["state"] >= 3 and not has_resolved:  # Downloading?
                        files = t2h("ls")["files"]
                        biggest_file = sorted(files, key=lambda x: x["size"])[-1]
                        percent_complete = (
                            float(biggest_file["complete_pieces"]) / float(biggest_file["total_pieces"]) * 100.0
                        )

                        if percent_complete >= 0.5:
                            plugin.log.info(
                                "Resolving to http://%s/files/%s" % (t2h_instance.bind_address, biggest_file["name"])
                            )
                            has_resolved = True
                            url_name = "/".join(map(urllib.quote, biggest_file["name"].split("/")))
                            plugin.set_resolved_url(
                                {
                                    "label": self.magnet_display_name,
                                    "label2": self.magnet_display_name,
                                    "path": "http://%s/files/%s" % (t2h_instance.bind_address, url_name),
                                    "is_playable": True,
                                }
                            )
                            break

                    xbmc.sleep(TORRENT2HTTP_POLL)

            # We are now playing
            plugin.log.info("Now playing torrent...")
            last_playing_event = 0
            with closing(
                OverlayText(w=OVERLAY_WIDTH, h=OVERLAY_HEIGHT, alignment=XBFONT_CENTER_X | XBFONT_CENTER_Y)
            ) as overlay:
                with nested(
                    self.attach(overlay.show, self.on_playback_paused),
                    self.attach(overlay.hide, self.on_playback_resumed, self.on_playback_stopped),
                ):
                    while not xbmc.abortRequested and self.isPlaying():
                        overlay.text = "\n".join(self._get_status_lines(t2h("status")))
                        now = time.time()
                        if (now - last_playing_event) > PLAYING_EVENT_INTERVAL:
                            track_event("video", "playing", self.magnet_display_name)
                            last_playing_event = now
                        xbmc.sleep(TORRENT2HTTP_POLL)

        plugin.log.info("Closing Torrent player.")
Exemple #12
0
    def loop(self):
        from xbmctorrent.utils import SafeDialogProgress

        has_resolved = False

        plugin.log.info("Starting torrent2http...")
        with closing(torrent2http.start(
                **self.torrent2http_options)) as t2h_instance:
            t2h = lambda cmd: url_get_json("http://%s/%s" %
                                           (t2h_instance.bind_address, cmd))

            track_event("video", "download", self.magnet_display_name)

            if not self._wait_t2h_startup(t2h):
                return

            plugin.log.info("Opening download dialog...")
            with closing(SafeDialogProgress(delay_create=0)) as dialog:
                dialog.create(plugin.name)

                plugin.log.info("Waiting for file resolution...")
                while not has_resolved:
                    if xbmc.abortRequested or dialog.iscanceled():
                        return

                    status = t2h("status")

                    if status["state"] >= 0:
                        dialog.update(int(status["progress"] * 100),
                                      *self._get_status_lines(status))

                    if status[
                            "state"] >= 3 and not has_resolved:  # Downloading?
                        files = t2h("ls")["files"]
                        biggest_file = sorted(files,
                                              key=lambda x: x["size"])[-1]
                        percent_complete = float(
                            biggest_file["complete_pieces"]) / float(
                                biggest_file["total_pieces"]) * 100.0

                        if percent_complete >= 0.5:
                            plugin.log.info("Resolving to http://%s/files/%s" %
                                            (t2h_instance.bind_address,
                                             biggest_file["name"]))
                            has_resolved = True
                            url_name = "/".join(
                                map(urllib.quote,
                                    biggest_file["name"].split("/")))
                            plugin.set_resolved_url({
                                "label":
                                self.magnet_display_name,
                                "label2":
                                self.magnet_display_name,
                                "path":
                                "http://%s/files/%s" %
                                (t2h_instance.bind_address, url_name),
                                "is_playable":
                                True,
                            })
                            break

                    xbmc.sleep(TORRENT2HTTP_POLL)

            # We are now playing
            plugin.log.info("Now playing torrent...")
            last_playing_event = 0
            with closing(
                    OverlayText(w=OVERLAY_WIDTH,
                                h=OVERLAY_HEIGHT,
                                alignment=XBFONT_CENTER_X
                                | XBFONT_CENTER_Y)) as overlay:
                with nested(
                        self.attach(overlay.show, self.on_playback_paused),
                        self.attach(overlay.hide, self.on_playback_resumed,
                                    self.on_playback_stopped)):
                    while not xbmc.abortRequested and self.isPlaying():
                        overlay.text = "\n".join(
                            self._get_status_lines(t2h("status")))
                        now = time.time()
                        if (now - last_playing_event) > PLAYING_EVENT_INTERVAL:
                            track_event("video", "playing",
                                        self.magnet_display_name)
                            last_playing_event = now
                        xbmc.sleep(TORRENT2HTTP_POLL)

        plugin.log.info("Closing Torrent player.")