diff --git a/bridges/WhydBridge.php b/bridges/WhydBridge.php index 78bc303b..2e258733 100644 --- a/bridges/WhydBridge.php +++ b/bridges/WhydBridge.php @@ -8,7 +8,7 @@ * @description Returns 10 newest music from user profile * @maintainer kranack * @update 2014-07-18 -* @use1(u="username/id") +* @use1(u="username") * */ class WhydBridge extends BridgeAbstract{ @@ -21,16 +21,22 @@ class WhydBridge extends BridgeAbstract{ if (isset($param['u'])) { $this->request = $param['u']; - if (strlen(preg_replace("/[^0-9a-f]/",'', $this->request)) == 24) // is input the userid ? + if (strlen(preg_replace("/[^0-9a-f]/",'', $this->request)) == 24) { // is input the userid ? $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); - else // input may be the username - $html = file_get_html('http://www.whyd.com/'.urlencode($this->request)) or $this->returnError('No results for this query.', 404); - + } else { // input may be the username + $html = file_get_html('http://www.whyd.com/search?q='.urlencode($this->request)) or $this->returnError('No results for this query.', 404); + for ($j = 0; $j < 5; $j++) { + if (strtolower($html->find('div.user', $j)->find('a',0)->plaintext) == strtolower($this->request)) { + $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); + break; + } + } + } $this->name = $html->find('div#profileTop', 0)->find('h1', 0)->plaintext; } else { - $this->returnError('You must specify username or id', 400); + $this->returnError('You must specify username', 400); } for($i = 0; $i < 10; $i++) { @@ -53,6 +59,7 @@ class WhydBridge extends BridgeAbstract{ } public function getCacheDuration(){ - return 1; // 10 minutes + return 600; // 10 minutes } } +