torrents.py: Add link to torrent page into .torrent comment metadata

This commit is contained in:
TheAMM 2017-11-04 23:46:50 +02:00
parent 96468a5a11
commit b4c0ad9e84
1 changed files with 7 additions and 1 deletions

View File

@ -447,6 +447,12 @@ def _get_cached_torrent_file(torrent):
'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))
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)