Skip to content

Commit

Permalink
NyaaTorrentsBridge: add torrent to enclosures and generate better fee…
Browse files Browse the repository at this point in the history
…d name (#3996)

* NyaaTorrentsBridge: add torrent to enclosures and generate better feed name

* NyaaTorrentsBridge: fix accidental () in bridge name
  • Loading branch information
Phantop authored Mar 6, 2024
1 parent 7a7f8d5 commit f7c1b71
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions bridges/NyaaTorrentsBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,20 @@ public function collectData()
$feed = $feedParser->parseFeed(getContents($this->getURI()));

foreach ($feed['items'] as $item) {
$item['id'] = str_replace(['https://nyaa.si/download/', '.torrent'], '', $item['uri']);
$item['uri'] = str_replace('/download/', '/view/', $item['uri']);
$item['enclosures'] = [$item['uri']];
$item['uri'] = str_replace('.torrent', '', $item['uri']);
$item['uri'] = str_replace('/download/', '/view/', $item['uri']);
$item['id'] = str_replace('https://nyaa.si/view/', '', $item['uri']);
$dom = getSimpleHTMLDOMCached($item['uri']);
if ($dom) {
$description = $dom->find('#torrent-description', 0)->innertext ?? '';
$itemDom = str_get_html(markdownToHtml(html_entity_decode($description)));
$item_image = $this->getURI() . 'static/img/avatar/default.png';
foreach ($itemDom->find('img') as $img) {
if (strpos($img->src, 'prez') === false) {
$item_image = $img->src;
break;
}
}
$item['enclosures'] = [$item_image];
$item['content'] = (string) $itemDom;
$item['content'] = markdownToHtml(html_entity_decode($description));

$magnet = $dom->find('div.panel-footer.clearfix > a', 1)->href;
// can't put raw magnet link in enclosure, this gives information on
// magnet contents and works a way to sent magnet value
$magnet = 'https://torrent.parts/#' . html_entity_decode($magnet);
array_push($item['enclosures'], $magnet);
}
$this->items[] = $item;
if (count($this->items) >= 10) {
Expand All @@ -90,6 +88,15 @@ public function collectData()
}
}

public function getName()
{
$name = parent::getName();
$name .= $this->getInput('u') ? ' - ' . $this->getInput('u') : '';
$name .= $this->getInput('q') ? ' - ' . $this->getInput('q') : '';
$name .= $this->getInput('c') ? ' (' . $this->getKey('c') . ')' : '';
return $name;
}

public function getIcon()
{
return self::URI . 'static/favicon.png';
Expand Down

0 comments on commit f7c1b71

Please sign in to comment.