def new_download(self, infohash, torrent_data, permid):
     basename = binascii.hexlify(infohash) + '.torrent'
     torrentfilename = os.path.join(self.helpdir, basename)
     tfile = open(torrentfilename, 'wb')
     tfile.write(torrent_data)
     tfile.close()
     if DEBUG:
         print >> sys.stderr, 'helper: new_download: Got metadata required for helping', show_permid_short(
             permid)
         print >> sys.stderr, 'helper: new_download: 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)
     dscfg.set_proxy_mode(PROXY_MODE_OFF)
     if DEBUG:
         print >> sys.stderr, 'helper: new_download: Starting a new download'
     d = self.session.start_download(tdef, dscfg)
     d.set_state_callback(self.state_callback, getpeerlist=False)
     network_got_ask_for_help_lambda = lambda: self.network_got_ask_for_help(
         permid, infohash)
     self.session.lm.rawserver.add_task(network_got_ask_for_help_lambda, 0)
 def get_coopdlconfig(self):
     dlconfig = self.sessconfig['coopdlconfig']
     if dlconfig is None:
         return
     else:
         from ACEStream.Core.DownloadConfig import DownloadStartupConfig
         return DownloadStartupConfig(dlconfig)
Esempio n. 3
0
    def resume_download(self, dltype, filename, initialdlstatus = None):
        try:
            pstate = self.load_download_pstate(filename)
            if DEBUG:
                log('lm::resume_download: dltype', dltype, 'filename', filename, 'dlconfig', pstate['dlconfig'])
            if DEBUG:
                log('lm::resume_download: status', dlstatus_strings[pstate['dlstate']['status']], 'progress', pstate['dlstate']['progress'])
                if pstate['engineresumedata'] is None:
                    log('lm::resume_download: resumedata None')
                else:
                    log('lm::resume_download: resumedata len', len(pstate['engineresumedata']))
            dscfg = DownloadStartupConfig(dlconfig=pstate['dlconfig'])
            if dltype == DLTYPE_TORRENT:
                tdef = TorrentDef.load_from_dict(pstate['metainfo'])
                d = self.add(tdef, dscfg, pstate, initialdlstatus)
            elif dltype == DLTYPE_DIRECT:
                main_url = pstate['url']
                d = self.add_direct_download(main_url, dscfg, pstate, initialdlstatus)
            if initialdlstatus == DLSTATUS_STOPPED:
                dest_files = d.get_dest_files(get_all=True)
                if DEBUG:
                    log('lm::resume_download: check dest files: dest_files', dest_files)
                got_existing_file = False
                for filename, savepath in dest_files:
                    if os.path.exists(savepath):
                        got_existing_file = True
                        break

                if not got_existing_file:
                    if DEBUG:
                        log('lm::resume_download: none of the files exists, remove this download')
                    self.remove(d, removecontent=True)
        except Exception as e:
            if DEBUG:
                log('lm::resume_download: failed to load checkpoint: filename', filename)
                print_exc()
            try:
                if os.access(filename, os.F_OK):
                    os.remove(filename)
            except:
                print_exc()