2014-02-09 18:33:02 +04:00
|
|
|
<?php
|
2017-02-11 18:16:56 +03:00
|
|
|
class BandcampBridge extends BridgeAbstract {
|
|
|
|
|
|
|
|
const MAINTAINER = 'sebsauvage';
|
|
|
|
const NAME = 'Bandcamp Tag';
|
2017-03-18 22:02:18 +03:00
|
|
|
const URI = 'https://bandcamp.com/';
|
2017-02-11 18:16:56 +03: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 14:08:34 +03:00
|
|
|
const IMGURI = 'https://f4.bcbits.com/';
|
|
|
|
const IMGSIZE_300PX = 23;
|
|
|
|
const IMGSIZE_700PX = 16;
|
2017-02-11 18:16:56 +03:00
|
|
|
|
2018-10-26 19:07:34 +03:00
|
|
|
public function getIcon() {
|
|
|
|
return 'https://s4.bcbits.com/img/bc_favicon.ico';
|
|
|
|
}
|
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
public function collectData(){
|
2019-02-24 14:08:34 +03: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 18:16:56 +03:00
|
|
|
|
2019-02-24 14:08:34 +03:00
|
|
|
$json = json_decode($content);
|
2017-02-11 18:16:56 +03:00
|
|
|
|
2019-02-24 14:08:34 +03:00
|
|
|
if ($json->ok !== true) {
|
|
|
|
returnServerError('Invalid response');
|
|
|
|
}
|
2017-02-11 18:16:56 +03:00
|
|
|
|
2019-02-24 14:08:34 +03: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 18:16:56 +03:00
|
|
|
|
2019-02-24 14:08:34 +03: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 18:16:56 +03:00
|
|
|
|
2019-02-24 14:08:34 +03: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 18:16:56 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 14:08:34 +03:00
|
|
|
private function buildRequestJson(){
|
|
|
|
$requestJson = array(
|
|
|
|
'tag' => $this->getInput('tag'),
|
|
|
|
'page' => 1,
|
|
|
|
'sort' => 'date'
|
|
|
|
);
|
|
|
|
return json_encode($requestJson);
|
|
|
|
}
|
2017-02-15 00:36:33 +03:00
|
|
|
|
2019-02-24 14:08:34 +03:00
|
|
|
private function getImageUrl($id, $size){
|
|
|
|
return self::IMGURI . 'img/a' . $id . '_' . $size . '.jpg';
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
2017-07-29 20:28:00 +03:00
|
|
|
if(!is_null($this->getInput('tag'))) {
|
2017-02-15 00:20:55 +03:00
|
|
|
return $this->getInput('tag') . ' - Bandcamp Tag';
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getName();
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
2014-02-09 18:33:02 +04:00
|
|
|
}
|