Skip to content

Commit

Permalink
Don't convert japenese kanzi
Browse files Browse the repository at this point in the history
Signed-off-by: baolong24 <1667375308@qq.com>
  • Loading branch information
KaguraRinko committed Jan 4, 2022
1 parent 7e1e642 commit 9a12d20
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
14 changes: 13 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.md'
exclude 'META-INF/LICENSE-notice.md'
}
}

dependencies {
Expand All @@ -39,7 +49,9 @@ dependencies {
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation group: 'com.github.houbb', name: 'opencc4j', version: '1.7.1'
implementation group: 'io.github.kju2.languagedetector', name: 'language-detector', version: '1.0.5'

}
repositories {
mavenCentral()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.baolong24.statuslyricext.misc;

import java.util.HashSet;
import java.util.Set;

public class checkStringLang {

public static boolean isJapenese(String text) {
Set<Character.UnicodeBlock> japaneseUnicodeBlocks = new HashSet<Character.UnicodeBlock>() {{
add(Character.UnicodeBlock.HIRAGANA);
add(Character.UnicodeBlock.KATAKANA);
add(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS);
}};

for (char c : text.toCharArray()) {
if (japaneseUnicodeBlocks.contains(Character.UnicodeBlock.of(c))) {
return true;
} else
return false;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.net.URLEncoder;
import java.util.regex.Pattern;

import io.baolong24.statuslyricext.misc.checkStringLang;

public class LyricSearchUtil {

private static final Pattern LyricContentPattern = Pattern.compile("(\\[\\d\\d:\\d\\d\\.\\d{0,3}]|\\[\\d\\d:\\d\\d])[^\\r\\n]");
Expand All @@ -23,13 +25,16 @@ public static String getSearchKey(MediaMetadata metadata) {
String ret;

if (ZhConverterUtil.isTraditional(title)) {
title = ZhConverterUtil.toSimple(title);
if (!(checkStringLang.isJapenese(title)))
title = ZhConverterUtil.toSimple(title);
}
if (ZhConverterUtil.isTraditional(artist)) {
artist = ZhConverterUtil.toSimple(artist);
if (!(checkStringLang.isJapenese(artist)))
artist = ZhConverterUtil.toSimple(artist);
}
if (ZhConverterUtil.isTraditional(album)) {
album = ZhConverterUtil.toSimple(album);
if (!(checkStringLang.isJapenese(album)))
album = ZhConverterUtil.toSimple(album);
}

if (!TextUtils.isEmpty(artist)) {
Expand Down Expand Up @@ -66,13 +71,16 @@ public static long getMetadataDistance(MediaMetadata metadata, String title, Str
String realAlbum = metadata.getString(MediaMetadata.METADATA_KEY_ALBUM);

if (ZhConverterUtil.isTraditional(realTitle)) {
realTitle = ZhConverterUtil.toSimple(realTitle);
if (!(checkStringLang.isJapenese(realTitle)))
realTitle = ZhConverterUtil.toSimple(realTitle);
}
if (ZhConverterUtil.isTraditional(realArtist)) {
realArtist = ZhConverterUtil.toSimple(realArtist);
if (!(checkStringLang.isJapenese(realArtist)))
realArtist = ZhConverterUtil.toSimple(realArtist);
}
if (ZhConverterUtil.isTraditional(realAlbum)) {
realAlbum = ZhConverterUtil.toSimple(realAlbum);
if (!(checkStringLang.isJapenese(realAlbum)))
realAlbum = ZhConverterUtil.toSimple(realAlbum);
}

if (!realTitle.contains(title) && !title.contains(realTitle) || TextUtils.isEmpty(title)) {
Expand Down

0 comments on commit 9a12d20

Please sign in to comment.