2018-04-20 16:57:09 +02: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 = array(
|
|
|
|
'Artist Releases' => array(
|
|
|
|
'artistid' => array(
|
|
|
|
'name' => 'Artist ID',
|
|
|
|
'type' => 'number',
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Label Releases' => array(
|
|
|
|
'labelid' => array(
|
|
|
|
'name' => 'Label ID',
|
|
|
|
'type' => 'number',
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'User Wantlist' => array(
|
|
|
|
'username_wantlist' => array(
|
|
|
|
'name' => 'Username',
|
|
|
|
'type' => 'text',
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'User Folder' => array(
|
|
|
|
'username_folder' => array(
|
|
|
|
'name' => 'Username',
|
|
|
|
'type' => 'text',
|
|
|
|
),
|
|
|
|
'folderid' => array(
|
|
|
|
'name' => 'Folder ID',
|
|
|
|
'type' => 'number',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
public function collectData() {
|
|
|
|
|
|
|
|
if(!empty($this->getInput('artistid')) || !empty($this->getInput('labelid'))) {
|
|
|
|
|
|
|
|
if(!empty($this->getInput('artistid'))) {
|
2018-06-29 23:55:33 +02:00
|
|
|
$data = getContents('https://api.discogs.com/artists/'
|
2018-04-20 16:57:09 +02:00
|
|
|
. $this->getInput('artistid')
|
2018-06-29 23:55:33 +02:00
|
|
|
. '/releases?sort=year&sort_order=desc')
|
|
|
|
or returnServerError('Unable to query discogs !');
|
2018-04-20 16:57:09 +02:00
|
|
|
} elseif(!empty($this->getInput('labelid'))) {
|
2018-06-29 23:55:33 +02:00
|
|
|
$data = getContents('https://api.discogs.com/labels/'
|
2018-04-20 16:57:09 +02:00
|
|
|
. $this->getInput('labelid')
|
2018-06-29 23:55:33 +02:00
|
|
|
. '/releases?sort=year&sort_order=desc')
|
|
|
|
or returnServerError('Unable to query discogs !');
|
2018-04-20 16:57:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$jsonData = json_decode($data, true);
|
2018-06-29 23:55:33 +02:00
|
|
|
foreach($jsonData['releases'] as $release) {
|
2018-04-20 16:57:09 +02:00
|
|
|
|
|
|
|
$item = array();
|
2018-06-29 23:55:33 +02: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;
|
|
|
|
$item['timestamp'] = DateTime::createFromFormat('Y', $release['year'])->getTimestamp();
|
2018-08-19 18:07:06 +02:00
|
|
|
if($item['timestamp'] < 0)
|
|
|
|
$item['timestamp'] = 0;
|
2018-06-29 23:55:33 +02:00
|
|
|
$item['content'] = $item['author'] . ' - ' . $item['title'];
|
2018-04-20 16:57:09 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
|
2018-06-29 23:55:33 +02:00
|
|
|
} elseif(!empty($this->getInput('username_wantlist')) || !empty($this->getInput('username_folder'))) {
|
2018-04-20 16:57:09 +02:00
|
|
|
|
2018-06-29 23:55:33 +02:00
|
|
|
if(!empty($this->getInput('username_wantlist'))) {
|
|
|
|
$data = getContents('https://api.discogs.com/users/'
|
2018-04-20 16:57:09 +02:00
|
|
|
. $this->getInput('username_wantlist')
|
2018-06-29 23:55:33 +02:00
|
|
|
. '/wants?sort=added&sort_order=desc')
|
|
|
|
or returnServerError('Unable to query discogs !');
|
|
|
|
$jsonData = json_decode($data, true)['wants'];
|
2018-04-20 16:57:09 +02:00
|
|
|
|
2018-06-29 23:55:33 +02:00
|
|
|
} elseif(!empty($this->getInput('username_folder'))) {
|
|
|
|
$data = getContents('https://api.discogs.com/users/'
|
2018-04-20 16:57:09 +02:00
|
|
|
. $this->getInput('username_folder')
|
2018-06-29 23:55:33 +02:00
|
|
|
. '/collection/folders/'
|
|
|
|
. $this->getInput('folderid')
|
|
|
|
.'/releases?sort=added&sort_order=desc')
|
|
|
|
or returnServerError('Unable to query discogs !');
|
|
|
|
$jsonData = json_decode($data, true)['releases'];
|
2018-04-20 16:57:09 +02:00
|
|
|
}
|
|
|
|
foreach($jsonData as $element) {
|
|
|
|
|
2018-06-29 23:55:33 +02:00
|
|
|
$infos = $element['basic_information'];
|
2018-04-20 16:57:09 +02:00
|
|
|
$item = array();
|
2018-06-29 23:55:33 +02: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'];
|
2018-04-20 16:57:09 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI() {
|
|
|
|
return self::URI;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return static::NAME;
|
|
|
|
}
|
|
|
|
}
|