<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:nyaa="{{ url_for('site.xmlns_nyaa', _external=True) }}" version="2.0">
	<channel>
		<title>{{ config.SITE_NAME }} - {{ term }} - {% if not magnet_links %}Torrent File{% else %}Magnet URI{% endif %} RSS</title>
		<description>RSS Feed for {{ term }}</description>
		<link>{{ url_for('main.home', _external=True) }}</link>
		<atom:link href="{{ url_for('main.home', page='rss', _external=True) }}" rel="self" type="application/rss+xml" />
		{% for torrent in torrent_query %}
		<item>
			<title>{{ torrent.display_name }}</title>
			{% if use_elastic %}
				{# ElasticSearch Torrent instances #}
				{% if torrent.has_torrent and not magnet_links %}
				<link>{{ url_for('torrents.download', torrent_id=torrent.meta.id, _external=True) }}</link>
				{% else %}
				<link>{{ create_magnet_from_es_torrent(torrent) }}</link>
				{% endif %}
				<guid isPermaLink="true">{{ url_for('torrents.view', torrent_id=torrent.meta.id, _external=True) }}</guid>
				<pubDate>{{ torrent.created_time|rfc822_es }}</pubDate>

				<nyaa:seeders>  {{- torrent.seed_count     }}</nyaa:seeders>
				<nyaa:leechers> {{- torrent.leech_count    }}</nyaa:leechers>
				<nyaa:downloads>{{- torrent.download_count }}</nyaa:downloads>
				<nyaa:infoHash> {{- torrent.info_hash      }}</nyaa:infoHash>
			{% else %}
				{# Database Torrent rows #}
				{% if torrent.has_torrent and not magnet_links %}
				<link>{{ url_for('torrents.download', torrent_id=torrent.id, _external=True) }}</link>
				{% else %}
				<link>{{ torrent.magnet_uri }}</link>
				{% endif %}
				<guid isPermaLink="true">{{ url_for('torrents.view', torrent_id=torrent.id, _external=True) }}</guid>
				<pubDate>{{ torrent.created_time|rfc822 }}</pubDate>

				<nyaa:seeders>  {{- torrent.stats.seed_count     }}</nyaa:seeders>
				<nyaa:leechers> {{- torrent.stats.leech_count    }}</nyaa:leechers>
				<nyaa:downloads>{{- torrent.stats.download_count }}</nyaa:downloads>
				<nyaa:infoHash> {{- torrent.info_hash_as_hex     }}</nyaa:infoHash>
			{% endif %}
			{% set cat_id = use_elastic and ((torrent.main_category_id|string) + '_' + (torrent.sub_category_id|string)) or torrent.sub_category.id_as_string %}
			<nyaa:categoryId>{{- cat_id }}</nyaa:categoryId>
			<nyaa:category>  {{- category_name(cat_id) }}</nyaa:category>
			<nyaa:size>      {{- torrent.filesize | filesizeformat(True) }}</nyaa:size>
			<nyaa:comments>  {{- torrent.comment_count }}</nyaa:comments>
			{% set torrent_id = use_elastic and torrent.meta.id or torrent.id %}
			<description><![CDATA[<a href="{{ url_for('torrents.view', torrent_id=torrent_id, _external=True) }}">#{{ torrent_id }} | {{ torrent.display_name }}</a> | {{ torrent.filesize | filesizeformat(True) }} | {{ category_name(cat_id) }} | {{ use_elastic and torrent.info_hash or torrent.info_hash_as_hex | upper }}]]></description>
		</item>
		{% endfor %}
	</channel>
</rss>
