WhydBridge.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. class WhydBridge extends BridgeAbstract{
  3. private $request;
  4. public $name;
  5. public function loadMetadatas() {
  6. $this->maintainer = "kranack";
  7. $this->name = "Whyd Bridge";
  8. $this->uri = "http://www.whyd.com/";
  9. $this->description = "Returns 10 newest music from user profile";
  10. $this->parameters[] = array(
  11. 'u'=>array(
  12. 'name'=>'username/id',
  13. 'required'=>true
  14. )
  15. );
  16. }
  17. public function collectData(array $param){
  18. $html = '';
  19. if (isset($param['u']))
  20. {
  21. $this->request = $param['u'];
  22. if (strlen(preg_replace("/[^0-9a-f]/",'', $this->request)) == 24) { // is input the userid ?
  23. $html = $this->getSimpleHTMLDOM('http://www.whyd.com/u/'.preg_replace("/[^0-9a-f]/",'', $this->request)) or $this->returnServerError('No results for this query.');
  24. } else { // input may be the username
  25. $html = $this->getSimpleHTMLDOM('http://www.whyd.com/search?q='.urlencode($this->request)) or $this->returnServerError('No results for this query.');
  26. for ($j = 0; $j < 5; $j++) {
  27. if (strtolower($html->find('div.user', $j)->find('a',0)->plaintext) == strtolower($this->request)) {
  28. $html = $this->getSimpleHTMLDOM('http://www.whyd.com' . $html->find('div.user', $j)->find('a', 0)->getAttribute('href')) or $this->returnServerError('No results for this query');
  29. break;
  30. }
  31. }
  32. }
  33. $this->name = $html->find('div#profileTop', 0)->find('h1', 0)->plaintext;
  34. }
  35. else
  36. {
  37. $this->returnClientError('You must specify username');
  38. }
  39. for($i = 0; $i < 10; $i++) {
  40. $track = $html->find('div.post', $i);
  41. $item = array();
  42. $item['author'] = $track->find('h2', 0)->plaintext;
  43. $item['title'] = $track->find('h2', 0)->plaintext;
  44. $item['content'] = $track->find('a.thumb',0) . '<br/>' . $track->find('h2', 0)->plaintext;
  45. $item['id'] = 'http://www.whyd.com' . $track->find('a.no-ajaxy',0)->getAttribute('href');
  46. $item['uri'] = 'http://www.whyd.com' . $track->find('a.no-ajaxy',0)->getAttribute('href');
  47. $this->items[] = $item;
  48. }
  49. }
  50. public function getName(){
  51. return (!empty($this->name) ? $this->name .' - ' : '') .'Whyd Bridge';
  52. }
  53. public function getCacheDuration(){
  54. return 600; // 10 minutes
  55. }
  56. }