Exemple #1
0
    def setup(self):
        """
        This sets up a Tribler session, loads the managers and the XML-RPC server.
        :return: Nothing.
        """

        _logger.error("Loading XMLRPCServer")
        print "----------------------Loading XMLRPCServer"
        self.xmlrpc = XMLRPCServer(iface="0.0.0.0", port=8000)

        _logger.error("Loading TriblerSessionService")
        print "----------------------Loading TriblerSessionService"
        self.tribler = TriblerSession(self.xmlrpc)
        self.tribler.start_session()

        # Wait for dispersy to initialize
        print "----------------------Waiting for Dispersy to initialize"
        while not self.tribler.is_running():
            time.sleep(0.1)
        print "----------------------Dispersy is initialized!"

        # Disable ChannelManager
        #_logger.error("Loading ChannelManager")
        #self.cm = ChannelManager.getInstance(self.tribler.get_session(), self.xmlrpc)

        _logger.error("Loading TorrentManager")
        print "----------------------Loading TorrentManager"
        self.tm = TorrentManager.getInstance(self.tribler.get_session(),
                                             self.xmlrpc)

        _logger.error("Loading DownloadManager")
        print "----------------------Loading DownloadManager"
        self.dm = DownloadManager.getInstance(self.tribler.get_session(),
                                              self.xmlrpc)

        _logger.error("Loading ConfigurationManager")
        print "----------------------Loading ConfigurationManager"
        # Load this last because it sets settings in other managers
        self.sm = SettingsManager.getInstance(self.tribler.get_session(),
                                              self.xmlrpc)

        _logger.error("Now running XMLRPC on http://%s:%s/tribler" %
                      (self.xmlrpc._iface, self.xmlrpc._port))
        print "----------------------Now running XMLRPC on http://%s:%s/tribler" % (
            self.xmlrpc._iface, self.xmlrpc._port)
        self.xmlrpc.start_server()

        # TODO: test streaming:
        tdef = TorrentDef.load_from_url(URL)
        if tdef is None:
            raise TypeError('Torrent could not be loaded from ' + URL +
                            '. Check if you\'ve got an internet connection.')
        self.info_hash = hexlify(tdef.get_infohash())
        #self.tribler.get_session().set_install_dir(FILES_DIR + u'/lib/python2.7/site-packages')
        self.dm.add_torrent(self.info_hash, tdef.get_name())

        Clock.schedule_interval(lambda dt: self.poller(), 3.0)
Exemple #2
0
    def setup(self):
        """
        This sets up a Tribler session, loads the managers and the XML-RPC server.
        :return: Nothing.
        """

        _logger.error("Loading XMLRPCServer")
        print "----------------------Loading XMLRPCServer"
        self.xmlrpc = XMLRPCServer(iface="0.0.0.0", port=8000)

        _logger.error("Loading TriblerSessionService")
        print "----------------------Loading TriblerSessionService"
        self.tribler = TriblerSession(self.xmlrpc)
        self.tribler.start_session()

        # Wait for dispersy to initialize
        print "----------------------Waiting for Dispersy to initialize"
        while not self.tribler.is_running():
            time.sleep(0.1)
        print "----------------------Dispersy is initialized!"

        # Disable ChannelManager
        #_logger.error("Loading ChannelManager")
        #self.cm = ChannelManager.getInstance(self.tribler.get_session(), self.xmlrpc)

        _logger.error("Loading TorrentManager")
        print "----------------------Loading TorrentManager"
        self.tm = TorrentManager.getInstance(self.tribler.get_session(), self.xmlrpc)

        _logger.error("Loading DownloadManager")
        print "----------------------Loading DownloadManager"
        self.dm = DownloadManager.getInstance(self.tribler.get_session(), self.xmlrpc)

        _logger.error("Loading ConfigurationManager")
        print "----------------------Loading ConfigurationManager"
        # Load this last because it sets settings in other managers
        self.sm = SettingsManager.getInstance(self.tribler.get_session(), self.xmlrpc)

        _logger.error("Now running XMLRPC on http://%s:%s/tribler" % (self.xmlrpc._iface, self.xmlrpc._port))
        print "----------------------Now running XMLRPC on http://%s:%s/tribler" % (self.xmlrpc._iface, self.xmlrpc._port)
        self.xmlrpc.start_server()

        # TODO: test streaming:
        tdef = TorrentDef.load_from_url(URL)
        if tdef is None:
            raise TypeError('Torrent could not be loaded from ' + URL + '. Check if you\'ve got an internet connection.')
        self.info_hash = hexlify(tdef.get_infohash())
        #self.tribler.get_session().set_install_dir(FILES_DIR + u'/lib/python2.7/site-packages')
        self.dm.add_torrent(self.info_hash, tdef.get_name())

        Clock.schedule_interval(lambda dt: self.poller(), 3.0)
Exemple #3
0
class TriblerPlay(App):

    tribler = None
    xmlrpc = None
    dm = None
    tm = None
    cm = None

    info_hash = None
    in_vod_mode = False
    started_streaming = False
    vod_uri = None

    # Called by Kivy
    def build(self):
        self.text_input = TextInput(text='Placeholder')
        print "----------------------RUNNING TRIBLER SETUP"
        tribler_play.setup()
        return self.text_input

    def setup(self):
        """
        This sets up a Tribler session, loads the managers and the XML-RPC server.
        :return: Nothing.
        """

        _logger.error("Loading XMLRPCServer")
        print "----------------------Loading XMLRPCServer"
        self.xmlrpc = XMLRPCServer(iface="0.0.0.0", port=8000)

        _logger.error("Loading TriblerSessionService")
        print "----------------------Loading TriblerSessionService"
        self.tribler = TriblerSession(self.xmlrpc)
        self.tribler.start_session()

        # Wait for dispersy to initialize
        print "----------------------Waiting for Dispersy to initialize"
        while not self.tribler.is_running():
            time.sleep(0.1)
        print "----------------------Dispersy is initialized!"

        # Disable ChannelManager
        #_logger.error("Loading ChannelManager")
        #self.cm = ChannelManager.getInstance(self.tribler.get_session(), self.xmlrpc)

        _logger.error("Loading TorrentManager")
        print "----------------------Loading TorrentManager"
        self.tm = TorrentManager.getInstance(self.tribler.get_session(),
                                             self.xmlrpc)

        _logger.error("Loading DownloadManager")
        print "----------------------Loading DownloadManager"
        self.dm = DownloadManager.getInstance(self.tribler.get_session(),
                                              self.xmlrpc)

        _logger.error("Loading ConfigurationManager")
        print "----------------------Loading ConfigurationManager"
        # Load this last because it sets settings in other managers
        self.sm = SettingsManager.getInstance(self.tribler.get_session(),
                                              self.xmlrpc)

        _logger.error("Now running XMLRPC on http://%s:%s/tribler" %
                      (self.xmlrpc._iface, self.xmlrpc._port))
        print "----------------------Now running XMLRPC on http://%s:%s/tribler" % (
            self.xmlrpc._iface, self.xmlrpc._port)
        self.xmlrpc.start_server()

        # TODO: test streaming:
        tdef = TorrentDef.load_from_url(URL)
        if tdef is None:
            raise TypeError('Torrent could not be loaded from ' + URL +
                            '. Check if you\'ve got an internet connection.')
        self.info_hash = hexlify(tdef.get_infohash())
        #self.tribler.get_session().set_install_dir(FILES_DIR + u'/lib/python2.7/site-packages')
        self.dm.add_torrent(self.info_hash, tdef.get_name())

        Clock.schedule_interval(lambda dt: self.poller(), 3.0)
        # TODO: end test streaming.

    def stop(self):
        self.tribler.stop_session()
        self.xmlrpc = None

    def keep_running(self):
        return self.tribler.is_running()

    def poller(self):
        if self.started_streaming:
            return

        downloads = self.tribler.get_session().get_downloads()
        if len(downloads) == 0:
            print "----------------------Download not started yet."
            return
        download = downloads[0]
        print "----------------------Download progress so far: " + str(
            download.progress)

        download_progress = self.dm.get_progress(self.info_hash)
        if download_progress == False:
            print "----------------------Can't query progress yet."
            return

        #print "----------------------vod_prebuf_frac = " + download_progress['vod_prebuf_frac']
        #print "----------------------down = " + download_progress['down']
        print "----------------------vod_eta = " + str(
            download_progress['vod_eta'])
        print "----------------------vod_playable = " + str(
            download_progress['vod_playable'])
        if download_progress["vod_playable"]:
            print "----------------------Download is VOD playable, starting external VLC player."
            self.started_streaming = True
            self.start_external_android_player()
        elif (download_progress["status"] == 3
              or download_progress["status"] == 4
              or download_progress["status"] == 5) and not self.in_vod_mode:
            print "----------------------Going into VOD mode."
            self.in_vod_mode = True
            self.vod_uri = self.dm.start_vod(self.info_hash)
            if self.vod_uri is False:
                raise TypeError('Could not start VOD download mode.')
        else:
            print "----------------------Not yet in VOD mode (and therefor also not yet started streaming)."

    def start_external_android_player(self):
        self.text_input.text = self.vod_uri  # TODO: remove me, this is only for testing

        # Start the action chooser intent:
        intent = Intent(Intent.ACTION_VIEW)
        intent.setDataAndType(Uri.parse(self.vod_uri), "video/*")
        PythonActivity.mActivity.startActivity(
            Intent.createChooser(intent, "Complete action using"))

    def on_start(self):
        pass

    def on_stop(self):
        pass

    def on_pause(self):
        return True  # Needed to start external VLC

    def on_resume(self):
        pass
Exemple #4
0
class TriblerPlay(App):

    tribler = None
    xmlrpc = None
    dm = None
    tm = None
    cm = None

    info_hash = None
    in_vod_mode = False
    started_streaming = False
    vod_uri = None

    # Called by Kivy
    def build(self):
        self.text_input = TextInput(text='Placeholder')
        print "----------------------RUNNING TRIBLER SETUP"
        tribler_play.setup()
        return self.text_input

    def setup(self):
        """
        This sets up a Tribler session, loads the managers and the XML-RPC server.
        :return: Nothing.
        """

        _logger.error("Loading XMLRPCServer")
        print "----------------------Loading XMLRPCServer"
        self.xmlrpc = XMLRPCServer(iface="0.0.0.0", port=8000)

        _logger.error("Loading TriblerSessionService")
        print "----------------------Loading TriblerSessionService"
        self.tribler = TriblerSession(self.xmlrpc)
        self.tribler.start_session()

        # Wait for dispersy to initialize
        print "----------------------Waiting for Dispersy to initialize"
        while not self.tribler.is_running():
            time.sleep(0.1)
        print "----------------------Dispersy is initialized!"

        # Disable ChannelManager
        #_logger.error("Loading ChannelManager")
        #self.cm = ChannelManager.getInstance(self.tribler.get_session(), self.xmlrpc)

        _logger.error("Loading TorrentManager")
        print "----------------------Loading TorrentManager"
        self.tm = TorrentManager.getInstance(self.tribler.get_session(), self.xmlrpc)

        _logger.error("Loading DownloadManager")
        print "----------------------Loading DownloadManager"
        self.dm = DownloadManager.getInstance(self.tribler.get_session(), self.xmlrpc)

        _logger.error("Loading ConfigurationManager")
        print "----------------------Loading ConfigurationManager"
        # Load this last because it sets settings in other managers
        self.sm = SettingsManager.getInstance(self.tribler.get_session(), self.xmlrpc)

        _logger.error("Now running XMLRPC on http://%s:%s/tribler" % (self.xmlrpc._iface, self.xmlrpc._port))
        print "----------------------Now running XMLRPC on http://%s:%s/tribler" % (self.xmlrpc._iface, self.xmlrpc._port)
        self.xmlrpc.start_server()

        # TODO: test streaming:
        tdef = TorrentDef.load_from_url(URL)
        if tdef is None:
            raise TypeError('Torrent could not be loaded from ' + URL + '. Check if you\'ve got an internet connection.')
        self.info_hash = hexlify(tdef.get_infohash())
        #self.tribler.get_session().set_install_dir(FILES_DIR + u'/lib/python2.7/site-packages')
        self.dm.add_torrent(self.info_hash, tdef.get_name())

        Clock.schedule_interval(lambda dt: self.poller(), 3.0)
        # TODO: end test streaming.

    def stop(self):
        self.tribler.stop_session()
        self.xmlrpc = None

    def keep_running(self):
        return self.tribler.is_running()

    def poller(self):
        if self.started_streaming:
            return
          
        downloads = self.tribler.get_session().get_downloads()
        if len(downloads) == 0:
            print "----------------------Download not started yet."
            return
        download = downloads[0]
        print "----------------------Download progress so far: " + str(download.progress)

        download_progress = self.dm.get_progress(self.info_hash)
        if download_progress == False:
            print "----------------------Can't query progress yet."
            return

        #print "----------------------vod_prebuf_frac = " + download_progress['vod_prebuf_frac']
        #print "----------------------down = " + download_progress['down']
        print "----------------------vod_eta = " + str(download_progress['vod_eta'])
        print "----------------------vod_playable = " + str(download_progress['vod_playable'])
        if download_progress["vod_playable"]:
            print "----------------------Download is VOD playable, starting external VLC player."
            self.started_streaming = True
            self.start_external_android_player()
        elif (download_progress["status"] == 3 or download_progress["status"] == 4 or download_progress["status"] == 5) and not self.in_vod_mode:
            print "----------------------Going into VOD mode."
            self.in_vod_mode = True
            self.vod_uri = self.dm.start_vod(self.info_hash)
            if self.vod_uri is False:
                raise TypeError('Could not start VOD download mode.')
        else:
            print "----------------------Not yet in VOD mode (and therefor also not yet started streaming)."

    def start_external_android_player(self):
        self.text_input.text = self.vod_uri # TODO: remove me, this is only for testing

        # Start the action chooser intent:
        intent = Intent(Intent.ACTION_VIEW)
        intent.setDataAndType(Uri.parse(self.vod_uri), "video/*")
        PythonActivity.mActivity.startActivity(Intent.createChooser(intent, "Complete action using"))

    def on_start(self):
        pass

    def on_stop(self):
        pass

    def on_pause(self):
        return True # Needed to start external VLC

    def on_resume(self):
        pass