Skip to content

Commit

Permalink
fix: 处理某些情况下没有匹配结果项的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Light authored and Light committed Jun 26, 2022
1 parent 9517e1c commit 6256203
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
28 changes: 18 additions & 10 deletions src/qqSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@

class AumQQSource {
private $mArtist = '';
private $lowArtist = '';
private $cArtist = '';
private $mTitle = '';
private $lowTitle = '';
private $cTitle = '';
public function __construct() {}

public function getLyricsList($artist, $title, $info) {
$artist = trim($artist);
$this->mArtist = $artist;
$this->lowArtist = strtolower($artist);
$this->cArtist = $this->getCleanStr($artist);

$title = trim($title);
$this->mTitle = $title;
$this->lowTitle = strtolower($title);
$this->cTitle = $this->getCleanStr($title);

$list = AumQQHandler::search($title, $artist);
$list = AumQQHandler::search($this->mTitle, $this->mArtist);
if (count($list) === 0) {
return 0;
}

$exactMatchArray = array();
$partialMatchArray = array();
foreach ($list as $item) {
$lowSong = strtolower($item['song']);
if ($this->lowTitle === $lowSong) {
$cSong = $this->getCleanStr($item['song']);
if ($this->cTitle === $cSong) {
array_push($exactMatchArray, $item);
} elseif ($this->isPartialMatch($lowSong, $this->lowTitle)) {
} elseif ($this->isPartialMatch($cSong, $this->cTitle)) {
array_push($partialMatchArray, $item);
}
}
Expand Down Expand Up @@ -89,8 +89,8 @@ private function findSongItems($songArray) {
$foundArray = array();
foreach ($songArray as $item) {
foreach ($item['singers'] as $singer) {
$lowSinger = strtolower($singer);
if ($this->isPartialMatch($this->lowArtist, $lowSinger)) {
$cSinger = $this->getCleanStr($singer);
if ($this->isPartialMatch($this->cArtist, $cSinger)) {
array_push($foundArray, $item);
break;
}
Expand All @@ -102,5 +102,13 @@ private function findSongItems($songArray) {
private function decodeHtmlSpecialChars($str) {
return htmlspecialchars_decode($str, ENT_QUOTES | ENT_HTML5);
}

private function getCleanStr($str) {
$lowStr = strtolower($str);
return str_replace(
array(" ", "", "", "", "", "", "", "", "", "", ""),
array("", ",", ":", ";", "!", "?", "", "", "(", ")", "."),
$lowStr);
}
}

4 changes: 3 additions & 1 deletion test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
array('title' => 'Reign Fall', 'artist' => 'Chamillionaire&Scarface&Killer Mike'),
array('title' => 'ひとつのハートで-《神龙斗士》TV动画第1-32集片头曲', 'artist' => '三重野瞳'),
array('title' => '빠빠빠', 'artist' => 'Crayon Pop'),
array('title' => '유후', 'artist' => 'Brave Girls')
array('title' => '유후', 'artist' => 'Brave Girls'),
array('title' => 'Mood(Explicit)', 'artist' => '24KGoldn&iann dior'),
array('title' => 'Silence(Illenium Remix)', 'artist' => 'Khalid&Illenium&marshmello')
);

foreach ($testArray as $key => $item) {
Expand Down

0 comments on commit 6256203

Please sign in to comment.