finished torrent ext

This commit is contained in:
raspbeguy 2016-05-24 15:48:18 +02:00
parent 6b7c44eeb3
commit 2b597a6dee

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
'''
feedgen.ext.podcast
feedgen.ext.torrent
~~~~~~~~~~~~~~~~~~~
Extends the FeedGenerator to produce torrent feeds.
@ -30,9 +30,11 @@ class TorrentEntryExtension(BaseEntryExtension):
def __init__(self):
self.__torrent_enclosure = None
self.__torrent_media = None
self.__torrent_guid = None
self.__torrent_filename = None
self.__torrent_url = None
self.__torrent_hash = None
self.__torrent_length = None
self.__torrent_contentlength = None
def extend_rss(self, entry):
@ -40,5 +42,80 @@ class TorrentEntryExtension(BaseEntryExtension):
:param feed: The RSS item XML element to use.
'''
if self.__torrent_enclosure:
enclosure = etree.SubElement(entry, '{%s}enclosure' % TORRENT_NS)
enclosure = etree.SubElement(entry, '{%s}enclosure' % TORRENT_NS)
guid = etree.SubElement(entry, '{%s}guid' % TORRENT_NS)
torrent = etree.SubElement(entry, '{%s]torrent' % TORRENT_NS)
enclosure.attrib['type'] = 'application/x-bittorrent'
if self.__torrent_url:
enclosure.attrib['url'] = self.__torrent_url
guid.text = self.__torrent_url
if self.__torrent_filename:
torrent_filename = etree.SubElement(torrent, '{%s}filename' % TORRENT_NS)
torrent_filename.text = self.__torrent_filename
if self.__torrent_length:
enclosure.attrib['length'] = self.__torrent_length
if self.__torrent_contentlength:
torrent_length = etree.SubElement(torrent, '{%s}contentlength' % TORRENT_NS)
torrent_length.text = self.__torrent_contentlength
if self.__torrent_hash:
torrent_hash = etree.SubElement(torrent, '{%s}infohash' % TORRENT_NS)
torrent_hash.text = self.__torrent_hash
torrent.magnet = etree.SubElement(torrent, '{%s}magneturi' % TORRENT_NS)
torrent_magnet.text = 'magnet:?xt=urn:btih:' + self.__torrent_hash
def torrent_filename(self, torrent_filename=None):
'''Get or set the name of the torrent file.
:param torrent_filename: The name of the torrent file.
:returns: The name of the torrent file.
'''
if not torrent_filename is None:
self.__torrent_filename = torrent_filename
return self.__torrent_filename
def torrent_url (self, torrent_url=None):
'''Get or set the URL of the torrent.
:param torrent_url: The torrent URL.
:returns: The torrent URL.
'''
if not torrent_url is None:
self.__torrent_url = torrent_url
return self.__torrent_url
def torrent_hash (self, torrent_hash=None):
'''Get or set the hash of the target file.
:param torrent_url: The target file hash.
:returns: The target hash file.
'''
if not torrent_hash is None:
self.__torrent_hash = torrent_hash
return self.__torrent_hash
def torrent_length (self, torrent_length=None):
'''Get or set the size of the torrent file.
:param torrent_length: The torrent size.
:returns: The torrent size.
'''
if not torrent_length is None:
self.__torrent_length = torrent_length
return self.__torrent_length
def torrent_contentlength (self, torrent_contentlength=None):
'''Get or set the size of the target file.
:param torrent_contentlength: The target file size.
:returns: The target file size.
'''
if not torrent_contentlength is None:
self.__torrent_contentlength = torrent_contentlength
return self.__torrent_contentlength