2014-02-09 15:33:02 +01:00
|
|
|
<?php
|
2017-02-11 16:16:56 +01:00
|
|
|
class BandcampBridge extends BridgeAbstract {
|
|
|
|
|
|
|
|
const MAINTAINER = 'sebsauvage';
|
|
|
|
const NAME = 'Bandcamp Tag';
|
2017-03-18 20:02:18 +01:00
|
|
|
const URI = 'https://bandcamp.com/';
|
2017-02-11 16:16:56 +01:00
|
|
|
const CACHE_TIMEOUT = 600; // 10min
|
|
|
|
const DESCRIPTION = 'New bandcamp release by tag';
|
|
|
|
const PARAMETERS = array( array(
|
|
|
|
'tag' => array(
|
|
|
|
'name' => 'tag',
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true
|
|
|
|
)
|
|
|
|
));
|
2019-02-24 12:08:34 +01:00
|
|
|
const IMGURI = 'https://f4.bcbits.com/';
|
|
|
|
const IMGSIZE_300PX = 23;
|
|
|
|
const IMGSIZE_700PX = 16;
|
2017-02-11 16:16:56 +01:00
|
|
|
|
2018-10-26 18:07:34 +02:00
|
|
|
public function getIcon() {
|
|
|
|
return 'https://s4.bcbits.com/img/bc_favicon.ico';
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
public function collectData(){
|
2019-02-24 12:08:34 +01:00
|
|
|
$url = self::URI . 'api/hub/1/dig_deeper';
|
|
|
|
$data = $this->buildRequestJson();
|
|
|
|
$header = array(
|
|
|
|
'Content-Type: application/json',
|
|
|
|
'Content-Length: ' . strlen($data)
|
|
|
|
);
|
|
|
|
$opts = array(
|
|
|
|
CURLOPT_CUSTOMREQUEST => 'POST',
|
|
|
|
CURLOPT_POSTFIELDS => $data
|
|
|
|
);
|
|
|
|
$content = getContents($url, $header, $opts)
|
|
|
|
or returnServerError('Could not complete request to: ' . $url);
|
2017-02-11 16:16:56 +01:00
|
|
|
|
2019-02-24 12:08:34 +01:00
|
|
|
$json = json_decode($content);
|
2017-02-11 16:16:56 +01:00
|
|
|
|
2019-02-24 12:08:34 +01:00
|
|
|
if ($json->ok !== true) {
|
|
|
|
returnServerError('Invalid response');
|
|
|
|
}
|
2017-02-11 16:16:56 +01:00
|
|
|
|
2019-02-24 12:08:34 +01:00
|
|
|
foreach ($json->items as $entry) {
|
|
|
|
$url = $entry->tralbum_url;
|
|
|
|
$artist = $entry->artist;
|
|
|
|
$title = $entry->title;
|
|
|
|
// e.g. record label is the releaser, but not the artist
|
|
|
|
$releaser = $entry->band_name !== $entry->artist ? $entry->band_name : null;
|
2017-02-11 16:16:56 +01:00
|
|
|
|
2019-02-24 12:08:34 +01:00
|
|
|
$full_title = $artist . ' - ' . $title;
|
|
|
|
$full_artist = $artist;
|
|
|
|
if (isset($releaser)) {
|
|
|
|
$full_title .= ' (' . $releaser . ')';
|
|
|
|
$full_artist .= ' (' . $releaser . ')';
|
|
|
|
}
|
|
|
|
$small_img = $this->getImageUrl($entry->art_id, self::IMGSIZE_300PX);
|
|
|
|
$img = $this->getImageUrl($entry->art_id, self::IMGSIZE_700PX);
|
2017-02-11 16:16:56 +01:00
|
|
|
|
2019-02-24 12:08:34 +01:00
|
|
|
$item = array(
|
|
|
|
'uri' => $url,
|
|
|
|
'author' => $full_artist,
|
|
|
|
'title' => $full_title
|
|
|
|
);
|
|
|
|
$item['content'] = "<img src='$small_img' /><br/>$full_title";
|
|
|
|
$item['enclosures'] = array($img);
|
2017-02-11 16:16:56 +01:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 12:08:34 +01:00
|
|
|
private function buildRequestJson(){
|
|
|
|
$requestJson = array(
|
|
|
|
'tag' => $this->getInput('tag'),
|
|
|
|
'page' => 1,
|
|
|
|
'sort' => 'date'
|
|
|
|
);
|
|
|
|
return json_encode($requestJson);
|
|
|
|
}
|
2017-02-14 22:36:33 +01:00
|
|
|
|
2019-02-24 12:08:34 +01:00
|
|
|
private function getImageUrl($id, $size){
|
|
|
|
return self::IMGURI . 'img/a' . $id . '_' . $size . '.jpg';
|
2017-02-11 16:16:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
2017-07-29 19:28:00 +02:00
|
|
|
if(!is_null($this->getInput('tag'))) {
|
2017-02-14 22:20:55 +01:00
|
|
|
return $this->getInput('tag') . ' - Bandcamp Tag';
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getName();
|
2017-02-11 16:16:56 +01:00
|
|
|
}
|
2014-02-09 15:33:02 +01:00
|
|
|
}
|