1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-06 00:27:27 +02:00

[FanaticalBridge] Create a new bridge (#4624)

Provides a fairly barebones bridge for Fanatical bundles:
- Tags detail bundle tiers and prices
- Contents name and link to each bundle item
- Images for each item are in enclosures
This commit is contained in:
July
2025-08-03 18:21:04 -04:00
committed by GitHub
parent 8ae2c2e3c3
commit 5b97899734

View File

@@ -0,0 +1,95 @@
<?php
class FanaticalBridge extends BridgeAbstract
{
const NAME = 'Fanatical';
const MAINTAINER = 'phantop';
const URI = 'https://www.fanatical.com/en/';
const DESCRIPTION = 'Returns bundles from Fanatical.';
const PARAMETERS = [[
'type' => [
'name' => 'Bundle type',
'type' => 'list',
'defaultValue' => 'all',
'values' => [
'All' => 'all',
'Books' => 'book-',
'ELearning' => 'elearning-',
'Games' => '',
'Software' => 'software-',
]
]
]];
const IMGURL = 'https://fanatical.imgix.net/product/original/';
public function collectData()
{
$api = 'https://www.fanatical.com/api/all/en';
$json = json_decode(getContents($api), true)['pickandmix'];
$type = $this->getInput('type');
foreach ($json as $element) {
if ($type != 'all') {
if ($element['type'] != $type . 'bundle') {
continue;
}
}
$item = [
'categories' => [$element['type']],
'content' => '<ul>',
'enclosures' => [self::IMGURL . $element['cover_image']],
'timestamp' => $element['valid_from'],
'title' => $element['name'],
'uri' => parent::getURI() . 'pick-and-mix/' . $element['slug'],
];
$slugs = [];
foreach ($element['products'] as $product) {
$slug = $product['slug'];
if (in_array($slug, $slugs)) {
continue;
}
$slugs[] = $slug;
$uri = parent::getURI() . 'game/' . $slug;
$item['content'] .= '<li><a href="' . $uri . '">' . $product['name'] . '</a></li>';
$item['enclosures'][] = self::IMGURL . $product['cover'];
}
foreach ($element['tiers'] as $tier) {
$count = $tier['quantity'];
$price = round($tier['price']['USD'] / 100, 2);
$per = round($price / $count, 2);
$item['categories'][] = "$count at $per for $price total";
}
$item['content'] .= '</ul>';
$this->items[] = $item;
}
}
public function getName()
{
$name = parent::getName();
$name .= $this->getKey('type') ? ' - ' . $this->getKey('type') : '';
return $name;
}
public function getURI()
{
$uri = parent::getURI();
$type = $this->getKey('type');
if ($type) {
$uri .= 'bundle/';
if ($type != 'All') {
$uri .= strtolower($type);
}
}
return $uri;
}
public function getIcon()
{
return 'https://cdn.fanatical.com/production/icons/fanatical-icon-android-chrome-192x192.png';
}
}