修复对存在错误时间标签的歌词的解析

This commit is contained in:
lyswhut 2023-04-22 21:17:18 +08:00
parent 2fcb560e91
commit ffe8891202
4 changed files with 53 additions and 45 deletions

View File

@ -1,7 +1,5 @@
package cn.toside.music.mobile.lyric;
import com.facebook.react.bridge.Promise;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -15,9 +13,7 @@ import java.util.regex.Pattern;
public class LyricPlayer {
final String timeFieldExp = "^(?:\\[[\\d:.]+])+";
final String timeExp = "[\\d:.]+";
final String timeLabelRxp = "^(\\[[\\d:]+\\.)0+(\\d+])";
final String timeLabelFixRxp = "(?:\\.0+|0+)$";
final String timeExp = "\\d{1,3}(:\\d{1,3}){0,2}(?:\\.\\d{1,3})";
// HashMap tagRegMap;
Pattern timeFieldPattern;
Pattern timePattern;
@ -117,6 +113,16 @@ public class LyricPlayer {
}
}
final String t_rxp_1 = "^0+(\\d+)";
final String t_rxp_2 = ":0+(\\d+)";
final String t_rxp_3 = "\\.0+(\\d+)";
private String formatTimeLabel(String label) {
return label.replaceAll(t_rxp_1, "$1")
.replaceAll(t_rxp_2, ":$1")
.replaceAll(t_rxp_3, ".$1");
}
private void parseExtendedLyric(HashMap linesMap, String extendedLyric) {
String[] extendedLyricLines = extendedLyric.split("\r\n|\n|\r");
for (String translationLine : extendedLyricLines) {
@ -129,9 +135,7 @@ public class LyricPlayer {
Matcher timeMatchResult = timePattern.matcher(timeField);
while (timeMatchResult.find()) {
String timeStr = timeMatchResult.group();
if (timeStr.contains(".")) timeStr = timeStr.replaceAll(timeLabelRxp, "$1$2");
else timeStr += ".0";
timeStr = timeStr.replaceAll(timeLabelFixRxp, "");
timeStr = formatTimeLabel(timeStr);
HashMap targetLine = (HashMap) linesMap.get(timeStr);
if (targetLine != null) ((ArrayList<String>) targetLine.get("extendedLyrics")).add(text);
}
@ -156,10 +160,7 @@ public class LyricPlayer {
if (text.length() > 0) {
Matcher timeMatchResult = timePattern.matcher(timeField);
while (timeMatchResult.find()) {
String timeStr = timeMatchResult.group();
if (timeStr.contains(".")) timeStr = timeStr.replaceAll(timeLabelRxp, "$1$2");
else timeStr += ".0";
timeStr = timeStr.replaceAll(timeLabelFixRxp, "");
String timeStr = formatTimeLabel(timeMatchResult.group());
if (linesMap.containsKey(timeStr)) {
((ArrayList<String>) ((HashMap) linesMap.get(timeStr)).get("extendedLyrics")).add(text);
continue;
@ -180,13 +181,18 @@ public class LyricPlayer {
minutes = timeArr[0];
seconds = timeArr[1];
break;
case 1:
hours = "0";
minutes = "0";
seconds = timeArr[0];
break;
default:
continue;
}
if (seconds.contains(".")) {
timeArr = seconds.split("\\.");
seconds = timeArr[0];
milliseconds = timeArr[1];
if (timeArr.length > 1) milliseconds = timeArr[1];
}
HashMap<String, Object> lineInfo = new HashMap<>();
int time = Integer.parseInt(hours) * 60 * 60 * 1000

56
package-lock.json generated
View File

@ -15,10 +15,10 @@
"@react-native-community/checkbox": "^0.5.15",
"@react-native-community/slider": "^4.4.2",
"iconv-lite": "^0.6.3",
"lrc-file-parser": "^2.3.1",
"lrc-file-parser": "^2.3.2",
"pako": "^2.1.0",
"react": "18.2.0",
"react-native": "0.71.5",
"react-native": "0.71.7",
"react-native-background-timer": "github:lyswhut/react-native-background-timer#88b1d05b2dcdc5af72bf365bf7ff00eec114d428",
"react-native-exception-handler": "^2.10.10",
"react-native-fs": "^2.20.0",
@ -34,8 +34,8 @@
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@babel/preset-env": "^7.21.4",
"@babel/runtime": "^7.21.0",
"@tsconfig/react-native": "^2.0.3",
"@types/react": "^18.0.31",
"@tsconfig/react-native": "^3.0.0",
"@types/react": "^18.0.38",
"@types/react-native": "^0.70.13",
"@types/react-native-background-timer": "^2.0.0",
"@types/react-native-vector-icons": "^6.4.13",
@ -3231,9 +3231,9 @@
}
},
"node_modules/@tsconfig/react-native": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@tsconfig/react-native/-/react-native-2.0.3.tgz",
"integrity": "sha512-jE58snEKBd9DXfyR4+ssZmYJ/W2mOSnNrvljR0aLyQJL9JKX6vlWELHkRjb3HBbcM9Uy0hZGijXbqEAjOERW2A==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@tsconfig/react-native/-/react-native-3.0.0.tgz",
"integrity": "sha512-4NapbL5hywv83w0K7psaQnD15f7vOwrUkKZUxKYExqmkSPOg56+LkVbpCBuHYHJFoX3wyuau/tFxo1XFYogeUw==",
"dev": true
},
"node_modules/@types/istanbul-lib-coverage": {
@ -3283,9 +3283,9 @@
"dev": true
},
"node_modules/@types/react": {
"version": "18.0.33",
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.33.tgz",
"integrity": "sha512-sHxzVxeanvQyQ1lr8NSHaj0kDzcNiGpILEVt69g9S31/7PfMvNCKLKcsHw4lYKjs3cGNJjXSP4mYzX43QlnjNA==",
"version": "18.0.38",
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.38.tgz",
"integrity": "sha512-ExsidLLSzYj4cvaQjGnQCk4HFfVT9+EZ9XZsQ8Hsrcn8QNgXtpZ3m9vSIC2MWtx7jHictK6wYhQgGh6ic58oOw==",
"dev": true,
"dependencies": {
"@types/prop-types": "*",
@ -8386,9 +8386,9 @@
}
},
"node_modules/lrc-file-parser": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/lrc-file-parser/-/lrc-file-parser-2.3.1.tgz",
"integrity": "sha512-e3ErKypTV21pMsL5Rg4YwwX/+HGN4xVPebHwvzWYQgQI+FUTxqW/ByhjtVxhOnxSsoHWFWGRWT6Tje8ODE+i/Q=="
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/lrc-file-parser/-/lrc-file-parser-2.3.2.tgz",
"integrity": "sha512-iInpWhRdfMBsnre6R3i3IayjgGE0koqncQxEB4X+QMgY7bkp9Kh2z1jqLQKg6LQmHUAte4v3LgFLG3Wz6UCyvw=="
},
"node_modules/lru-cache": {
"version": "5.1.1",
@ -10161,9 +10161,9 @@
"integrity": "sha512-txfpPCQYiazVdcbMRhatqWKcAxJweUu2wDXvts5/7Wyp6+Y9cHojqXHsLPEckzutfHlxZhG8Oiundbmp8Fd6eQ=="
},
"node_modules/react-native": {
"version": "0.71.5",
"resolved": "https://registry.npmjs.org/react-native/-/react-native-0.71.5.tgz",
"integrity": "sha512-fMptnHXoIPotg7gPYAvjMRnfC6gUSkTJzgaIDQJTY/f5F+g6qph5J1xT9LCuWuNguyQ9dh8b0MZTK5ROvTTV9w==",
"version": "0.71.7",
"resolved": "https://registry.npmjs.org/react-native/-/react-native-0.71.7.tgz",
"integrity": "sha512-Id6iRLS581fJMFGbBl1jP5uSmjExtGOvw5Gvh7694zISXjsRAsFMmU+izs0pyCLqDBoHK7y4BT7WGPGw693nYw==",
"dependencies": {
"@jest/create-cache-key-function": "^29.2.1",
"@react-native-community/cli": "10.2.2",
@ -14585,9 +14585,9 @@
}
},
"@tsconfig/react-native": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@tsconfig/react-native/-/react-native-2.0.3.tgz",
"integrity": "sha512-jE58snEKBd9DXfyR4+ssZmYJ/W2mOSnNrvljR0aLyQJL9JKX6vlWELHkRjb3HBbcM9Uy0hZGijXbqEAjOERW2A==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@tsconfig/react-native/-/react-native-3.0.0.tgz",
"integrity": "sha512-4NapbL5hywv83w0K7psaQnD15f7vOwrUkKZUxKYExqmkSPOg56+LkVbpCBuHYHJFoX3wyuau/tFxo1XFYogeUw==",
"dev": true
},
"@types/istanbul-lib-coverage": {
@ -14637,9 +14637,9 @@
"dev": true
},
"@types/react": {
"version": "18.0.33",
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.33.tgz",
"integrity": "sha512-sHxzVxeanvQyQ1lr8NSHaj0kDzcNiGpILEVt69g9S31/7PfMvNCKLKcsHw4lYKjs3cGNJjXSP4mYzX43QlnjNA==",
"version": "18.0.38",
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.38.tgz",
"integrity": "sha512-ExsidLLSzYj4cvaQjGnQCk4HFfVT9+EZ9XZsQ8Hsrcn8QNgXtpZ3m9vSIC2MWtx7jHictK6wYhQgGh6ic58oOw==",
"dev": true,
"requires": {
"@types/prop-types": "*",
@ -18435,9 +18435,9 @@
}
},
"lrc-file-parser": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/lrc-file-parser/-/lrc-file-parser-2.3.1.tgz",
"integrity": "sha512-e3ErKypTV21pMsL5Rg4YwwX/+HGN4xVPebHwvzWYQgQI+FUTxqW/ByhjtVxhOnxSsoHWFWGRWT6Tje8ODE+i/Q=="
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/lrc-file-parser/-/lrc-file-parser-2.3.2.tgz",
"integrity": "sha512-iInpWhRdfMBsnre6R3i3IayjgGE0koqncQxEB4X+QMgY7bkp9Kh2z1jqLQKg6LQmHUAte4v3LgFLG3Wz6UCyvw=="
},
"lru-cache": {
"version": "5.1.1",
@ -19793,9 +19793,9 @@
"integrity": "sha512-txfpPCQYiazVdcbMRhatqWKcAxJweUu2wDXvts5/7Wyp6+Y9cHojqXHsLPEckzutfHlxZhG8Oiundbmp8Fd6eQ=="
},
"react-native": {
"version": "0.71.5",
"resolved": "https://registry.npmjs.org/react-native/-/react-native-0.71.5.tgz",
"integrity": "sha512-fMptnHXoIPotg7gPYAvjMRnfC6gUSkTJzgaIDQJTY/f5F+g6qph5J1xT9LCuWuNguyQ9dh8b0MZTK5ROvTTV9w==",
"version": "0.71.7",
"resolved": "https://registry.npmjs.org/react-native/-/react-native-0.71.7.tgz",
"integrity": "sha512-Id6iRLS581fJMFGbBl1jP5uSmjExtGOvw5Gvh7694zISXjsRAsFMmU+izs0pyCLqDBoHK7y4BT7WGPGw693nYw==",
"requires": {
"@jest/create-cache-key-function": "^29.2.1",
"@react-native-community/cli": "10.2.2",

View File

@ -48,10 +48,10 @@
"@react-native-community/checkbox": "^0.5.15",
"@react-native-community/slider": "^4.4.2",
"iconv-lite": "^0.6.3",
"lrc-file-parser": "^2.3.1",
"lrc-file-parser": "^2.3.2",
"pako": "^2.1.0",
"react": "18.2.0",
"react-native": "0.71.5",
"react-native": "0.71.7",
"react-native-background-timer": "github:lyswhut/react-native-background-timer#88b1d05b2dcdc5af72bf365bf7ff00eec114d428",
"react-native-exception-handler": "^2.10.10",
"react-native-fs": "^2.20.0",
@ -67,8 +67,8 @@
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@babel/preset-env": "^7.21.4",
"@babel/runtime": "^7.21.0",
"@tsconfig/react-native": "^2.0.3",
"@types/react": "^18.0.31",
"@tsconfig/react-native": "^3.0.0",
"@types/react": "^18.0.38",
"@types/react-native": "^0.70.13",
"@types/react-native-background-timer": "^2.0.0",
"@types/react-native-vector-icons": "^6.4.13",

View File

@ -9,7 +9,9 @@
- 修复mg搜索不显示时长的问题@Folltoshe
- 修复mg评论加载失败的问题@Folltoshe
- 修复在Android 5.1下报错的问题
- 修复对存在错误时间标签的歌词的解析
### 其他
- 更新kg、tx、wy等平台排行榜列表
- 更新react native到v0.71.7