1
0

BandcampBridge.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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
  24. . ' - '
  25. . $release->find('div.itemtext', 0)->plaintext;
  26. $item['title'] = $release->find('div.itemsubtext', 0)->plaintext
  27. . ' - '
  28. . $release->find('div.itemtext', 0)->plaintext;
  29. $item['content'] = '<img src="'
  30. . $uri
  31. . '"/><br/>'
  32. . $release->find('div.itemsubtext', 0)->plaintext
  33. . ' - '
  34. . $release->find('div.itemtext', 0)->plaintext;
  35. $item['id'] = $release->find('a', 0)->getAttribute('href');
  36. $item['uri'] = $release->find('a', 0)->getAttribute('href');
  37. $this->items[] = $item;
  38. }
  39. }
  40. public function getURI(){
  41. return self::URI . 'tag/' . urlencode($this->getInput('tag')) . '?sort_field=date';
  42. }
  43. public function getName(){
  44. return $this->getInput('tag') . ' - Bandcamp Tag';
  45. }
  46. }