aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar David Pedersen <Limero@users.noreply.github.com> 2019-02-06 17:43:20 +0100
committerGravatar LogMANOriginal <LogMANOriginal@users.noreply.github.com> 2019-02-06 17:43:20 +0100
commit29b187fc1223e8c7575b8935d7d2ca219efced40 (patch)
tree2ce096d40d735b4b2ca5f956caed43084943f6ff
parent80f6a8b3d4dbb1d37225959283a8ff2c51fc9ef8 (diff)
downloadrss-bridge-29b187fc1223e8c7575b8935d7d2ca219efced40.tar.gz
rss-bridge-29b187fc1223e8c7575b8935d7d2ca219efced40.tar.zst
rss-bridge-29b187fc1223e8c7575b8935d7d2ca219efced40.zip
[AppleMusicBridge] Add new bridge (#1026)
-rw-r--r--bridges/AppleMusicBridge.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/bridges/AppleMusicBridge.php b/bridges/AppleMusicBridge.php
new file mode 100644
index 00000000..5a4f40a4
--- /dev/null
+++ b/bridges/AppleMusicBridge.php
@@ -0,0 +1,62 @@
+<?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';
+ const PARAMETERS = [[
+ 'url' => [
+ 'name' => 'Artist URL',
+ 'exampleValue' => 'https://itunes.apple.com/us/artist/dunderpatrullen/329796274',
+ 'required' => true,
+ ],
+ 'imgSize' => [
+ 'name' => 'Image size for thumbnails (in px)',
+ 'type' => 'number',
+ 'defaultValue' => 512,
+ 'required' => true,
+ ]
+ ]];
+ const CACHE_TIMEOUT = 21600; // 6 hours
+
+ public function collectData() {
+ $url = $this->getInput('url');
+ $html = getSimpleHTMLDOM($url)
+ or returnServerError('Could not request: ' . $url);
+
+ $imgSize = $this->getInput('imgSize');
+
+ // 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') {
+ $this->items[] = [
+ 'title' => $obj->attributes->artistName . ' - ' . $obj->attributes->name,
+ 'uri' => $obj->attributes->url,
+ 'timestamp' => $obj->attributes->releaseDate,
+ 'enclosures' => $obj->relationships->artwork->data->id,
+ ];
+ } elseif ($obj->type === 'image') {
+ $images[$obj->id] = $obj->attributes->url;
+ }
+ }
+
+ // Add the images to each item
+ foreach ($this->items as &$item) {
+ $item['enclosures'] = [
+ 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'];
+ });
+ }
+}