本文整理汇总了Python中libtorrent.session方法的典型用法代码示例。如果您正苦于以下问题:Python libtorrent.session方法的具体用法?Python libtorrent.session怎么用?Python libtorrent.session使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libtorrent
的用法示例。
在下文中一共展示了libtorrent.session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def __init__(self, v1, v2, v3, v4, row=None, from_client=None):
QtCore.QThread.__init__(self)
self.handle = v1
self.count = v2
self.count_limit = v3
self.session = v4
if row:
self.current_index = row
else:
self.current_index = 0
self.from_client = from_client
self.start_next = False
self.session_signal.connect(session_finished)
self.progress_signal.connect(print_progress)
self.progress_signal_end.connect(print_progress_complete)
self.ui = None
示例2: create_torrent_session
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def create_torrent_session(
resource: str, save_path: pathlib.Path, seed_mode: bool):
"""Create a torrent session given a torrent file
:param str resource: torrent resource
:param pathlib.Path save_path: path to save torrented files to
:param bool seed_mode: seed mode
:param list port_range: port range to listen on
:return: torrent_handle
"""
torrent_handle = _TORRENT_SESSION.add_torrent({
'ti': libtorrent.torrent_info(
str(_TORRENTS[resource]['torrent_file'])),
'save_path': str(save_path),
'seed_mode': seed_mode
})
logger.info('created torrent session for {} is_seed={}'.format(
resource, torrent_handle.is_seed()))
return torrent_handle
示例3: _remove_torrent_from_session
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def _remove_torrent_from_session(resource: str, torrent_handle) -> None:
"""Remove a torrent from the session
:param str resource: torrent resource
:param torrent_handle: torrent handle
"""
_TORRENT_SESSION.remove_torrent(torrent_handle)
# wait for removal alert
retries = 5
while True:
alert = _TORRENT_SESSION.pop_alert()
if not alert:
retries -= 1
if retries == 0:
break
else:
time.sleep(1)
continue
if isinstance(alert, str):
logger.warning('received alert: {}'.format(alert))
else:
logger.warning('received alert: {}'.format(alert.message()))
logger.info('removed torrent for {}'.format(resource))
示例4: download_metadata
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def download_metadata(address, binhash, metadata_queue, timeout=40):
metadata = None
start_time = time.time()
try:
session = lt.session()
r = random.randrange(10000, 50000)
session.listen_on(r, r + 10)
session.add_dht_router('router.bittorrent.com', 6881)
session.add_dht_router('router.utorrent.com', 6881)
session.add_dht_router('dht.transmission.com', 6881)
session.add_dht_router('127.0.0.1', 6881)
session.start_dht()
metadata = fetch_torrent(session, binhash.encode('hex'), timeout)
session = None
except Exception:
traceback.print_exc()
finally:
metadata_queue.put((binhash, address, metadata, 'lt', start_time))
示例5: main
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def main():
if os.path.exists("~/Downloads/ubuntu-18.04.3-live-server-amd64.torrent"):
os.remove("~/Downloads/ubuntu-18.04.3-live-server-amd64.torrent")
if os.path.exists("~/Downloads/ubuntu-18.04.3-live-server-amd64.iso"):
os.remove("~/Downloads/ubuntu-18.04.3-live-server-amd64.iso")
btih = "dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c"
executor = None
session = TorrentSession(asyncio.get_event_loop(), executor)
session2 = TorrentSession(asyncio.get_event_loop(), executor)
await session.bind('localhost', port=4040)
await session2.bind('localhost', port=4041)
btih = await session.add_fake_torrent()
session2._session.add_dht_node(('localhost', 4040))
await session2.add_torrent(btih, "/tmp/down")
while True:
await asyncio.sleep(100)
await session.pause()
executor.shutdown()
示例6: run
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def run(self):
global new_count, new_count_limit, total_size_content
count_limit = self.count_limit
s = self.handle.status()
while (not self.session.is_paused()):
s = self.handle.status()
if not self.handle.is_seed():
out = str(int(s.progress*100))+'%'
else:
out = 'SEEDING'
out_percent = int(s.progress*100)
TD = str(int(s.total_download/(1024*1024)))+'M'
TU = str(int(s.total_upload/(1024*1024)))+'M'
TDR = u'\u2193'+str(int(s.download_rate/1024)) + 'K' + '('+TD+')'
TUR = u'\u2191'+str(int(s.upload_rate/1024)) + 'K'+'('+TU+')'
out1 = str(out)+' '+total_size_content+' '+TDR +' '+TUR+' '+'P:'+str(s.num_peers)
if s.state == 1:
out1 = 'Checking Please Wait: '+str(out)
self.progress_signal.emit(out1, out_percent)
if (s.progress * 100) >= 99 and (s.state != 1):
partial_down = False
for k in range(count, count_limit+1):
if handle.piece_priority(k) == 0:
handle.piece_priority(k, 2)
partial_down = True
if not partial_down:
if self.from_client:
if not self.start_next:
self.start_next = True
self.process_next()
else:
self.session_signal.emit('..Starting Next Download..')
time.sleep(5)
time.sleep(1)
if self.ui and self.ui.torrent_status_command == 'all':
msg = get_torrent_info_all(self.ui)
self.ui.gui_signals.update_torrent_status(msg)
self.progress_signal_end.emit('complete')
示例7: get_torrent_info_magnet
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def get_torrent_info_magnet(v1, v3, u, p_bar, tmp_dir):
global handle, ses, info, count, count_limit, file_name, ui, progress, tmp_dir_folder
ui = u
progress = p_bar
tmp_dir_folder = tmp_dir
progress.setValue(0)
progress.show()
sett = lt.session_settings()
sett.user_agent = 'qBittorrent v3.3.5'
sett.always_send_user_agent = True
fingerprint = lt.fingerprint('qB', 3, 3, 5, 0)
ses = lt.session(fingerprint)
ses.listen_on(40000, 50000)
ses.set_settings(sett)
handle = lt.add_magnet_uri(ses, v1, {'save_path':v3})
i = 0
while (not handle.has_metadata()):
time.sleep(1)
i = i+1
print('finding metadata {0}'.format(i))
if i > 300:
print('No Metadata Available: {0}s'.format(i))
break
info = handle.get_torrent_info()
handle.set_sequential_download(True)
print(handle.trackers())
return handle, ses, info
示例8: downloadtorrent
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def downloadtorrent(link):
try:
params = {
'save_path' : savePath,
'storage_mode': lt.storage_mode_t(2),
'paused': False,
'auto_managed': True,
'duplicate_is_error': True
}
#Inicia o Download
ses = lt.session()
ses.listen_on(6881, 6891)
handle = lt.add_magnet_uri(ses, link, params)
ses.start_dht()
while (not handle.has_metadata()):
time.sleep(1)
while (handle.status().state != lt.torrent_status.seeding):
s = handle.status()
time.sleep(5)
except:
pass
示例9: fetch_torrent
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def fetch_torrent(session, ih, timeout):
name = ih.upper()
url = 'magnet:?xt=urn:btih:%s' % (name,)
params = {
'save_path': '/tmp/downloads/',
'storage_mode': lt.storage_mode_t(2),
'paused': False,
'auto_managed': False,
'duplicate_is_error': True}
try:
handle = lt.add_magnet_uri(session, url, params)
except Exception:
return None
handle.set_sequential_download(1)
meta = None
down_path = None
for i in range(0, timeout):
if handle.has_metadata():
info = handle.get_torrent_info()
down_path = '/tmp/downloads/%s' % info.name()
meta = info.metadata()
break
time.sleep(1)
if down_path and os.path.exists(down_path):
os.system('rm -rf "%s"' % down_path)
session.remove_torrent(handle)
return meta
示例10: quit
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def quit(self):
"""
Quits all the transfers and the active session
"""
transfers = self.transfers.copy()
for torrent in transfers:
self.remove(torrent)
示例11: __init__
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def __init__(self, loop, executor):
self._loop = loop
self._executor = executor
self._session: Optional[libtorrent.session] = None
self._handles = {}
self.tasks = []
self.wait_start = True
示例12: bind
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def bind(self, interface: str = '0.0.0.0', port: int = 10889):
settings = {
'listen_interfaces': f"{interface}:{port}",
'enable_outgoing_utp': True,
'enable_incoming_utp': True,
'enable_outgoing_tcp': False,
'enable_incoming_tcp': False
}
self._session = await self._loop.run_in_executor(
self._executor, libtorrent.session, settings # pylint: disable=c-extension-no-member
)
self.tasks.append(self._loop.create_task(self.process_alerts()))
示例13: __init__
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def __init__(
self, listening_port=None, dht_routers=[], filelist_dir=None, download_dir=None
):
self.locks = LockManager()
self.session = libtorrent.session()
if listening_port:
self.session.listen_on(listening_port, listening_port)
else:
rand = random.randrange(17000, 18000)
self.session.listen_on(rand, rand + 10000)
for router, port in dht_routers:
self.session.add_dht_router(router, port)
self.session.start_dht()
self.filelist_dir = filelist_dir
self.download_dir = download_dir
示例14: remove_torrent
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def remove_torrent(self, magnet_hash, remove_files=False):
try:
h = self.torrents[magnet_hash]
except KeyError:
return
try:
self.session.remove_torrent(h)
except Exception:
pass
del self.torrents[magnet_hash]
if remove_files:
try:
shutil.rmtree(os.path.join(self.download_dir, magnet_hash))
except FileNotFoundError:
pass
示例15: _add_magnet_link_to_downloads
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import session [as 别名]
def _add_magnet_link_to_downloads(self, magnet_link):
magnet_hash = get_hash(magnet_link)
h = libtorrent.add_magnet_uri(
self.session,
magnet_link,
dict(save_path=os.path.join(self.download_dir, magnet_hash)),
)
files = get_torrent_info(h).files()
prioritize_files(h, [0] * len(files))
self.torrents[magnet_hash] = h
return h