BandcampBridge.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. class BandcampBridge extends BridgeAbstract{
  3. private $request;
  4. public function loadMetadatas() {
  5. $this->maintainer = "sebsauvage";
  6. $this->name = "Bandcamp Tag";
  7. $this->uri = "http://bandcamp.com/";
  8. $this->description = "New bandcamp release by tag";
  9. $this->update = "2014-05-25";
  10. $this->parameters[] =
  11. '[
  12. {
  13. "name" : "tag",
  14. "type" : "text",
  15. "identifier" : "tag"
  16. }
  17. ]';
  18. }
  19. public function collectData(array $param){
  20. $html = '';
  21. if (isset($param['tag'])) {
  22. $this->request = $param['tag'];
  23. $html = $this->file_get_html('http://bandcamp.com/tag/'.urlencode($this->request).'?sort_field=date') or $this->returnError('No results for this query.', 404);
  24. }
  25. else {
  26. $this->returnError('You must specify tag (/tag/...)', 400);
  27. }
  28. foreach($html->find('li.item') as $release) {
  29. $script = $release->find('div.art', 0)->getAttribute('onclick');
  30. $uri = ltrim($script, "return 'url(");
  31. $uri = rtrim($uri, "')");
  32. $item = new \Item();
  33. $item->name = $release->find('div.itemsubtext',0)->plaintext . ' - ' . $release->find('div.itemtext',0)->plaintext;
  34. $item->title = $release->find('div.itemsubtext',0)->plaintext . ' - ' . $release->find('div.itemtext',0)->plaintext;
  35. $item->content = '<img src="' . $uri . '"/><br/>' . $release->find('div.itemsubtext',0)->plaintext . ' - ' . $release->find('div.itemtext',0)->plaintext;
  36. $item->id = $release->find('a',0)->getAttribute('href');
  37. $item->uri = $release->find('a',0)->getAttribute('href');
  38. $this->items[] = $item;
  39. }
  40. }
  41. public function getName(){
  42. return (!empty($this->request) ? $this->request .' - ' : '') .'Bandcamp Tag';
  43. }
  44. public function getURI(){
  45. return 'http://bandcamp.com';
  46. }
  47. public function getCacheDuration(){
  48. return 600; // 10 minutes
  49. }
  50. }