Browse Source

Added a random result to the top of search result

pull/8/head
Ludy Su 7 years ago
parent
commit
5a90ac24c0
  1. 30
      netease.php

30
netease.php

@ -53,28 +53,38 @@ class LudysuNetEaseLrc {
} }
// Try to find the artists that match exactly // Try to find the artists that match exactly
$artistMatchArray = array();
foreach ($songArray as $song) { foreach ($songArray as $song) {
$elem = array(
'id' => $song['id'],
'artist' => $song['artists'][0]["name"],
'title' => $song['name'],
'alt' => $song['alias'][0] . "; Album: " . $song['album']
);
array_push($foundArray, $elem);
// Match artist
foreach ($song['artists'] as $item) { foreach ($song['artists'] as $item) {
if (strtolower($item['name']) === strtolower($artist)) { if (strtolower($item['name']) === strtolower($artist)) {
array_push($foundArray, $song['id']); $elem['artist'] = $item['name'];
array_push($artistMatchArray, $elem);
break; break;
} }
} }
} }
if (count($foundArray) == 0) { if (count($artistMatchArray) > 0) {
foreach ($songArray as $song) { $foundArray = $artistMatchArray;
array_push($foundArray, $song["id"]);
}
} }
// It's not easy for user to select the best match, so randomize the restult so that next time a new one will be returned // It's not easy for user to select the best match, so randomize the first match so that next time a new one will be returned
shuffle($foundArray); $info->addTrackInfoToList($artist, $title, "@@@" . $foundArray[rand(0, count($foundArray) - 1)]['id'], "I'm feeling lucky. Random result of the best matches.");
foreach ($foundArray as $songId) { foreach ($foundArray as $song) {
$info->addTrackInfoToList($artist, $title, $songId, ''); // add artist, title, id, lrc preview (or additional comment)
$info->addTrackInfoToList($song['artist'], $song['title'], $song['id'], $song['id'] . "; " . $song['alt']);
} }
return count($foundArray) ; return count($foundArray) + 1;
} }
/** /**

Loading…
Cancel
Save