[AppleMusicBridge] Complete rebuild for new site (#2134)

This commit is contained in:
Bockiii 2021-05-30 20:08:39 +02:00 committed by GitHub
parent 2ae9793f2c
commit b074abcc0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 45 deletions

View File

@ -4,67 +4,53 @@ class AppleMusicBridge extends BridgeAbstract {
const NAME = 'Apple Music'; const NAME = 'Apple Music';
const URI = 'https://www.apple.com'; const URI = 'https://www.apple.com';
const DESCRIPTION = 'Fetches the latest releases from an artist'; const DESCRIPTION = 'Fetches the latest releases from an artist';
const MAINTAINER = 'Limero'; const MAINTAINER = 'bockiii';
const PARAMETERS = array(array( const PARAMETERS = array(array(
'url' => array( 'artist' => array(
'name' => 'Artist URL', 'name' => 'Artist ID',
'exampleValue' => 'https://itunes.apple.com/us/artist/dunderpatrullen/329796274', 'exampleValue' => '909253',
'required' => true, 'required' => true,
), ),
'imgSize' => array( 'limit' => array(
'name' => 'Image size for thumbnails (in px)', 'name' => 'Latest X Releases (max 50)',
'type' => 'number', 'defaultValue' => '10',
'defaultValue' => 512,
'required' => true, 'required' => true,
) ),
)); ));
const CACHE_TIMEOUT = 21600; // 6 hours const CACHE_TIMEOUT = 21600; // 6 hours
private $title;
public function collectData() { public function collectData() {
$url = $this->getInput('url'); # Limit the amount of releases to 50
if ($this->getInput('limit') > 50) {
$limit = 50;
} else {
$limit = $this->getInput('limit');
}
$url = 'https://itunes.apple.com/lookup?id='
. $this->getInput('artist')
. '&entity=album&limit='
. $limit .
'&sort=recent';
$html = getSimpleHTMLDOM($url) $html = getSimpleHTMLDOM($url)
or returnServerError('Could not request: ' . $url); or returnServerError('Could not request: ' . $url);
$imgSize = $this->getInput('imgSize');
$this->title = $html->find('title', 0)->innertext;
// 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); $json = json_decode($html);
// Loop through each object foreach ($json->results as $obj) {
foreach ($json->included as $obj) { if ($obj->wrapperType === 'collection') {
if ($obj->type === 'lockup/album') {
$this->items[] = array( $this->items[] = array(
'title' => $obj->attributes->artistName . ' - ' . $obj->attributes->name, 'title' => $obj->artistName . ' - ' . $obj->collectionName,
'uri' => $obj->attributes->url, 'uri' => $obj->collectionViewUrl,
'timestamp' => $obj->attributes->releaseDate, 'timestamp' => $obj->releaseDate,
'enclosures' => $obj->relationships->artwork->data->id, 'enclosures' => $obj->artworkUrl100,
'content' => '<a href=' . $obj->collectionViewUrl
. '><img src="' . $obj->artworkUrl100 . '" /></a><br><br>'
. $obj->artistName . ' - ' . $obj->collectionName
. '<br>'
. $obj->copyright,
); );
} elseif ($obj->type === 'image') {
$images[$obj->id] = $obj->attributes->url;
} }
} }
// Add the images to each item
foreach ($this->items as &$item) {
$item['enclosures'] = array(
str_replace('{w}x{h}bb.{f}', $imgSize . 'x0w.jpg', $images[$item['enclosures']]),
);
}
// Sort the order to put the latest albums first
usort($this->items, function($a, $b){
return $a['timestamp'] < $b['timestamp'];
});
}
public function getName() {
return $this->title ?: parent::getName();
} }
} }