Skip to content

Commit

Permalink
update searching
Browse files Browse the repository at this point in the history
  • Loading branch information
itisbean committed Mar 1, 2021
1 parent 98e4b55 commit 77958f3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,26 @@ $api->getBestSeller();
*/
$api->getYoRank();
```

### Search Lyrics

```php
/**
* 搜索歌詞
* @param string $text
* @return array
*/
$api->searchLyrics('跑车开走');
```


### Search Songs

```php
/**
* 搜索歌曲
* @param string $name
* @return array
*/
$api->searchSong('东京人寿');
```
51 changes: 36 additions & 15 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,15 @@ public function __construct()
*/
public function searchSinger($name)
{
$data = $this->_keywordSearch($name);
$data = $this->keywordSearch($name);
if ($data === false) {
return $this->_error();
}
if (empty($data['zhida']['zhida_singer'])) {
return $this->_success();
}
$singer = $data['zhida']['zhida_singer'];
return $this->_success([
'singerID' => $singer['singerID'],
'singerMID' => $singer['singerMID'],
'singerName' => $singer['singerName'],
'singerName_hilight' => $singer['singername_hilight'],
'singerPic' => $singer['singerPic'],
'songNum' => $singer['songNum'],
'albumNum' => $singer['albumNum'],
'mvNum' => $singer['mvNum']
]);
return $this->_success($singer);
}


Expand Down Expand Up @@ -86,7 +77,7 @@ private function _keywordSearchBak($keyword)
* @param string $keyword
* @return array|bool
*/
private function _keywordSearch($keyword, $type = '')
private function keywordSearch($keyword, $type = '')
{
$url = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp';
$param = [
Expand All @@ -99,8 +90,20 @@ private function _keywordSearch($keyword, $type = '')
'platform' => 'yqq.json',
'needNewCode' => 0,
];
if ($type && $type == 'lyric') {
$param['t'] = 7;
switch ($type) {
case 'lyric':
$param['t'] = 7;
break;
case 'album':
$param['t'] = 8;
break;
case 'song':
$param['t'] = 0;
break;
case 'mv':
$param['t'] = 12;
default:
break;
}
return $this->_get('url', $url, $param);
}
Expand Down Expand Up @@ -613,7 +616,7 @@ public function getBullet()
*/
public function searchLyrics($text)
{
$data = $this->_keywordSearch($text, 'lyric');
$data = $this->keywordSearch($text, 'lyric');
if ($data === false) {
return $this->_error();
}
Expand All @@ -623,4 +626,22 @@ public function searchLyrics($text)
$data = $data['lyric']['list'];
return $this->_success($data);
}

/**
* 搜索歌曲
* @param string $name
* @return array
*/
public function searchSong($name)
{
$data = $this->keywordSearch($name, 'song');
if ($data === false) {
return $this->_error();
}
if (empty($data['song']['list'])) {
return $this->_success();
}
$data = $data['song']['list'];
return $this->_success($data);
}
}

0 comments on commit 77958f3

Please sign in to comment.