def do_help(self, infohash, torrent_data, permid): basename = binascii.hexlify( infohash) + '.torrent' # ignore .tribe stuff, not vital torrentfilename = os.path.join(self.helpdir, basename) tfile = open(torrentfilename, "wb") tfile.write(torrent_data) tfile.close() if DEBUG: print >> sys.stderr, "helpmsg: Got metadata required for helping", show_permid_short( permid) print >> sys.stderr, "helpmsg: torrent: ", torrentfilename tdef = TorrentDef.load(torrentfilename) if self.dlconfig is None: dscfg = DownloadStartupConfig() else: dscfg = DownloadStartupConfig(self.dlconfig) dscfg.set_coopdl_coordinator_permid(permid) dscfg.set_dest_dir(self.helpdir) # Start new download self.session.start_download(tdef, dscfg)
def start_torrent(self, torrent): tdef = TorrentDef.load(torrent) if not os.access(self._directory, os.F_OK): os.makedirs(self._directory) dscfg = DownloadStartupConfig() dscfg.set_dest_dir(self._directory) dscfg.set_video_events([ simpledefs.VODEVENT_START, simpledefs.VODEVENT_PAUSE, simpledefs.VODEVENT_RESUME ]) dscfg.set_max_speed(simpledefs.DOWNLOAD, self._max_dl_rate) dscfg.set_max_speed(simpledefs.UPLOAD, self._max_ul_rate) dscfg.set_peer_type("S") #dscfg.set_video_event_callback(self.video_callback) # supporter should not play the files ! d = self._session.start_download(tdef, dscfg) d.set_state_callback(self.state_callback) time.sleep(1) # give the download some time to fully initialize d.sd.dow.choker.set_supporter_server(True) self._tracker_url = tdef.get_tracker()[:tdef.get_tracker(). find("announce")] self._id = d.sd.peerid self._choke_objects.append(d.sd.dow.choker)
def setUpDownloadConfig(self): dscfg = DownloadStartupConfig() print >>sys.stderr,"test: Downloading to",self.config_path dscfg.set_dest_dir(self.config_path) dscfg.set_breakup_seed_bitfield(False) return dscfg
def get_coopdlconfig(self): """ Return the DownloadStartupConfig that is used when helping others in a cooperative download. @return DownloadStartupConfig """ dlconfig = self.sessconfig['coopdlconfig'] if dlconfig is None: return None else: from BaseLib.Core.DownloadConfig import DownloadStartupConfig return DownloadStartupConfig(dlconfig)
def setUpPostSession(self): """ override TestAsServer """ TestAsServer.setUpPostSession(self) # Let Tribler start downloading an non-functioning torrent, so # we can talk to a normal download engine. self.torrentfn = os.path.join('extend_hs_dir', 'dummydata.merkle.torrent') tdef = TorrentDef.load(self.torrentfn) dscfg = DownloadStartupConfig() dscfg.set_dest_dir(self.config_path) dscfg.set_video_event_callback(self.vod_ready_callback) self.d = self.session.start_download(tdef, dscfg) # This is the infohash of the torrent in test/extend_hs_dir self.infohash = '\xccg\x07\xe2\x9e!]\x16\xae{\xb8\x10?\xf9\xa5\xf9\x07\xfdBk' self.mylistenport = 4810
# tdef.get_tracker() returns the announce-url; we must omit the "announce" part tracker_url = tdef.get_tracker()[:tdef.get_tracker().find("announce")] if tdef.get_bitrate() == None: print >> sys.stderr, "Provided torrent file has no bitrate information. Exiting." sys.exit(1) BITRATE = tdef.get_bitrate() print >> sys.stderr, "Calculated bitrate is %d" % BITRATE client_stats['video_duration'] = int(tdef.get_length() / tdef.get_bitrate()) if not os.access(options.directory, os.F_OK): os.makedirs(options.directory) dscfg = DownloadStartupConfig() dscfg.set_dest_dir(options.directory) global my_dir my_dir = options.directory dscfg.set_video_events([ simpledefs.VODEVENT_START, simpledefs.VODEVENT_PAUSE, simpledefs.VODEVENT_RESUME ]) dscfg.set_video_event_callback(vod_event_callback) dscfg.set_max_speed(simpledefs.DOWNLOAD, options.dlrate) dscfg.set_max_speed(simpledefs.UPLOAD, options.ulrate) if dscfg.get_mode() == simpledefs.DLMODE_VOD: print >> sys.stderr, 'Client runs in streaming mode' d = s.start_download(tdef, dscfg)
def setUpDownloadConfig(self): dscfg = DownloadStartupConfig() dscfg.set_dest_dir(self.config_path) return dscfg