WhydBridge.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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->update = "2014-07-18";
  11. $this->parameters[] =
  12. '[
  13. {
  14. "name" : "username/id",
  15. "identifier" : "u"
  16. }
  17. ]';
  18. }
  19. public function collectData(array $param){
  20. $html = '';
  21. if (isset($param['u']))
  22. {
  23. $this->request = $param['u'];
  24. if (strlen(preg_replace("/[^0-9a-f]/",'', $this->request)) == 24) { // is input the userid ?
  25. $html = $this->file_get_html('http://www.whyd.com/u/'.preg_replace("/[^0-9a-f]/",'', $this->request)) or $this->returnError('No results for this query.', 404);
  26. } else { // input may be the username
  27. $html = $this->file_get_html('http://www.whyd.com/search?q='.urlencode($this->request)) or $this->returnError('No results for this query.', 404);
  28. for ($j = 0; $j < 5; $j++) {
  29. if (strtolower($html->find('div.user', $j)->find('a',0)->plaintext) == strtolower($this->request)) {
  30. $html = $this->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);
  31. break;
  32. }
  33. }
  34. }
  35. $this->name = $html->find('div#profileTop', 0)->find('h1', 0)->plaintext;
  36. }
  37. else
  38. {
  39. $this->returnError('You must specify username', 400);
  40. }
  41. for($i = 0; $i < 10; $i++) {
  42. $track = $html->find('div.post', $i);
  43. $item = new \Item();
  44. $item->name = $track->find('h2', 0)->plaintext;
  45. $item->title = $track->find('h2', 0)->plaintext;
  46. $item->content = $track->find('a.thumb',0) . '<br/>' . $track->find('h2', 0)->plaintext;
  47. $item->id = 'http://www.whyd.com' . $track->find('a.no-ajaxy',0)->getAttribute('href');
  48. $item->uri = 'http://www.whyd.com' . $track->find('a.no-ajaxy',0)->getAttribute('href');
  49. $this->items[] = $item;
  50. }
  51. }
  52. public function getName(){
  53. return (!empty($this->name) ? $this->name .' - ' : '') .'Whyd Bridge';
  54. }
  55. public function getURI(){
  56. return 'http://www.whyd.com/';
  57. }
  58. public function getCacheDuration(){
  59. return 600; // 10 minutes
  60. }
  61. }