mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-26 11:26:31 +03:00
b96c25a3af
Bandcamp tags pages have a new layout and now use a POST API endpoint to view each page of releases. Output of this bridge should be almost the same as before, with a few small improvements: - Small album image in 'content', larger album image in 'enclosures' - RSS item titles/authors are appended with the releaser in parentheses if the artist name and the releaser are different (i.e. Record Label's Bandcamp releases an album called Bar by the band named Foo, it would get the title 'Foo - Bar (Record Label)' and the author 'Foo (Record Label)')
91 lines
2.3 KiB
PHP
91 lines
2.3 KiB
PHP
<?php
|
|
class BandcampBridge extends BridgeAbstract {
|
|
|
|
const MAINTAINER = 'sebsauvage';
|
|
const NAME = 'Bandcamp Tag';
|
|
const URI = 'https://bandcamp.com/';
|
|
const CACHE_TIMEOUT = 600; // 10min
|
|
const DESCRIPTION = 'New bandcamp release by tag';
|
|
const PARAMETERS = array( array(
|
|
'tag' => array(
|
|
'name' => 'tag',
|
|
'type' => 'text',
|
|
'required' => true
|
|
)
|
|
));
|
|
const IMGURI = 'https://f4.bcbits.com/';
|
|
const IMGSIZE_300PX = 23;
|
|
const IMGSIZE_700PX = 16;
|
|
|
|
public function getIcon() {
|
|
return 'https://s4.bcbits.com/img/bc_favicon.ico';
|
|
}
|
|
|
|
public function collectData(){
|
|
$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);
|
|
|
|
$json = json_decode($content);
|
|
|
|
if ($json->ok !== true) {
|
|
returnServerError('Invalid response');
|
|
}
|
|
|
|
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;
|
|
|
|
$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);
|
|
|
|
$item = array(
|
|
'uri' => $url,
|
|
'author' => $full_artist,
|
|
'title' => $full_title
|
|
);
|
|
$item['content'] = "<img src='$small_img' /><br/>$full_title";
|
|
$item['enclosures'] = array($img);
|
|
$this->items[] = $item;
|
|
}
|
|
}
|
|
|
|
private function buildRequestJson(){
|
|
$requestJson = array(
|
|
'tag' => $this->getInput('tag'),
|
|
'page' => 1,
|
|
'sort' => 'date'
|
|
);
|
|
return json_encode($requestJson);
|
|
}
|
|
|
|
private function getImageUrl($id, $size){
|
|
return self::IMGURI . 'img/a' . $id . '_' . $size . '.jpg';
|
|
}
|
|
|
|
public function getName(){
|
|
if(!is_null($this->getInput('tag'))) {
|
|
return $this->getInput('tag') . ' - Bandcamp Tag';
|
|
}
|
|
|
|
return parent::getName();
|
|
}
|
|
}
|