本文整理汇总了Python中libtorrent.torrent_info方法的典型用法代码示例。如果您正苦于以下问题:Python libtorrent.torrent_info方法的具体用法?Python libtorrent.torrent_info怎么用?Python libtorrent.torrent_info使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libtorrent
的用法示例。
在下文中一共展示了libtorrent.torrent_info方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_torrent_session
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import torrent_info [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
示例2: getCompleteList
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import torrent_info [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
示例3: getEpnList
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import torrent_info [as 别名]
def getEpnList(self, name, opt, depth_list, extra_info, siteName, category):
summary = ""
torrent_dest = os.path.join(siteName, name+'.torrent')
info = lt.torrent_info(torrent_dest)
file_arr = []
for f in info.files():
file_path = f.path
file_path = os.path.basename(file_path)
file_arr.append(file_path)
record_history = True
return (file_arr, 'Summary Not Available', 'No.jpg', record_history, depth_list)
示例4: _get_torrent_info
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import torrent_info [as 别名]
def _get_torrent_info(self, torrent, download_dir):
import libtorrent as lt
torrent_file = None
magnet = None
info = {}
file_info = {}
if torrent.startswith('magnet:?'):
magnet = torrent
info = lt.parse_magnet_uri(magnet)
info['magnet'] = magnet
elif torrent.startswith('http://') or torrent.startswith('https://'):
response = requests.get(torrent, headers=self.headers, allow_redirects=True)
torrent_file = os.path.join(download_dir, self._generate_rand_filename())
with open(torrent_file, 'wb') as f:
f.write(response.content)
else:
torrent_file = os.path.abspath(os.path.expanduser(torrent))
if not os.path.isfile(torrent_file):
raise RuntimeError('{} is not a valid torrent file'.format(torrent_file))
if torrent_file:
file_info = lt.torrent_info(torrent_file)
info = {
'name': file_info.name(),
'url': torrent,
'trackers': [t.url for t in list(file_info.trackers())],
'save_path': download_dir,
}
return info, file_info, torrent_file, magnet
示例5: _create_fake_torrent
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import torrent_info [as 别名]
def _create_fake_torrent(tmpdir):
# beware, that's just for testing
path = os.path.join(tmpdir, 'tmp')
with open(path, 'wb') as myfile:
size = myfile.write(bytes([random.randint(0, 255) for _ in range(40)]) * 1024)
file_storage = libtorrent.file_storage()
file_storage.add_file('tmp', size)
t = libtorrent.create_torrent(file_storage, 0, 4 * 1024 * 1024)
libtorrent.set_piece_hashes(t, tmpdir)
info = libtorrent.torrent_info(t.generate())
btih = sha1(info.metadata()).hexdigest()
return info, btih
示例6: get_torrent_download_location
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import torrent_info [as 别名]
def get_torrent_download_location(url, home_dir, download_loc):
tmp_arr = url.split('&')
site = tmp_arr[0]
opt = tmp_arr[1]
site_Name = tmp_arr[2]
row = -1
ep_n = ''
if len(tmp_arr) == 7:
name = tmp_arr[3]
if tmp_arr[4] == 'False':
vi_deo_local_stream = False
else:
vi_deo_local_stream = True
row = int(tmp_arr[5])
ep_n = tmp_arr[6]
elif len(tmp_arr) > 7:
new_tmp_arr = tmp_arr[3:]
row_index = -1
local_stream_index = -1
for i, j in enumerate(new_tmp_arr):
if j.isnumeric():
row = int(j)
row_index = i
if j.lower() == 'true' or j.lower() == 'false':
if j.lower() == 'false':
vi_deo_local_stream = False
else:
vi_deo_local_stream = True
local_stream_index = i
if local_stream_index >= 0:
name = '&'.join(new_tmp_arr[:-(len(new_tmp_arr)-local_stream_index)])
if row_index >= 0:
ep_n = '&'.join(new_tmp_arr[(row_index+1):])
torrent_loc = os.path.join(home_dir, 'History', site, name+'.torrent')
info = lt.torrent_info(torrent_loc)
i = 0
fileIndex = int(row)
file_found = False
for f in info.files():
if fileIndex == i:
fileStr = f
i = i+1
print(fileStr.path)
file_name = os.path.join(download_loc, fileStr.path)
return file_name
示例7: start_url
# 需要导入模块: import libtorrent [as 别名]
# 或者: from libtorrent import torrent_info [as 别名]
def start_url(self, uri):
"""
Función encargada iniciar la descarga del torrent desde la url, permite:
- Url apuntando a un .torrent
- Url magnet
- Archivo .torrent local
"""
if self._th:
raise Exception('Torrent is already started')
if uri.startswith('http://') or uri.startswith('https://'):
torrent_data = self.download_torrent(uri)
info = lt.torrent_info(lt.bdecode(torrent_data))
tp = {'ti':info}
resume_data= self._cache.get_resume(info_hash=str(info.info_hash()))
if resume_data:
tp['resume_data']=resume_data
elif uri.startswith('magnet:'):
tp={'url':uri}
resume_data=self._cache.get_resume(info_hash=Cache.hash_from_magnet(uri))
if resume_data:
tp['resume_data']=resume_data
elif os.path.isfile(uri):
if os.access(uri,os.R_OK):
info = lt.torrent_info(uri)
tp= {'ti':info}
resume_data= self._cache.get_resume(info_hash=str(info.info_hash()))
if resume_data:
tp['resume_data']=resume_data
else:
raise ValueError('Invalid torrent path %s' % uri)
else:
raise ValueError("Invalid torrent %s" %uri)
tp.update(self.torrent_paramss)
self._th = self._ses.add_torrent(tp)
for tr in self.INITIAL_TRACKERS:
self._th.add_tracker({'url':tr})
self._th.set_sequential_download(True)
self._th.force_reannounce()
self._th.force_dht_announce()
self._monitor.start()
self._dispatcher.do_start(self._th, self._ses)
self.server.run()