Example #1
0
    def _start_download(self, torrent):
        tdef = TorrentDef.load(torrent)
        dscfg = DownloadStartupConfig()
        #disable PEX protocol, otherwise it will crash if two clients are running on the same machine!
        #dscfg.set_ut_pex_max_addrs_from_peer(0)

        dscfg.set_dest_dir(self._config.get_directory())
        if common_utils.has_torrent_video_files(
                tdef) and not self._config.is_supporter_seed():
            dscfg.set_video_event_callback(self._handlers.video_event_callback)
        self._logger.warn("Download directory: " + dscfg.get_dest_dir())
        dscfg.set_max_speed(UPLOAD, self._config.get_upload_limit())
        dscfg.set_max_speed(DOWNLOAD, self._config.get_download_limit())
        con_lim = self._config.get_connection_limit()
        dscfg.set_max_conns(con_lim)
        dscfg.set_max_conns_to_initiate((con_lim + 1) / 2)
        dscfg.set_min_peers((con_lim + 2) / 3)
        dscfg.set_max_uploads(self._config.get_max_upload_slots_per_download())
        dscfg.set_peer_type("G")

        self._logger.warn("Files available: %s" % tdef.get_files())

        if dscfg.get_mode() == DLMODE_VOD:
            self._logger.warn("RUN in streaming mode")
            if tdef.is_multifile_torrent():
                for file in tdef.get_files():
                    if file.endswith(".avi"):
                        dscfg.set_selected_files([file])
                        break
        else:
            self._logger.warn("RUN in file sharing mode")

        d = self._session.start_download(tdef, dscfg)
        d.set_state_callback(self._handlers.state_callback, getpeerlist=True)
 def _start_download(self, torrent):
     tdef = TorrentDef.load(torrent)
     dscfg = DownloadStartupConfig()
     #disable PEX protocol, otherwise it will crash if two clients are running on the same machine!
     #dscfg.set_ut_pex_max_addrs_from_peer(0)
     
     dscfg.set_dest_dir(self._config.get_directory())
     if common_utils.has_torrent_video_files(tdef) and not self._config.is_supporter_seed():
         dscfg.set_video_event_callback(self._handlers.video_event_callback)
     self._logger.warn("Download directory: " + dscfg.get_dest_dir())
     dscfg.set_max_speed(UPLOAD, self._config.get_upload_limit())
     dscfg.set_max_speed(DOWNLOAD, self._config.get_download_limit())
     con_lim = self._config.get_connection_limit()
     dscfg.set_max_conns(con_lim)
     dscfg.set_max_conns_to_initiate((con_lim+1)/2)
     dscfg.set_min_peers((con_lim+2)/3)
     dscfg.set_max_uploads(self._config.get_max_upload_slots_per_download())
     dscfg.set_peer_type("G")
     
     self._logger.warn("Files available: %s" % tdef.get_files())
     
     if dscfg.get_mode() == DLMODE_VOD:
         self._logger.warn("RUN in streaming mode")
         if tdef.is_multifile_torrent():
             for file in tdef.get_files():
                 if file.endswith(".avi"):
                     dscfg.set_selected_files([file])
                     break
     else:
         self._logger.warn("RUN in file sharing mode")
         
     d = self._session.start_download(tdef, dscfg)
     d.set_state_callback(self._handlers.state_callback, getpeerlist=True)
 def test_tdef_has_video_files_expected_false(self):
     try:
         tdef = TorrentDef.load("torrents/ubuntu.torrent")
         self.assertFalse(has_torrent_video_files(tdef))
     except:
         self.fail("There was an error while loading the torrent files.")
 def test_tdef_has_video_files_expected_true(self):
     try:
         tdef = TorrentDef.load("torrents/Locality-Demo.mp4.tstream")
         self.assertTrue(has_torrent_video_files(tdef))
     except:
         self.fail("There was some error while loading the torrent file.")
 def test_tdef_has_video_files_expected_false(self):
     try:
         tdef = TorrentDef.load("torrents/ubuntu.torrent")
         self.assertFalse(has_torrent_video_files(tdef))
     except:
         self.fail("There was an error while loading the torrent files.")
 def test_tdef_has_video_files_expected_true(self):
     try:
         tdef = TorrentDef.load("torrents/Locality-Demo.mp4.tstream")
         self.assertTrue(has_torrent_video_files(tdef))
     except:
         self.fail("There was some error while loading the torrent file.")