WhydBridge.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * WhydBridge
  4. * Returns the newest music from user
  5. *
  6. * @name Whyd Bridge
  7. * @homepage http://www.whyd.com/
  8. * @description Returns 10 newest music from user profile
  9. * @maintainer kranack
  10. * @update 2014-07-18
  11. * @use1(u="username/id")
  12. *
  13. */
  14. class WhydBridge extends BridgeAbstract{
  15. private $request;
  16. private $name;
  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 = file_get_html('http://www.whyd.com/u/'.preg_replace("/[^0-9a-f]/",'', $this->request)) or $this->returnError('No results for this query.', 404);
  24. } else { // input may be the username
  25. $html = file_get_html('http://www.whyd.com/search?q='.urlencode($this->request)) or $this->returnError('No results for this query.', 404);
  26. for ($j = 0; $j < 5; $j++) {
  27. if (strtolower($html->find('div.user', $j)->find('a',0)->plaintext) == strtolower($this->request)) {
  28. $html = file_get_html('http://www.whyd.com' . $html->find('div.user', $j)->find('a', 0)->getAttribute('href')) or $this->returnError('No results for this query', 404);
  29. break;
  30. }
  31. }
  32. }
  33. $this->name = $html->find('div#profileTop', 0)->find('h1', 0)->plaintext;
  34. }
  35. else
  36. {
  37. $this->returnError('You must specify username', 400);
  38. }
  39. for($i = 0; $i < 10; $i++) {
  40. $track = $html->find('div.post', $i);
  41. $item = new \Item();
  42. $item->name = $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 getURI(){
  54. return 'http://www.whyd.com/';
  55. }
  56. public function getCacheDuration(){
  57. return 600; // 10 minutes
  58. }
  59. }