From 3fadb710dab8e8ffd99f2cd6edb5ddd4074edc7a Mon Sep 17 00:00:00 2001 From: Ludy Su Date: Fri, 10 Nov 2017 00:22:21 +1300 Subject: [PATCH] Lyric translation: beta version --- netease.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/netease.php b/netease.php index 9fef0e9..9c902af 100644 --- a/netease.php +++ b/netease.php @@ -168,29 +168,39 @@ class LudysuNetEaseLrc { $resultLrc = ""; $orgLines = $this->processLrcLine($orgLrc); $transLines = $this->processLrcLine($transLrc); - var_dump($orgLines); + //var_dump($orgLines); - foreach ($orgLines as $key => $value) { + foreach ($orgLines as $elem) { + $key = $elem['tag']; // time tag + $value = $elem['lrc']; // lyric line $resultLrc .= $key . $value; // Find matching translation $trans = ""; - // $lastMatchCursor = 0; - // for ($i = $lastMatchCursor; $i < count($transLines); $i++) { - // // Check for matching time tag - // if ($key === $transLines[0]) { - // $lastMatchCursor = $i; - // $trans = $transLines[1]; - // } - // } - - if (!$this->isNullOrEmptyString($key) && $this->isNullOrEmptyString($trans)) { // $key is empty when it's not time tag, just metadata + if (!$this->isNullOrEmptyString($key)) { + $lastMatchCursor = 0; + for ($i = $lastMatchCursor; $i < count($transLines); $i++) { + $tKey = $transLines[$i]['tag']; + $tValue = $transLines[$i]['lrc']; + echo $key . " =? " . $tKey . "\n"; + // Check for matching time tag + if ($key === $tKey) { + $lastMatchCursor = $i + 1; + $trans = $tValue; + break; + } + } + } + + echo "\n"; + + if (!$this->isNullOrEmptyString($trans)) { // $key is empty when it's not time tag, just metadata $resultLrc .= " 【" . $trans . "】\n"; } $resultLrc .= "\n"; } - // var_dump($resultLrc); + //var_dump($resultLrc); } return $resultLrc; }