From bbd047fb15c4ece5d0540db8fe229425076b114e Mon Sep 17 00:00:00 2001 From: Stefan Grassberger Date: Wed, 19 Aug 2015 23:37:11 +0200 Subject: [PATCH] Add option to show either magnet or torrent links in feed, closes #13 --- config-sample.php | 2 ++ index.php | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/config-sample.php b/config-sample.php index 8f0b57c..ddcf740 100644 --- a/config-sample.php +++ b/config-sample.php @@ -29,6 +29,8 @@ define('MINIMUM_FILESIZE', 3); /* in GB */ define('MAXIMUM_FILESIZE', 19); /* in GB */ +define('FEED_DOWNLOAD_LINK', 'both'); /* torrent, magnet, both */ + $sites = array( /* prioritize sites to search */ 'extratorrent', 'kickasstorrents' diff --git a/index.php b/index.php index c53f134..54c205e 100644 --- a/index.php +++ b/index.php @@ -58,19 +58,29 @@ $item->appendChild( $torrentContentLength ); } - if ($film->torrentFile) { - $enclosure = $xml->createElement( "enclosure" ); - $enclosure->setAttribute( "url", $film->torrentFile ); - if ($film->torrentSize) $enclosure->setAttribute( "length", $film->torrentSize ); - $enclosure->setAttribute( "type", "application/x-bittorrent" ); - $item->appendChild( $enclosure ); + if ((!$film->torrentFile && !$film->torrentMagnet) || + (FEED_DOWNLOAD_LINK === 'torrent' && !$film->torrentFile) || + (FEED_DOWNLOAD_LINK === 'magnet' && !$film->torrentMagnet) ) { + continue; + } + + $enclosure = $xml->createElement( "enclosure" ); + if ($film->torrentSize) $enclosure->setAttribute( "length", $film->torrentSize ); + $enclosure->setAttribute( "type", "application/x-bittorrent" ); + $link = $xml->createElement( "link" ); - $link = $xml->createElement( "link" ); + if ((FEED_DOWNLOAD_LINK === 'both' || FEED_DOWNLOAD_LINK === 'torrent') && $film->torrentFile) { + $enclosure->setAttribute( "url", $film->torrentFile ); $link->appendChild( new DOMText( $film->torrentFile ) ); - $item->appendChild( $link ); + } else if (FEED_DOWNLOAD_LINK === 'magnet' && $film->torrentMagnet) { + $enclosure->setAttribute( "url", $film->torrentMagnet ); + $link->appendChild( new DOMText( $film->torrentMagnet ) ); } - if ($film->torrentMagnet) { + $item->appendChild( $enclosure ); + $item->appendChild( $link ); + + if ((FEED_DOWNLOAD_LINK === 'both' || FEED_DOWNLOAD_LINK === 'magnet') && $film->torrentMagnet) { $torrentMagnetURI = $xml->createElement( "torrent:magnetURI" ); $torrentMagnetURI->appendChild( new DOMText( $film->torrentMagnet ) ); $item->appendChild( $torrentMagnetURI );