1
0

BandcampBridge.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class BandcampBridge extends BridgeAbstract{
  3. const MAINTAINER = "sebsauvage";
  4. const NAME = "Bandcamp Tag";
  5. const URI = "http://bandcamp.com/";
  6. const CACHE_TIMEOUT = 600; // 10min
  7. const DESCRIPTION = "New bandcamp release by tag";
  8. const PARAMETERS = array( array(
  9. 'tag'=>array(
  10. 'name'=>'tag',
  11. 'type'=>'text',
  12. 'required'=>true
  13. )
  14. ));
  15. public function collectData(){
  16. $html = getSimpleHTMLDOM($this->getURI())
  17. or returnServerError('No results for this query.');
  18. foreach($html->find('li.item') as $release) {
  19. $script = $release->find('div.art', 0)->getAttribute('onclick');
  20. $uri = ltrim($script, "return 'url(");
  21. $uri = rtrim($uri, "')");
  22. $item = array();
  23. $item['author'] = $release->find('div.itemsubtext',0)->plaintext . ' - ' . $release->find('div.itemtext',0)->plaintext;
  24. $item['title'] = $release->find('div.itemsubtext',0)->plaintext . ' - ' . $release->find('div.itemtext',0)->plaintext;
  25. $item['content'] = '<img src="' . $uri . '"/><br/>' . $release->find('div.itemsubtext',0)->plaintext . ' - ' . $release->find('div.itemtext',0)->plaintext;
  26. $item['id'] = $release->find('a',0)->getAttribute('href');
  27. $item['uri'] = $release->find('a',0)->getAttribute('href');
  28. $this->items[] = $item;
  29. }
  30. }
  31. public function getURI(){
  32. return self::URI.'tag/'.urlencode($this->getInput('tag')).'?sort_field=date';
  33. }
  34. public function getName(){
  35. return $this->getInput('tag') .' - '.'Bandcamp Tag';
  36. }
  37. }