2016-05-24 00:46:11 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2016-12-21 02:04:24 +01:00
|
|
|
feedgen.ext.torrent
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2016-05-24 00:46:11 +02:00
|
|
|
|
2016-12-21 02:04:24 +01:00
|
|
|
Extends the FeedGenerator to produce torrent feeds.
|
2016-05-24 00:46:11 +02:00
|
|
|
|
2016-12-21 02:04:24 +01:00
|
|
|
:copyright: 2016, Raspbeguy <raspbeguy@hashtagueule.fr>
|
2016-05-24 00:46:11 +02:00
|
|
|
|
2016-12-21 02:04:24 +01:00
|
|
|
:license: FreeBSD and LGPL, see license.* for more details.
|
2016-05-24 00:46:11 +02:00
|
|
|
'''
|
|
|
|
|
2018-03-04 20:05:29 +01:00
|
|
|
from feedgen.ext.base import BaseEntryExtension, BaseExtension
|
2020-01-25 15:58:49 +01:00
|
|
|
from feedgen.util import xml_elem
|
2016-05-24 00:46:11 +02:00
|
|
|
|
|
|
|
TORRENT_NS = 'http://xmlns.ezrss.it/0.1/dtd/'
|
|
|
|
|
2016-12-21 02:04:24 +01:00
|
|
|
|
2016-05-24 00:46:11 +02:00
|
|
|
class TorrentExtension(BaseExtension):
|
2016-12-21 02:04:24 +01:00
|
|
|
'''FeedGenerator extension for torrent feeds.
|
|
|
|
'''
|
|
|
|
def extend_ns(self):
|
|
|
|
return {'torrent': TORRENT_NS}
|
2016-05-24 00:46:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TorrentEntryExtension(BaseEntryExtension):
|
2018-03-04 10:52:55 +01:00
|
|
|
'''FeedEntry extension for torrent feeds
|
2016-12-21 02:04:24 +01:00
|
|
|
'''
|
|
|
|
def __init__(self):
|
|
|
|
self.__torrent_filename = None
|
|
|
|
self.__torrent_infohash = None
|
|
|
|
self.__torrent_contentlength = None
|
|
|
|
self.__torrent_seeds = None
|
|
|
|
self.__torrent_peers = None
|
2017-03-13 20:55:14 +01:00
|
|
|
self.__torrent_verified = None
|
2016-12-21 02:04:24 +01:00
|
|
|
|
|
|
|
def extend_rss(self, entry):
|
|
|
|
'''Add additional fields to an RSS item.
|
|
|
|
|
|
|
|
:param feed: The RSS item XML element to use.
|
|
|
|
'''
|
|
|
|
if self.__torrent_filename:
|
2020-01-25 15:58:49 +01:00
|
|
|
filename = xml_elem('{%s}filename' % TORRENT_NS, entry)
|
2016-12-21 02:04:24 +01:00
|
|
|
filename.text = self.__torrent_filename
|
|
|
|
|
|
|
|
if self.__torrent_contentlength:
|
2020-01-25 15:58:49 +01:00
|
|
|
contentlength = xml_elem('{%s}contentlength' % TORRENT_NS, entry)
|
2016-12-21 02:04:24 +01:00
|
|
|
contentlength.text = self.__torrent_contentlength
|
|
|
|
|
|
|
|
if self.__torrent_infohash:
|
2020-01-25 15:58:49 +01:00
|
|
|
infohash = xml_elem('{%s}infohash' % TORRENT_NS, entry)
|
2016-12-21 02:04:24 +01:00
|
|
|
infohash.text = self.__torrent_infohash
|
2020-01-25 15:58:49 +01:00
|
|
|
magnet = xml_elem('{%s}magneturi' % TORRENT_NS, entry)
|
2016-12-21 02:04:24 +01:00
|
|
|
magnet.text = 'magnet:?xt=urn:btih:' + self.__torrent_infohash
|
|
|
|
|
|
|
|
if self.__torrent_seeds:
|
2020-01-25 15:58:49 +01:00
|
|
|
seeds = xml_elem('{%s}seed' % TORRENT_NS, entry)
|
2016-12-21 02:04:24 +01:00
|
|
|
seeds.text = self.__torrent_seeds
|
|
|
|
|
|
|
|
if self.__torrent_peers:
|
2020-01-25 15:58:49 +01:00
|
|
|
peers = xml_elem('{%s}peers' % TORRENT_NS, entry)
|
2016-12-21 02:04:24 +01:00
|
|
|
peers.text = self.__torrent_peers
|
|
|
|
|
2017-03-13 20:55:14 +01:00
|
|
|
if self.__torrent_verified:
|
2020-01-25 15:58:49 +01:00
|
|
|
verified = xml_elem('{%s}verified' % TORRENT_NS, entry)
|
2016-12-21 02:04:24 +01:00
|
|
|
verified.text = self.__torrent_verified
|
|
|
|
|
|
|
|
def 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 torrent_filename is not None:
|
|
|
|
self.__torrent_filename = torrent_filename
|
|
|
|
return self.__torrent_filename
|
|
|
|
|
|
|
|
def infohash(self, torrent_infohash=None):
|
|
|
|
'''Get or set the hash of the target file.
|
|
|
|
|
|
|
|
:param torrent_infohash: The target file hash.
|
|
|
|
:returns: The target hash file.
|
|
|
|
'''
|
|
|
|
if torrent_infohash is not None:
|
|
|
|
self.__torrent_infohash = torrent_infohash
|
|
|
|
return self.__torrent_infohash
|
|
|
|
|
|
|
|
def 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 torrent_contentlength is not None:
|
|
|
|
self.__torrent_contentlength = torrent_contentlength
|
|
|
|
return self.__torrent_contentlength
|
|
|
|
|
|
|
|
def seeds(self, torrent_seeds=None):
|
|
|
|
'''Get or set the number of seeds.
|
|
|
|
|
|
|
|
:param torrent_seeds: The seeds number.
|
|
|
|
:returns: The seeds number.
|
|
|
|
'''
|
|
|
|
if torrent_seeds is not None:
|
|
|
|
self.__torrent_seeds = torrent_seeds
|
|
|
|
return self.__torrent_seeds
|
|
|
|
|
|
|
|
def peers(self, torrent_peers=None):
|
|
|
|
'''Get or set the number od peers
|
|
|
|
|
|
|
|
:param torrent_infohash: The peers number.
|
|
|
|
:returns: The peers number.
|
|
|
|
'''
|
|
|
|
if torrent_peers is not None:
|
|
|
|
self.__torrent_peers = torrent_peers
|
|
|
|
return self.__torrent_peers
|
|
|
|
|
|
|
|
def verified(self, torrent_verified=None):
|
|
|
|
'''Get or set the number of verified peers.
|
|
|
|
|
|
|
|
:param torrent_infohash: The verified peers number.
|
|
|
|
:returns: The verified peers number.
|
|
|
|
'''
|
|
|
|
if torrent_verified is not None:
|
|
|
|
self.__torrent_verified = torrent_verified
|
|
|
|
return self.__torrent_verified
|