[YGGTorrentBridge] Changed base URL and one parameter name (#2826)

This commit is contained in:
Gilles 2022-06-18 05:06:59 +02:00 committed by GitHub
parent d0bea1627e
commit ce63d8a706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 20 deletions

View File

@ -7,7 +7,7 @@ class YGGTorrentBridge extends BridgeAbstract {
const MAINTAINER = 'teromene'; const MAINTAINER = 'teromene';
const NAME = 'Yggtorrent Bridge'; const NAME = 'Yggtorrent Bridge';
const URI = 'https://yggtorrent.is'; const URI = 'https://www5.yggtorrent.fi';
const DESCRIPTION = 'Returns torrent search from Yggtorrent'; const DESCRIPTION = 'Returns torrent search from Yggtorrent';
const PARAMETERS = array( const PARAMETERS = array(
@ -16,7 +16,7 @@ class YGGTorrentBridge extends BridgeAbstract {
'name' => 'category', 'name' => 'category',
'type' => 'list', 'type' => 'list',
'values' => array( 'values' => array(
'Toute les catégories' => 'all.all', 'Toutes les catégories' => 'all.all',
'Film/Vidéo - Toutes les sous-catégories' => '2145.all', 'Film/Vidéo - Toutes les sous-catégories' => '2145.all',
'Film/Vidéo - Animation' => '2145.2178', 'Film/Vidéo - Animation' => '2145.2178',
'Film/Vidéo - Animation Série' => '2145.2179', 'Film/Vidéo - Animation Série' => '2145.2179',
@ -62,7 +62,8 @@ class YGGTorrentBridge extends BridgeAbstract {
'nom' => array( 'nom' => array(
'name' => 'Nom', 'name' => 'Nom',
'description' => 'Nom du torrent', 'description' => 'Nom du torrent',
'type' => 'text' 'type' => 'text',
'exampleValue' => 'matrix'
), ),
'description' => array( 'description' => array(
'name' => 'Description', 'name' => 'Description',
@ -84,7 +85,6 @@ class YGGTorrentBridge extends BridgeAbstract {
); );
public function collectData() { public function collectData() {
$catInfo = explode('.', $this->getInput('cat')); $catInfo = explode('.', $this->getInput('cat'));
$category = $catInfo[0]; $category = $catInfo[0];
$subcategory = $catInfo[1]; $subcategory = $catInfo[1];
@ -93,9 +93,9 @@ class YGGTorrentBridge extends BridgeAbstract {
. $this->getInput('nom') . $this->getInput('nom')
. '&description=' . '&description='
. $this->getInput('description') . $this->getInput('description')
. '&fichier='
. $this->getInput('fichier')
. '&file=' . '&file='
. $this->getInput('fichier')
. '&uploader='
. $this->getInput('uploader') . $this->getInput('uploader')
. '&category=' . '&category='
. $category . $category
@ -113,30 +113,37 @@ class YGGTorrentBridge extends BridgeAbstract {
if($count == 22) break; // Stop processing after 21 items (20 + 1 table header) if($count == 22) break; // Stop processing after 21 items (20 + 1 table header)
$item = array(); $item = array();
$item['timestamp'] = $row->find('.hidden', 1)->plaintext; $item['timestamp'] = $row->find('.hidden', 1)->plaintext;
$item['title'] = $row->find('a', 1)->plaintext; $item['title'] = $row->find('a#torrent_name', 0)->plaintext;
$item['uri'] = $row->find('a', 1)->href; $item['uri'] = $this->processLink($row->find('a#torrent_name', 0)->href);
$torrentData = $this->collectTorrentData($row->find('a', 1)->href);
$item['author'] = $torrentData['author'];
$item['content'] = $torrentData['content'];
$item['seeders'] = $row->find('td', 7)->plaintext; $item['seeders'] = $row->find('td', 7)->plaintext;
$item['leechers'] = $row->find('td', 8)->plaintext; $item['leechers'] = $row->find('td', 8)->plaintext;
$item['size'] = $row->find('td', 5)->plaintext; $item['size'] = $row->find('td', 5)->plaintext;
$item = array_merge($item, $this->collectTorrentData($item['uri']));
$this->items[] = $item; $this->items[] = $item;
} }
} }
private function collectTorrentData($url) { /**
* 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);
}
//For weird reason, the link we get can be invalid, we fix it. private function collectTorrentData($url) {
$url_full = explode('/', $url); $page = defaultLinkTo(getSimpleHTMLDOMCached($url), self::URI);
$url_full[4] = urlencode($url_full[4]); $author = $page->find('.informations tr', 5)->find('td', 1)->plaintext;
$url_full[5] = urlencode($url_full[5]);
$url_full[6] = urlencode($url_full[6]);
$url = implode('/', $url_full);
$page = getSimpleHTMLDOMCached($url);
$author = $page->find('.informations', 0)->find('a', 4)->plaintext;
$content = $page->find('.default', 1); $content = $page->find('.default', 1);
return array('author' => $author, 'content' => $content); return array('author' => $author, 'content' => $content);
} }