metowolf / Meting

:cake: Wow, such a powerful music API framework
MIT License
1.73k stars 488 forks source link

Pagination Problem #52

Closed fung626 closed 6 years ago

fung626 commented 6 years ago

I want to setup a pagination search function in my application. And I have finished API part by follow your instruction

$api = new Meting('netease');

$data = $api->format(true)->search('Soldier', [
    'page' => 1,
    'limit' => 50
]);

echo $data;

The data have successfully received. However, without the total I can't calculate the last page. Same as your NeteaseCloudMusicApi repo songCount data.

Also, I had reviewed Meting.php. And I found out there is a parameter call total in netease. By default set it to true, but I still can't get the total.

My question is how I get the total when run the search function? thanks in advance

metowolf commented 6 years ago

set format with false, the total is in res.data.song.totalnum

$data = $api->format(false)->search('Soldier', [
    'page' => 1,
    'limit' => 30
]);
{
   "subcode" : 0,
   "code" : 0,
   "message" : "",
   "tips" : "",
   "notice" : "",
   "data" : {
      "totaltime" : 0,
      "keyword" : "Soldier",
      "song" : {
         "curnum" : 1,
         "totalnum" : 396,
         "list" : [
            {
              ...
            }
         ],
         "curpage" : 1
      },
      "priority" : 0,
      "qc" : [],
      "tab" : 0,
      "semantic" : {
         "list" : [],
         "totalnum" : 0,
         "curnum" : 0,
         "curpage" : 1
      },
      "taglist" : []
   }
}
fung626 commented 6 years ago

How about the other sources ? Only netease return total ?

metowolf commented 6 years ago

Try yourself without format 😆

fung626 commented 6 years ago

thx for help :)