当前位置: 首页>>代码示例>>Python>>正文


Python libtorrent.bencode方法代码示例

本文整理汇总了Python中libtorrent.bencode方法的典型用法代码示例。如果您正苦于以下问题:Python libtorrent.bencode方法的具体用法?Python libtorrent.bencode怎么用?Python libtorrent.bencode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在libtorrent的用法示例。


在下文中一共展示了libtorrent.bencode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_torrent

# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import bencode [as 别名]
def generate_torrent(incl_file: pathlib.Path, resource_hash: str) -> dict:
    """Generate torrent file for a given file and write it to disk
    :param pathlib.Path incl_file: file to include in torrent
    :param str resource_hash: resource hash
    :rtype: tuple
    :return: (torrent file as pathlib, torrent file data sha1 hash)
    """
    fs = libtorrent.file_storage()
    libtorrent.add_files(fs, str(incl_file))
    tor = libtorrent.create_torrent(fs)
    tor.set_creator('libtorrent {}'.format(libtorrent.version))
    libtorrent.set_piece_hashes(tor, str(incl_file.parent))
    torrent = tor.generate()
    torrent_data = libtorrent.bencode(torrent)
    fp = _TORRENT_DIR / '{}.torrent'.format(resource_hash)
    with fp.open('wb') as f:
        f.write(torrent_data)
    return fp, hashlib.sha1(torrent_data).hexdigest() 
开发者ID:Azure,项目名称:cortana-intelligence-inventory-optimization,代码行数:20,代码来源:cascade.py

示例2: get

# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import bencode [as 别名]
def get(self):
        response = {}

        info_hashes = self.get_arguments('info_hash')
        for info_hash in info_hashes:
            info_hash = str(info_hash)
            response[info_hash] = {}
            numwant = 100
            compact = True
            no_peer_id = 1

            complete, incomplete, _ = self.get_peers(info_hash, numwant,
                                                     compact, no_peer_id,
                                                     self.tracker_interval * 2)

            response[info_hash]['complete'] = complete
            response[info_hash]['downloaded'] = complete
            response[info_hash]['incomplete'] = incomplete

        self.set_header('content-type', 'text/plain')
        self.write(bencode(response))
        self.finish() 
开发者ID:dchirikov,项目名称:luna,代码行数:24,代码来源:tracker.py

示例3: make_torrent

# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import bencode [as 别名]
def make_torrent(path, save):
    fs = lt.file_storage()
    lt.add_files(fs, path)
    if fs.num_files() == 0:
        print 'no files added'
        sys.exit(1)

    input = os.path.abspath(path)
    basename = os.path.basename(path)
    t = lt.create_torrent(fs, 0, 4 * 1024 * 1024)

    t.add_tracker("http://10.0.1.5:8760/announce")
    t.set_creator('libtorrent %s' % lt.version)

    lt.set_piece_hashes(t, os.path.split(input)[0], lambda x: sys.stderr.write('.'))
    sys.stderr.write('\n')

    save = os.path.dirname(input)
    save = "%s/%s.torrent" % (save, basename)
    f=open(save, "wb")
    f.write(lt.bencode(t.generate()))
    f.close()
    print "the bt torrent file is store at %s" % save 
开发者ID:soarpenguin,项目名称:python-scripts,代码行数:25,代码来源:bt.py

示例4: getCompleteList

# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import bencode [as 别名]
def getCompleteList(self, opt, ui, progress, tmp_dir, hist_folder):
        m = ['Not Able To Open']
        if opt == 'Open':
            MainWindow = QtWidgets.QWidget()
            item, ok = QtWidgets.QInputDialog.getText(ui, 'Input Dialog', 'Enter Torrent Url or Magnet Link or local torrent file path')
            if ok and item:
                if (item.startswith('http') or (os.path.isfile(item) and item.endswith('.torrent'))):
                    home = hist_folder
                    name1 = os.path.basename(item).replace('.torrent', '')
                    torrent_dest1 = os.path.join(tmp_dir, name1+'.torrent')
                    if not os.path.exists(torrent_dest1):
                        if item.startswith('http'):
                            ccurl(item+'#'+'-o'+'#'+torrent_dest1)
                        else:
                            shutil.copy(item, torrent_dest1)
                    if os.path.exists(torrent_dest1):
                        info = lt.torrent_info(torrent_dest1)
                        name = info.name()
                        torrent_dest = os.path.join(home, name+'.torrent')
                        shutil.copy(torrent_dest1, torrent_dest)
                    m = [name]
                elif item.startswith('magnet:'):
                    
                    torrent_handle, stream_session, info = get_torrent_info_magnet(item, tmp_dir, ui, progress, tmp_dir)
                    torrent_file = lt.create_torrent(info)
                    
                    home = hist_folder
                    name = info.name()
                    torrent_dest = os.path.join(home, name+'.torrent')
                    
                    with open(torrent_dest, "wb") as f:
                        f.write(lt.bencode(torrent_file.generate()))
                        
                    torrent_handle.pause()
                    stream_session.pause()
                    m = [name]
        m.append(1)
        return m 
开发者ID:kanishka-linux,项目名称:kawaii-player,代码行数:40,代码来源:Torrent.py

示例5: save_resume

# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import bencode [as 别名]
def save_resume(self):
        """
        Función encargada guardar los metadatos para continuar una descarga mas rapidamente
        """
        if self._th.need_save_resume_data() and self._th.is_valid() and self.meta:
            r = ResumeData(self)
            start=time.time()
            while (time.time() - start) <= 5 :
                if r.data or r.failed:
                    break
                time.sleep(0.1)
            if r.data:
                self._cache.save_resume(self.unique_file_id,lt.bencode(r.data)) 
开发者ID:pelisalacarta-ce,项目名称:pelisalacarta-ce,代码行数:15,代码来源:client.py

示例6: file_complete

# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import bencode [as 别名]
def file_complete(self, torrent):
        info_hash=str(torrent.info_hash())
        nt=lt.create_torrent(torrent)
        tname=self._tname(info_hash)
        f = open(tname, 'wb')
        f.write(lt.bencode(nt.generate()))
        f.close() 
开发者ID:pelisalacarta-ce,项目名称:pelisalacarta-ce,代码行数:9,代码来源:cache.py

示例7: create_torrent

# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import bencode [as 别名]
def create_torrent(self):
        # TODO check if root
        tarball_uid = self.get('tarball')
        if not tarball_uid:
            self.log.error("No tarball in DB.")
            return False

        cluster = Cluster(mongo_db=self._mongo_db)
        tarball = cluster.get('path') + "/torrents/" + tarball_uid + ".tgz"
        if not os.path.exists(tarball):
            self.log.error("Wrong path in DB.")
            return False

        tracker_address = cluster.get('frontend_address')
        if tracker_address == '':
            self.log.error("Tracker address needs to be configured.")
            return False

        tracker_port = cluster.get('frontend_port')
        if tracker_port == 0:
            self.log.error("Tracker port needs to be configured.")
            return False

        user = cluster.get('user')
        user_id = pwd.getpwnam(user).pw_uid
        grp_id = pwd.getpwnam(user).pw_gid

        old_cwd = os.getcwd()
        os.chdir(os.path.dirname(tarball))

        uid = str(uuid.uuid4())
        torrentfile = cluster.get('path') + "/torrents/" + uid + ".torrent"

        fs = libtorrent.file_storage()
        libtorrent.add_files(fs, os.path.basename(tarball))
        t = libtorrent.create_torrent(fs)
        if cluster.get('frontend_https'):
            proto = 'https'
        else:
            proto = 'http'
        t.add_tracker((proto + "://" + str(tracker_address) +
                       ":" + str(tracker_port) + "/announce"))

        t.set_creator(torrent_key)
        t.set_comment(uid)
        libtorrent.set_piece_hashes(t, ".")

        f = open(torrentfile, 'w')
        f.write(libtorrent.bencode(t.generate()))
        f.close()
        os.chown(torrentfile, user_id, grp_id)

        self.set('torrent', str(uid))
        os.chdir(old_cwd)

        return True 
开发者ID:dchirikov,项目名称:luna,代码行数:58,代码来源:osimage.py


注:本文中的libtorrent.bencode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。