1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-18 14:22:38 +02:00
This commit is contained in:
Dag
2023-10-13 01:02:19 +02:00
committed by GitHub
parent 44fb2c98bc
commit e379019db2
4 changed files with 72 additions and 57 deletions

View File

@@ -1,6 +1,6 @@
<?php
class NyaaTorrentsBridge extends FeedExpander
class NyaaTorrentsBridge extends BridgeAbstract
{
const MAINTAINER = 'ORelio & Jisagi';
const NAME = 'NyaaTorrents';
@@ -62,44 +62,57 @@ class NyaaTorrentsBridge extends FeedExpander
public function collectData()
{
$this->collectExpandableDatas($this->getURI(), 20);
}
// Manually parsing because we need to acccess the nyaa namespace in the xml
$xml = simplexml_load_string(getContents($this->getURI()));
$channel = $xml->channel[0];
$feed = [];
$feed['title'] = trim((string)$channel->title);
$feed['uri'] = trim((string)$channel->link);
if (!empty($channel->image)) {
$feed['icon'] = trim((string)$channel->image->url);
}
$items = $xml->channel[0]->item;
foreach ($items as $feedItem) {
$item = [
'title' => (string) $feedItem->title,
'uri' => (string) $feedItem->link,
];
protected function parseItem($newsItem)
{
$item = parent::parseItem($newsItem);
$nyaaFields = (array)($newsItem->children('nyaa', true));
$item['id'] = str_replace(['https://nyaa.si/download/', '.torrent'], '', $item['uri']);
$item['id'] = str_replace(['https://nyaa.si/download/', '.torrent'], '', $item['uri']);
$nyaaNamespace = (array)($feedItem->children('nyaa', true));
$item = array_merge($item, $nyaaNamespace);
$item = array_merge($item, $nyaaFields);
// Convert URI from torrent file to web page
$item['uri'] = str_replace('/download/', '/view/', $item['uri']);
$item['uri'] = str_replace('.torrent', '', $item['uri']);
// Convert URI from torrent file to web page
$item['uri'] = str_replace('/download/', '/view/', $item['uri']);
$item['uri'] = str_replace('.torrent', '', $item['uri']);
$item_html = getSimpleHTMLDOMCached($item['uri']);
if ($item_html) {
// Retrieve full description from page contents
$item_desc = str_get_html(
markdownToHtml(html_entity_decode($item_html->find('#torrent-description', 0)->innertext))
);
$item_html = getSimpleHTMLDOMCached($item['uri']);
if ($item_html) {
// Retrieve full description from page contents
$item_desc = str_get_html(
markdownToHtml(html_entity_decode($item_html->find('#torrent-description', 0)->innertext))
);
// Retrieve image for thumbnail or generic logo fallback
$item_image = $this->getURI() . 'static/img/avatar/default.png';
foreach ($item_desc->find('img') as $img) {
if (strpos($img->src, 'prez') === false) {
$item_image = $img->src;
break;
// Retrieve image for thumbnail or generic logo fallback
$item_image = $this->getURI() . 'static/img/avatar/default.png';
foreach ($item_desc->find('img') as $img) {
if (strpos($img->src, 'prez') === false) {
$item_image = $img->src;
break;
}
}
$item['enclosures'] = [$item_image];
$item['content'] = $item_desc;
}
$item['enclosures'] = [$item_image];
$item['content'] = $item_desc;
$this->items[] = $item;
if (count($this->items) >= 10) {
break;
}
}
return $item;
}
public function getIcon()