From 6b7c44eeb3af0dad7717c0cb4618f2cd1746597b Mon Sep 17 00:00:00 2001 From: raspbeguy Date: Tue, 24 May 2016 00:46:11 +0200 Subject: [PATCH] Creation of torrent extention --- feedgen/ext/torrent.py | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 feedgen/ext/torrent.py diff --git a/feedgen/ext/torrent.py b/feedgen/ext/torrent.py new file mode 100644 index 0000000..eab61fa --- /dev/null +++ b/feedgen/ext/torrent.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +''' + feedgen.ext.podcast + ~~~~~~~~~~~~~~~~~~~ + + Extends the FeedGenerator to produce torrent feeds. + + :copyright: 2016, Raspbeguy + + :license: FreeBSD and LGPL, see license.* for more details. +''' + +from lxml import etree +from feedgen.ext.base import BaseExtension,BaseEntryExtension + +TORRENT_NS = 'http://xmlns.ezrss.it/0.1/dtd/' + +class TorrentExtension(BaseExtension): + '''FeedGenerator extension for torrent feeds. + ''' + + + def extend_ns(self): + return {'torrent' : TORRENT_NS} + + +class TorrentEntryExtension(BaseEntryExtension): + '''FeedEntry extention for torrent feeds + ''' + + + def __init__(self): + self.__torrent_enclosure = None + self.__torrent_media = None + self.__torrent_guid = None + + + def extend_rss(self, entry): + '''Add additional fields to an RSS item. + + :param feed: The RSS item XML element to use. + ''' + if self.__torrent_enclosure: + enclosure = etree.SubElement(entry, '{%s}enclosure' % TORRENT_NS)