BandcampBridge.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. class BandcampBridge extends BridgeAbstract {
  3. const MAINTAINER = 'sebsauvage';
  4. const NAME = 'Bandcamp Tag';
  5. const URI = 'https://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. if(!is_null($this->getInput('tag'))) {
  42. return self::URI . 'tag/' . urlencode($this->getInput('tag')) . '?sort_field=date';
  43. }
  44. return parent::getURI();
  45. }
  46. public function getName(){
  47. if(!is_null($this->getInput('tag'))) {
  48. return $this->getInput('tag') . ' - Bandcamp Tag';
  49. }
  50. return parent::getName();
  51. }
  52. }