def _make_torrent_file(torrent): with open(torrent.info_dict_path, 'rb') as in_file: bencoded_info = in_file.read() bencoded_torrent_data = torrents.create_bencoded_torrent( torrent, bencoded_info) return bencoded_torrent_data, len(bencoded_torrent_data)
def _get_cached_torrent_file(torrent): # Note: obviously temporary cached_torrent = os.path.join(app.config['BASE_DIR'], 'torrent_cache', str(torrent.id) + '.torrent') if not os.path.exists(cached_torrent): with open(cached_torrent, 'wb') as out_file: out_file.write(torrents.create_bencoded_torrent(torrent)) return open(cached_torrent, 'rb')
def _get_cached_torrent_file(torrent): # Note: obviously temporary cached_torrent = os.path.join(app.config['BASE_DIR'], 'torrent_cache', str(torrent.id) + '.torrent') if not os.path.exists(cached_torrent): with open(cached_torrent, 'wb') as out_file: metadata_base = torrents.create_default_metadata_base(torrent) # Replace the default comment with url to the torrent page metadata_base['comment'] = flask.url_for('torrents.view', torrent_id=torrent.id, _external=True) out_file.write(torrents.create_bencoded_torrent(torrent, metadata_base)) return open(cached_torrent, 'rb'), os.path.getsize(cached_torrent)