1
0

Neue Bridge für Humble Bundle

This commit is contained in:
Akamaru
2025-10-02 17:33:59 +02:00
parent c2cce1b17c
commit 12ce8192ed

122
HumbleBundlesBridge.php Normal file
View File

@@ -0,0 +1,122 @@
<?php
class HumbleBundlesBridge extends BridgeAbstract {
const MAINTAINER = 'Akamaru';
const NAME = 'Humble Bundle';
const URI = 'https://www.humblebundle.com/';
const CACHE_TIMEOUT = 3600; // 1h
const DESCRIPTION = 'Get the latest bundles from Humble Bundle.';
public function getIcon() {
return 'https://www.humblebundle.com/favicon.ico';
}
const PARAMETERS = [
[
'category' => [
'name' => 'Category',
'type' => 'list',
'values' => [
'All' => 'all',
'Games' => 'games',
'Books' => 'books',
'Software' => 'software',
],
'defaultValue' => 'all',
],
],
];
public function collectData() {
$html = getSimpleHTMLDOM(self::URI . 'bundles');
if (!$html) return;
// Find the script tag with id "landingPage-json-data"
$scriptTag = $html->find('script#landingPage-json-data', 0);
if (!$scriptTag) return;
$jsonData = $scriptTag->innertext;
$data = json_decode($jsonData, true);
if (!$data) return;
$category = $this->getInput('category');
$bundles = [];
// Get bundles based on category
if ($category === 'all') {
// Collect all bundles from all categories
if (isset($data['data']['games']['mosaic'][0]['products'])) {
$bundles = array_merge($bundles, $data['data']['games']['mosaic'][0]['products']);
}
if (isset($data['data']['books']['mosaic'][0]['products'])) {
$bundles = array_merge($bundles, $data['data']['books']['mosaic'][0]['products']);
}
if (isset($data['data']['software']['mosaic'][0]['products'])) {
$bundles = array_merge($bundles, $data['data']['software']['mosaic'][0]['products']);
}
// Sort by start date (newest first)
usort($bundles, function($a, $b) {
$timeA = isset($a['start_date|datetime']) ? strtotime($a['start_date|datetime']) : 0;
$timeB = isset($b['start_date|datetime']) ? strtotime($b['start_date|datetime']) : 0;
return $timeB - $timeA;
});
} else {
// Get bundles for specific category
if (isset($data['data'][$category]['mosaic'][0]['products'])) {
$bundles = $data['data'][$category]['mosaic'][0]['products'];
}
}
foreach ($bundles as $bundle) {
$item = [];
$item['title'] = $bundle['tile_name'] ?? $bundle['tile_short_name'] ?? 'Unknown Bundle';
$item['uri'] = self::URI . ltrim($bundle['product_url'], '/');
$item['uid'] = $bundle['machine_name'];
// Author
if (isset($bundle['author'])) {
$item['author'] = $bundle['author'];
}
// Timestamp
if (isset($bundle['start_date|datetime'])) {
$item['timestamp'] = strtotime($bundle['start_date|datetime']);
}
// Build content
$content = '';
// Add image
if (isset($bundle['tile_image'])) {
$content .= '<div style="text-align: center;"><img src="' . $bundle['tile_image'] . '" alt="' . htmlspecialchars($item['title']) . '"></div><br>';
$item['enclosures'][] = $bundle['tile_image'];
}
// Add marketing blurb
if (isset($bundle['detailed_marketing_blurb'])) {
$content .= '<p>' . $bundle['marketing_blurb'] . '</p><br>';
$content .= '<p>' . $bundle['detailed_marketing_blurb'] . '</p>';
} elseif (isset($bundle['marketing_blurb'])) {
$content .= '<p>' . $bundle['marketing_blurb'] . '</p>';
}
// Add highlights
if (isset($bundle['highlights']) && is_array($bundle['highlights'])) {
$content .= '<p><strong>Details:</strong></p><ul>';
foreach ($bundle['highlights'] as $highlight) {
$content .= '<li>' . htmlspecialchars($highlight) . '</li>';
}
if (isset($bundle['end_date|datetime'])) {
$endDate = date('Y-m-d H:i:s', strtotime($bundle['end_date|datetime']));
$content .= '<li>Ends: ' . $endDate . '</li>';
}
$content .= '</ul>';
}
$item['content'] = $content;
$this->items[] = $item;
}
}
}