[BandcampBridge] Update to use newer POST API (#1045)
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)')
This commit is contained in:
parent
dc1b1b13cc
commit
b96c25a3af
1 changed files with 50 additions and 26 deletions
|
@ -13,48 +13,72 @@ class BandcampBridge extends BridgeAbstract {
|
||||||
'required' => true
|
'required' => true
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
const IMGURI = 'https://f4.bcbits.com/';
|
||||||
|
const IMGSIZE_300PX = 23;
|
||||||
|
const IMGSIZE_700PX = 16;
|
||||||
|
|
||||||
public function getIcon() {
|
public function getIcon() {
|
||||||
return 'https://s4.bcbits.com/img/bc_favicon.ico';
|
return 'https://s4.bcbits.com/img/bc_favicon.ico';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function collectData(){
|
public function collectData(){
|
||||||
$html = getSimpleHTMLDOM($this->getURI())
|
$url = self::URI . 'api/hub/1/dig_deeper';
|
||||||
or returnServerError('No results for this query.');
|
$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);
|
||||||
|
|
||||||
foreach($html->find('li.item') as $release) {
|
$json = json_decode($content);
|
||||||
$script = $release->find('div.art', 0)->getAttribute('onclick');
|
|
||||||
$uri = ltrim($script, "return 'url(");
|
|
||||||
$uri = rtrim($uri, "')");
|
|
||||||
|
|
||||||
$item = array();
|
if ($json->ok !== true) {
|
||||||
$item['author'] = $release->find('div.itemsubtext', 0)->plaintext
|
returnServerError('Invalid response');
|
||||||
. ' - '
|
}
|
||||||
. $release->find('div.itemtext', 0)->plaintext;
|
|
||||||
|
|
||||||
$item['title'] = $release->find('div.itemsubtext', 0)->plaintext
|
foreach ($json->items as $entry) {
|
||||||
. ' - '
|
$url = $entry->tralbum_url;
|
||||||
. $release->find('div.itemtext', 0)->plaintext;
|
$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;
|
||||||
|
|
||||||
$item['content'] = '<img src="'
|
$full_title = $artist . ' - ' . $title;
|
||||||
. $uri
|
$full_artist = $artist;
|
||||||
. '"/><br/>'
|
if (isset($releaser)) {
|
||||||
. $release->find('div.itemsubtext', 0)->plaintext
|
$full_title .= ' (' . $releaser . ')';
|
||||||
. ' - '
|
$full_artist .= ' (' . $releaser . ')';
|
||||||
. $release->find('div.itemtext', 0)->plaintext;
|
}
|
||||||
|
$small_img = $this->getImageUrl($entry->art_id, self::IMGSIZE_300PX);
|
||||||
|
$img = $this->getImageUrl($entry->art_id, self::IMGSIZE_700PX);
|
||||||
|
|
||||||
$item['id'] = $release->find('a', 0)->getAttribute('href');
|
$item = array(
|
||||||
$item['uri'] = $release->find('a', 0)->getAttribute('href');
|
'uri' => $url,
|
||||||
|
'author' => $full_artist,
|
||||||
|
'title' => $full_title
|
||||||
|
);
|
||||||
|
$item['content'] = "<img src='$small_img' /><br/>$full_title";
|
||||||
|
$item['enclosures'] = array($img);
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getURI(){
|
private function buildRequestJson(){
|
||||||
if(!is_null($this->getInput('tag'))) {
|
$requestJson = array(
|
||||||
return self::URI . 'tag/' . urlencode($this->getInput('tag')) . '?sort_field=date';
|
'tag' => $this->getInput('tag'),
|
||||||
}
|
'page' => 1,
|
||||||
|
'sort' => 'date'
|
||||||
|
);
|
||||||
|
return json_encode($requestJson);
|
||||||
|
}
|
||||||
|
|
||||||
return parent::getURI();
|
private function getImageUrl($id, $size){
|
||||||
|
return self::IMGURI . 'img/a' . $id . '_' . $size . '.jpg';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName(){
|
public function getName(){
|
||||||
|
|
Loading…
Reference in a new issue