2019-02-06 17:43:20 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AppleMusicBridge extends BridgeAbstract {
|
|
|
|
const NAME = 'Apple Music';
|
|
|
|
const URI = 'https://www.apple.com';
|
|
|
|
const DESCRIPTION = 'Fetches the latest releases from an artist';
|
|
|
|
const MAINTAINER = 'Limero';
|
2019-11-01 18:06:38 +01:00
|
|
|
const PARAMETERS = array(array(
|
|
|
|
'url' => array(
|
2019-02-06 17:43:20 +01:00
|
|
|
'name' => 'Artist URL',
|
|
|
|
'exampleValue' => 'https://itunes.apple.com/us/artist/dunderpatrullen/329796274',
|
|
|
|
'required' => true,
|
2019-11-01 18:06:38 +01:00
|
|
|
),
|
|
|
|
'imgSize' => array(
|
2019-02-06 17:43:20 +01:00
|
|
|
'name' => 'Image size for thumbnails (in px)',
|
|
|
|
'type' => 'number',
|
|
|
|
'defaultValue' => 512,
|
|
|
|
'required' => true,
|
2019-11-01 18:06:38 +01:00
|
|
|
)
|
|
|
|
));
|
2019-02-06 17:43:20 +01:00
|
|
|
const CACHE_TIMEOUT = 21600; // 6 hours
|
|
|
|
|
2020-11-16 18:15:39 +01:00
|
|
|
private $title;
|
|
|
|
|
2019-02-06 17:43:20 +01:00
|
|
|
public function collectData() {
|
|
|
|
$url = $this->getInput('url');
|
|
|
|
$html = getSimpleHTMLDOM($url)
|
|
|
|
or returnServerError('Could not request: ' . $url);
|
|
|
|
|
|
|
|
$imgSize = $this->getInput('imgSize');
|
|
|
|
|
2020-11-16 18:15:39 +01:00
|
|
|
$this->title = $html->find('title', 0)->innertext;
|
|
|
|
|
2019-02-06 17:43:20 +01:00
|
|
|
// Grab the json data from the page
|
|
|
|
$html = $html->find('script[id=shoebox-ember-data-store]', 0);
|
|
|
|
$html = strstr($html, '{');
|
|
|
|
$html = substr($html, 0, -9);
|
|
|
|
$json = json_decode($html);
|
|
|
|
|
|
|
|
// Loop through each object
|
|
|
|
foreach ($json->included as $obj) {
|
|
|
|
if ($obj->type === 'lockup/album') {
|
2019-11-01 18:06:38 +01:00
|
|
|
$this->items[] = array(
|
2019-02-06 17:43:20 +01:00
|
|
|
'title' => $obj->attributes->artistName . ' - ' . $obj->attributes->name,
|
|
|
|
'uri' => $obj->attributes->url,
|
|
|
|
'timestamp' => $obj->attributes->releaseDate,
|
|
|
|
'enclosures' => $obj->relationships->artwork->data->id,
|
2019-11-01 18:06:38 +01:00
|
|
|
);
|
2019-02-06 17:43:20 +01:00
|
|
|
} elseif ($obj->type === 'image') {
|
|
|
|
$images[$obj->id] = $obj->attributes->url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the images to each item
|
|
|
|
foreach ($this->items as &$item) {
|
2019-11-01 18:06:38 +01:00
|
|
|
$item['enclosures'] = array(
|
2019-02-06 17:43:20 +01:00
|
|
|
str_replace('{w}x{h}bb.{f}', $imgSize . 'x0w.jpg', $images[$item['enclosures']]),
|
2019-11-01 18:06:38 +01:00
|
|
|
);
|
2019-02-06 17:43:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the order to put the latest albums first
|
|
|
|
usort($this->items, function($a, $b){
|
|
|
|
return $a['timestamp'] < $b['timestamp'];
|
|
|
|
});
|
|
|
|
}
|
2020-11-16 18:15:39 +01:00
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return $this->title ?: parent::getName();
|
|
|
|
}
|
2019-02-06 17:43:20 +01:00
|
|
|
}
|