rss-bridge/bridges/YGGTorrentBridge.php

151 lines
4.7 KiB
PHP
Raw Normal View History

2018-04-18 22:57:27 +03:00
<?php
/* This is a mashup of FlickrExploreBridge by sebsauvage and FlickrTagBridge
* by erwang.providing the functionality of both in one.
*/
class YGGTorrentBridge extends BridgeAbstract {
const MAINTAINER = 'teromene';
const NAME = 'Yggtorrent Bridge';
const URI = 'https://www5.yggtorrent.fi';
2018-04-18 22:57:27 +03:00
const DESCRIPTION = 'Returns torrent search from Yggtorrent';
const PARAMETERS = array(
array(
'cat' => array(
'name' => 'category',
'type' => 'list',
'values' => array(
'Toutes les catégories' => 'all.all',
'Film/Vidéo - Toutes les sous-catégories' => '2145.all',
'Film/Vidéo - Animation' => '2145.2178',
'Film/Vidéo - Animation Série' => '2145.2179',
'Film/Vidéo - Concert' => '2145.2180',
'Film/Vidéo - Documentaire' => '2145.2181',
'Film/Vidéo - Émission TV' => '2145.2182',
'Film/Vidéo - Film' => '2145.2183',
'Film/Vidéo - Série TV' => '2145.2184',
'Film/Vidéo - Spectacle' => '2145.2185',
'Film/Vidéo - Sport' => '2145.2186',
'Film/Vidéo - Vidéo-clips' => '2145.2186',
'Audio - Toutes les sous-catégories' => '2139.all',
'Audio - Karaoké' => '2139.2147',
'Audio - Musique' => '2139.2148',
'Audio - Podcast Radio' => '2139.2150',
'Audio - Samples' => '2139.2149',
'Jeu vidéo - Toutes les sous-catégories' => '2142.all',
'Jeu vidéo - Autre' => '2142.2167',
'Jeu vidéo - Linux' => '2142.2159',
'Jeu vidéo - MacOS' => '2142.2160',
'Jeu vidéo - Microsoft' => '2142.2162',
'Jeu vidéo - Nintendo' => '2142.2163',
'Jeu vidéo - Smartphone' => '2142.2165',
'Jeu vidéo - Sony' => '2142.2164',
'Jeu vidéo - Tablette' => '2142.2166',
'Jeu vidéo - Windows' => '2142.2161',
'eBook - Toutes les sous-catégories' => '2140.all',
'eBook - Audio' => '2140.2151',
'eBook - Bds' => '2140.2152',
'eBook - Comics' => '2140.2153',
'eBook - Livres' => '2140.2154',
'eBook - Mangas' => '2140.2155',
'eBook - Presse' => '2140.2156',
'Emulation - Toutes les sous-catégories' => '2141.all',
'Emulation - Emulateurs' => '2141.2157',
'Emulation - Roms' => '2141.2158',
'GPS - Toutes les sous-catégories' => '2141.all',
'GPS - Applications' => '2141.2168',
'GPS - Cartes' => '2141.2169',
'GPS - Divers' => '2141.2170'
2018-04-18 22:57:27 +03:00
)
),
'nom' => array(
'name' => 'Nom',
'description' => 'Nom du torrent',
'type' => 'text',
'exampleValue' => 'matrix'
2018-04-18 22:57:27 +03:00
),
'description' => array(
'name' => 'Description',
'description' => 'Description du torrent',
'type' => 'text'
2018-04-18 22:57:27 +03:00
),
'fichier' => array(
'name' => 'Fichier',
'description' => 'Fichier du torrent',
'type' => 'text'
2018-04-18 22:57:27 +03:00
),
'uploader' => array(
'name' => 'Uploader',
'description' => 'Uploader du torrent',
'type' => 'text'
2018-04-18 22:57:27 +03:00
),
)
);
public function collectData() {
$catInfo = explode('.', $this->getInput('cat'));
2018-04-18 22:57:27 +03:00
$category = $catInfo[0];
$subcategory = $catInfo[1];
$html = getSimpleHTMLDOM(self::URI . '/engine/search?name='
. $this->getInput('nom')
. '&description='
. $this->getInput('description')
. '&file='
. $this->getInput('fichier')
. '&uploader='
. $this->getInput('uploader')
. '&category='
2018-04-18 22:57:27 +03:00
. $category
. '&sub_category='
2018-04-18 22:57:27 +03:00
. $subcategory
. '&do=search&order=desc&sort=publish_date');
2018-04-18 22:57:27 +03:00
$count = 0;
$results = $html->find('.results', 0);
if(!$results) return;
foreach($results->find('tr') as $row) {
2018-04-18 22:57:27 +03:00
$count++;
Catching up | [Main] Debug mode, parse utils, MIME | [Bridges] Add/Improve 20 bridges (#802) * Debug mode improvements - Improve debug warning message - Restore error reporting in debug mode - Fix 'notice' messages for unset fields * Add parsing utility functions html.php - extractFromDelimiters - stripWithDelimiters - stripRecursiveHTMLSection - markdownToHtml (partial) bridges - remove now-duplicate functions - call functions from html.php instead * [Anidex] New bridge Anime torrent tracker * [Anime-Ultime] Restore thumbnail * [CNET] Recreate bridge Full rewrite as the previous one was broken * [Dilbert] Minor URI fix Use new self::URI property * [EstCeQuonMetEnProd] Fix content extraction Bridge was broken * [Facebook] Fix "SpSonsSoriSsés" label ... which was taking space in item title * [Futura-Sciences] Use HTTPS, More cleanup Use HTTPS as FS now offer HTTPS Clean additional useless HTML elements * [GBATemp] Multiple fixes - Fix categories: missing "break" statements - Restore thumbnail as enclosure - Fix date extraction - Fix user blog post extraction - Use getSimpleHTMLDOMCached * [JapanExpo] Fix bridge, HTTPS, thumbnails - Fix getSimpleHTMLDOMCached call - Upgrade to HTTPS as JE now offers HTTPS - Restore thumbnails as enclosures * [LeMondeInformatique] Fix bridge, HTTPS - Upgrade to HTTPS as LMI now offers HTTPS - Restore thumbnails using small images - Fix content extraction - Fix text encoding issue * [Nextgov] Fix content extraction - Restore thumbnail and use small image - Field extraction fixes * [NextInpact] Add categories and filtering by type - Offer all RSS feeds - Allow filtering by article type - Implement extraction for brief articles - Remove article limit, many brief articles are publied all at once * [NyaaTorrents] New bridge Anime torrent tracker * [Releases3DS] Cache content, restore thumbnail - Use getSimpleHTMLDOMCached - Restore thumbnail as enclosure * [TheHackerNews] Fix bridge - Fix content extraction including article body - Restore thumbnail as enclosure * [WeLiveSecurity] HTTPS, Fix content extraction - Upgrade to HTTPS as WLS now offers HTTPS - Fix content extraction including article body * [WordPress] Reduce timeout, more content selectors - Reduce timeout to use default one (1h) - Add new content selector (articleBody) - Find thumbnail and set as enclosure - Fix <script> cleanup * [YGGTorrent] Increase limit, use cache - Increase item limit as uploads are very frequent - Use getSimpleHTMLDOMCached * [ZDNet] Rewrite with FeedExpander - Upgrade to HTTPS as ZD now offers HTTPS - Use FeedExpander for secondary fields - Fix content extraction for article body * [Main] Handle MIME type for enclosures Many feed readers will ignore enclosures (e.g. thumbnails) with no MIME type. This commit adds automatic MIME type detection based on file extension (which may be inaccurate but is the only way without fetching the content). One can force enclosure type using #.ext anchor (hacky, needs improving) * [FeedExpander] Improve field extraction - Add support for passing enclosures - Improve author and uri extraction - Fix 'notice' PHP error messages * [Pull] Coding style fixes for #802 * [Pull] Implementing changes for #802 - Fix coding style issues with str append - Remove useless CACHE_TIMEOUT - Use count() instead of $limit - Use defaultLinkTo() + handle strings - Use http_build_query() - Fix missing </em> - Remove error_reporting(0) - warning CSS (@LogMANOriginal) - Fix typo in FeedExpander comment * [Main] More documentation for markdownToHtml See #802 for more details
2018-09-09 22:20:13 +03:00
if($count == 1) continue; // Skip table header
if($count == 22) break; // Stop processing after 21 items (20 + 1 table header)
2018-04-18 22:57:27 +03:00
$item = array();
$item['timestamp'] = $row->find('.hidden', 1)->plaintext;
$item['title'] = $row->find('a#torrent_name', 0)->plaintext;
$item['uri'] = $this->processLink($row->find('a#torrent_name', 0)->href);
$item['seeders'] = $row->find('td', 7)->plaintext;
$item['leechers'] = $row->find('td', 8)->plaintext;
$item['size'] = $row->find('td', 5)->plaintext;
$item = array_merge($item, $this->collectTorrentData($item['uri']));
2018-04-18 22:57:27 +03:00
$this->items[] = $item;
}
}
/**
* Convert special characters like é to %C3%A9 in the url
*/
private function processLink($url) {
$url = explode('/', $url);
foreach($url as $index => $value) {
// Skip https://{self::URI}/
if ($index < 3) {
continue;
}
// Decode first so that characters like + are not encoded
$url[$index] = urlencode(urldecode($value));
}
return implode('/', $url);
}
2018-04-18 22:57:27 +03:00
private function collectTorrentData($url) {
$page = defaultLinkTo(getSimpleHTMLDOMCached($url), self::URI);
$author = $page->find('.informations tr', 5)->find('td', 1)->plaintext;
$content = $page->find('.default', 1);
return array('author' => $author, 'content' => $content);
2018-04-18 22:57:27 +03:00
}
}