150 lines
4.3 KiB
PHP
150 lines
4.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
class AppStoreUpdateBridge extends BridgeAbstract
|
|
{
|
|
const MAINTAINER = 'Akamaru';
|
|
const NAME = 'App Store Update Bridge';
|
|
const URI = 'https://apps.apple.com/';
|
|
const CACHE_TIMEOUT = 3600; // 1 hour
|
|
const DESCRIPTION = 'Returns app updates from the Apple App Store using iTunes API';
|
|
|
|
const PARAMETERS = [
|
|
[
|
|
'app_id' => [
|
|
'name' => 'App ID',
|
|
'type' => 'text',
|
|
'required' => true,
|
|
'title' => 'The numeric App ID from the App Store URL (e.g., 383457673)',
|
|
'exampleValue' => '383457673'
|
|
],
|
|
'country' => [
|
|
'name' => 'Country Code',
|
|
'type' => 'text',
|
|
'required' => false,
|
|
'defaultValue' => 'de',
|
|
'title' => 'Two-letter country code (e.g., de, us, fr, jp)',
|
|
'exampleValue' => 'de'
|
|
]
|
|
]
|
|
];
|
|
|
|
private ?array $appData = null;
|
|
|
|
private function getAppData(): ?array
|
|
{
|
|
if ($this->appData !== null) {
|
|
return $this->appData;
|
|
}
|
|
|
|
$appId = $this->getInput('app_id');
|
|
if (!$appId) {
|
|
return null;
|
|
}
|
|
|
|
$country = $this->getInput('country') ?: 'de';
|
|
|
|
$apiUrl = sprintf(
|
|
'https://itunes.apple.com/lookup?id=%s&country=%s',
|
|
urlencode($appId),
|
|
urlencode($country)
|
|
);
|
|
|
|
$json = getContents($apiUrl);
|
|
$data = json_decode($json, true);
|
|
|
|
if (!$data || $data['resultCount'] === 0) {
|
|
return null;
|
|
}
|
|
|
|
$this->appData = $data['results'][0];
|
|
return $this->appData;
|
|
}
|
|
|
|
public function collectData()
|
|
{
|
|
$appData = $this->getAppData();
|
|
|
|
if (!$appData) {
|
|
returnServerError('Could not find app with the given ID');
|
|
}
|
|
|
|
$country = $this->getInput('country') ?: 'de';
|
|
$appId = $this->getInput('app_id');
|
|
|
|
// Parse release date
|
|
$releaseDate = $appData['currentVersionReleaseDate'] ?? $appData['releaseDate'] ?? null;
|
|
$timestamp = $releaseDate ? strtotime($releaseDate) : time();
|
|
|
|
// If the date doesn't contain a year, use current year
|
|
if ($timestamp === false) {
|
|
$timestamp = time();
|
|
}
|
|
|
|
// Format release notes
|
|
$releaseNotes = $appData['releaseNotes'] ?? 'No release notes available.';
|
|
$content = nl2br(htmlspecialchars($releaseNotes));
|
|
|
|
$item = [
|
|
'uri' => sprintf('https://apps.apple.com/%s/app/id%s', $country, $appId),
|
|
'title' => sprintf('%s %s', $appData['trackName'] ?? 'App', $appData['version'] ?? ''),
|
|
'content' => $content,
|
|
'timestamp' => $timestamp,
|
|
'author' => $appData['artistName'] ?? null,
|
|
'uid' => sprintf('%s-%s', $appId, $appData['version'] ?? 'unknown'),
|
|
'enclosures' => [
|
|
$appData['artworkUrl512'] ?? $appData['artworkUrl100'] ?? null
|
|
]
|
|
];
|
|
|
|
$this->items[] = $item;
|
|
}
|
|
|
|
public function getName()
|
|
{
|
|
$appData = $this->getAppData();
|
|
if ($appData && isset($appData['trackName'])) {
|
|
return sprintf('%s - App Store Updates', $appData['trackName']);
|
|
}
|
|
return parent::getName();
|
|
}
|
|
|
|
public function getURI()
|
|
{
|
|
$appId = $this->getInput('app_id');
|
|
$country = $this->getInput('country') ?: 'de';
|
|
|
|
if ($appId) {
|
|
return sprintf('https://apps.apple.com/%s/app/id%s', $country, $appId);
|
|
}
|
|
return parent::getURI();
|
|
}
|
|
|
|
public function getIcon()
|
|
{
|
|
$appData = $this->getAppData();
|
|
if ($appData && isset($appData['artworkUrl100'])) {
|
|
return $appData['artworkUrl100'];
|
|
}
|
|
return 'https://www.google.com/s2/favicons?domain=apple.com&sz=32';
|
|
}
|
|
|
|
public function detectParameters($url)
|
|
{
|
|
// Match URLs like:
|
|
// https://apps.apple.com/de/app/plex-film-tv/id383457673
|
|
// https://apps.apple.com/us/app/id383457673
|
|
$pattern = '/apps\.apple\.com\/([a-z]{2})\/app\/(?:[^\/]+\/)?id(\d+)/i';
|
|
|
|
if (preg_match($pattern, $url, $matches)) {
|
|
return [
|
|
'country' => $matches[1],
|
|
'app_id' => $matches[2]
|
|
];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|