1
0
Files
Bridges/GalleryEpicBridge.php
2025-07-03 21:58:26 +02:00

122 lines
4.4 KiB
PHP

<?php
class GalleryEpicBridge extends BridgeAbstract
{
const MAINTAINER = 'Brawl, Gemini';
const NAME = 'GalleryEpic Bridge';
const URI = 'https://galleryepic.com/';
const DESCRIPTION = 'Returns the latest albums for a cosplayer on GalleryEpic.';
const PARAMETERS = [
[
'cosplayer_id' => [
'name' => 'Cosplayer ID',
'type' => 'number',
'required' => true,
'title' => 'Enter the Cosplayer ID (e.g., 95 from https://galleryepic.com/en/coser/95/1)',
'exampleValue' => 95
]
]
];
const CACHE_TIMEOUT = 21600; // 6 hours
private $feedName = null;
public function collectData()
{
$cosplayerId = $this->getInput('cosplayer_id');
if (!$cosplayerId) {
returnServerError('Cosplayer ID is required.');
}
// Set a default feed name before fetching content
$this->feedName = static::NAME . ' for Cosplayer ID ' . $cosplayerId;
$url = self::URI . 'en/coser/' . $cosplayerId . '/1';
$html = getSimpleHTMLDOM($url);
if (!$html) {
returnServerError('Could not request_uri: ' . $url);
}
// Extract cosplayer name for a more specific feed title
$cosplayerNameElement = $html->find('h4.scroll-m-20.text-xl.font-semibold.tracking-tight', 0);
if ($cosplayerNameElement) {
$cosplayerName = trim($cosplayerNameElement->plaintext);
$this->feedName = $cosplayerName . ' - GalleryEpic Albums';
} else {
// Fallback if name couldn't be extracted, keep the default with ID
$this->feedName = 'GalleryEpic Albums for Cosplayer ID ' . $cosplayerId;
}
$albums = $html->find('div.space-y-3.relative');
foreach ($albums as $albumElement) {
$item = [];
$linkElement = $albumElement->find('a.space-y-3', 0);
if ($linkElement) {
$item['uri'] = self::URI . ltrim($linkElement->href, '/');
}
$titleElement = $albumElement->find('h3.font-medium', 0);
if ($titleElement) {
$item['title'] = $titleElement->plaintext;
}
$seriesElement = $albumElement->find('p.text-xs.text-muted-foreground', 0);
$seriesText = $seriesElement ? $seriesElement->plaintext : '';
$imageElement = $albumElement->find('img[variant="cover"]', 0);
$imageUrl = $imageElement ? $imageElement->src : '';
$imagePCountElement = $albumElement->find('p.absolute.bottom-2.right-2', 0);
$imagePCount = $imagePCountElement ? str_replace('P', '', $imagePCountElement->plaintext) : '';
$item['content'] = '<p>';
if ($seriesText) {
$item['content'] .= 'Series: ' . $seriesText . '<br>';
}
if ($imagePCount) {
$item['content'] .= 'Pictures: ' . $imagePCount . '<br>';
}
$item['content'] .= '</p>';
if ($imageUrl) {
$item['content'] .= '<a href="' . $item['uri'] . '"><img src="' . $imageUrl . '" /></a>';
}
// Try to find a download link (optional)
$downloadLinkElement = $albumElement->find('a[href*="/download/cosplay/"]', 0);
if ($downloadLinkElement) {
$item['content'] .= '<br><a href="' . self::URI . ltrim($downloadLinkElement->href, '/') . '">Download Album</a>';
}
if (isset($item['uri']) && isset($item['title'])) {
$this->items[] = $item;
}
}
}
public function getIcon()
{
return 'https://galleryepic.com/icons/icon-192x192.png';
}
public function getName()
{
if (!is_null($this->feedName)) {
return $this->feedName;
}
// Fallback for before collectData runs or if no cosplayer_id input
if (!is_null($this->getInput('cosplayer_id'))) {
return static::NAME . ' for Cosplayer ID ' . $this->getInput('cosplayer_id');
}
return parent::getName(); // Returns static::NAME by default
}
public function getURI()
{
if (!is_null($this->getInput('cosplayer_id'))) {
return self::URI . 'en/coser/' . $this->getInput('cosplayer_id') . '/1';
}
return parent::getURI();
}
}