BandcampBridge.php 1.7 KB

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