2018-04-20 17:57:09 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class DiscogsBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const MAINTAINER = 'teromene';
|
|
|
|
const NAME = 'DiscogsBridge';
|
|
|
|
const URI = 'https://www.discogs.com/';
|
|
|
|
const DESCRIPTION = 'Returns releases from discogs';
|
|
|
|
const PARAMETERS = [
|
|
|
|
'Artist Releases' => [
|
|
|
|
'artistid' => [
|
|
|
|
'name' => 'Artist ID',
|
|
|
|
'type' => 'number',
|
2022-03-24 13:59:34 +03:00
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => '28104',
|
|
|
|
'title' => 'Only the ID from an artist page. EG /artist/28104-Aesop-Rock is 28104'
|
2022-11-03 22:33:43 +03:00
|
|
|
],
|
|
|
|
'image' => [
|
|
|
|
'name' => 'Include Image',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'defaultValue' => 'checked',
|
|
|
|
'title' => 'Whether to include image (if bridge is configured with a personal access token)',
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2018-04-20 17:57:09 +03:00
|
|
|
],
|
|
|
|
'Label Releases' => [
|
|
|
|
'labelid' => [
|
|
|
|
'name' => 'Label ID',
|
|
|
|
'type' => 'number',
|
2022-03-24 13:59:34 +03:00
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => '8201',
|
|
|
|
'title' => 'Only the ID from a label page. EG /label/8201-Rhymesayers-Entertainment is 8201'
|
2022-11-03 22:33:43 +03:00
|
|
|
],
|
|
|
|
'image' => [
|
|
|
|
'name' => 'Include Image',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'defaultValue' => 'checked',
|
|
|
|
'title' => 'Whether to include image (if bridge is configured with a personal access token)',
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2018-04-20 17:57:09 +03:00
|
|
|
],
|
|
|
|
'User Wantlist' => [
|
|
|
|
'username_wantlist' => [
|
|
|
|
'name' => 'Username',
|
|
|
|
'type' => 'text',
|
2022-03-24 13:59:34 +03:00
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'TheBlindMaster',
|
2022-11-03 22:33:43 +03:00
|
|
|
],
|
|
|
|
'image' => [
|
|
|
|
'name' => 'Include Image',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'defaultValue' => 'checked',
|
|
|
|
'title' => 'Whether to include image (if bridge is configured with a personal access token)',
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2018-04-20 17:57:09 +03:00
|
|
|
],
|
|
|
|
'User Folder' => [
|
|
|
|
'username_folder' => [
|
|
|
|
'name' => 'Username',
|
|
|
|
'type' => 'text',
|
|
|
|
],
|
|
|
|
'folderid' => [
|
|
|
|
'name' => 'Folder ID',
|
|
|
|
'type' => 'number',
|
2022-11-03 22:33:43 +03:00
|
|
|
],
|
|
|
|
'image' => [
|
|
|
|
'name' => 'Include Image',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'defaultValue' => 'checked',
|
|
|
|
'title' => 'Whether to include image (if bridge is configured with a personal access token)',
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2022-11-03 22:33:43 +03:00
|
|
|
],
|
|
|
|
];
|
|
|
|
const CONFIGURATION = [
|
|
|
|
/**
|
|
|
|
* When a personal access token is provided, Discogs' API will
|
|
|
|
* return images as part of artist and label information.
|
|
|
|
*
|
|
|
|
* @see https://www.discogs.com/settings/developers
|
|
|
|
*/
|
|
|
|
'personal_access_token' => [
|
|
|
|
'required' => false,
|
|
|
|
],
|
2018-04-20 17:57:09 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-04-20 17:57:09 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2022-11-03 22:33:43 +03:00
|
|
|
$headers = [];
|
|
|
|
|
|
|
|
if ($this->getOption('personal_access_token')) {
|
|
|
|
$headers = ['Authorization: Discogs token=' . $this->getOption('personal_access_token')];
|
|
|
|
}
|
|
|
|
|
2018-04-20 17:57:09 +03:00
|
|
|
if (!empty($this->getInput('artistid')) || !empty($this->getInput('labelid'))) {
|
|
|
|
if (!empty($this->getInput('artistid'))) {
|
2022-11-03 22:33:43 +03:00
|
|
|
$url = 'https://api.discogs.com/artists/'
|
|
|
|
. $this->getInput('artistid')
|
|
|
|
. '/releases?sort=year&sort_order=desc';
|
|
|
|
$data = getContents($url, $headers);
|
2018-04-20 17:57:09 +03:00
|
|
|
} elseif (!empty($this->getInput('labelid'))) {
|
2022-11-03 22:33:43 +03:00
|
|
|
$url = 'https://api.discogs.com/labels/'
|
|
|
|
. $this->getInput('labelid')
|
|
|
|
. '/releases?sort=year&sort_order=desc';
|
|
|
|
$data = getContents($url, $headers);
|
2018-04-20 17:57:09 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-04-20 17:57:09 +03:00
|
|
|
$jsonData = json_decode($data, true);
|
2022-11-03 22:33:43 +03:00
|
|
|
|
2018-06-30 00:55:33 +03:00
|
|
|
foreach ($jsonData['releases'] as $release) {
|
2018-04-20 17:57:09 +03:00
|
|
|
$item = [];
|
2018-06-30 00:55:33 +03:00
|
|
|
$item['author'] = $release['artist'];
|
|
|
|
$item['title'] = $release['title'];
|
|
|
|
$item['id'] = $release['id'];
|
|
|
|
$resId = array_key_exists('main_release', $release) ? $release['main_release'] : $release['id'];
|
|
|
|
$item['uri'] = self::URI . $this->getInput('artistid') . '/release/' . $resId;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-01-05 17:24:44 +03:00
|
|
|
if (isset($release['year'])) {
|
|
|
|
$item['timestamp'] = DateTime::createFromFormat('Y', $release['year'])->getTimestamp();
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-06-30 00:55:33 +03:00
|
|
|
$item['content'] = $item['author'] . ' - ' . $item['title'];
|
2022-11-03 22:33:43 +03:00
|
|
|
|
|
|
|
if (isset($release['thumb']) && $this->getInput('image') === true) {
|
|
|
|
$item['content'] = sprintf(
|
|
|
|
'<img src="%s"/><br/><br/>%s',
|
|
|
|
$release['thumb'],
|
|
|
|
$item['content'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-20 17:57:09 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2018-06-30 00:55:33 +03:00
|
|
|
} elseif (!empty($this->getInput('username_wantlist')) || !empty($this->getInput('username_folder'))) {
|
|
|
|
if (!empty($this->getInput('username_wantlist'))) {
|
2022-11-03 22:33:43 +03:00
|
|
|
$url = 'https://api.discogs.com/users/'
|
|
|
|
. $this->getInput('username_wantlist')
|
|
|
|
. '/wants?sort=added&sort_order=desc';
|
|
|
|
$data = getContents($url, $headers);
|
2018-06-30 00:55:33 +03:00
|
|
|
$jsonData = json_decode($data, true)['wants'];
|
|
|
|
} elseif (!empty($this->getInput('username_folder'))) {
|
2022-11-03 22:33:43 +03:00
|
|
|
$url = 'https://api.discogs.com/users/'
|
|
|
|
. $this->getInput('username_folder')
|
|
|
|
. '/collection/folders/'
|
|
|
|
. $this->getInput('folderid')
|
|
|
|
. '/releases?sort=added&sort_order=desc';
|
|
|
|
$data = getContents($url, $headers);
|
2018-06-30 00:55:33 +03:00
|
|
|
$jsonData = json_decode($data, true)['releases'];
|
2018-04-20 17:57:09 +03:00
|
|
|
}
|
|
|
|
foreach ($jsonData as $element) {
|
2018-06-30 00:55:33 +03:00
|
|
|
$infos = $element['basic_information'];
|
2018-04-20 17:57:09 +03:00
|
|
|
$item = [];
|
2018-06-30 00:55:33 +03:00
|
|
|
$item['title'] = $infos['title'];
|
|
|
|
$item['author'] = $infos['artists'][0]['name'];
|
|
|
|
$item['id'] = $infos['artists'][0]['id'];
|
|
|
|
$item['uri'] = self::URI . $infos['artists'][0]['id'] . '/release/' . $infos['id'];
|
|
|
|
$item['timestamp'] = strtotime($element['date_added']);
|
|
|
|
$item['content'] = $item['author'] . ' - ' . $item['title'];
|
2022-11-03 22:33:43 +03:00
|
|
|
|
|
|
|
if (isset($infos['thumb']) && $this->getInput('image') === true) {
|
|
|
|
$item['content'] = sprintf(
|
|
|
|
'<img src="%s"/><br/><br/>%s',
|
|
|
|
$infos['thumb'],
|
|
|
|
$item['content'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-20 17:57:09 +03:00
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2018-04-20 17:57:09 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-04-20 17:57:09 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
return self::URI;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-04-20 17:57:09 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return static::NAME;
|
|
|
|
}
|
|
|
|
}
|